2018-03-07 11:56:50 +01:00
|
|
|
import {Component, OnInit} from '@angular/core';
|
2017-05-10 11:04:06 +02:00
|
|
|
|
2018-03-07 11:56:50 +01:00
|
|
|
import {FormControl} from '@angular/forms';
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
import {Observable} from 'rxjs/Observable';
|
2018-10-04 14:08:29 +02:00
|
|
|
import {Decoration} from '../../../models/model-interfaces';
|
|
|
|
import {DecorationService} from '../../../services/army-management/decoration.service';
|
|
|
|
import {Fraction} from '../../../utils/fraction.enum';
|
2018-07-03 20:58:21 +02:00
|
|
|
import {MatButtonToggleGroup} from '@angular/material';
|
2018-10-04 14:08:29 +02:00
|
|
|
import {UIHelpers} from '../../../utils/global.helpers';
|
2018-10-04 11:48:22 +02:00
|
|
|
import {TranslateService} from '@ngx-translate/core';
|
2017-05-10 11:04:06 +02:00
|
|
|
|
|
|
|
@Component({
|
2018-07-08 18:27:24 +02:00
|
|
|
selector: 'cc-decoration-list',
|
2017-05-10 11:04:06 +02:00
|
|
|
templateUrl: './decoration-list.component.html',
|
2019-02-25 14:32:29 +01:00
|
|
|
styleUrls: ['./decoration-list.component.scss']
|
2017-05-10 11:04:06 +02:00
|
|
|
})
|
|
|
|
export class DecorationListComponent implements OnInit {
|
|
|
|
|
|
|
|
selectedDecorationId: string | number = null;
|
|
|
|
|
|
|
|
decorations$: Observable<Decoration[]>;
|
|
|
|
|
|
|
|
searchTerm = new FormControl();
|
|
|
|
|
2018-07-05 21:57:47 +02:00
|
|
|
radioModel = '';
|
2017-05-10 11:04:06 +02:00
|
|
|
|
2017-11-08 19:23:15 +01:00
|
|
|
readonly fraction = Fraction;
|
|
|
|
|
2017-05-10 11:04:06 +02:00
|
|
|
constructor(private decorationService: DecorationService,
|
|
|
|
private router: Router,
|
2018-10-04 11:48:22 +02:00
|
|
|
private route: ActivatedRoute,
|
|
|
|
private translate: TranslateService) {
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.decorations$ = this.decorationService.decorations$;
|
2018-07-08 17:59:11 +02:00
|
|
|
}
|
2017-05-10 11:04:06 +02:00
|
|
|
|
2018-07-08 17:59:11 +02:00
|
|
|
initObservable(observables: any) {
|
|
|
|
Observable.merge(observables.params as Observable<string>, observables.searchTerm)
|
2018-02-26 09:04:27 +01:00
|
|
|
.distinctUntilChanged()
|
|
|
|
.switchMap(query => this.decorationService.findDecorations(query, this.radioModel))
|
|
|
|
.subscribe();
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
|
2017-10-08 12:17:21 +02:00
|
|
|
openNewDecorationForm() {
|
2017-05-16 20:06:00 +02:00
|
|
|
this.selectedDecorationId = null;
|
2017-05-10 11:04:06 +02:00
|
|
|
this.router.navigate([{outlets: {'right': ['new']}}], {relativeTo: this.route});
|
|
|
|
}
|
|
|
|
|
|
|
|
selectDecoration(decorationId: string | number) {
|
|
|
|
this.selectedDecorationId = decorationId;
|
2017-05-16 20:06:00 +02:00
|
|
|
this.router.navigate([{outlets: {'right': ['edit', decorationId]}}], {relativeTo: this.route});
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteDecoration(decoration) {
|
2017-05-16 23:51:03 +02:00
|
|
|
let fraction = 'Global';
|
2018-03-08 09:44:35 +01:00
|
|
|
if (decoration.fraction === 'BLUFOR') {
|
|
|
|
fraction = Fraction.BLUFOR;
|
|
|
|
} else if (decoration.fraction === 'OPFOR') {
|
|
|
|
fraction = Fraction.OPFOR;
|
|
|
|
}
|
2017-05-16 20:06:00 +02:00
|
|
|
|
2018-10-04 11:48:22 +02:00
|
|
|
this.translate.get('decorations.list.delete.confirm', {
|
|
|
|
name: decoration.name,
|
|
|
|
fraction: fraction
|
|
|
|
}).subscribe((confirmQuestion) => {
|
|
|
|
if (confirm(confirmQuestion)) {
|
|
|
|
this.decorationService.deleteDecoration(decoration)
|
|
|
|
.subscribe((res) => {
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
|
2018-07-03 20:58:21 +02:00
|
|
|
filterDecorations(group?: MatButtonToggleGroup) {
|
|
|
|
this.radioModel = UIHelpers.toggleReleaseButton(this.radioModel, group);
|
2017-10-08 18:13:20 +02:00
|
|
|
this.decorations$ = this.decorationService.findDecorations(this.searchTerm.value, this.radioModel);
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
}
|