diff options
Diffstat (limited to 'client/src/app/+admin/users/user-list/user-list.component.ts')
-rw-r--r-- | client/src/app/+admin/users/user-list/user-list.component.ts | 91 |
1 files changed, 31 insertions, 60 deletions
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 7187a2008..c3fa55825 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,82 +1,37 @@ | |||
1 | import { Component } from '@angular/core' | 1 | import { Component, OnInit } from '@angular/core' |
2 | import { SortMeta } from 'primeng/primeng' | ||
2 | 3 | ||
3 | import { NotificationsService } from 'angular2-notifications' | 4 | import { NotificationsService } from 'angular2-notifications' |
4 | 5 | ||
5 | import { ConfirmService } from '../../../core' | 6 | import { ConfirmService } from '../../../core' |
6 | import { RestDataSource, User, Utils } from '../../../shared' | 7 | import { RestTable, RestPagination, User } from '../../../shared' |
7 | import { UserService } from '../shared' | 8 | import { UserService } from '../shared' |
8 | import { Router } from '@angular/router' | ||
9 | 9 | ||
10 | @Component({ | 10 | @Component({ |
11 | selector: 'my-user-list', | 11 | selector: 'my-user-list', |
12 | templateUrl: './user-list.component.html', | 12 | templateUrl: './user-list.component.html', |
13 | styleUrls: [ './user-list.component.scss' ] | 13 | styleUrls: [ './user-list.component.scss' ] |
14 | }) | 14 | }) |
15 | export class UserListComponent { | 15 | export class UserListComponent extends RestTable implements OnInit { |
16 | usersSource: RestDataSource = null | 16 | users: User[] = [] |
17 | tableSettings = { | 17 | totalRecords = 0 |
18 | mode: 'external', | 18 | rowsPerPage = 10 |
19 | attr: { | 19 | sort: SortMeta = { field: 'id', order: 1 } |
20 | class: 'table-hover' | 20 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
21 | }, | ||
22 | hideSubHeader: true, | ||
23 | actions: { | ||
24 | position: 'right', | ||
25 | add: false, | ||
26 | edit: true, | ||
27 | delete: true | ||
28 | }, | ||
29 | delete: { | ||
30 | deleteButtonContent: Utils.getRowDeleteButton() | ||
31 | }, | ||
32 | edit: { | ||
33 | editButtonContent: Utils.getRowEditButton() | ||
34 | }, | ||
35 | pager: { | ||
36 | display: true, | ||
37 | perPage: 10 | ||
38 | }, | ||
39 | columns: { | ||
40 | id: { | ||
41 | title: 'ID', | ||
42 | sortDirection: 'asc' | ||
43 | }, | ||
44 | username: { | ||
45 | title: 'Username' | ||
46 | }, | ||
47 | email: { | ||
48 | title: 'Email' | ||
49 | }, | ||
50 | videoQuota: { | ||
51 | title: 'Video quota' | ||
52 | }, | ||
53 | role: { | ||
54 | title: 'Role', | ||
55 | sort: false | ||
56 | }, | ||
57 | createdAt: { | ||
58 | title: 'Created Date', | ||
59 | valuePrepareFunction: Utils.dateToHuman | ||
60 | } | ||
61 | } | ||
62 | } | ||
63 | 21 | ||
64 | constructor ( | 22 | constructor ( |
65 | private router: Router, | ||
66 | private notificationsService: NotificationsService, | 23 | private notificationsService: NotificationsService, |
67 | private confirmService: ConfirmService, | 24 | private confirmService: ConfirmService, |
68 | private userService: UserService | 25 | private userService: UserService |
69 | ) { | 26 | ) { |
70 | this.usersSource = this.userService.getDataSource() | 27 | super() |
71 | } | 28 | } |
72 | 29 | ||
73 | editUser ({ data }: { data: User }) { | 30 | ngOnInit () { |
74 | this.router.navigate([ '/admin', 'users', data.id, 'update' ]) | 31 | this.loadData() |
75 | } | 32 | } |
76 | 33 | ||
77 | removeUser ({ data }: { data: User }) { | 34 | removeUser (user: User) { |
78 | const user = data | ||
79 | |||
80 | if (user.username === 'root') { | 35 | if (user.username === 'root') { |
81 | this.notificationsService.error('Error', 'You cannot delete root.') | 36 | this.notificationsService.error('Error', 'You cannot delete root.') |
82 | return | 37 | return |
@@ -89,12 +44,28 @@ export class UserListComponent { | |||
89 | this.userService.removeUser(user).subscribe( | 44 | this.userService.removeUser(user).subscribe( |
90 | () => { | 45 | () => { |
91 | this.notificationsService.success('Success', `User ${user.username} deleted.`) | 46 | this.notificationsService.success('Success', `User ${user.username} deleted.`) |
92 | this.usersSource.refresh() | 47 | this.loadData() |
93 | }, | 48 | }, |
94 | 49 | ||
95 | err => this.notificationsService.error('Error', err.text) | 50 | err => this.notificationsService.error('Error', err) |
96 | ) | 51 | ) |
97 | } | 52 | } |
98 | ) | 53 | ) |
99 | } | 54 | } |
55 | |||
56 | getRouterUserEditLink (user: User) { | ||
57 | return [ '/admin', 'users', user.id, 'update' ] | ||
58 | } | ||
59 | |||
60 | protected loadData () { | ||
61 | this.userService.getUsers(this.pagination, this.sort) | ||
62 | .subscribe( | ||
63 | resultList => { | ||
64 | this.users = resultList.data | ||
65 | this.totalRecords = resultList.total | ||
66 | }, | ||
67 | |||
68 | err => this.notificationsService.error('Error', err) | ||
69 | ) | ||
70 | } | ||
100 | } | 71 | } |