]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix tags in search filters
authorChocobozzz <me@florianbigard.com>
Tue, 11 Aug 2020 07:22:42 +0000 (09:22 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 11 Aug 2020 07:41:55 +0000 (09:41 +0200)
12 files changed:
client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-edit.component.html
client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-edit.ts
client/src/app/+search/search-filters.component.html
client/src/app/+videos/+video-edit/shared/video-edit.component.ts
client/src/app/+videos/+video-edit/video-add-components/video-send.ts
client/src/app/+videos/+video-edit/video-update.component.ts
client/src/app/core/rest/rest.service.ts
client/src/app/helpers/utils.ts
client/src/app/shared/shared-forms/select-channel.component.ts
client/src/app/shared/shared-forms/select-tags.component.html
client/src/app/shared/shared-forms/select-tags.component.ts
client/src/app/shared/shared-search/advanced-search.model.ts

index e61509efd21576dce0771ab2c0f0d663140ac28c..56060359a0f841c847b10dd90e3f18156a23076a 100644 (file)
 
         <div class="form-group">
           <label i18n>Channel</label>
-          <div class="peertube-select-container">
-            <select formControlName="videoChannelId" class="form-control">
-              <option i18n value="undefined" disabled>Channel to bind the playlist to</option>
-              <option></option>
-              <option *ngFor="let channel of userVideoChannels" [value]="channel.id">{{ channel.label }}</option>
-            </select>
-          </div>
+
+          <my-select-channel
+            labelForId="videoChannelIdl" [items]="userVideoChannels" formControlName="videoChannelId"
+          ></my-select-channel>
 
           <div *ngIf="formErrors['videoChannelId']" class="form-error">
             {{ formErrors['videoChannelId'] }}
index 7ae8de75e0263ee2f6cba280ee7ef2561a9a0571..94a0f616817d3b5215e2f08cf9c3db84a5ef7273 100644 (file)
@@ -1,11 +1,12 @@
 import { FormReactive } from '@app/shared/shared-forms'
+import { SelectChannelItem } from '@app/shared/shared-forms/select-channel.component'
 import { VideoConstant, VideoPlaylistPrivacy } from '@shared/models'
 import { VideoPlaylist } from '@shared/models/videos/playlist/video-playlist.model'
 
 export abstract class MyAccountVideoPlaylistEdit extends FormReactive {
   // Declare it here to avoid errors in create template
   videoPlaylistToUpdate: VideoPlaylist
-  userVideoChannels: { id: number, label: string }[] = []
+  userVideoChannels: SelectChannelItem[] = []
   videoPlaylistPrivacies: VideoConstant<VideoPlaylistPrivacy>[] = []
 
   abstract isCreation (): boolean
index b36b1d2aefe158d00018a404999665d3a8a579c7..1d1e7b868fd8f9c90ded0756817299a23bd80601 100644 (file)
         <button i18n class="reset-button reset-button-small" (click)="resetField('tagsAllOf')" *ngIf="advancedSearch.tagsAllOf">
           Reset
         </button>
-        <my-select-tags labelForId="tagsAllOf" id="tagsAllOf" [(ngModel)]="advancedSearch.tagsAllOf"></my-select-tags>
+        <my-select-tags name="tagsAllOf" labelForId="tagsAllOf" id="tagsAllOf" [(ngModel)]="advancedSearch.tagsAllOf"></my-select-tags>
       </div>
 
       <div class="form-group">
         <button i18n class="reset-button reset-button-small" (click)="resetField('tagsOneOf')" *ngIf="advancedSearch.tagsOneOf">
           Reset
         </button>
-        <my-select-tags labelForId="tagsOneOf" id="tagsOneOf" [(ngModel)]="advancedSearch.tagsOneOf"></my-select-tags>
+        <my-select-tags name="tagsOneOf" labelForId="tagsOneOf" id="tagsOneOf" [(ngModel)]="advancedSearch.tagsOneOf"></my-select-tags>
       </div>
 
       <div class="form-group" *ngIf="isSearchTargetEnabled()">
index 4cd3838dede60c1bd6518245ac21c8bd0f1b232f..48c5508f4616bcd040de506a26c0160652935ec0 100644 (file)
@@ -1,16 +1,17 @@
+import { forkJoin } from 'rxjs'
 import { map } from 'rxjs/operators'
 import { Component, Input, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core'
 import { FormArray, FormControl, FormGroup, ValidatorFn, Validators } from '@angular/forms'
 import { ServerService } from '@app/core'
 import { removeElementFromArray } from '@app/helpers'
 import { FormReactiveValidationMessages, FormValidatorService, VideoValidatorsService } from '@app/shared/shared-forms'
+import { SelectChannelItem } from '@app/shared/shared-forms/select-channel.component'
+import { InstanceService } from '@app/shared/shared-instance'
 import { VideoCaptionEdit, VideoEdit, VideoService } from '@app/shared/shared-main'
+import { I18n } from '@ngx-translate/i18n-polyfill'
 import { ServerConfig, VideoConstant, VideoPrivacy } from '@shared/models'
 import { I18nPrimengCalendarService } from './i18n-primeng-calendar.service'
 import { VideoCaptionAddModalComponent } from './video-caption-add-modal.component'
-import { I18n } from '@ngx-translate/i18n-polyfill'
-import { forkJoin } from 'rxjs'
-import { InstanceService } from '@app/shared/shared-instance'
 
 type VideoLanguages = VideoConstant<string> & { group?: string }
 
@@ -23,7 +24,7 @@ export class VideoEditComponent implements OnInit, OnDestroy {
   @Input() form: FormGroup
   @Input() formErrors: { [ id: string ]: string } = {}
   @Input() validationMessages: FormReactiveValidationMessages = {}
-  @Input() userVideoChannels: { id: number, label: string, support: string }[] = []
+  @Input() userVideoChannels: SelectChannelItem[] = []
   @Input() schedulePublicationPossible = true
   @Input() videoCaptions: (VideoCaptionEdit & { captionPath?: string })[] = []
   @Input() waitTranscodingEnabled = true
index 86f2b376f645258ef057200d7dd4220aa9c89dc7..c55e5f9233ae557834b11ff0dd641fc7c717a550 100644 (file)
@@ -3,6 +3,7 @@ import { Directive, EventEmitter, OnInit } from '@angular/core'
 import { AuthService, CanComponentDeactivateResult, Notifier, ServerService } from '@app/core'
 import { populateAsyncUserVideoChannels } from '@app/helpers'
 import { FormReactive } from '@app/shared/shared-forms'
+import { SelectChannelItem } from '@app/shared/shared-forms/select-channel.component'
 import { VideoCaptionEdit, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
 import { LoadingBarService } from '@ngx-loading-bar/core'
 import { ServerConfig, VideoConstant, VideoPrivacy } from '@shared/models'
@@ -10,7 +11,7 @@ import { ServerConfig, VideoConstant, VideoPrivacy } from '@shared/models'
 @Directive()
 // tslint:disable-next-line: directive-class-suffix
 export abstract class VideoSend extends FormReactive implements OnInit {
-  userVideoChannels: { id: number, label: string, support: string, avatarPath?: string }[] = []
+  userVideoChannels: SelectChannelItem[] = []
   videoPrivacies: VideoConstant<VideoPrivacy>[] = []
   videoCaptions: VideoCaptionEdit[] = []
 
index de4f65df3ee56d31f04dae494ecd346825cbc3e4..263c71f3b813ec1eda420180eb55510b95c76535 100644 (file)
@@ -3,6 +3,7 @@ import { Component, HostListener, OnInit } from '@angular/core'
 import { ActivatedRoute, Router } from '@angular/router'
 import { Notifier } from '@app/core'
 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
+import { SelectChannelItem } from '@app/shared/shared-forms/select-channel.component'
 import { VideoCaptionEdit, VideoCaptionService, VideoDetails, VideoEdit, VideoService } from '@app/shared/shared-main'
 import { LoadingBarService } from '@ngx-loading-bar/core'
 import { I18n } from '@ngx-translate/i18n-polyfill'
@@ -17,7 +18,7 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
   video: VideoEdit
 
   isUpdatingVideo = false
-  userVideoChannels: { id: number, label: string, support: string, avatar?: string }[] = []
+  userVideoChannels: SelectChannelItem[] = []
   schedulePublicationPossible = false
   videoCaptions: VideoCaptionEdit[] = []
   waitTranscodingEnabled = true
index 9e32c6d582eefc3405f2b8b52844d8ceea71738b..4f1fc884846f636b6f4baee4c8738b5394c57681 100644 (file)
@@ -49,7 +49,7 @@ export class RestService {
       const value = object[name]
       if (value === undefined || value === null) continue
 
-      if (Array.isArray(value) && value.length !== 0) {
+      if (Array.isArray(value)) {
         for (const v of value) params = params.append(name, v)
       } else {
         params = params.append(name, value)
index aa37fdd46b8dfd70bbcbcca66621bca66d561c1a..b925e6d987350580acfdd0321157c9578ee7f5b9 100644 (file)
@@ -1,6 +1,7 @@
 import { DatePipe } from '@angular/common'
 import { environment } from '../../environments/environment'
 import { AuthService } from '../core/auth'
+import { SelectChannelItem } from '@app/shared/shared-forms/select-channel.component'
 
 // Thanks: https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
 function getParameterByName (name: string, url: string) {
@@ -18,7 +19,7 @@ function getParameterByName (name: string, url: string) {
 
 function populateAsyncUserVideoChannels (
   authService: AuthService,
-  channel: { id: number, label: string, support?: string, avatarPath?: string, recent?: boolean }[]
+  channel: SelectChannelItem[]
 ) {
   return new Promise(res => {
     authService.userInformationLoaded
index de98c8c0af04ceea8584620c579e0f8493635e94..ef4192095dbeff601c86352d25b57257bac103f7 100644 (file)
@@ -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
 
index 0609c9d2087c5fa6cc40f64560e270889d7c2214..e1cd50882c02e65ee983671953cb8ffce9fd8aea 100644 (file)
@@ -1,6 +1,6 @@
 <ng-select
-  [items]="items"
-  [(ngModel)]="_items"
+  [items]="availableItems"
+  [(ngModel)]="selectedItems"
   (ngModelChange)="onModelChange()"
   i18n-placeholder placeholder="Enter a new tag"
   [maxSelectedItems]="5"
index 2e07d7e8f968c7535881540177ec93209739335c..a8a19d7887fece59054676883003002726aecc28 100644 (file)
@@ -14,14 +14,14 @@ import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms'
   ]
 })
 export class SelectTagsComponent implements ControlValueAccessor {
-  @Input() items: string[] = []
-  @Input() _items: string[] = []
+  @Input() availableItems: string[] = []
+  @Input() selectedItems: string[] = []
 
   propagateChange = (_: any) => { /* 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)
   }
 }
index 516854a8c210360a6feb67e27346f4b9bf5ebcfc..30badc8faf20ef52a07e5ecc23965b250df5fa70 100644 (file)
@@ -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