2018-03-07 11:56:50 +01:00
|
|
|
import {Component, OnInit} from '@angular/core';
|
|
|
|
import {Location} from '@angular/common';
|
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';
|
|
|
|
import {UserService} from '../../services/army-management/user.service';
|
|
|
|
import {User} from '../../models/model-interfaces';
|
|
|
|
import {ADD, LOAD} from '../../services/stores/user.store';
|
|
|
|
import {Fraction} from '../../utils/fraction.enum';
|
2018-07-03 20:42:10 +02:00
|
|
|
import {MatButtonToggleGroup} from '@angular/material';
|
|
|
|
import {UIHelpers} from '../../utils/global.helpers';
|
2017-05-10 11:04:06 +02:00
|
|
|
|
|
|
|
@Component({
|
2018-07-08 18:27:24 +02:00
|
|
|
selector: 'cc-user-list',
|
2017-05-10 11:04:06 +02:00
|
|
|
templateUrl: './user-list.component.html',
|
2017-10-06 20:11:18 +02:00
|
|
|
styleUrls: ['./user-list.component.css', '../../style/select-list.css']
|
2017-05-10 11:04:06 +02:00
|
|
|
})
|
|
|
|
export class UserListComponent implements OnInit {
|
|
|
|
|
|
|
|
selectedUserId: string | number = null;
|
|
|
|
|
|
|
|
users$: Observable<User[]>;
|
|
|
|
|
|
|
|
searchTerm = new FormControl();
|
|
|
|
|
2018-07-05 21:57:47 +02:00
|
|
|
radioModel = '';
|
2017-05-10 11:04:06 +02:00
|
|
|
|
2017-10-14 15:26:05 +02:00
|
|
|
throttle = 300;
|
|
|
|
|
|
|
|
scrollDistance = 1;
|
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
limit = 20;
|
2018-02-26 09:04:27 +01:00
|
|
|
|
2017-11-08 19:40:51 +01:00
|
|
|
readonly fraction = Fraction;
|
2017-10-14 15:26:05 +02:00
|
|
|
|
2017-05-10 11:04:06 +02:00
|
|
|
constructor(private userService: UserService,
|
|
|
|
private router: Router,
|
2018-07-08 18:27:24 +02:00
|
|
|
private route: ActivatedRoute) {
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.users$ = this.userService.users$;
|
2018-07-08 18:27:24 +02:00
|
|
|
}
|
2017-05-10 11:04:06 +02:00
|
|
|
|
2018-07-08 18:27:24 +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.filterUsers())
|
|
|
|
.subscribe();
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
openNewUserForm() {
|
2017-05-14 16:35:44 +02:00
|
|
|
this.selectedUserId = null;
|
2017-05-17 15:55:22 +02:00
|
|
|
this.router.navigate([{outlets: {'right': ['new']}}], {relativeTo: this.route});
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
|
2017-05-13 14:57:40 +02:00
|
|
|
selectUser(userId: string) {
|
2017-05-10 11:04:06 +02:00
|
|
|
this.selectedUserId = userId;
|
2017-05-17 15:55:22 +02:00
|
|
|
this.router.navigate([{outlets: {'right': ['edit', userId]}}], {relativeTo: this.route});
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
|
2017-05-15 17:18:04 +02:00
|
|
|
awardUser(userId) {
|
2017-05-13 14:57:40 +02:00
|
|
|
this.selectedUserId = userId;
|
|
|
|
this.router.navigate([{outlets: {'right': ['award', userId]}}], {relativeTo: this.route});
|
|
|
|
}
|
|
|
|
|
2017-05-13 23:49:17 +02:00
|
|
|
deleteUser(user: User) {
|
2017-05-16 20:06:00 +02:00
|
|
|
if (confirm('Soll der Teilnehmer "' + user.username + '" wirklich gelöscht werden?')) {
|
2017-05-14 15:41:50 +02:00
|
|
|
this.userService.deleteUser(user)
|
2018-02-26 09:04:27 +01:00
|
|
|
.subscribe((res) => {
|
2018-03-07 11:56:50 +01:00
|
|
|
});
|
2017-05-14 15:41:50 +02:00
|
|
|
}
|
2017-05-13 23:49:17 +02:00
|
|
|
}
|
|
|
|
|
2018-07-05 21:57:47 +02:00
|
|
|
filterUsers(action?, group?: MatButtonToggleGroup) {
|
2017-10-14 17:47:55 +02:00
|
|
|
if (!action || action === LOAD) {
|
2017-10-14 15:26:05 +02:00
|
|
|
this.offset = 0;
|
|
|
|
this.limit = 20;
|
|
|
|
}
|
2018-07-03 20:42:10 +02:00
|
|
|
this.radioModel = UIHelpers.toggleReleaseButton(this.radioModel, group);
|
2017-10-14 15:26:05 +02:00
|
|
|
return this.users$ = this.userService.findUsers(this.searchTerm.value, this.radioModel,
|
|
|
|
null, this.limit, this.offset, action);
|
|
|
|
}
|
|
|
|
|
|
|
|
onScrollDown() {
|
|
|
|
if (this.offset + this.limit > this.userService.totalCount) {
|
|
|
|
this.limit = this.userService.totalCount - this.offset;
|
|
|
|
}
|
2018-03-07 11:56:50 +01:00
|
|
|
if (this.limit !== 0) {
|
2017-10-14 15:26:05 +02:00
|
|
|
this.offset += this.limit;
|
|
|
|
this.filterUsers(ADD);
|
|
|
|
}
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
}
|