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 | 50 |
1 files changed, 42 insertions, 8 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 8f01c7d51..0b72b07c1 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 | |||
@@ -5,6 +5,7 @@ import { Actor, DropdownAction } from '@app/shared/shared-main' | |||
5 | import { UserBanModalComponent } from '@app/shared/shared-moderation' | 5 | import { UserBanModalComponent } from '@app/shared/shared-moderation' |
6 | import { I18n } from '@ngx-translate/i18n-polyfill' | 6 | import { I18n } from '@ngx-translate/i18n-polyfill' |
7 | import { ServerConfig, User } from '@shared/models' | 7 | import { ServerConfig, User } from '@shared/models' |
8 | import { Params, Router, ActivatedRoute } from '@angular/router' | ||
8 | 9 | ||
9 | @Component({ | 10 | @Component({ |
10 | selector: 'my-user-list', | 11 | selector: 'my-user-list', |
@@ -30,6 +31,8 @@ export class UserListComponent extends RestTable implements OnInit { | |||
30 | private serverService: ServerService, | 31 | private serverService: ServerService, |
31 | private userService: UserService, | 32 | private userService: UserService, |
32 | private auth: AuthService, | 33 | private auth: AuthService, |
34 | private route: ActivatedRoute, | ||
35 | private router: Router, | ||
33 | private i18n: I18n | 36 | private i18n: I18n |
34 | ) { | 37 | ) { |
35 | super() | 38 | super() |
@@ -50,6 +53,14 @@ export class UserListComponent extends RestTable implements OnInit { | |||
50 | 53 | ||
51 | this.initialize() | 54 | this.initialize() |
52 | 55 | ||
56 | this.route.queryParams | ||
57 | .subscribe(params => { | ||
58 | this.search = params.search || '' | ||
59 | |||
60 | this.setTableFilter(this.search) | ||
61 | this.loadData() | ||
62 | }) | ||
63 | |||
53 | this.bulkUserActions = [ | 64 | this.bulkUserActions = [ |
54 | [ | 65 | [ |
55 | { | 66 | { |
@@ -102,6 +113,26 @@ export class UserListComponent extends RestTable implements OnInit { | |||
102 | this.loadData() | 113 | this.loadData() |
103 | } | 114 | } |
104 | 115 | ||
116 | /* Table filter functions */ | ||
117 | onUserSearch (event: Event) { | ||
118 | this.onSearch(event) | ||
119 | this.setQueryParams((event.target as HTMLInputElement).value) | ||
120 | } | ||
121 | |||
122 | setQueryParams (search: string) { | ||
123 | const queryParams: Params = {} | ||
124 | if (search) Object.assign(queryParams, { search }) | ||
125 | |||
126 | this.router.navigate([ '/admin/users/list' ], { queryParams }) | ||
127 | } | ||
128 | |||
129 | resetTableFilter () { | ||
130 | this.setTableFilter('') | ||
131 | this.setQueryParams('') | ||
132 | this.resetSearch() | ||
133 | } | ||
134 | /* END Table filter functions */ | ||
135 | |||
105 | switchToDefaultAvatar ($event: Event) { | 136 | switchToDefaultAvatar ($event: Event) { |
106 | ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL() | 137 | ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL() |
107 | } | 138 | } |
@@ -165,14 +196,17 @@ export class UserListComponent extends RestTable implements OnInit { | |||
165 | protected loadData () { | 196 | protected loadData () { |
166 | this.selectedUsers = [] | 197 | this.selectedUsers = [] |
167 | 198 | ||
168 | this.userService.getUsers(this.pagination, this.sort, this.search) | 199 | this.userService.getUsers({ |
169 | .subscribe( | 200 | pagination: this.pagination, |
170 | resultList => { | 201 | sort: this.sort, |
171 | this.users = resultList.data | 202 | search: this.search |
172 | this.totalRecords = resultList.total | 203 | }).subscribe( |
173 | }, | 204 | resultList => { |
205 | this.users = resultList.data | ||
206 | this.totalRecords = resultList.total | ||
207 | }, | ||
174 | 208 | ||
175 | err => this.notifier.error(err.message) | 209 | err => this.notifier.error(err.message) |
176 | ) | 210 | ) |
177 | } | 211 | } |
178 | } | 212 | } |