]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
CommitLineData
28798b5d 1import { Component } from '@angular/core';
7da18e44 2
7ddd02c9
C
3import { NotificationsService } from 'angular2-notifications';
4
5769e1db 5import { ConfirmService } from '../../../core';
28798b5d 6import { User, Utils } from '../../../shared';
7da18e44
C
7import { UserService } from '../shared';
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
C
14export 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 }
7af75da4 52 };
7da18e44 53
7ddd02c9
C
54 constructor(
55 private notificationsService: NotificationsService,
5769e1db 56 private confirmService: ConfirmService,
7ddd02c9 57 private userService: UserService
28798b5d
C
58 ) {
59 this.usersSource = this.userService.getDataSource();
7da18e44
C
60 }
61
28798b5d
C
62 removeUser({ data }) {
63 const user: User = data;
7da18e44 64
28798b5d
C
65 if (user.username === 'root') {
66 this.notificationsService.error('Error', 'You cannot delete root.');
67 return;
68 }
7da18e44 69
5769e1db
C
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.`);
28798b5d 77 this.usersSource.refresh();
5769e1db
C
78 },
79
80 err => this.notificationsService.error('Error', err.text)
81 );
82 }
83 );
7da18e44
C
84 }
85}