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 | 60 |
1 files changed, 57 insertions, 3 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 3c83859e0..f5f8f3e4a 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,4 +1,4 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | 1 | import { Component, OnInit, ViewChild } from '@angular/core' |
2 | import { NotificationsService } from 'angular2-notifications' | 2 | import { NotificationsService } from 'angular2-notifications' |
3 | import { SortMeta } from 'primeng/components/common/sortmeta' | 3 | import { SortMeta } from 'primeng/components/common/sortmeta' |
4 | import { ConfirmService } from '../../../core' | 4 | import { ConfirmService } from '../../../core' |
@@ -6,6 +6,8 @@ import { RestPagination, RestTable, User } from '../../../shared' | |||
6 | import { UserService } from '../shared' | 6 | import { UserService } from '../shared' |
7 | import { I18n } from '@ngx-translate/i18n-polyfill' | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
8 | import { DropdownAction } from '@app/shared/buttons/action-dropdown.component' | 8 | import { DropdownAction } from '@app/shared/buttons/action-dropdown.component' |
9 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | ||
10 | import { UserBanModalComponent } from '@app/+admin/users/user-list/user-ban-modal.component' | ||
9 | 11 | ||
10 | @Component({ | 12 | @Component({ |
11 | selector: 'my-user-list', | 13 | selector: 'my-user-list', |
@@ -13,6 +15,8 @@ import { DropdownAction } from '@app/shared/buttons/action-dropdown.component' | |||
13 | styleUrls: [ './user-list.component.scss' ] | 15 | styleUrls: [ './user-list.component.scss' ] |
14 | }) | 16 | }) |
15 | export class UserListComponent extends RestTable implements OnInit { | 17 | export class UserListComponent extends RestTable implements OnInit { |
18 | @ViewChild('userBanModal') userBanModal: UserBanModalComponent | ||
19 | |||
16 | users: User[] = [] | 20 | users: User[] = [] |
17 | totalRecords = 0 | 21 | totalRecords = 0 |
18 | rowsPerPage = 10 | 22 | rowsPerPage = 10 |
@@ -20,6 +24,9 @@ export class UserListComponent extends RestTable implements OnInit { | |||
20 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | 24 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
21 | userActions: DropdownAction<User>[] = [] | 25 | userActions: DropdownAction<User>[] = [] |
22 | 26 | ||
27 | private userToBan: User | ||
28 | private openedModal: NgbModalRef | ||
29 | |||
23 | constructor ( | 30 | constructor ( |
24 | private notificationsService: NotificationsService, | 31 | private notificationsService: NotificationsService, |
25 | private confirmService: ConfirmService, | 32 | private confirmService: ConfirmService, |
@@ -30,12 +37,22 @@ export class UserListComponent extends RestTable implements OnInit { | |||
30 | 37 | ||
31 | this.userActions = [ | 38 | this.userActions = [ |
32 | { | 39 | { |
33 | type: 'edit', | 40 | label: this.i18n('Edit'), |
34 | linkBuilder: this.getRouterUserEditLink | 41 | linkBuilder: this.getRouterUserEditLink |
35 | }, | 42 | }, |
36 | { | 43 | { |
37 | type: 'delete', | 44 | label: this.i18n('Delete'), |
38 | handler: user => this.removeUser(user) | 45 | handler: user => this.removeUser(user) |
46 | }, | ||
47 | { | ||
48 | label: this.i18n('Ban'), | ||
49 | handler: user => this.openBanUserModal(user), | ||
50 | isDisplayed: user => !user.blocked | ||
51 | }, | ||
52 | { | ||
53 | label: this.i18n('Unban'), | ||
54 | handler: user => this.unbanUser(user), | ||
55 | isDisplayed: user => user.blocked | ||
39 | } | 56 | } |
40 | ] | 57 | ] |
41 | } | 58 | } |
@@ -44,6 +61,43 @@ export class UserListComponent extends RestTable implements OnInit { | |||
44 | this.loadSort() | 61 | this.loadSort() |
45 | } | 62 | } |
46 | 63 | ||
64 | hideBanUserModal () { | ||
65 | this.userToBan = undefined | ||
66 | this.openedModal.close() | ||
67 | } | ||
68 | |||
69 | openBanUserModal (user: User) { | ||
70 | if (user.username === 'root') { | ||
71 | this.notificationsService.error(this.i18n('Error'), this.i18n('You cannot ban root.')) | ||
72 | return | ||
73 | } | ||
74 | |||
75 | this.userBanModal.openModal(user) | ||
76 | } | ||
77 | |||
78 | onUserBanned () { | ||
79 | this.loadData() | ||
80 | } | ||
81 | |||
82 | async unbanUser (user: User) { | ||
83 | const message = this.i18n('Do you really want to unban {{username}}?', { username: user.username }) | ||
84 | const res = await this.confirmService.confirm(message, this.i18n('Unban')) | ||
85 | if (res === false) return | ||
86 | |||
87 | this.userService.unbanUser(user) | ||
88 | .subscribe( | ||
89 | () => { | ||
90 | this.notificationsService.success( | ||
91 | this.i18n('Success'), | ||
92 | this.i18n('User {{username}} unbanned.', { username: user.username }) | ||
93 | ) | ||
94 | this.loadData() | ||
95 | }, | ||
96 | |||
97 | err => this.notificationsService.error(this.i18n('Error'), err.message) | ||
98 | ) | ||
99 | } | ||
100 | |||
47 | async removeUser (user: User) { | 101 | async removeUser (user: User) { |
48 | if (user.username === 'root') { | 102 | if (user.username === 'root') { |
49 | this.notificationsService.error(this.i18n('Error'), this.i18n('You cannot delete root.')) | 103 | this.notificationsService.error(this.i18n('Error'), this.i18n('You cannot delete root.')) |