aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared')
-rw-r--r--client/src/app/shared/shared-forms/select-channel.component.ts13
-rw-r--r--client/src/app/shared/shared-forms/select-tags.component.html4
-rw-r--r--client/src/app/shared/shared-forms/select-tags.component.ts12
-rw-r--r--client/src/app/shared/shared-search/advanced-search.model.ts32
4 files changed, 39 insertions, 22 deletions
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 @@
1import { Component, Input, forwardRef, ViewChild } from '@angular/core' 1import { Component, forwardRef, Input } from '@angular/core'
2import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms' 2import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
3import { Actor } from '../shared-main' 3import { Actor } from '../shared-main'
4 4
5export type SelectChannelItem = {
6 id: number
7 label: string
8 support: string
9 avatarPath?: string
10}
11
5@Component({ 12@Component({
6 selector: 'my-select-channel', 13 selector: 'my-select-channel',
7 styleUrls: [ './select-shared.component.scss' ], 14 styleUrls: [ './select-shared.component.scss' ],
@@ -15,7 +22,7 @@ import { Actor } from '../shared-main'
15 ] 22 ]
16}) 23})
17export class SelectChannelComponent implements ControlValueAccessor { 24export class SelectChannelComponent implements ControlValueAccessor {
18 @Input() items: { id: number, label: string, support: string, avatarPath?: string }[] = [] 25 @Input() items: SelectChannelItem[] = []
19 26
20 selectedId: number 27 selectedId: number
21 28
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 @@
1<ng-select 1<ng-select
2 [items]="items" 2 [items]="availableItems"
3 [(ngModel)]="_items" 3 [(ngModel)]="selectedItems"
4 (ngModelChange)="onModelChange()" 4 (ngModelChange)="onModelChange()"
5 i18n-placeholder placeholder="Enter a new tag" 5 i18n-placeholder placeholder="Enter a new tag"
6 [maxSelectedItems]="5" 6 [maxSelectedItems]="5"
diff --git a/client/src/app/shared/shared-forms/select-tags.component.ts b/client/src/app/shared/shared-forms/select-tags.component.ts
index 2e07d7e8f..a8a19d788 100644
--- a/client/src/app/shared/shared-forms/select-tags.component.ts
+++ b/client/src/app/shared/shared-forms/select-tags.component.ts
@@ -14,14 +14,14 @@ import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms'
14 ] 14 ]
15}) 15})
16export class SelectTagsComponent implements ControlValueAccessor { 16export class SelectTagsComponent implements ControlValueAccessor {
17 @Input() items: string[] = [] 17 @Input() availableItems: string[] = []
18 @Input() _items: string[] = [] 18 @Input() selectedItems: string[] = []
19 19
20 propagateChange = (_: any) => { /* empty */ } 20 propagateChange = (_: any) => { /* empty */ }
21 21
22 writeValue (items: string[]) { 22 writeValue (items: string[]) {
23 this._items = items 23 this.selectedItems = items
24 this.propagateChange(this._items) 24 this.propagateChange(this.selectedItems)
25 } 25 }
26 26
27 registerOnChange (fn: (_: any) => void) { 27 registerOnChange (fn: (_: any) => void) {
@@ -33,6 +33,8 @@ export class SelectTagsComponent implements ControlValueAccessor {
33 } 33 }
34 34
35 onModelChange () { 35 onModelChange () {
36 this.propagateChange(this._items) 36 console.log(this.selectedItems)
37
38 this.propagateChange(this.selectedItems)
37 } 39 }
38} 40}
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 {
15 15
16 languageOneOf: string 16 languageOneOf: string
17 17
18 tagsOneOf: string 18 tagsOneOf: string[]
19 tagsAllOf: string 19 tagsAllOf: string[]
20 20
21 durationMin: number // seconds 21 durationMin: number // seconds
22 durationMax: number // seconds 22 durationMax: number // seconds
@@ -37,8 +37,10 @@ export class AdvancedSearch {
37 categoryOneOf?: string 37 categoryOneOf?: string
38 licenceOneOf?: string 38 licenceOneOf?: string
39 languageOneOf?: string 39 languageOneOf?: string
40 tagsOneOf?: string 40
41 tagsAllOf?: string 41 tagsOneOf?: any
42 tagsAllOf?: any
43
42 durationMin?: string 44 durationMin?: string
43 durationMax?: string 45 durationMax?: string
44 sort?: string 46 sort?: string
@@ -55,8 +57,8 @@ export class AdvancedSearch {
55 this.categoryOneOf = options.categoryOneOf || undefined 57 this.categoryOneOf = options.categoryOneOf || undefined
56 this.licenceOneOf = options.licenceOneOf || undefined 58 this.licenceOneOf = options.licenceOneOf || undefined
57 this.languageOneOf = options.languageOneOf || undefined 59 this.languageOneOf = options.languageOneOf || undefined
58 this.tagsOneOf = options.tagsOneOf || undefined 60 this.tagsOneOf = this.intoArray(options.tagsOneOf)
59 this.tagsAllOf = options.tagsAllOf || undefined 61 this.tagsAllOf = this.intoArray(options.tagsAllOf)
60 this.durationMin = parseInt(options.durationMin, 10) 62 this.durationMin = parseInt(options.durationMin, 10)
61 this.durationMax = parseInt(options.durationMax, 10) 63 this.durationMax = parseInt(options.durationMax, 10)
62 64
@@ -69,13 +71,11 @@ export class AdvancedSearch {
69 } 71 }
70 72
71 containsValues () { 73 containsValues () {
72 const exceptions = new Set([ 'sort', 'searchTarget' ])
73
74 const obj = this.toUrlObject() 74 const obj = this.toUrlObject()
75 for (const k of Object.keys(obj)) { 75 for (const k of Object.keys(obj)) {
76 if (this.silentFilters.has(k)) continue 76 if (this.silentFilters.has(k)) continue
77 77
78 if (obj[k] !== undefined && obj[k] !== '') return true 78 if (this.isValidValue(obj[k])) return true
79 } 79 }
80 80
81 return false 81 return false
@@ -127,8 +127,8 @@ export class AdvancedSearch {
127 categoryOneOf: this.intoArray(this.categoryOneOf), 127 categoryOneOf: this.intoArray(this.categoryOneOf),
128 licenceOneOf: this.intoArray(this.licenceOneOf), 128 licenceOneOf: this.intoArray(this.licenceOneOf),
129 languageOneOf: this.intoArray(this.languageOneOf), 129 languageOneOf: this.intoArray(this.languageOneOf),
130 tagsOneOf: this.intoArray(this.tagsOneOf), 130 tagsOneOf: this.tagsOneOf,
131 tagsAllOf: this.intoArray(this.tagsAllOf), 131 tagsAllOf: this.tagsAllOf,
132 durationMin: this.durationMin, 132 durationMin: this.durationMin,
133 durationMax: this.durationMax, 133 durationMax: this.durationMax,
134 sort: this.sort, 134 sort: this.sort,
@@ -143,12 +143,20 @@ export class AdvancedSearch {
143 for (const k of Object.keys(obj)) { 143 for (const k of Object.keys(obj)) {
144 if (this.silentFilters.has(k)) continue 144 if (this.silentFilters.has(k)) continue
145 145
146 if (obj[k] !== undefined && obj[k] !== '') acc++ 146 if (this.isValidValue(obj[k])) acc++
147 } 147 }
148 148
149 return acc 149 return acc
150 } 150 }
151 151
152 private isValidValue (val: any) {
153 if (val === undefined) return false
154 if (val === '') return false
155 if (Array.isArray(val) && val.length === 0) return false
156
157 return true
158 }
159
152 private intoArray (value: any) { 160 private intoArray (value: any) {
153 if (!value) return undefined 161 if (!value) return undefined
154 if (Array.isArray(value)) return value 162 if (Array.isArray(value)) return value