]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/users/user-list/user-list.component.ts
Add ability to unfollow a server
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-list / user-list.component.ts
1 import { Component } from '@angular/core'
2 import { SortMeta } from 'primeng/components/common/sortmeta'
3
4 import { NotificationsService } from 'angular2-notifications'
5
6 import { ConfirmService } from '../../../core'
7 import { RestTable, RestPagination, User } from '../../../shared'
8 import { UserService } from '../shared'
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 extends RestTable {
16 users: User[] = []
17 totalRecords = 0
18 rowsPerPage = 10
19 sort: SortMeta = { field: 'id', order: 1 }
20 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
21
22 constructor (
23 private notificationsService: NotificationsService,
24 private confirmService: ConfirmService,
25 private userService: UserService
26 ) {
27 super()
28 }
29
30 removeUser (user: User) {
31 if (user.username === 'root') {
32 this.notificationsService.error('Error', 'You cannot delete root.')
33 return
34 }
35
36 this.confirmService.confirm('Do you really want to delete this user?', 'Delete').subscribe(
37 res => {
38 if (res === false) return
39
40 this.userService.removeUser(user).subscribe(
41 () => {
42 this.notificationsService.success('Success', `User ${user.username} deleted.`)
43 this.loadData()
44 },
45
46 err => this.notificationsService.error('Error', err.message)
47 )
48 }
49 )
50 }
51
52 getRouterUserEditLink (user: User) {
53 return [ '/admin', 'users', user.id, 'update' ]
54 }
55
56 protected loadData () {
57 this.userService.getUsers(this.pagination, this.sort)
58 .subscribe(
59 resultList => {
60 this.users = resultList.data
61 this.totalRecords = resultList.total
62 },
63
64 err => this.notificationsService.error('Error', err.message)
65 )
66 }
67 }