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