From af7fd04a6706fb781e4622167b08dc6c9376f06a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 29 Jul 2021 15:19:22 +0200 Subject: Add ability to filter by host in search page --- .../src/app/+search/search-filters.component.html | 16 +++++++++++---- client/src/app/+search/search-filters.component.ts | 8 ++++---- client/src/app/+search/search.component.html | 2 ++ client/src/app/+search/search.component.scss | 4 ++++ client/src/app/+search/search.component.ts | 24 ++++++++++++++++++---- 5 files changed, 42 insertions(+), 12 deletions(-) (limited to 'client/src/app/+search') diff --git a/client/src/app/+search/search-filters.component.html b/client/src/app/+search/search-filters.component.html index 421bc7f6f..4b87a2102 100644 --- a/client/src/app/+search/search-filters.component.html +++ b/client/src/app/+search/search-filters.component.html @@ -63,7 +63,7 @@
- +
@@ -79,7 +79,7 @@
- +
@@ -174,6 +174,14 @@
+
+ + + +
+
diff --git a/client/src/app/+search/search-filters.component.ts b/client/src/app/+search/search-filters.component.ts index afa523b91..5972ba553 100644 --- a/client/src/app/+search/search-filters.component.ts +++ b/client/src/app/+search/search-filters.component.ts @@ -108,14 +108,14 @@ export class SearchFiltersComponent implements OnInit { this.loadOriginallyPublishedAtYears() } - onInputUpdated () { + onDurationOrPublishedUpdated () { this.updateModelFromDurationRange() this.updateModelFromPublishedRange() this.updateModelFromOriginallyPublishedAtYears() } formUpdated () { - this.onInputUpdated() + this.onDurationOrPublishedUpdated() this.filtered.emit(this.advancedSearch) } @@ -127,7 +127,7 @@ export class SearchFiltersComponent implements OnInit { this.durationRange = undefined this.publishedDateRange = undefined - this.onInputUpdated() + this.onDurationOrPublishedUpdated() } resetField (fieldName: string, value?: any) { @@ -136,7 +136,7 @@ export class SearchFiltersComponent implements OnInit { resetLocalField (fieldName: string, value?: any) { this[fieldName] = value - this.onInputUpdated() + this.onDurationOrPublishedUpdated() } resetOriginalPublicationYears () { diff --git a/client/src/app/+search/search.component.html b/client/src/app/+search/search.component.html index b28abca6a..dc8b4d595 100644 --- a/client/src/app/+search/search.component.html +++ b/client/src/app/+search/search.component.html @@ -24,6 +24,8 @@
+ +
{{ error }}
diff --git a/client/src/app/+search/search.component.scss b/client/src/app/+search/search.component.scss index fca704d27..b521825e5 100644 --- a/client/src/app/+search/search.component.scss +++ b/client/src/app/+search/search.component.scss @@ -15,6 +15,10 @@ padding: 40px; } +.alert-danger { + margin-top: 10px; +} + .results-header { font-size: 16px; padding-bottom: 20px; diff --git a/client/src/app/+search/search.component.ts b/client/src/app/+search/search.component.ts index 235bbfa4c..250062e0c 100644 --- a/client/src/app/+search/search.component.ts +++ b/client/src/app/+search/search.component.ts @@ -4,6 +4,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' import { AuthService, HooksService, MetaService, Notifier, ServerService, User, UserService } from '@app/core' import { immutableAssign } from '@app/helpers' +import { validateHost } from '@app/shared/form-validators/host-validators' import { Video, VideoChannel } from '@app/shared/shared-main' import { AdvancedSearch, SearchService } from '@app/shared/shared-search' import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature' @@ -16,6 +17,8 @@ import { HTMLServerConfig, SearchTargetType } from '@shared/models' templateUrl: './search.component.html' }) export class SearchComponent implements OnInit, OnDestroy { + error: string + results: (Video | VideoChannel)[] = [] pagination = { @@ -89,8 +92,10 @@ export class SearchComponent implements OnInit, OnDestroy { this.advancedSearch.searchTarget = this.getDefaultSearchTarget() } - // Don't hide filters if we have some of them AND the user just came on the webpage - this.isSearchFilterCollapsed = this.isInitialLoad === false || !this.advancedSearch.containsValues() + this.error = this.checkFieldsAndGetError() + + // Don't hide filters if we have some of them AND the user just came on the webpage, or we have an error + this.isSearchFilterCollapsed = !this.error && (this.isInitialLoad === false || !this.advancedSearch.containsValues()) this.isInitialLoad = false this.search() @@ -126,6 +131,9 @@ export class SearchComponent implements OnInit, OnDestroy { } search () { + this.error = this.checkFieldsAndGetError() + if (this.error) return + this.isSearching = true forkJoin([ @@ -280,7 +288,7 @@ export class SearchComponent implements OnInit, OnDestroy { const params = { search: this.currentSearch, componentPagination: immutableAssign(this.pagination, { itemsPerPage: this.channelsPerPage }), - searchTarget: this.advancedSearch.searchTarget + advancedSearch: this.advancedSearch } return this.hooks.wrapObsFun( @@ -298,7 +306,7 @@ export class SearchComponent implements OnInit, OnDestroy { const params = { search: this.currentSearch, componentPagination: immutableAssign(this.pagination, { itemsPerPage: this.playlistsPerPage }), - searchTarget: this.advancedSearch.searchTarget + advancedSearch: this.advancedSearch } return this.hooks.wrapObsFun( @@ -319,4 +327,12 @@ export class SearchComponent implements OnInit, OnDestroy { return 'local' } + + private checkFieldsAndGetError () { + if (this.advancedSearch.host && !validateHost(this.advancedSearch.host)) { + return $localize`PeerTube instance host filter is invalid` + } + + return undefined + } } -- cgit v1.2.3