-
-
-
-
-
- Grafik |
- Bezeichnung |
- Begründung |
- Datum |
- LÖschen |
- |
-
-
-
-
-
-
- 1
- |
-
- 2016-04-16 12:02:12
- |
-
- Herman
- Melville
- |
-
- 222
- |
-
- Paid online
- |
-
-
-
-
-
-
-
-
-
-
-
- |
-
-
-
-
-
-
+
+
+
+
+ Bild |
+ Bezeichnung |
+ Begründung |
+ Datum |
+ |
+
+
+
+
+
+
+ |
+
+
+ |
+
+ {{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 @@