]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/users/user-list/user-list.component.ts
Fix client admin
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-list / user-list.component.ts
CommitLineData
df98563e 1import { Component } from '@angular/core'
7da18e44 2
df98563e 3import { NotificationsService } from 'angular2-notifications'
7ddd02c9 4
df98563e 5import { ConfirmService } from '../../../core'
42374cf5 6import { RestDataSource, User, Utils } from '../../../shared'
df98563e 7import { UserService } from '../shared'
7da18e44
C
8
9@Component({
10 selector: 'my-user-list',
ec8d8440
C
11 templateUrl: './user-list.component.html',
12 styleUrls: [ './user-list.component.scss' ]
7da18e44 13})
28798b5d 14export class UserListComponent {
42374cf5 15 usersSource: RestDataSource = null
28798b5d
C
16 tableSettings = {
17 mode: 'external',
18 attr: {
19 class: 'table-hover'
20 },
21 hideSubHeader: true,
22 actions: {
23 position: 'right',
24 add: false,
25 edit: false,
26 delete: true
27 },
28 delete: {
29 deleteButtonContent: Utils.getRowDeleteButton()
30 },
31 pager: {
32 display: true,
33 perPage: 10
34 },
35 columns: {
36 id: {
37 title: 'ID',
38 sortDirection: 'asc'
39 },
40 username: {
41 title: 'Username'
42 },
ad4a8a1c
C
43 email: {
44 title: 'Email'
45 },
28798b5d
C
46 role: {
47 title: 'Role',
48 sort: false
49 },
50 createdAt: {
51 title: 'Created Date',
52 valuePrepareFunction: Utils.dateToHuman
53 }
54 }
df98563e 55 }
7da18e44 56
df98563e 57 constructor (
7ddd02c9 58 private notificationsService: NotificationsService,
5769e1db 59 private confirmService: ConfirmService,
7ddd02c9 60 private userService: UserService
28798b5d 61 ) {
df98563e 62 this.usersSource = this.userService.getDataSource()
7da18e44
C
63 }
64
df98563e
C
65 removeUser ({ data }) {
66 const user: User = data
7da18e44 67
28798b5d 68 if (user.username === 'root') {
df98563e
C
69 this.notificationsService.error('Error', 'You cannot delete root.')
70 return
28798b5d 71 }
7da18e44 72
5769e1db
C
73 this.confirmService.confirm('Do you really want to delete this user?', 'Delete').subscribe(
74 res => {
df98563e 75 if (res === false) return
5769e1db
C
76
77 this.userService.removeUser(user).subscribe(
78 () => {
df98563e
C
79 this.notificationsService.success('Success', `User ${user.username} deleted.`)
80 this.usersSource.refresh()
5769e1db
C
81 },
82
83 err => this.notificationsService.error('Error', err.text)
df98563e 84 )
5769e1db 85 }
df98563e 86 )
7da18e44
C
87 }
88}