2016-08-09 21:45:21 +02:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
|
2017-01-27 16:14:11 +01:00
|
|
|
import { NotificationsService } from 'angular2-notifications';
|
|
|
|
|
2017-01-27 16:54:44 +01:00
|
|
|
import { ConfirmService } from '../../../core';
|
2016-08-09 21:45:21 +02:00
|
|
|
import { User } from '../../../shared';
|
|
|
|
import { UserService } from '../shared';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-user-list',
|
2016-09-19 22:49:31 +02:00
|
|
|
templateUrl: './user-list.component.html',
|
|
|
|
styleUrls: [ './user-list.component.scss' ]
|
2016-08-09 21:45:21 +02:00
|
|
|
})
|
|
|
|
export class UserListComponent implements OnInit {
|
|
|
|
totalUsers: number;
|
|
|
|
users: User[];
|
|
|
|
|
2017-01-27 16:14:11 +01:00
|
|
|
constructor(
|
|
|
|
private notificationsService: NotificationsService,
|
2017-01-27 16:54:44 +01:00
|
|
|
private confirmService: ConfirmService,
|
2017-01-27 16:14:11 +01:00
|
|
|
private userService: UserService
|
|
|
|
) {}
|
2016-08-09 21:45:21 +02:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.getUsers();
|
|
|
|
}
|
|
|
|
|
|
|
|
getUsers() {
|
|
|
|
this.userService.getUsers().subscribe(
|
|
|
|
({ users, totalUsers }) => {
|
|
|
|
this.users = users;
|
|
|
|
this.totalUsers = totalUsers;
|
|
|
|
},
|
|
|
|
|
2017-01-27 16:14:11 +01:00
|
|
|
err => this.notificationsService.error('Error', err.text)
|
2016-08-09 21:45:21 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
removeUser(user: User) {
|
2017-01-27 16:54:44 +01:00
|
|
|
this.confirmService.confirm('Do you really want to delete this user?', 'Delete').subscribe(
|
|
|
|
res => {
|
|
|
|
if (res === false) return;
|
|
|
|
|
|
|
|
this.userService.removeUser(user).subscribe(
|
|
|
|
() => {
|
|
|
|
this.notificationsService.success('Success', `User ${user.username} deleted.`);
|
|
|
|
this.getUsers();
|
|
|
|
},
|
|
|
|
|
|
|
|
err => this.notificationsService.error('Error', err.text)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
2016-08-09 21:45:21 +02:00
|
|
|
}
|
|
|
|
}
|