82 lines
2.6 KiB
TypeScript
82 lines
2.6 KiB
TypeScript
import {Component, OnInit} from '@angular/core';
|
|
|
|
import {FormControl} from '@angular/forms';
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
import {Observable} from 'rxjs/Observable';
|
|
import {Decoration} from '../../../models/model-interfaces';
|
|
import {DecorationService} from '../../../services/army-management/decoration.service';
|
|
import {Fraction} from '../../../utils/fraction.enum';
|
|
import {MatButtonToggleGroup} from '@angular/material';
|
|
import {UIHelpers} from '../../../utils/global.helpers';
|
|
import {TranslateService} from '@ngx-translate/core';
|
|
|
|
@Component({
|
|
selector: 'cc-decoration-list',
|
|
templateUrl: './decoration-list.component.html',
|
|
styleUrls: ['./decoration-list.component.scss']
|
|
})
|
|
export class DecorationListComponent implements OnInit {
|
|
|
|
selectedDecorationId: string | number = null;
|
|
|
|
decorations$: Observable<Decoration[]>;
|
|
|
|
searchTerm = new FormControl();
|
|
|
|
radioModel = '';
|
|
|
|
readonly fraction = Fraction;
|
|
|
|
constructor(private decorationService: DecorationService,
|
|
private router: Router,
|
|
private route: ActivatedRoute,
|
|
private translate: TranslateService) {
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.decorations$ = this.decorationService.decorations$;
|
|
}
|
|
|
|
initObservable(observables: any) {
|
|
Observable.merge(observables.params as Observable<string>, observables.searchTerm)
|
|
.distinctUntilChanged()
|
|
.switchMap(query => this.decorationService.findDecorations(query, this.radioModel))
|
|
.subscribe();
|
|
}
|
|
|
|
openNewDecorationForm() {
|
|
this.selectedDecorationId = null;
|
|
this.router.navigate([{outlets: {'right': ['new']}}], {relativeTo: this.route});
|
|
}
|
|
|
|
selectDecoration(decorationId: string | number) {
|
|
this.selectedDecorationId = decorationId;
|
|
this.router.navigate([{outlets: {'right': ['edit', decorationId]}}], {relativeTo: this.route});
|
|
}
|
|
|
|
deleteDecoration(decoration) {
|
|
let fraction = 'Global';
|
|
if (decoration.fraction === 'BLUFOR') {
|
|
fraction = Fraction.BLUFOR;
|
|
} else if (decoration.fraction === 'OPFOR') {
|
|
fraction = Fraction.OPFOR;
|
|
}
|
|
|
|
this.translate.get('decorations.list.delete.confirm', {
|
|
name: decoration.name,
|
|
fraction: fraction
|
|
}).subscribe((confirmQuestion) => {
|
|
if (confirm(confirmQuestion)) {
|
|
this.decorationService.deleteDecoration(decoration)
|
|
.subscribe((res) => {
|
|
});
|
|
}
|
|
})
|
|
}
|
|
|
|
filterDecorations(group?: MatButtonToggleGroup) {
|
|
this.radioModel = UIHelpers.toggleReleaseButton(this.radioModel, group);
|
|
this.decorations$ = this.decorationService.findDecorations(this.searchTerm.value, this.radioModel);
|
|
}
|
|
}
|