X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Badmin%2Fusers%2Fuser-list%2Fuser-list.component.ts;h=0b72b07c175e2cd855cac3103d365a3a4ae3d2af;hb=8491293b02ed2ec53eb0fa128161ea0b08d3def9;hp=8f01c7d51497c586e2848bc843f98900c0966300;hpb=2b587cad93381a1901df3c993bf1db90bbb0891f;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 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' import { UserBanModalComponent } from '@app/shared/shared-moderation' import { I18n } from '@ngx-translate/i18n-polyfill' import { ServerConfig, User } from '@shared/models' +import { Params, Router, ActivatedRoute } from '@angular/router' @Component({ selector: 'my-user-list', @@ -30,6 +31,8 @@ export class UserListComponent extends RestTable implements OnInit { private serverService: ServerService, private userService: UserService, private auth: AuthService, + private route: ActivatedRoute, + private router: Router, private i18n: I18n ) { super() @@ -50,6 +53,14 @@ export class UserListComponent extends RestTable implements OnInit { this.initialize() + this.route.queryParams + .subscribe(params => { + this.search = params.search || '' + + this.setTableFilter(this.search) + this.loadData() + }) + this.bulkUserActions = [ [ { @@ -102,6 +113,26 @@ export class UserListComponent extends RestTable implements OnInit { this.loadData() } + /* Table filter functions */ + onUserSearch (event: Event) { + this.onSearch(event) + this.setQueryParams((event.target as HTMLInputElement).value) + } + + setQueryParams (search: string) { + const queryParams: Params = {} + if (search) Object.assign(queryParams, { search }) + + this.router.navigate([ '/admin/users/list' ], { queryParams }) + } + + resetTableFilter () { + this.setTableFilter('') + this.setQueryParams('') + this.resetSearch() + } + /* END Table filter functions */ + switchToDefaultAvatar ($event: Event) { ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL() } @@ -165,14 +196,17 @@ export class UserListComponent extends RestTable implements OnInit { protected loadData () { this.selectedUsers = [] - this.userService.getUsers(this.pagination, this.sort, this.search) - .subscribe( - resultList => { - this.users = resultList.data - this.totalRecords = resultList.total - }, + this.userService.getUsers({ + pagination: this.pagination, + sort: this.sort, + search: this.search + }).subscribe( + resultList => { + this.users = resultList.data + this.totalRecords = resultList.total + }, - err => this.notifier.error(err.message) - ) + err => this.notifier.error(err.message) + ) } }