]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/search/search-filters.component.ts
Reorganize client shared modules
[github/Chocobozzz/PeerTube.git] / client / src / app / search / search-filters.component.ts
index 762a6b7f2833264677df9de6c5d631598f5fb74b..14a5d04846f495236e8b9b020acf2bcab58eefd4 100644 (file)
@@ -1,8 +1,10 @@
 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
+import { ValidatorFn } from '@angular/forms'
 import { ServerService } from '@app/core'
-import { I18n } from '@ngx-translate/i18n-polyfill'
 import { AdvancedSearch } from '@app/search/advanced-search.model'
-import { VideoConstant } from '../../../../shared'
+import { VideoValidatorsService } from '@app/shared/shared-forms'
+import { I18n } from '@ngx-translate/i18n-polyfill'
+import { ServerConfig, VideoConstant } from '@shared/models'
 
 @Component({
   selector: 'my-search-filters',
@@ -18,6 +20,9 @@ export class SearchFiltersComponent implements OnInit {
   videoLicences: VideoConstant<number>[] = []
   videoLanguages: VideoConstant<string>[] = []
 
+  tagValidators: ValidatorFn[]
+  tagValidatorsMessages: { [ name: string ]: string }
+
   publishedDateRanges: { id: string, label: string }[] = []
   sorts: { id: string, label: string }[] = []
   durationRanges: { id: string, label: string }[] = []
@@ -28,11 +33,20 @@ export class SearchFiltersComponent implements OnInit {
   originallyPublishedStartYear: string
   originallyPublishedEndYear: string
 
+  private serverConfig: ServerConfig
+
   constructor (
     private i18n: I18n,
+    private videoValidatorsService: VideoValidatorsService,
     private serverService: ServerService
   ) {
+    this.tagValidators = this.videoValidatorsService.VIDEO_TAGS.VALIDATORS
+    this.tagValidatorsMessages = this.videoValidatorsService.VIDEO_TAGS.MESSAGES
     this.publishedDateRanges = [
+      {
+        id: 'any_published_date',
+        label: this.i18n('Any')
+      },
       {
         id: 'today',
         label: this.i18n('Today')
@@ -53,16 +67,20 @@ export class SearchFiltersComponent implements OnInit {
 
     this.durationRanges = [
       {
-        id: 'short',
-        label: this.i18n('Short (< 4 min)')
+        id: 'any_duration',
+        label: this.i18n('Any')
       },
       {
-        id: 'long',
-        label: this.i18n('Long (> 10 min)')
+        id: 'short',
+        label: this.i18n('Short (< 4 min)')
       },
       {
         id: 'medium',
         label: this.i18n('Medium (4-10 min)')
+      },
+      {
+        id: 'long',
+        label: this.i18n('Long (> 10 min)')
       }
     ]
 
@@ -83,23 +101,56 @@ export class SearchFiltersComponent implements OnInit {
   }
 
   ngOnInit () {
-    this.videoCategories = this.serverService.getVideoCategories()
-    this.videoLicences = this.serverService.getVideoLicences()
-    this.videoLanguages = this.serverService.getVideoLanguages()
+    this.serverConfig = this.serverService.getTmpConfig()
+    this.serverService.getConfig()
+        .subscribe(config => this.serverConfig = config)
+
+    this.serverService.getVideoCategories().subscribe(categories => this.videoCategories = categories)
+    this.serverService.getVideoLicences().subscribe(licences => this.videoLicences = licences)
+    this.serverService.getVideoLanguages().subscribe(languages => this.videoLanguages = languages)
 
     this.loadFromDurationRange()
     this.loadFromPublishedRange()
     this.loadOriginallyPublishedAtYears()
   }
 
-  formUpdated () {
+  inputUpdated () {
     this.updateModelFromDurationRange()
     this.updateModelFromPublishedRange()
     this.updateModelFromOriginallyPublishedAtYears()
+  }
 
+  formUpdated () {
+    this.inputUpdated()
     this.filtered.emit(this.advancedSearch)
   }
 
+  reset () {
+    this.advancedSearch.reset()
+    this.durationRange = undefined
+    this.publishedDateRange = undefined
+    this.originallyPublishedStartYear = undefined
+    this.originallyPublishedEndYear = undefined
+    this.inputUpdated()
+  }
+
+  resetField (fieldName: string, value?: any) {
+    this.advancedSearch[fieldName] = value
+  }
+
+  resetLocalField (fieldName: string, value?: any) {
+    this[fieldName] = value
+    this.inputUpdated()
+  }
+
+  resetOriginalPublicationYears () {
+    this.originallyPublishedStartYear = this.originallyPublishedEndYear = undefined
+  }
+
+  isSearchTargetEnabled () {
+    return this.serverConfig.search.searchIndex.enabled && this.serverConfig.search.searchIndex.disableLocalSearch !== true
+  }
+
   private loadOriginallyPublishedAtYears () {
     this.originallyPublishedStartYear = this.advancedSearch.originallyPublishedStartDate
       ? new Date(this.advancedSearch.originallyPublishedStartDate).getFullYear().toString()
@@ -215,5 +266,4 @@ export class SearchFiltersComponent implements OnInit {
 
     this.advancedSearch.startDate = date.toISOString()
   }
-
 }