From cddf45035389cc7d9003ea2b64fff3c28cd368d9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 24 Jul 2018 10:13:54 +0200 Subject: [PATCH] Add ability to sort the search --- .../src/app/search/advanced-search.model.ts | 15 +++++++++++-- .../app/search/search-filters.component.html | 9 ++++++++ .../app/search/search-filters.component.ts | 22 ++++++++++++++++--- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/client/src/app/search/advanced-search.model.ts b/client/src/app/search/advanced-search.model.ts index aad436788..ce22c3f84 100644 --- a/client/src/app/search/advanced-search.model.ts +++ b/client/src/app/search/advanced-search.model.ts @@ -18,6 +18,8 @@ export class AdvancedSearch { durationMin: number // seconds durationMax: number // seconds + sort: string + constructor (options?: { startDate?: string endDate?: string @@ -29,6 +31,7 @@ export class AdvancedSearch { tagsAllOf?: string durationMin?: string durationMax?: string + sort?: string }) { if (!options) return @@ -45,11 +48,15 @@ export class AdvancedSearch { if (isNaN(this.durationMin)) this.durationMin = undefined if (isNaN(this.durationMax)) this.durationMax = undefined + + this.sort = options.sort || '-match' } containsValues () { const obj = this.toUrlObject() for (const k of Object.keys(obj)) { + if (k === 'sort') continue // Exception + if (obj[k] !== undefined) return true } @@ -67,6 +74,8 @@ export class AdvancedSearch { this.tagsAllOf = undefined this.durationMin = undefined this.durationMax = undefined + + this.sort = '-match' } toUrlObject () { @@ -80,7 +89,8 @@ export class AdvancedSearch { tagsOneOf: this.tagsOneOf, tagsAllOf: this.tagsAllOf, durationMin: this.durationMin, - durationMax: this.durationMax + durationMax: this.durationMax, + sort: this.sort } } @@ -95,7 +105,8 @@ export class AdvancedSearch { tagsOneOf: this.tagsOneOf ? this.tagsOneOf.split(',') : undefined, tagsAllOf: this.tagsAllOf ? this.tagsAllOf.split(',') : undefined, durationMin: this.durationMin, - durationMax: this.durationMax + durationMax: this.durationMax, + sort: this.sort } } } diff --git a/client/src/app/search/search-filters.component.html b/client/src/app/search/search-filters.component.html index f8b3675e5..74bb781f4 100644 --- a/client/src/app/search/search-filters.component.html +++ b/client/src/app/search/search-filters.component.html @@ -2,6 +2,15 @@
+
+
Sort
+ +
+ + +
+
+
Published date
diff --git a/client/src/app/search/search-filters.component.ts b/client/src/app/search/search-filters.component.ts index 4219f99a9..a40648eb4 100644 --- a/client/src/app/search/search-filters.component.ts +++ b/client/src/app/search/search-filters.component.ts @@ -23,6 +23,7 @@ export class SearchFiltersComponent implements OnInit { videoLanguages: VideoConstant[] = [] publishedDateRanges: { id: string, label: string }[] = [] + sorts: { id: string, label: string }[] = [] durationRanges: { id: string, label: string }[] = [] publishedDateRange: string @@ -59,15 +60,30 @@ export class SearchFiltersComponent implements OnInit { this.durationRanges = [ { id: 'short', - label: this.i18n('Short (< 4 minutes)') + label: this.i18n('Short (< 4 min)') }, { id: 'long', - label: this.i18n('Long (> 10 minutes)') + label: this.i18n('Long (> 10 min)') }, { id: 'medium', - label: this.i18n('Medium (4-10 minutes)') + label: this.i18n('Medium (4-10 min)') + } + ] + + this.sorts = [ + { + id: '-match', + label: this.i18n('Relevance') + }, + { + id: '-publishedAt', + label: this.i18n('Publish date') + }, + { + id: '-views', + label: this.i18n('Views') } ] } -- 2.25.1