Update Angular -> 8.2.0
[oweals/peertube.git] / client / src / app / search / search-filters.component.ts
index 4219f99a9642dcfdeaaf86b025ab6cb1fc2ed6d7..e13aa91bf09729ca497d7a86d2fe50336cd2af08 100644 (file)
@@ -1,10 +1,6 @@
 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
-import { ActivatedRoute } from '@angular/router'
-import { RedirectService, ServerService } from '@app/core'
-import { NotificationsService } from 'angular2-notifications'
-import { SearchService } from '@app/search/search.service'
+import { ServerService } from '@app/core'
 import { I18n } from '@ngx-translate/i18n-polyfill'
-import { MetaService } from '@ngx-meta/core'
 import { AdvancedSearch } from '@app/search/advanced-search.model'
 import { VideoConstant } from '../../../../shared'
 
@@ -18,23 +14,22 @@ export class SearchFiltersComponent implements OnInit {
 
   @Output() filtered = new EventEmitter<AdvancedSearch>()
 
-  videoCategories: VideoConstant<string>[] = []
-  videoLicences: VideoConstant<string>[] = []
+  videoCategories: VideoConstant<number>[] = []
+  videoLicences: VideoConstant<number>[] = []
   videoLanguages: VideoConstant<string>[] = []
 
   publishedDateRanges: { id: string, label: string }[] = []
+  sorts: { id: string, label: string }[] = []
   durationRanges: { id: string, label: string }[] = []
 
   publishedDateRange: string
   durationRange: string
 
+  originallyPublishedStartYear: string
+  originallyPublishedEndYear: string
+
   constructor (
     private i18n: I18n,
-    private route: ActivatedRoute,
-    private metaService: MetaService,
-    private redirectService: RedirectService,
-    private notificationsService: NotificationsService,
-    private searchService: SearchService,
     private serverService: ServerService
   ) {
     this.publishedDateRanges = [
@@ -59,15 +54,30 @@ export class SearchFiltersComponent implements OnInit {
     this.durationRanges = [
       {
         id: 'short',
-        label: this.i18n('Short (< 4 minutes)')
+        label: this.i18n('Short (< 4 min)')
+      },
+      {
+        id: 'medium',
+        label: this.i18n('Medium (4-10 min)')
       },
       {
         id: 'long',
-        label: this.i18n('Long (> 10 minutes)')
+        label: this.i18n('Long (> 10 min)')
+      }
+    ]
+
+    this.sorts = [
+      {
+        id: '-match',
+        label: this.i18n('Relevance')
       },
       {
-        id: 'medium',
-        label: this.i18n('Medium (4-10 minutes)')
+        id: '-publishedAt',
+        label: this.i18n('Publish date')
+      },
+      {
+        id: '-views',
+        label: this.i18n('Views')
       }
     ]
   }
@@ -79,15 +89,27 @@ export class SearchFiltersComponent implements OnInit {
 
     this.loadFromDurationRange()
     this.loadFromPublishedRange()
+    this.loadOriginallyPublishedAtYears()
   }
 
   formUpdated () {
     this.updateModelFromDurationRange()
     this.updateModelFromPublishedRange()
+    this.updateModelFromOriginallyPublishedAtYears()
 
     this.filtered.emit(this.advancedSearch)
   }
 
+  private loadOriginallyPublishedAtYears () {
+    this.originallyPublishedStartYear = this.advancedSearch.originallyPublishedStartDate
+      ? new Date(this.advancedSearch.originallyPublishedStartDate).getFullYear().toString()
+      : null
+
+    this.originallyPublishedEndYear = this.advancedSearch.originallyPublishedEndDate
+      ? new Date(this.advancedSearch.originallyPublishedEndDate).getFullYear().toString()
+      : null
+  }
+
   private loadFromDurationRange () {
     if (this.advancedSearch.durationMin || this.advancedSearch.durationMax) {
       const fourMinutes = 60 * 4
@@ -120,6 +142,32 @@ export class SearchFiltersComponent implements OnInit {
     }
   }
 
+  private updateModelFromOriginallyPublishedAtYears () {
+    const baseDate = new Date()
+    baseDate.setHours(0, 0, 0, 0)
+    baseDate.setMonth(0, 1)
+
+    if (this.originallyPublishedStartYear) {
+      const year = parseInt(this.originallyPublishedStartYear, 10)
+      const start = new Date(baseDate)
+      start.setFullYear(year)
+
+      this.advancedSearch.originallyPublishedStartDate = start.toISOString()
+    } else {
+      this.advancedSearch.originallyPublishedStartDate = null
+    }
+
+    if (this.originallyPublishedEndYear) {
+      const year = parseInt(this.originallyPublishedEndYear, 10)
+      const end = new Date(baseDate)
+      end.setFullYear(year)
+
+      this.advancedSearch.originallyPublishedEndDate = end.toISOString()
+    } else {
+      this.advancedSearch.originallyPublishedEndDate = null
+    }
+  }
+
   private updateModelFromDurationRange () {
     if (!this.durationRange) return
 
@@ -167,4 +215,5 @@ export class SearchFiltersComponent implements OnInit {
 
     this.advancedSearch.startDate = date.toISOString()
   }
+
 }