]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/users/user-list/user-list.component.ts
Client: fix lint
[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 { User, Utils } from '../../../shared';
7 import { UserService } from '../shared';
8
9 @Component({
10 selector: 'my-user-list',
11 templateUrl: './user-list.component.html',
12 styleUrls: [ './user-list.component.scss' ]
13 })
14 export class UserListComponent {
15 usersSource = null;
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 },
43 role: {
44 title: 'Role',
45 sort: false
46 },
47 createdAt: {
48 title: 'Created Date',
49 valuePrepareFunction: Utils.dateToHuman
50 }
51 }
52 };
53
54 constructor(
55 private notificationsService: NotificationsService,
56 private confirmService: ConfirmService,
57 private userService: UserService
58 ) {
59 this.usersSource = this.userService.getDataSource();
60 }
61
62 removeUser({ data }) {
63 const user: User = data;
64
65 if (user.username === 'root') {
66 this.notificationsService.error('Error', 'You cannot delete root.');
67 return;
68 }
69
70 this.confirmService.confirm('Do you really want to delete this user?', 'Delete').subscribe(
71 res => {
72 if (res === false) return;
73
74 this.userService.removeUser(user).subscribe(
75 () => {
76 this.notificationsService.success('Success', `User ${user.username} deleted.`);
77 this.usersSource.refresh();
78 },
79
80 err => this.notificationsService.error('Error', err.text)
81 );
82 }
83 );
84 }
85 }