1 import { Component, OnInit } 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 implements OnInit {
19 sort: SortMeta = { field: 'createdAt', order: 1 }
20 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
23 private notificationsService: NotificationsService,
24 private confirmService: ConfirmService,
25 private userService: UserService
34 async removeUser (user: User) {
35 if (user.username === 'root') {
36 this.notificationsService.error('Error', 'You cannot delete root.')
40 const res = await this.confirmService.confirm('Do you really want to delete this user?', 'Delete')
41 if (res === false) return
43 this.userService.removeUser(user).subscribe(
45 this.notificationsService.success('Success', `User ${user.username} deleted.`)
49 err => this.notificationsService.error('Error', err.message)
53 getRouterUserEditLink (user: User) {
54 return [ '/admin', 'users', user.id, 'update' ]
57 protected loadData () {
58 this.userService.getUsers(this.pagination, this.sort)
61 this.users = resultList.data
62 this.totalRecords = resultList.total
65 err => this.notificationsService.error('Error', err.message)