1 import { Component } from '@angular/core'
3 import { NotificationsService } from 'angular2-notifications'
4 import { SortMeta } from 'primeng/components/common/sortmeta'
6 import { ConfirmService } from '../../../core'
7 import { RestPagination, RestTable, User } from '../../../shared'
8 import { UserService } from '../shared'
11 selector: 'my-user-list',
12 templateUrl: './user-list.component.html',
13 styleUrls: [ './user-list.component.scss' ]
15 export class UserListComponent extends RestTable {
19 sort: SortMeta = { field: 'id', order: 1 }
20 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
23 private notificationsService: NotificationsService,
24 private confirmService: ConfirmService,
25 private userService: UserService
30 async removeUser (user: User) {
31 if (user.username === 'root') {
32 this.notificationsService.error('Error', 'You cannot delete root.')
36 const res = await this.confirmService.confirm('Do you really want to delete this user?', 'Delete')
37 if (res === false) return
39 this.userService.removeUser(user).subscribe(
41 this.notificationsService.success('Success', `User ${user.username} deleted.`)
45 err => this.notificationsService.error('Error', err.message)
49 getRouterUserEditLink (user: User) {
50 return [ '/admin', 'users', user.id, 'update' ]
53 protected loadData () {
54 this.userService.getUsers(this.pagination, this.sort)
57 this.users = resultList.data
58 this.totalRecords = resultList.total
61 err => this.notificationsService.error('Error', err.message)