From 2e46eb97154da909b82d5efe1d336a3412594ff0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 3 May 2021 14:33:34 +0200 Subject: Refactor search filters --- .../abuse-list-table.component.html | 7 +- .../abuse-list-table.component.ts | 19 ++---- .../advanced-input-filter.component.html | 8 ++- .../advanced-input-filter.component.ts | 77 +++++++++++++++++++--- .../misc/top-menu-dropdown.component.scss | 4 +- .../account-blocklist.component.html | 9 +-- .../account-blocklist.component.scss | 10 --- .../account-blocklist.component.ts | 4 +- .../app/shared/shared-moderation/moderation.scss | 17 ----- .../server-blocklist.component.html | 14 ++-- .../server-blocklist.component.scss | 18 ----- .../server-blocklist.component.ts | 6 +- .../videos-selection.component.html | 4 +- .../videos-selection.component.ts | 3 + 14 files changed, 104 insertions(+), 96 deletions(-) (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/shared-abuse-list/abuse-list-table.component.html b/client/src/app/shared/shared-abuse-list/abuse-list-table.component.html index 22f84a96e..b1c065c7a 100644 --- a/client/src/app/shared/shared-abuse-list/abuse-list-table.component.html +++ b/client/src/app/shared/shared-abuse-list/abuse-list-table.component.html @@ -1,6 +1,7 @@
- +
diff --git a/client/src/app/shared/shared-abuse-list/abuse-list-table.component.ts b/client/src/app/shared/shared-abuse-list/abuse-list-table.component.ts index f393c0d1e..4dc2b4f10 100644 --- a/client/src/app/shared/shared-abuse-list/abuse-list-table.component.ts +++ b/client/src/app/shared/shared-abuse-list/abuse-list-table.component.ts @@ -3,7 +3,7 @@ import truncate from 'lodash-es/truncate' import { SortMeta } from 'primeng/api' import { buildVideoLink, buildVideoOrPlaylistEmbed } from 'src/assets/player/utils' import { environment } from 'src/environments/environment' -import { AfterViewInit, Component, Input, OnInit, ViewChild } from '@angular/core' +import { Component, Input, OnInit, ViewChild } from '@angular/core' import { DomSanitizer } from '@angular/platform-browser' import { ActivatedRoute, Router } from '@angular/router' import { ConfirmService, MarkdownService, Notifier, RestPagination, RestTable } from '@app/core' @@ -11,10 +11,10 @@ import { Account, Actor, DropdownAction, Video, VideoService } from '@app/shared import { AbuseService, BlocklistService, VideoBlockService } from '@app/shared/shared-moderation' import { VideoCommentService } from '@app/shared/shared-video-comment' import { AbuseState, AdminAbuse } from '@shared/models' +import { AdvancedInputFilter } from '../shared-forms' import { AbuseMessageModalComponent } from './abuse-message-modal.component' import { ModerationCommentModalComponent } from './moderation-comment-modal.component' import { ProcessedAbuse } from './processed-abuse.model' -import { AdvancedInputFilter } from '../shared-forms' const logger = debug('peertube:moderation:AbuseListTableComponent') @@ -23,7 +23,7 @@ const logger = debug('peertube:moderation:AbuseListTableComponent') templateUrl: './abuse-list-table.component.html', styleUrls: [ '../shared-moderation/moderation.scss', './abuse-list-table.component.scss' ] }) -export class AbuseListTableComponent extends RestTable implements OnInit, AfterViewInit { +export class AbuseListTableComponent extends RestTable implements OnInit { @Input() viewType: 'admin' | 'user' @ViewChild('abuseMessagesModal', { static: true }) abuseMessagesModal: AbuseMessageModalComponent @@ -89,11 +89,6 @@ export class AbuseListTableComponent extends RestTable implements OnInit, AfterV ] this.initialize() - this.listenToSearchChange() - } - - ngAfterViewInit () { - if (this.search) this.setTableFilter(this.search, false) } isAdminView () { @@ -109,7 +104,7 @@ export class AbuseListTableComponent extends RestTable implements OnInit, AfterV } onModerationCommentUpdated () { - this.loadData() + this.reloadData() } isAbuseAccepted (abuse: AdminAbuse) { @@ -152,7 +147,7 @@ export class AbuseListTableComponent extends RestTable implements OnInit, AfterV this.abuseService.removeAbuse(abuse).subscribe( () => { this.notifier.success($localize`Abuse deleted.`) - this.loadData() + this.reloadData() }, err => this.notifier.error(err.message) @@ -162,7 +157,7 @@ export class AbuseListTableComponent extends RestTable implements OnInit, AfterV updateAbuseState (abuse: AdminAbuse, state: AbuseState) { this.abuseService.updateAbuse(abuse, { state }) .subscribe( - () => this.loadData(), + () => this.reloadData(), err => this.notifier.error(err.message) ) @@ -189,7 +184,7 @@ export class AbuseListTableComponent extends RestTable implements OnInit, AfterV return Actor.IS_LOCAL(abuse.reporterAccount.host) } - protected loadData () { + protected reloadData () { logger('Loading data.') const options = { diff --git a/client/src/app/shared/shared-forms/advanced-input-filter.component.html b/client/src/app/shared/shared-forms/advanced-input-filter.component.html index 03c4f127b..10d1296cf 100644 --- a/client/src/app/shared/shared-forms/advanced-input-filter.component.html +++ b/client/src/app/shared/shared-forms/advanced-input-filter.component.html @@ -1,5 +1,5 @@
-
+
@@ -10,13 +10,15 @@ {{ filter.label }} -
+ + Clear filters
diff --git a/client/src/app/shared/shared-forms/advanced-input-filter.component.ts b/client/src/app/shared/shared-forms/advanced-input-filter.component.ts index 394090751..1b0eed34b 100644 --- a/client/src/app/shared/shared-forms/advanced-input-filter.component.ts +++ b/client/src/app/shared/shared-forms/advanced-input-filter.component.ts @@ -1,27 +1,88 @@ -import { Component, EventEmitter, Input, Output } from '@angular/core' -import { Params } from '@angular/router' +import * as debug from 'debug' +import { Subject } from 'rxjs' +import { debounceTime, distinctUntilChanged } from 'rxjs/operators' +import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' +import { ActivatedRoute, Params, Router } from '@angular/router' export type AdvancedInputFilter = { label: string queryParams: Params } +const logger = debug('peertube:AdvancedInputFilterComponent') + @Component({ selector: 'my-advanced-input-filter', templateUrl: './advanced-input-filter.component.html', styleUrls: [ './advanced-input-filter.component.scss' ] }) -export class AdvancedInputFilterComponent { +export class AdvancedInputFilterComponent implements OnInit { @Input() filters: AdvancedInputFilter[] = [] - @Output() resetTableFilter = new EventEmitter() - @Output() search = new EventEmitter() + @Output() search = new EventEmitter() + + searchValue: string + + private searchStream: Subject + + constructor ( + private route: ActivatedRoute, + private router: Router + ) { } + + ngOnInit () { + this.initSearchStream() + this.listenToRouteSearchChange() + } - onSearch (event: Event) { - this.search.emit(event) + onInputSearch (event: Event) { + this.updateSearch((event.target as HTMLInputElement).value) } onResetTableFilter () { - this.resetTableFilter.emit() + this.updateSearch('') + } + + hasFilters () { + return this.filters.length !== 0 + } + + private updateSearch (value: string) { + this.searchValue = value + this.searchStream.next(this.searchValue) + } + + private listenToRouteSearchChange () { + this.route.queryParams + .subscribe(params => { + const search = params.search || '' + + logger('On route search change "%s".', search) + + this.updateSearch(search) + }) + } + + private initSearchStream () { + this.searchStream = new Subject() + + this.searchStream + .pipe( + debounceTime(200), + distinctUntilChanged() + ) + .subscribe(() => { + logger('On search "%s".', this.searchValue) + + this.setQueryParams(this.searchValue) + this.search.emit(this.searchValue) + }) + } + + private setQueryParams (search: string) { + const queryParams: Params = {} + + if (search) Object.assign(queryParams, { search }) + this.router.navigate([ ], { queryParams }) } } diff --git a/client/src/app/shared/shared-main/misc/top-menu-dropdown.component.scss b/client/src/app/shared/shared-main/misc/top-menu-dropdown.component.scss index 84dd7dce3..ffabb3646 100644 --- a/client/src/app/shared/shared-main/misc/top-menu-dropdown.component.scss +++ b/client/src/app/shared/shared-main/misc/top-menu-dropdown.component.scss @@ -11,12 +11,12 @@ } } -::ng-deep .dropdown-toggle::after { +.sub-menu ::ng-deep .dropdown-toggle::after { position: relative; top: 2px; } -::ng-deep .dropdown-menu { +.sub-menu ::ng-deep .dropdown-menu { margin-top: 0 !important; } diff --git a/client/src/app/shared/shared-moderation/account-blocklist.component.html b/client/src/app/shared/shared-moderation/account-blocklist.component.html index e914a7c3c..a9fac0810 100644 --- a/client/src/app/shared/shared-moderation/account-blocklist.component.html +++ b/client/src/app/shared/shared-moderation/account-blocklist.component.html @@ -11,13 +11,8 @@ >
-
- - - Clear filters +
+
diff --git a/client/src/app/shared/shared-moderation/account-blocklist.component.scss b/client/src/app/shared/shared-moderation/account-blocklist.component.scss index 63a9df823..bc441811e 100644 --- a/client/src/app/shared/shared-moderation/account-blocklist.component.scss +++ b/client/src/app/shared/shared-moderation/account-blocklist.component.scss @@ -1,16 +1,6 @@ @import '_variables'; @import '_mixins'; -.caption { - justify-content: flex-end; - - input { - @include peertube-input-text(250px); - - flex-grow: 1; - } -} - .chip { @include chip; } diff --git a/client/src/app/shared/shared-moderation/account-blocklist.component.ts b/client/src/app/shared/shared-moderation/account-blocklist.component.ts index 1bce65bf0..1146aeec0 100644 --- a/client/src/app/shared/shared-moderation/account-blocklist.component.ts +++ b/client/src/app/shared/shared-moderation/account-blocklist.component.ts @@ -44,12 +44,12 @@ export class GenericAccountBlocklistComponent extends RestTable implements OnIni : $localize`Account ${blockedAccount.nameWithHost} unmuted by your instance.` ) - this.loadData() + this.reloadData() } ) } - protected loadData () { + protected reloadData () { const operation = this.mode === BlocklistComponentType.Account ? this.blocklistService.getUserAccountBlocklist({ pagination: this.pagination, diff --git a/client/src/app/shared/shared-moderation/moderation.scss b/client/src/app/shared/shared-moderation/moderation.scss index ab43d8457..b13d06f03 100644 --- a/client/src/app/shared/shared-moderation/moderation.scss +++ b/client/src/app/shared/shared-moderation/moderation.scss @@ -39,27 +39,10 @@ } } -.input-group { - @include peertube-input-group(300px); - - .dropdown-toggle::after { - margin-left: 0; - } -} - .chip { @include chip; } -.caption { - justify-content: flex-end; - - input { - @include peertube-input-text(250px); - flex-grow: 1; - } -} - my-action-dropdown.show { ::ng-deep .dropdown-root { display: block !important; diff --git a/client/src/app/shared/shared-moderation/server-blocklist.component.html b/client/src/app/shared/shared-moderation/server-blocklist.component.html index 537186f05..c6d29bb21 100644 --- a/client/src/app/shared/shared-moderation/server-blocklist.component.html +++ b/client/src/app/shared/shared-moderation/server-blocklist.component.html @@ -4,8 +4,9 @@ @@ -18,13 +19,8 @@
-
- - - Clear filters +
+
diff --git a/client/src/app/shared/shared-moderation/server-blocklist.component.scss b/client/src/app/shared/shared-moderation/server-blocklist.component.scss index af21c0c20..a22972c5f 100644 --- a/client/src/app/shared/shared-moderation/server-blocklist.component.scss +++ b/client/src/app/shared/shared-moderation/server-blocklist.component.scss @@ -16,15 +16,6 @@ a { } } -.caption { - justify-content: flex-end; - - input { - @include peertube-input-text(250px); - flex-grow: 1; - } -} - .unblock-button { @include peertube-button; @include grey-button; @@ -34,15 +25,6 @@ a { @include create-button; } -.caption { - justify-content: flex-end; - - input { - @include peertube-input-text(250px); - flex-grow: 1; - } -} - .chip { @include chip; } diff --git a/client/src/app/shared/shared-moderation/server-blocklist.component.ts b/client/src/app/shared/shared-moderation/server-blocklist.component.ts index 546fd53c3..274d8f6e9 100644 --- a/client/src/app/shared/shared-moderation/server-blocklist.component.ts +++ b/client/src/app/shared/shared-moderation/server-blocklist.component.ts @@ -46,7 +46,7 @@ export class GenericServerBlocklistComponent extends RestTable implements OnInit : $localize`Instance ${host} unmuted by your instance.` ) - this.loadData() + this.reloadData() } ) } @@ -69,13 +69,13 @@ export class GenericServerBlocklistComponent extends RestTable implements OnInit : $localize`Instance ${domain} muted by your instance.` ) - this.loadData() + this.reloadData() } ) }) } - protected loadData () { + protected reloadData () { const operation = this.mode === BlocklistComponentType.Account ? this.blocklistService.getUserServerBlocklist({ pagination: this.pagination, diff --git a/client/src/app/shared/shared-video-miniature/videos-selection.component.html b/client/src/app/shared/shared-video-miniature/videos-selection.component.html index dec9e99f3..4ee90ce7f 100644 --- a/client/src/app/shared/shared-video-miniature/videos-selection.component.html +++ b/client/src/app/shared/shared-video-miniature/videos-selection.component.html @@ -1,9 +1,9 @@ -
No results.
+
{{ noResultMessage }}
-
+
diff --git a/client/src/app/shared/shared-video-miniature/videos-selection.component.ts b/client/src/app/shared/shared-video-miniature/videos-selection.component.ts index f8c3800d7..d64ee9b98 100644 --- a/client/src/app/shared/shared-video-miniature/videos-selection.component.ts +++ b/client/src/app/shared/shared-video-miniature/videos-selection.component.ts @@ -31,6 +31,9 @@ export class VideosSelectionComponent extends AbstractVideoList implements OnIni @Input() pagination: ComponentPagination @Input() titlePage: string @Input() miniatureDisplayOptions: MiniatureDisplayOptions + @Input() noResultMessage = $localize`No results.` + @Input() enableSelection = true + @Input() loadOnInit = true @Input() getVideosObservableFunction: (page: number, sort?: VideoSortField) => Observable> -- cgit v1.2.3