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