]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/users/user-list/user-list.component.ts
Merge branch 'feature/design' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-list / user-list.component.ts
CommitLineData
7e9334c3 1import { Component } from '@angular/core'
3523b64a 2import { SortMeta } from 'primeng/components/common/sortmeta'
7da18e44 3
df98563e 4import { NotificationsService } from 'angular2-notifications'
7ddd02c9 5
df98563e 6import { ConfirmService } from '../../../core'
d592e0a9 7import { RestTable, RestPagination, User } from '../../../shared'
df98563e 8import { UserService } from '../shared'
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})
7e9334c3 15export class UserListComponent extends RestTable {
d592e0a9
C
16 users: User[] = []
17 totalRecords = 0
18 rowsPerPage = 10
19 sort: SortMeta = { field: 'id', order: 1 }
20 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
7da18e44 21
df98563e 22 constructor (
7ddd02c9 23 private notificationsService: NotificationsService,
5769e1db 24 private confirmService: ConfirmService,
7ddd02c9 25 private userService: UserService
28798b5d 26 ) {
d592e0a9 27 super()
7da18e44
C
28 }
29
d592e0a9 30 removeUser (user: User) {
28798b5d 31 if (user.username === 'root') {
df98563e
C
32 this.notificationsService.error('Error', 'You cannot delete root.')
33 return
28798b5d 34 }
7da18e44 35
5769e1db
C
36 this.confirmService.confirm('Do you really want to delete this user?', 'Delete').subscribe(
37 res => {
df98563e 38 if (res === false) return
5769e1db
C
39
40 this.userService.removeUser(user).subscribe(
41 () => {
df98563e 42 this.notificationsService.success('Success', `User ${user.username} deleted.`)
d592e0a9 43 this.loadData()
5769e1db
C
44 },
45
bfb3a98f 46 err => this.notificationsService.error('Error', err.message)
df98563e 47 )
5769e1db 48 }
df98563e 49 )
7da18e44 50 }
d592e0a9
C
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
bfb3a98f 64 err => this.notificationsService.error('Error', err.message)
d592e0a9
C
65 )
66 }
7da18e44 67}