]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/users/user-list/user-list.component.ts
User routes: :id/update -> update/:id
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-list / user-list.component.ts
CommitLineData
ab998f7b 1import { Component, OnInit } from '@angular/core'
7da18e44 2
df98563e 3import { NotificationsService } from 'angular2-notifications'
1f30a185 4import { SortMeta } from 'primeng/components/common/sortmeta'
7ddd02c9 5
df98563e 6import { ConfirmService } from '../../../core'
1f30a185 7import { RestPagination, RestTable, 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})
ab998f7b 15export class UserListComponent extends RestTable implements OnInit {
d592e0a9
C
16 users: User[] = []
17 totalRecords = 0
18 rowsPerPage = 10
ab998f7b 19 sort: SortMeta = { field: 'createdAt', order: 1 }
d592e0a9 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
ab998f7b
C
30 ngOnInit () {
31 this.loadSort()
32 }
33
1f30a185 34 async removeUser (user: User) {
28798b5d 35 if (user.username === 'root') {
df98563e
C
36 this.notificationsService.error('Error', 'You cannot delete root.')
37 return
28798b5d 38 }
7da18e44 39
1f30a185
C
40 const res = await this.confirmService.confirm('Do you really want to delete this user?', 'Delete')
41 if (res === false) return
5769e1db 42
1f30a185
C
43 this.userService.removeUser(user).subscribe(
44 () => {
45 this.notificationsService.success('Success', `User ${user.username} deleted.`)
46 this.loadData()
47 },
5769e1db 48
1f30a185 49 err => this.notificationsService.error('Error', err.message)
df98563e 50 )
7da18e44 51 }
d592e0a9
C
52
53 getRouterUserEditLink (user: User) {
9b9b1805 54 return [ '/admin', 'users', 'update', user.id ]
d592e0a9
C
55 }
56
57 protected loadData () {
58 this.userService.getUsers(this.pagination, this.sort)
59 .subscribe(
60 resultList => {
61 this.users = resultList.data
62 this.totalRecords = resultList.total
63 },
64
bfb3a98f 65 err => this.notificationsService.error('Error', err.message)
d592e0a9
C
66 )
67 }
7da18e44 68}