import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
import { ServerService } from '@app/core'
-import { VideoValidatorsService } from '@app/shared/shared-forms'
import { AdvancedSearch } from '@app/shared/shared-search'
-import { I18n } from '@ngx-translate/i18n-polyfill'
-import { ServerConfig, VideoConstant } from '@shared/models'
+import { HTMLServerConfig, VideoConstant } from '@shared/models'
+
+type FormOption = { id: string, label: string }
@Component({
selector: 'my-search-filters',
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[] = []
+ videoType: FormOption[] = []
publishedDateRange: string
durationRange: string
originallyPublishedStartYear: string
originallyPublishedEndYear: string
- private serverConfig: ServerConfig
+ private serverConfig: HTMLServerConfig
constructor (
- private i18n: I18n,
- private videoValidatorsService: VideoValidatorsService,
private serverService: ServerService
) {
this.publishedDateRanges = [
- {
- id: 'any_published_date',
- label: this.i18n('Any')
- },
{
id: 'today',
- label: this.i18n('Today')
+ label: $localize`Today`
},
{
id: 'last_7days',
- label: this.i18n('Last 7 days')
+ label: $localize`Last 7 days`
},
{
id: 'last_30days',
- label: this.i18n('Last 30 days')
+ label: $localize`Last 30 days`
},
{
id: 'last_365days',
- label: this.i18n('Last 365 days')
+ label: $localize`Last 365 days`
}
]
- this.durationRanges = [
+ this.videoType = [
{
- id: 'any_duration',
- label: this.i18n('Any')
+ id: 'vod',
+ label: $localize`VOD videos`
},
+ {
+ id: 'live',
+ label: $localize`Live videos`
+ }
+ ]
+
+ this.durationRanges = [
{
id: 'short',
- label: this.i18n('Short (< 4 min)')
+ label: $localize`Short (< 4 min)`
},
{
id: 'medium',
- label: this.i18n('Medium (4-10 min)')
+ label: $localize`Medium (4-10 min)`
},
{
id: 'long',
- label: this.i18n('Long (> 10 min)')
+ label: $localize`Long (> 10 min)`
}
]
this.sorts = [
{
id: '-match',
- label: this.i18n('Relevance')
+ label: $localize`Relevance`
},
{
id: '-publishedAt',
- label: this.i18n('Publish date')
+ label: $localize`Publish date`
},
{
id: '-views',
- label: this.i18n('Views')
+ label: $localize`Views`
}
]
}
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)
this.loadOriginallyPublishedAtYears()
}
- inputUpdated () {
+ onInputUpdated () {
this.updateModelFromDurationRange()
this.updateModelFromPublishedRange()
this.updateModelFromOriginallyPublishedAtYears()
}
formUpdated () {
- this.inputUpdated()
+ this.onInputUpdated()
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.onInputUpdated()
}
resetField (fieldName: string, value?: any) {
resetLocalField (fieldName: string, value?: any) {
this[fieldName] = value
- this.inputUpdated()
+ this.onInputUpdated()
}
resetOriginalPublicationYears () {