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