72 lines
2.3 KiB
TypeScript
72 lines
2.3 KiB
TypeScript
import {Component} from '@angular/core';
|
|
|
|
import {FormControl} from '@angular/forms';
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
import {Observable} from 'rxjs/Observable';
|
|
import {AppUser, Squad} from '../../models/model-interfaces';
|
|
import {Fraction} from '../../utils/fraction.enum';
|
|
import {MatButtonToggleGroup} from '@angular/material';
|
|
import {UIHelpers} from '../../utils/global.helpers';
|
|
import {TranslateService} from '@ngx-translate/core';
|
|
import {AppUserService} from '../../services/app-user-service/app-user.service';
|
|
import {SquadService} from '../../services/army-management/squad.service';
|
|
|
|
@Component({
|
|
selector: 'cc-app-user-list',
|
|
templateUrl: './app-user-list.component.html',
|
|
styleUrls: ['./app-user-list.component.scss']
|
|
})
|
|
export class AppUserListComponent {
|
|
|
|
selectedUserId: string | number = null;
|
|
|
|
appUsers$: Observable<AppUser[]>;
|
|
|
|
readonly fraction = Fraction;
|
|
|
|
searchTerm = new FormControl();
|
|
|
|
radioModel = '';
|
|
|
|
constructor(private appUserService: AppUserService,
|
|
private squadService: SquadService,
|
|
private router: Router,
|
|
private route: ActivatedRoute,
|
|
private translate: TranslateService) {
|
|
this.appUsers$ = this.appUserService.getUsers();
|
|
}
|
|
|
|
initObservable(observables: any) {
|
|
Observable.merge(observables.params as Observable<string>, observables.searchTerm)
|
|
.distinctUntilChanged()
|
|
.switchMap(query => this.filterAppUsers())
|
|
.subscribe();
|
|
}
|
|
|
|
openNewUserForm() {
|
|
this.selectedUserId = null;
|
|
this.router.navigate([{outlets: {'right': ['new']}}], {relativeTo: this.route});
|
|
}
|
|
|
|
selectUser(userId: string) {
|
|
this.selectedUserId = userId;
|
|
this.router.navigate([{outlets: {'right': ['edit', userId]}}], {relativeTo: this.route});
|
|
}
|
|
|
|
deleteUser(user: AppUser) {
|
|
this.translate.get('users.list.delete.confirm', {name: user.username}).subscribe((confirmQuestion) => {
|
|
if (confirm(confirmQuestion)) {
|
|
this.appUserService.deleteUser(user)
|
|
.subscribe((res) => {
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
filterAppUsers(group?: MatButtonToggleGroup) {
|
|
this.radioModel = UIHelpers.toggleReleaseButton(this.radioModel, group);
|
|
// TODO: Add filter attribute submit
|
|
return this.appUsers$ = this.appUserService.getUsers();
|
|
}
|
|
}
|