import {Component, OnInit} 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'; import {SquadService} from '../services/army-management/squad.service'; import {Fraction} from '../utils/fraction.enum'; @Component({ selector: 'admin-panel', templateUrl: './admin.component.html', styleUrls: ['./admin.component.css', '../style/overview.css'] }) export class AdminComponent implements OnInit { users$: Observable; squads: Squad[] = []; showSuccessLabel = false; readonly fraction = Fraction; constructor(private appUserService: AppUserService, private squadService: SquadService) { } ngOnInit() { this.users$ = this.appUserService.getUsers(); this.squadService.findSquads().subscribe(squads => { this.squads = squads; }); } updateAppUser(user) { const updateObject = { _id: user._id, squad: user.squad, activated: user.activated, permission: user.permission }; if (updateObject.squad === '0') { updateObject.squad = null; } this.appUserService.updateUser(updateObject) .subscribe(resUser => { this.showSuccessLabel = true; setTimeout(() => { this.showSuccessLabel = false; }, 2000); }); } deleteUser(user) { if (confirm('Soll der Nutzer "' + user.username + '" wirklich gelöscht werden?')) { this.appUserService.deleteUser(user) .subscribe((res) => { }); } } /** * compare ngValue with ngModel to assign selected element */ equals(o1: Squad, o2: Squad) { if (o1 && o2) { return o1._id === o2._id; } } }