1 import { Component, OnInit } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { SortMeta } from 'primeng/components/common/sortmeta'
4 import { ConfirmService } from '../../../core'
5 import { RestPagination, RestTable, User } from '../../../shared'
6 import { UserService } from '../shared'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
10 selector: 'my-user-list',
11 templateUrl: './user-list.component.html',
12 styleUrls: [ './user-list.component.scss' ]
14 export class UserListComponent extends RestTable implements OnInit {
18 sort: SortMeta = { field: 'createdAt', order: 1 }
19 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
22 private notificationsService: NotificationsService,
23 private confirmService: ConfirmService,
24 private userService: UserService,
34 async removeUser (user: User) {
35 if (user.username === 'root') {
36 this.notificationsService.error(this.i18n('Error'), this.i18n('You cannot delete root.'))
40 const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this user?'), this.i18n('Delete'))
41 if (res === false) return
43 this.userService.removeUser(user).subscribe(
45 this.notificationsService.success(
47 this.i18n('User {{username}} deleted.', { username: user.username })
52 err => this.notificationsService.error(this.i18n('Error'), err.message)
56 getRouterUserEditLink (user: User) {
57 return [ '/admin', 'users', 'update', user.id ]
60 protected loadData () {
61 this.userService.getUsers(this.pagination, this.sort)
64 this.users = resultList.data
65 this.totalRecords = resultList.total
68 err => this.notificationsService.error(this.i18n('Error'), err.message)