2017-06-08 19:46:36 +02:00
|
|
|
import {Component} from "@angular/core";
|
|
|
|
import {AppUser, Squad} from "../models/model-interfaces";
|
|
|
|
import {Observable} from "rxjs/Observable";
|
|
|
|
import {AppUserService} from "../services/app-user-service/app-user.service";
|
2017-10-22 18:06:37 +02:00
|
|
|
import {SquadService} from "../services/army-management/squad.service";
|
2017-11-08 14:44:32 +01:00
|
|
|
import {Fraction} from "../utils/fraction.enum";
|
2017-06-08 19:46:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'admin-panel',
|
|
|
|
templateUrl: './admin.component.html',
|
2017-10-07 19:32:16 +02:00
|
|
|
styleUrls: ['./admin.component.css', '../style/overview.css']
|
2017-06-08 19:46:36 +02:00
|
|
|
})
|
|
|
|
export class AdminComponent {
|
|
|
|
|
|
|
|
users$: Observable<AppUser[]>;
|
|
|
|
|
|
|
|
squads: Squad[] = [];
|
|
|
|
|
|
|
|
showSuccessLabel = false;
|
|
|
|
|
2017-11-08 14:44:32 +01:00
|
|
|
readonly fraction = Fraction;
|
|
|
|
|
2017-06-08 19:46:36 +02:00
|
|
|
constructor(private appUserService: AppUserService,
|
|
|
|
private squadService: SquadService) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.users$ = this.appUserService.getUsers();
|
|
|
|
this.squadService.findSquads().subscribe(squads => {
|
|
|
|
this.squads = squads;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
updateAppUser(user) {
|
|
|
|
let updateObject = {
|
|
|
|
_id: user._id,
|
|
|
|
squad: user.squad,
|
|
|
|
activated: user.activated,
|
|
|
|
permission: user.permission
|
|
|
|
};
|
|
|
|
|
|
|
|
if (updateObject.squad === "0") {
|
|
|
|
updateObject.squad = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.appUserService.updateUser(updateObject)
|
2018-02-26 09:04:27 +01:00
|
|
|
.subscribe(user => {
|
|
|
|
this.showSuccessLabel = true;
|
|
|
|
setTimeout(() => {
|
|
|
|
this.showSuccessLabel = false;
|
|
|
|
}, 2000)
|
|
|
|
})
|
2017-06-08 19:46:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
deleteUser(user) {
|
|
|
|
if (confirm('Soll der Nutzer "' + user.username + '" wirklich gelöscht werden?')) {
|
|
|
|
this.appUserService.deleteUser(user)
|
2018-02-26 09:04:27 +01:00
|
|
|
.subscribe((res) => {
|
|
|
|
})
|
2017-06-08 19:46:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* compare ngValue with ngModel to assign selected element
|
|
|
|
*/
|
2017-09-03 12:49:59 +02:00
|
|
|
equals(o1: Squad, o2: Squad) {
|
2017-06-08 19:46:36 +02:00
|
|
|
if (o1 && o2) {
|
|
|
|
return o1._id === o2._id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|