X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Badmin%2Fusers%2Fuser-list%2Fuser-list.component.ts;h=5121528080412933c85b1e0b3313817b38854c01;hb=621d99f53f47a11919ec243e05273ecf5907b444;hp=dbb85cedd7ac28bb1e652c5ecda4870ae36da307;hpb=b0f9f39ed70299a208d1b388c72de8b7f3510cb7;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+admin/users/user-list/user-list.component.ts b/client/src/app/+admin/users/user-list/user-list.component.ts index dbb85cedd..512152808 100644 --- a/client/src/app/+admin/users/user-list/user-list.component.ts +++ b/client/src/app/+admin/users/user-list/user-list.component.ts @@ -1,9 +1,10 @@ import { Component } from '@angular/core' import { NotificationsService } from 'angular2-notifications' +import { SortMeta } from 'primeng/components/common/sortmeta' import { ConfirmService } from '../../../core' -import { RestDataSource, User, Utils } from '../../../shared' +import { RestPagination, RestTable, User } from '../../../shared' import { UserService } from '../shared' @Component({ @@ -11,81 +12,53 @@ import { UserService } from '../shared' templateUrl: './user-list.component.html', styleUrls: [ './user-list.component.scss' ] }) -export class UserListComponent { - usersSource: RestDataSource = null - tableSettings = { - mode: 'external', - attr: { - class: 'table-hover' - }, - hideSubHeader: true, - actions: { - position: 'right', - add: false, - edit: false, - delete: true - }, - delete: { - deleteButtonContent: Utils.getRowDeleteButton() - }, - pager: { - display: true, - perPage: 1 - }, - columns: { - id: { - title: 'ID', - sortDirection: 'asc' - }, - username: { - title: 'Username' - }, - email: { - title: 'Email' - }, - videoQuota: { - title: 'Video quota' - }, - role: { - title: 'Role', - sort: false - }, - createdAt: { - title: 'Created Date', - valuePrepareFunction: Utils.dateToHuman - } - } - } +export class UserListComponent extends RestTable { + users: User[] = [] + totalRecords = 0 + rowsPerPage = 10 + sort: SortMeta = { field: 'id', order: 1 } + pagination: RestPagination = { count: this.rowsPerPage, start: 0 } constructor ( private notificationsService: NotificationsService, private confirmService: ConfirmService, private userService: UserService ) { - this.usersSource = this.userService.getDataSource() + super() } - removeUser ({ data }) { - const user: User = data - + async removeUser (user: User) { if (user.username === 'root') { this.notificationsService.error('Error', 'You cannot delete root.') return } - this.confirmService.confirm('Do you really want to delete this user?', 'Delete').subscribe( - res => { - if (res === false) return + const res = await this.confirmService.confirm('Do you really want to delete this user?', 'Delete') + if (res === false) return - this.userService.removeUser(user).subscribe( - () => { - this.notificationsService.success('Success', `User ${user.username} deleted.`) - this.usersSource.refresh() - }, + this.userService.removeUser(user).subscribe( + () => { + this.notificationsService.success('Success', `User ${user.username} deleted.`) + this.loadData() + }, - err => this.notificationsService.error('Error', err.text) - ) - } + err => this.notificationsService.error('Error', err.message) ) } + + getRouterUserEditLink (user: User) { + return [ '/admin', 'users', user.id, 'update' ] + } + + protected loadData () { + this.userService.getUsers(this.pagination, this.sort) + .subscribe( + resultList => { + this.users = resultList.data + this.totalRecords = resultList.total + }, + + err => this.notificationsService.error('Error', err.message) + ) + } }