1 import { Component } from '@angular/core'
3 import { NotificationsService } from 'angular2-notifications'
5 import { ConfirmService } from '../../../core'
6 import { RestDataSource, User, Utils } from '../../../shared'
7 import { UserService } from '../shared'
8 import { Router } from '@angular/router'
11 selector: 'my-user-list',
12 templateUrl: './user-list.component.html',
13 styleUrls: [ './user-list.component.scss' ]
15 export class UserListComponent {
16 usersSource: RestDataSource = null
30 deleteButtonContent: Utils.getRowDeleteButton()
33 editButtonContent: Utils.getRowEditButton()
58 title: 'Created Date',
59 valuePrepareFunction: Utils.dateToHuman
65 private router: Router,
66 private notificationsService: NotificationsService,
67 private confirmService: ConfirmService,
68 private userService: UserService
70 this.usersSource = this.userService.getDataSource()
73 editUser ({ data }: { data: User }) {
74 this.router.navigate([ '/admin', 'users', data.id, 'update' ])
77 removeUser ({ data }: { data: User }) {
80 if (user.username === 'root') {
81 this.notificationsService.error('Error', 'You cannot delete root.')
85 this.confirmService.confirm('Do you really want to delete this user?', 'Delete').subscribe(
87 if (res === false) return
89 this.userService.removeUser(user).subscribe(
91 this.notificationsService.success('Success', `User ${user.username} deleted.`)
92 this.usersSource.refresh()
95 err => this.notificationsService.error('Error', err.text)