diff --git a/api/models/user.js b/api/models/user.js index 44866ca..f36a75e 100644 --- a/api/models/user.js +++ b/api/models/user.js @@ -13,9 +13,7 @@ const UserSchema = new Schema({ type: Number, get: v => Math.round(v), set: v => Math.round(v), - default: 0, - min: 0, - max: 22 + default: 0 }, squadId: { type: mongoose.Schema.Types.ObjectId, diff --git a/api/routes/squads.js b/api/routes/squads.js index 7ad10ee..63ba679 100644 --- a/api/routes/squads.js +++ b/api/routes/squads.js @@ -29,7 +29,7 @@ squads.route('/') if (req.query.q) { filter.name = {$regex: req.query.q, $options: 'i'} } - SquadModel.find(filter, {}, {sort: {sortingNumber: 'asc', fraction: 'asc'}}, (err, items) => { + SquadModel.find(filter, {}, {sort: {fraction: 'asc', sortingNumber: 'asc'}}, (err, items) => { if (err) { err.status = codes.servererror; return next(err); diff --git a/static/src/app/users/user-award/user-award.component.css b/static/src/app/users/user-award/user-award.component.css index 789b2f5..8cd0081 100644 --- a/static/src/app/users/user-award/user-award.component.css +++ b/static/src/app/users/user-award/user-award.component.css @@ -2,3 +2,22 @@ background-color: white; padding: 5px; } + +.trash { + cursor: pointer; +} + +.table { + overflow-wrap: break-word; + table-layout: fixed; +} + +.table-container { + overflow-x: auto; + width: 250%; + margin-top: 50px +} + +h3 { + margin-bottom: 20px; +} diff --git a/static/src/app/users/user-award/user-award.component.html b/static/src/app/users/user-award/user-award.component.html index 006fe4c..72cdd31 100644 --- a/static/src/app/users/user-award/user-award.component.html +++ b/static/src/app/users/user-award/user-award.component.html @@ -2,46 +2,47 @@

Teilnehmer auszeichnen

- - - - -
- -
- + - +
-
- - - - +
+
+   +
+
+ +
+
+   +
+
+   +
+
+ + + +
+ + -
-
- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - -
GrafikBezeichnungBegründungDatumLÖschen
- 1 - - 2016-04-16 12:02:12 - - Herman - Melville - - 222 - - Paid online - - - - - - - -
- - -
-
-
-
+
+ + + + + + + + + + + + + + + + + + + + +
BildBezeichnungBegründungDatum
+ + + + + {{award.decorationId.name}} + + {{award.reason}} + + {{award.date | date: 'dd.MM.yyyy'}} + + +
- diff --git a/static/src/app/users/user-award/user-award.component.ts b/static/src/app/users/user-award/user-award.component.ts index dd0fb61..8a1228e 100644 --- a/static/src/app/users/user-award/user-award.component.ts +++ b/static/src/app/users/user-award/user-award.component.ts @@ -1,12 +1,12 @@ 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 {Decoration, Squad, User} from "../../models/model-interfaces"; import {UserService} from "../../services/user-service/user.service"; -import {SquadService} from "../../services/squad-service/squad.service"; -import {RankService} from "../../services/rank-service/rank.service"; import {Subscription} from "rxjs"; import {NgForm} from "@angular/forms"; +import {AwardingService} from "../../services/awarding-service/awarding.service"; +import {DecorationService} from "../../services/decoration-service/decoration.service"; @Component({ @@ -19,68 +19,42 @@ export class UserAwardComponent { subscription: Subscription; - id: string; - - model = model; - showSuccessLabel = false; - ranksDisplay = 'none'; + user: User = {}; - user: User = {squad: {}}; + decorations: Decoration[]; - squads: Squad[] = []; - - ranks: Rank[] = []; + award: { decorationId: '', reason: '' }; saved = false; + decoPreviewDisplay = 'none'; + constructor(private router: Router, private route: ActivatedRoute, private userService: UserService, - private squadService: SquadService, - private rankService: RankService) { + private awardingService: AwardingService, + private decorationService: DecorationService) { } ngOnInit() { - // this.subscription = this.route.params - // .map(params => params['id']) - // .filter(id => id != undefined) - // .flatMap(id => this.userService.getUser(id)) - // .subscribe(user => { - // if (user.squad === null) { - // user.squad = "0"; - // this.ranksDisplay = 'none'; - // } else { - // this.rankService.findRanks('', user.squad.fraction).subscribe(ranks => { - // this.ranks = ranks; - // this.ranksDisplay = 'block'; - // }); - // } - // this.user = user; - // }); - // - // this.squadService.findSquads().subscribe(squads => { - // this.squads = squads; - // }); + this.subscription = this.route.params + .map(params => params['id']) + .filter(id => id != undefined) + .flatMap(id => this.userService.getUser(id)) + .subscribe(user => { + this.user = user; + }); + + this.decorationService.findDecorations().subscribe(decorations => { + this.decorations = decorations; + }); } ngOnDestroy() { - // this.subscription.unsubscribe(); - } - - toggleRanks() { - if (this.user.squad != '0') { - this.rankService.findRanks('', this.user.squad.fraction).subscribe( - ranks => { - this.ranks = ranks; - this.ranksDisplay = 'block'; - } - ); - } else { - this.ranksDisplay = 'none'; - } + this.subscription.unsubscribe(); } saveUser(rankLevel) { @@ -124,6 +98,63 @@ export class UserAwardComponent { } } + + toggleDecoPreview(descriptionField, decorationId, image) { + this.decoPreviewDisplay = 'flex'; // visible & keep same height for all children + + const description = this.decorations.find( + decoration => decoration._id === decorationId + ).description; + + image.src = 'resource/decoration/' + decorationId + '.png'; + descriptionField.innerHTML = description; + + } + + deleteAwarding(awardingId) { + this.awardingService.deleteAwarding(awardingId).subscribe((res) => { + this.awardingService.getUserAwardings(this.user._id) + .map((res) => res.json()) + .subscribe((awards) => { + this.user.awards = awards; + this.showSuccessLabel = true; + setTimeout(() => { + this.showSuccessLabel = false; + }, 2000) + }) + }) + } + + addAwarding(decorationField, reasonField, previewImage, descriptionField) { + const decorationId = decorationField.value; + const reason = reasonField.value; + if (decorationId && reason.length > 0) { + const award = { + "userId": this.user._id, + "decorationId": decorationId, + "reason": reason, + "date": Date.now() + }; + this.awardingService.addAwarding(award).subscribe(() => { + this.awardingService.getUserAwardings(this.user._id) + .map((res) => res.json()) + .subscribe(awards => { + this.user.awards = awards; + this.decoPreviewDisplay = 'none'; + decorationField.value = undefined; + reasonField.value = ''; + previewImage.src = ''; + descriptionField.innerHTML = ''; + this.showSuccessLabel = true; + setTimeout(() => { + this.showSuccessLabel = false; + }, 2000) + }) + }) + } + } + + canDeactivate(): boolean { if (this.saved || !this.form.dirty) { return true; diff --git a/static/src/app/users/user-list/user-item.component.html b/static/src/app/users/user-list/user-item.component.html index 2ad44e0..9a1f999 100644 --- a/static/src/app/users/user-list/user-item.component.html +++ b/static/src/app/users/user-list/user-item.component.html @@ -12,9 +12,9 @@
- - - + + +
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 b9d948b..ede8cdc 100644 --- a/static/src/app/users/user-list/user-list.component.ts +++ b/static/src/app/users/user-list/user-list.component.ts @@ -61,6 +61,13 @@ export class UserListComponent implements OnInit { this.router.navigate([{outlets: {'right': ['award', userId]}}], {relativeTo: this.route}); } + deleteUser(user: User) { + this.userService.deleteUser(user) + .subscribe((res) => { + + }) + } + filterUsersByFraction(query = '', fractionFilter) { this.users$ = this.userService.findUsers(query, fractionFilter); } 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 87f17e6..a60aba0 100644 --- a/static/src/app/users/user-overview/user-overview.component.html +++ b/static/src/app/users/user-overview/user-overview.component.html @@ -7,7 +7,8 @@ [(ngModel)]="user.username" name="title" id="title" - required maxlength="50"/> + required + maxlength="50"/> @@ -54,4 +55,11 @@ [disabled]="!form.valid"> Bestätigen + + + Erfolgreich gespeichert + + 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 2d6e921..f852a29 100644 --- a/static/src/app/users/user-overview/user-overview.component.ts +++ b/static/src/app/users/user-overview/user-overview.component.ts @@ -94,7 +94,6 @@ export class UserOverviewComponent { if (this.user.squad._id !== '0') { updateObject.squadId = this.user.squad._id } - console.log(updateObject) this.userService.updateUser(updateObject) .subscribe(user => { if (!user.squad) {