diff --git a/static/src/app/decorations/decoration-list/decoration-item.component.ts b/static/src/app/decorations/decoration-list/decoration-item.component.ts
index 943373c..05bbe86 100644
--- a/static/src/app/decorations/decoration-list/decoration-item.component.ts
+++ b/static/src/app/decorations/decoration-list/decoration-item.component.ts
@@ -8,24 +8,36 @@ import {Decoration} from "../../models/model-interfaces";
styleUrls: ['./decoration-item.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
inputs: ['decoration', 'selected'],
- outputs: ['decorationSelected'],
+ outputs: ['decorationDelete','decorationSelected'],
})
export class DecorationItemComponent {
selected: boolean;
decoration: Decoration;
+ imageSrc;
+ previewMargin;
decorationSelected = new EventEmitter();
-
+ decorationDelete = new EventEmitter();
constructor(private router: Router) {
+ }
+ ngOnInit() {
+ this.imageSrc = 'resource/decoration/' + this.decoration._id + '.png?' + Date.now();
+ if (!this.decoration.isMedal) {
+ this.previewMargin = '17px'
+ }
}
select() {
this.decorationSelected.emit(this.decoration._id)
}
+ delete() {
+ this.decorationDelete.emit(this.decoration);
+ }
+
ngAfterViewChecked() {
//var taskId = (this.task ? this.task.id : '');
// console.log(`Task ${taskId} checked ${++this.checkCounter} times`)
diff --git a/static/src/app/decorations/decoration-list/decoration-list.component.html b/static/src/app/decorations/decoration-list/decoration-list.component.html
index 24cfb0a..366e2f5 100644
--- a/static/src/app/decorations/decoration-list/decoration-list.component.html
+++ b/static/src/app/decorations/decoration-list/decoration-list.component.html
@@ -42,6 +42,7 @@
diff --git a/static/src/app/decorations/decoration-list/decoration-list.component.ts b/static/src/app/decorations/decoration-list/decoration-list.component.ts
index 62619b6..fae3837 100644
--- a/static/src/app/decorations/decoration-list/decoration-list.component.ts
+++ b/static/src/app/decorations/decoration-list/decoration-list.component.ts
@@ -48,12 +48,25 @@ export class DecorationListComponent implements OnInit {
}
openNewSquadForm() {
+ this.selectedDecorationId = null;
this.router.navigate([{outlets: {'right': ['new']}}], {relativeTo: this.route});
}
selectDecoration(decorationId: string | number) {
this.selectedDecorationId = decorationId;
- this.router.navigate([{outlets: {'right': ['overview', decorationId]}}], {relativeTo: this.route});
+ this.router.navigate([{outlets: {'right': ['edit', decorationId]}}], {relativeTo: this.route});
+ }
+
+ deleteDecoration(decoration) {
+ let fraction = 'GLOBAL';
+ if (decoration.fraction === 'BLUFOR') fraction = 'NATO';
+ else if (decoration.fraction === 'OPFOR') fraction = 'CSAT';
+
+ if (confirm('Soll die Auszeichnung "' + decoration.name + '" (' + fraction + ') wirklich gelöscht werden?')) {
+ this.decorationService.deleteDecoration(decoration)
+ .subscribe((res) => {
+ })
+ }
}
filterSquadsByFraction(query = '', fractionFilter) {
diff --git a/static/src/app/decorations/decoration-overview/decoration-overview.component.css b/static/src/app/decorations/decoration-overview/decoration-overview.component.css
deleted file mode 100644
index e69de29..0000000
diff --git a/static/src/app/decorations/decoration-overview/decoration-overview.component.html b/static/src/app/decorations/decoration-overview/decoration-overview.component.html
deleted file mode 100644
index 451d361..0000000
--- a/static/src/app/decorations/decoration-overview/decoration-overview.component.html
+++ /dev/null
@@ -1,134 +0,0 @@
-
-
Auszeichnung-Details
-
- Erfolgreich gespeichert
-
-
-
-
-
-
-
-
-
-
-
-
- {{decoration.name}}
-
-
-
-
-
-
-
-
-
-
-
- CSAT
-
-
- NATO
-
-
-
-
-
-
-
-
-
- Orden
-
-
- Ribbon
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{decoration.sortingNumber}}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Bild muss im PNG Format vorliegen
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/static/src/app/decorations/decoration-overview/decoration-overview.component.ts b/static/src/app/decorations/decoration-overview/decoration-overview.component.ts
deleted file mode 100644
index a4578e2..0000000
--- a/static/src/app/decorations/decoration-overview/decoration-overview.component.ts
+++ /dev/null
@@ -1,94 +0,0 @@
-import {Component} from "@angular/core";
-import {ActivatedRoute, Router} from "@angular/router";
-import {Decoration} from "../../models/model-interfaces";
-import {DecorationService} from "../../services/decoration-service/decoration.service";
-
-@Component({
- templateUrl: './decoration-overview.component.html',
- styleUrls: ['./decoration-overview.component.css', '../../style/overview.css'],
-})
-export class DecorationOverviewComponent {
-
- id: string;
-
- showSuccessLabel = false;
-
- showImageError = false;
-
- decoration: Decoration;
-
- fileList: FileList;
-
- previewImage;
-
- constructor(private router: Router,
- private route: ActivatedRoute,
- private decorationService: DecorationService) {
- }
-
- ngOnInit() {
- this.route.params.subscribe((params) => {
- this.decorationService.getDecoration(params['id']).subscribe(decoration => {
- this.decoration = decoration;
- this.previewImage = 'resource/decoration/' + this.decoration._id + '.png?' + Date.now();
- })
- })
- }
-
- // register file change and save to fileList
- fileChange(event) {
- if (!event.target.files[0].name.endsWith('.png')) {
- this.showImageError = true;
- this.fileList = undefined;
- } else {
- this.showImageError = false;
- this.fileList = event.target.files;
- }
- }
-
- update(attrName, inputField) {
- const inputValue = inputField.value;
- if (inputValue.length > 0 && (this.decoration[attrName] !== inputValue || attrName === 'description')) {
- const updateObject = {_id: this.decoration._id};
- updateObject[attrName] = inputValue;
- this.decorationService.submitDecoration(updateObject)
- .subscribe(decoration => {
- this.decoration = decoration;
- if (attrName != 'description') {
- inputField.value = '';
- }
- this.showSuccessLabel = true;
- setTimeout(() => {
- this.showSuccessLabel = false;
- }, 2000)
- })
- }
- }
-
- updateGraphic(fileInput) {
- if (this.fileList && this.fileList.length > 0) {
- let file: File = this.fileList[0];
- this.decorationService.submitDecoration({_id: this.decoration._id}, file)
- .subscribe((res) => {
- setTimeout(() => {
- this.previewImage = 'resource/decoration/' + this.decoration._id + '.png?' + Date.now();
- }, 300);
- fileInput.value = '';
- this.showSuccessLabel = true;
- setTimeout(() => {
- this.showSuccessLabel = false;
- }, 2000)
- })
- }
- }
-
- deleteDecoration(confirm) {
- if (confirm.toLowerCase() === this.decoration.name.toLocaleLowerCase()) {
- this.decorationService.deleteDecoration(this.decoration)
- .subscribe((res) => {
- this.router.navigate(['../..'], {relativeTo: this.route});
- })
- }
- }
-
-}
diff --git a/static/src/app/decorations/decoration.routing.ts b/static/src/app/decorations/decoration.routing.ts
index 5805cbb..c96720a 100644
--- a/static/src/app/decorations/decoration.routing.ts
+++ b/static/src/app/decorations/decoration.routing.ts
@@ -2,7 +2,6 @@ import {Routes} from "@angular/router";
import {DecorationComponent} from "./decoration.component";
import {DecorationListComponent} from "./decoration-list/decoration-list.component";
import {CreateDecorationComponent} from "./new-decoration/new-decoration.component";
-import {DecorationOverviewComponent} from "./decoration-overview/decoration-overview.component";
export const decorationsRoutes: Routes = [{
path: '', component: DecorationComponent,
@@ -19,10 +18,10 @@ export const decorationsRoutes: Routes = [{
outlet: 'right'
},
{
- path: 'overview/:id',
- component: DecorationOverviewComponent,
+ path: 'edit/:id',
+ component: CreateDecorationComponent,
outlet: 'right'
}];
-export const decorationsRoutingComponents = [DecorationComponent, DecorationListComponent, DecorationOverviewComponent, CreateDecorationComponent];
+export const decorationsRoutingComponents = [DecorationComponent, DecorationListComponent, CreateDecorationComponent];
diff --git a/static/src/app/decorations/new-decoration/new-decoration.component.css b/static/src/app/decorations/new-decoration/new-decoration.component.css
index c77d09c..0523e4c 100644
--- a/static/src/app/decorations/new-decoration/new-decoration.component.css
+++ b/static/src/app/decorations/new-decoration/new-decoration.component.css
@@ -1,3 +1,7 @@
+.preview-image {
+ margin: 10px;
+}
+
.form-control {
height: auto;
}
diff --git a/static/src/app/decorations/new-decoration/new-decoration.component.html b/static/src/app/decorations/new-decoration/new-decoration.component.html
index 4faa9e1..a1b5eca 100644
--- a/static/src/app/decorations/new-decoration/new-decoration.component.html
+++ b/static/src/app/decorations/new-decoration/new-decoration.component.html
@@ -1,5 +1,6 @@
diff --git a/static/src/app/decorations/new-decoration/new-decoration.component.ts b/static/src/app/decorations/new-decoration/new-decoration.component.ts
index f1afb40..370479f 100644
--- a/static/src/app/decorations/new-decoration/new-decoration.component.ts
+++ b/static/src/app/decorations/new-decoration/new-decoration.component.ts
@@ -1,9 +1,9 @@
import {Component, ViewChild} from "@angular/core";
import {ActivatedRoute, Router} from "@angular/router";
import {NgForm} from "@angular/forms";
-import * as model from "../../models/model-interfaces";
import {Decoration} from "../../models/model-interfaces";
import {DecorationService} from "../../services/decoration-service/decoration.service";
+import {Subscription} from "rxjs/Subscription";
@Component({
templateUrl: './new-decoration.component.html',
@@ -11,6 +11,8 @@ import {DecorationService} from "../../services/decoration-service/decoration.se
})
export class CreateDecorationComponent {
+ subscription: Subscription;
+
decoration: Decoration = {name: '', fraction: '', sortingNumber: 0};
fileList: FileList;
@@ -19,6 +21,10 @@ export class CreateDecorationComponent {
showImageError = false;
+ imagePreviewSrc;
+
+ showSuccessLabel = false;
+
@ViewChild(NgForm) form: NgForm;
constructor(private route: ActivatedRoute,
@@ -27,7 +33,18 @@ export class CreateDecorationComponent {
}
ngOnInit() {
+ this.subscription = this.route.params
+ .map(params => params['id'])
+ .filter(id => id != undefined)
+ .flatMap(id => this.decorationService.getDecoration(id))
+ .subscribe(decoration => {
+ this.decoration = decoration;
+ this.imagePreviewSrc = 'resource/decoration/' + this.decoration._id + '.png?' + Date.now();
+ });
+ }
+ ngOnDestroy() {
+ this.subscription.unsubscribe();
}
fileChange(event) {
@@ -40,22 +57,40 @@ export class CreateDecorationComponent {
}
}
- saveDecoration() {
- if (this.fileList) {
- let file: File = this.fileList[0];
- this.decorationService.submitDecoration(this.decoration, file)
- .subscribe(decoration => {
- this.saved = true;
- this.router.navigate(['../overview', decoration._id], {relativeTo: this.route});
- })
+ saveDecoration(fileInput) {
+ let file: File;
+ if (!this.decoration._id) {
+ if (this.fileList) {
+ file = this.fileList[0];
+ this.decorationService.submitDecoration(this.decoration, file)
+ .subscribe(rank => {
+ this.saved = true;
+ this.router.navigate(['..'], {relativeTo: this.route});
+ })
+ } else {
+ return window.alert(`Bild ist ein Pflichtfeld`);
+ }
} else {
- return window.alert(`Bild ist ein Pflichtfeld`);
+ if (this.fileList) {
+ file = this.fileList[0];
+ }
+ delete this.decoration['__v'];
+ this.decorationService.submitDecoration(this.decoration, file)
+ .subscribe(rank => {
+ setTimeout(() => {
+ this.imagePreviewSrc = 'resource/decoration/' + this.decoration._id + '.png?' + Date.now();
+ }, 300);
+ fileInput.value = '';
+ this.showSuccessLabel = true;
+ setTimeout(() => {
+ this.showSuccessLabel = false;
+ }, 2000)
+ })
}
}
cancel() {
- //this.location.back();
- this.router.navigate(['/cc-decorations']);
+ this.router.navigate([this.decoration._id ? '../..' : '..'], {relativeTo: this.route});
return false;
}
diff --git a/static/src/app/ranks/rank-list/rank-item.component.html b/static/src/app/ranks/rank-list/rank-item.component.html
index a1c9d8a..eecc2c3 100644
--- a/static/src/app/ranks/rank-list/rank-item.component.html
+++ b/static/src/app/ranks/rank-list/rank-item.component.html
@@ -16,6 +16,5 @@