From 9abd170dec9a0b929da1f0947e3c7019e38631da Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 11 Aug 2020 09:22:42 +0200 Subject: Fix tags in search filters --- .../shared-forms/select-channel.component.ts | 13 +++++++-- .../shared/shared-forms/select-tags.component.html | 4 +-- .../shared/shared-forms/select-tags.component.ts | 12 ++++---- .../shared/shared-search/advanced-search.model.ts | 32 ++++++++++++++-------- 4 files changed, 39 insertions(+), 22 deletions(-) (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/shared-forms/select-channel.component.ts b/client/src/app/shared/shared-forms/select-channel.component.ts index de98c8c0a..ef4192095 100644 --- a/client/src/app/shared/shared-forms/select-channel.component.ts +++ b/client/src/app/shared/shared-forms/select-channel.component.ts @@ -1,7 +1,14 @@ -import { Component, Input, forwardRef, ViewChild } from '@angular/core' -import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms' +import { Component, forwardRef, Input } from '@angular/core' +import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms' import { Actor } from '../shared-main' +export type SelectChannelItem = { + id: number + label: string + support: string + avatarPath?: string +} + @Component({ selector: 'my-select-channel', styleUrls: [ './select-shared.component.scss' ], @@ -15,7 +22,7 @@ import { Actor } from '../shared-main' ] }) export class SelectChannelComponent implements ControlValueAccessor { - @Input() items: { id: number, label: string, support: string, avatarPath?: string }[] = [] + @Input() items: SelectChannelItem[] = [] selectedId: number diff --git a/client/src/app/shared/shared-forms/select-tags.component.html b/client/src/app/shared/shared-forms/select-tags.component.html index 0609c9d20..e1cd50882 100644 --- a/client/src/app/shared/shared-forms/select-tags.component.html +++ b/client/src/app/shared/shared-forms/select-tags.component.html @@ -1,6 +1,6 @@ { /* empty */ } writeValue (items: string[]) { - this._items = items - this.propagateChange(this._items) + this.selectedItems = items + this.propagateChange(this.selectedItems) } registerOnChange (fn: (_: any) => void) { @@ -33,6 +33,8 @@ export class SelectTagsComponent implements ControlValueAccessor { } onModelChange () { - this.propagateChange(this._items) + console.log(this.selectedItems) + + this.propagateChange(this.selectedItems) } } diff --git a/client/src/app/shared/shared-search/advanced-search.model.ts b/client/src/app/shared/shared-search/advanced-search.model.ts index 516854a8c..30badc8fa 100644 --- a/client/src/app/shared/shared-search/advanced-search.model.ts +++ b/client/src/app/shared/shared-search/advanced-search.model.ts @@ -15,8 +15,8 @@ export class AdvancedSearch { languageOneOf: string - tagsOneOf: string - tagsAllOf: string + tagsOneOf: string[] + tagsAllOf: string[] durationMin: number // seconds durationMax: number // seconds @@ -37,8 +37,10 @@ export class AdvancedSearch { categoryOneOf?: string licenceOneOf?: string languageOneOf?: string - tagsOneOf?: string - tagsAllOf?: string + + tagsOneOf?: any + tagsAllOf?: any + durationMin?: string durationMax?: string sort?: string @@ -55,8 +57,8 @@ export class AdvancedSearch { this.categoryOneOf = options.categoryOneOf || undefined this.licenceOneOf = options.licenceOneOf || undefined this.languageOneOf = options.languageOneOf || undefined - this.tagsOneOf = options.tagsOneOf || undefined - this.tagsAllOf = options.tagsAllOf || undefined + this.tagsOneOf = this.intoArray(options.tagsOneOf) + this.tagsAllOf = this.intoArray(options.tagsAllOf) this.durationMin = parseInt(options.durationMin, 10) this.durationMax = parseInt(options.durationMax, 10) @@ -69,13 +71,11 @@ export class AdvancedSearch { } containsValues () { - const exceptions = new Set([ 'sort', 'searchTarget' ]) - const obj = this.toUrlObject() for (const k of Object.keys(obj)) { if (this.silentFilters.has(k)) continue - if (obj[k] !== undefined && obj[k] !== '') return true + if (this.isValidValue(obj[k])) return true } return false @@ -127,8 +127,8 @@ export class AdvancedSearch { categoryOneOf: this.intoArray(this.categoryOneOf), licenceOneOf: this.intoArray(this.licenceOneOf), languageOneOf: this.intoArray(this.languageOneOf), - tagsOneOf: this.intoArray(this.tagsOneOf), - tagsAllOf: this.intoArray(this.tagsAllOf), + tagsOneOf: this.tagsOneOf, + tagsAllOf: this.tagsAllOf, durationMin: this.durationMin, durationMax: this.durationMax, sort: this.sort, @@ -143,12 +143,20 @@ export class AdvancedSearch { for (const k of Object.keys(obj)) { if (this.silentFilters.has(k)) continue - if (obj[k] !== undefined && obj[k] !== '') acc++ + if (this.isValidValue(obj[k])) acc++ } return acc } + private isValidValue (val: any) { + if (val === undefined) return false + if (val === '') return false + if (Array.isArray(val) && val.length === 0) return false + + return true + } + private intoArray (value: any) { if (!value) return undefined if (Array.isArray(value)) return value -- cgit v1.2.3