diff --git a/api/routes/users.js b/api/routes/users.js index 6e98986..3a33a0d 100644 --- a/api/routes/users.js +++ b/api/routes/users.js @@ -91,8 +91,11 @@ users.route('/') return next(err); } res.status(codes.created); - res.locals.items = user; - next(); + getExtendedUser(user, next, (extUser) => { + res.locals.items = extUser; + res.locals.processed = true; + return next(); + }) }); }) diff --git a/static/src/app/army/army.component.ts b/static/src/app/army/army.component.ts index 8c71381..e1dfa52 100644 --- a/static/src/app/army/army.component.ts +++ b/static/src/app/army/army.component.ts @@ -10,17 +10,15 @@ import {ArmyService} from "../services/army-service/army.service"; }) export class ArmyComponent { - army: Army = {NATO: {squads: [], memberCount: 0}, CSAT: {squads: [], memberCount:0}}; + army: Army = {NATO: {squads: [], memberCount: 0}, CSAT: {squads: [], memberCount: 0}}; constructor(private armyService: ArmyService) { } - ngOnInit() { this.armyService.getArmy() .subscribe(army => { this.army = army; - console.log(army) }); }; } diff --git a/static/src/app/users/new-user/new-user.component.css b/static/src/app/users/new-user/new-user.component.css deleted file mode 100644 index e69de29..0000000 diff --git a/static/src/app/users/new-user/new-user.component.html b/static/src/app/users/new-user/new-user.component.html deleted file mode 100644 index 500df9a..0000000 --- a/static/src/app/users/new-user/new-user.component.html +++ /dev/null @@ -1,27 +0,0 @@ -
-

Neuen Teilnehmer hinzufügen

