From 8491293b02ed2ec53eb0fa128161ea0b08d3def9 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Thu, 2 Jul 2020 22:49:51 +0200 Subject: add blocked filter in users list to filter banned users fixes #2914 --- .../users/user-list/user-list.component.html | 29 +++++++++---- .../users/user-list/user-list.component.scss | 17 ++++++++ .../+admin/users/user-list/user-list.component.ts | 50 ++++++++++++++++++---- client/src/app/core/rest/rest.service.ts | 4 +- client/src/app/core/users/user.service.ts | 25 ++++++++++- 5 files changed, 106 insertions(+), 19 deletions(-) (limited to 'client/src') diff --git a/client/src/app/+admin/users/user-list/user-list.component.html b/client/src/app/+admin/users/user-list/user-list.component.html index 27d4a5787..9580a3c8a 100644 --- a/client/src/app/+admin/users/user-list/user-list.component.html +++ b/client/src/app/+admin/users/user-list/user-list.component.html @@ -16,14 +16,27 @@ -
- - - Clear filters +
+
+
+
+ +
+ +
+ + Banned users +
+
+ + + Clear filters +
+ Create user @@ -70,7 +83,7 @@ alt="Avatar" >
- + {{ user.account.displayName }} diff --git a/client/src/app/+admin/users/user-list/user-list.component.scss b/client/src/app/+admin/users/user-list/user-list.component.scss index 697b2c11b..2b84dec75 100644 --- a/client/src/app/+admin/users/user-list/user-list.component.scss +++ b/client/src/app/+admin/users/user-list/user-list.component.scss @@ -17,6 +17,12 @@ tr.banned > td { font-weight: $font-semibold; } +.user-table-primary-text .glyphicon { + font-size: 80%; + color: gray; + margin-left: 0.1rem; +} + .caption { justify-content: space-between; @@ -33,3 +39,14 @@ p-tableCheckbox { .chip { @include chip; } + +.input-group { + @include peertube-input-group(300px); + input { + flex: 1; + } + + .dropdown-toggle::after { + margin-left: 0; + } +} 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) + ) } } diff --git a/client/src/app/core/rest/rest.service.ts b/client/src/app/core/rest/rest.service.ts index c12b6bd41..9e32c6d58 100644 --- a/client/src/app/core/rest/rest.service.ts +++ b/client/src/app/core/rest/rest.service.ts @@ -9,11 +9,12 @@ interface QueryStringFilterPrefixes { prefix: string handler?: (v: string) => string | number multiple?: boolean + isBoolean?: boolean } } type ParseQueryStringFilterResult = { - [key: string]: string | number | (string | number)[] + [key: string]: string | number | boolean | (string | number | boolean)[] } @Injectable() @@ -96,6 +97,7 @@ export class RestService { return t }) .filter(t => !!t || t === 0) + .map(t => prefixObj.isBoolean ? t === 'true' : t) if (matchedTokens.length === 0) continue diff --git a/client/src/app/core/users/user.service.ts b/client/src/app/core/users/user.service.ts index ab395b1f9..2c817d45e 100644 --- a/client/src/app/core/users/user.service.ts +++ b/client/src/app/core/users/user.service.ts @@ -290,11 +290,32 @@ export class UserService { }) } - getUsers (pagination: RestPagination, sort: SortMeta, search?: string): Observable> { + getUsers (parameters: { + pagination: RestPagination + sort: SortMeta + search?: string + }): Observable> { + const { pagination, sort, search } = parameters + let params = new HttpParams() params = this.restService.addRestGetParams(params, pagination, sort) - if (search) params = params.append('search', search) + if (search) { + const filters = this.restService.parseQueryStringFilter(search, { + blocked: { + prefix: 'banned:', + isBoolean: true, + handler: v => { + if (v === 'true') return v + if (v === 'false') return v + + return undefined + } + } + }) + + params = this.restService.addObjectParams(params, filters) + } return this.authHttp.get>(UserService.BASE_USERS_URL, { params }) .pipe( -- cgit v1.2.3