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'
@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 = [
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')
}
]
}
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
}
}
+ 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
this.advancedSearch.startDate = date.toISOString()
}
+
}