- -
- - - - -
- - - - -
diff --git a/static/src/app/users/new-user/new-user.component.ts b/static/src/app/users/new-user/new-user.component.ts deleted file mode 100644 index 61beda0..0000000 --- a/static/src/app/users/new-user/new-user.component.ts +++ /dev/null @@ -1,50 +0,0 @@ -import {Component, ViewChild} from "@angular/core"; -import {ActivatedRoute, Router} from "@angular/router"; -import {NgForm} from "@angular/forms"; -import {User} from "../../models/model-interfaces"; -import {UserService} from "../../services/user-service/user.service"; - - -@Component({ - templateUrl: './new-user.component.html', - styleUrls: ['./new-user.component.css', '../../style/new-entry-form.css'] -}) -export class CreateUserComponent { - - user: User = {}; - - saved = false; - - @ViewChild(NgForm) form: NgForm; - - constructor(private route: ActivatedRoute, - private router: Router, - private userService: UserService) { - } - - ngOnInit() { - - } - - saveUser() { - this.userService.submitUser(this.user) - .subscribe(user => { - this.saved = true; - this.router.navigate(['../overview', user._id], {relativeTo: this.route}); - }) - } - - cancel() { - //this.location.back(); - this.router.navigate(['/cc-users']); - return false; - } - - canDeactivate(): boolean { - if (this.saved || !this.form.dirty) { - return true; - } - return window.confirm(`Ihr Formular besitzt ungespeicherte Änderungen, möchten Sie die Seite wirklich verlassen?`); - } - -} diff --git a/static/src/app/users/user-list/user-list.component.ts b/static/src/app/users/user-list/user-list.component.ts index 758de15..91de1c3 100644 --- a/static/src/app/users/user-list/user-list.component.ts +++ b/static/src/app/users/user-list/user-list.component.ts @@ -48,7 +48,8 @@ export class UserListComponent implements OnInit { } openNewUserForm() { - this.router.navigate([{outlets: {'right': ['new']}}], {relativeTo: this.route}); + this.selectedUserId = null; + this.router.navigate([{outlets: {'right': ['overview']}}], {relativeTo: this.route}); } selectUser(userId: string) { diff --git a/static/src/app/users/user-overview/user-overview.component.html b/static/src/app/users/user-overview/user-overview.component.html index a60aba0..5e18fee 100644 --- a/static/src/app/users/user-overview/user-overview.component.html +++ b/static/src/app/users/user-overview/user-overview.component.html @@ -1,5 +1,6 @@
-

Teilnehmer editieren

+

Teilnehmer editieren

+

Neuen Teilnehmer hinzufügen

diff --git a/static/src/app/users/user-overview/user-overview.component.ts b/static/src/app/users/user-overview/user-overview.component.ts index d18d05c..03d1130 100644 --- a/static/src/app/users/user-overview/user-overview.component.ts +++ b/static/src/app/users/user-overview/user-overview.component.ts @@ -1,6 +1,5 @@ import {Component, ViewChild} from "@angular/core"; import {ActivatedRoute, Router} from "@angular/router"; -import * as model from "../../models/model-interfaces"; import {Rank, Squad, User} from "../../models/model-interfaces"; import {UserService} from "../../services/user-service/user.service"; import {SquadService} from "../../services/squad-service/squad.service"; @@ -23,7 +22,7 @@ export class UserOverviewComponent { ranksDisplay = 'none'; - user: User = {squad: {}}; + user: User = {username: '', squad: '0', rank: {level: 0}}; squads: Squad[] = []; @@ -45,7 +44,6 @@ export class UserOverviewComponent { .filter(id => id != undefined) .flatMap(id => this.userService.getUser(id)) .subscribe(user => { - console.log(user.squad) if (!user.squad) { user.squad = "0"; this.ranksDisplay = 'none'; @@ -90,22 +88,31 @@ export class UserOverviewComponent { if (this.user.squad._id !== '0') { updateObject.squadId = this.user.squad._id } - this.userService.updateUser(updateObject) - .subscribe(user => { - if (!user.squad) { - user.squad = '0'; - } - this.user = user; - this.showSuccessLabel = true; - setTimeout(() => { - this.showSuccessLabel = false; - }, 2000) - }) + + if (this.user._id) { + this.userService.updateUser(updateObject) + .subscribe(user => { + if (!user.squad) { + user.squad = '0'; + } + this.user = user; + this.showSuccessLabel = true; + setTimeout(() => { + this.showSuccessLabel = false; + }, 2000) + }) + } else { + this.userService.submitUser(updateObject) + .subscribe(user => { + this.router.navigate(['..'], {relativeTo: this.route}); + return true; + }) + } } cancel() { - this.router.navigate(['../..'], {relativeTo: this.route}); + this.router.navigate([this.user._id ? '../..' : '..'], {relativeTo: this.route}); return false; } diff --git a/static/src/app/users/users.routing.ts b/static/src/app/users/users.routing.ts index e976a8f..3c53955 100644 --- a/static/src/app/users/users.routing.ts +++ b/static/src/app/users/users.routing.ts @@ -2,7 +2,6 @@ import {Routes} from "@angular/router"; import {UsersComponent} from "./users.component"; import {UserOverviewComponent} from "./user-overview/user-overview.component"; import {UserListComponent} from "./user-list/user-list.component"; -import {CreateUserComponent} from "./new-user/new-user.component"; import {UserAwardComponent} from "./user-award/user-award.component"; export const usersRoutes: Routes = [{ @@ -15,8 +14,8 @@ export const usersRoutes: Routes = [{ ] }, { - path: 'new', - component: CreateUserComponent, + path: 'overview', + component: UserOverviewComponent, outlet: 'right' }, { @@ -31,4 +30,4 @@ export const usersRoutes: Routes = [{ } ]; -export const usersRoutingComponents = [UsersComponent, UserListComponent, UserOverviewComponent, CreateUserComponent, UserAwardComponent]; +export const usersRoutingComponents = [UsersComponent, UserListComponent, UserOverviewComponent, UserAwardComponent];