]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+search/search-filters.component.ts
Merge branch 'release/5.0.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / +search / search-filters.component.ts
index a2af9a9427a3b3ab3a2ef0fed56a1c5628421475..f9de04706218d7106440e81a0d9d78e308fe56e9 100644 (file)
@@ -1,7 +1,9 @@
 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
 import { ServerService } from '@app/core'
 import { AdvancedSearch } from '@app/shared/shared-search'
-import { ServerConfig, VideoConstant } from '@shared/models'
+import { HTMLServerConfig, VideoConstant } from '@shared/models'
+
+type FormOption = { id: string, label: string }
 
 @Component({
   selector: 'my-search-filters',
@@ -17,9 +19,9 @@ export class SearchFiltersComponent implements OnInit {
   videoLicences: VideoConstant<number>[] = []
   videoLanguages: VideoConstant<string>[] = []
 
-  publishedDateRanges: { id: string, label: string }[] = []
-  sorts: { id: string, label: string }[] = []
-  durationRanges: { id: string, label: string }[] = []
+  publishedDateRanges: FormOption[] = []
+  sorts: FormOption[] = []
+  durationRanges: FormOption[] = []
 
   publishedDateRange: string
   durationRange: string
@@ -27,16 +29,12 @@ export class SearchFiltersComponent implements OnInit {
   originallyPublishedStartYear: string
   originallyPublishedEndYear: string
 
-  private serverConfig: ServerConfig
+  private serverConfig: HTMLServerConfig
 
   constructor (
     private serverService: ServerService
   ) {
     this.publishedDateRanges = [
-      {
-        id: 'any_published_date',
-        label: $localize`Any`
-      },
       {
         id: 'today',
         label: $localize`Today`
@@ -56,10 +54,6 @@ export class SearchFiltersComponent implements OnInit {
     ]
 
     this.durationRanges = [
-      {
-        id: 'any_duration',
-        label: $localize`Any`
-      },
       {
         id: 'short',
         label: $localize`Short (< 4 min)`
@@ -91,9 +85,7 @@ export class SearchFiltersComponent implements OnInit {
   }
 
   ngOnInit () {
-    this.serverConfig = this.serverService.getTmpConfig()
-    this.serverService.getConfig()
-        .subscribe(config => this.serverConfig = config)
+    this.serverConfig = this.serverService.getHTMLConfig()
 
     this.serverService.getVideoCategories().subscribe(categories => this.videoCategories = categories)
     this.serverService.getVideoLicences().subscribe(licences => this.videoLicences = licences)
@@ -104,24 +96,26 @@ export class SearchFiltersComponent implements OnInit {
     this.loadOriginallyPublishedAtYears()
   }
 
-  inputUpdated () {
+  onDurationOrPublishedUpdated () {
     this.updateModelFromDurationRange()
     this.updateModelFromPublishedRange()
     this.updateModelFromOriginallyPublishedAtYears()
   }
 
   formUpdated () {
-    this.inputUpdated()
+    this.onDurationOrPublishedUpdated()
     this.filtered.emit(this.advancedSearch)
   }
 
   reset () {
     this.advancedSearch.reset()
+
+    this.resetOriginalPublicationYears()
+
     this.durationRange = undefined
     this.publishedDateRange = undefined
-    this.originallyPublishedStartYear = undefined
-    this.originallyPublishedEndYear = undefined
-    this.inputUpdated()
+
+    this.onDurationOrPublishedUpdated()
   }
 
   resetField (fieldName: string, value?: any) {
@@ -130,7 +124,7 @@ export class SearchFiltersComponent implements OnInit {
 
   resetLocalField (fieldName: string, value?: any) {
     this[fieldName] = value
-    this.inputUpdated()
+    this.onDurationOrPublishedUpdated()
   }
 
   resetOriginalPublicationYears () {
@@ -144,11 +138,11 @@ export class SearchFiltersComponent implements OnInit {
   private loadOriginallyPublishedAtYears () {
     this.originallyPublishedStartYear = this.advancedSearch.originallyPublishedStartDate
       ? new Date(this.advancedSearch.originallyPublishedStartDate).getFullYear().toString()
-      : null
+      : undefined
 
     this.originallyPublishedEndYear = this.advancedSearch.originallyPublishedEndDate
       ? new Date(this.advancedSearch.originallyPublishedEndDate).getFullYear().toString()
-      : null
+      : undefined
   }
 
   private loadFromDurationRange () {
@@ -195,7 +189,7 @@ export class SearchFiltersComponent implements OnInit {
 
       this.advancedSearch.originallyPublishedStartDate = start.toISOString()
     } else {
-      this.advancedSearch.originallyPublishedStartDate = null
+      this.advancedSearch.originallyPublishedStartDate = undefined
     }
 
     if (this.originallyPublishedEndYear) {
@@ -205,7 +199,7 @@ export class SearchFiltersComponent implements OnInit {
 
       this.advancedSearch.originallyPublishedEndDate = end.toISOString()
     } else {
-      this.advancedSearch.originallyPublishedEndDate = null
+      this.advancedSearch.originallyPublishedEndDate = undefined
     }
   }