X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fsearch%2Fsearch-filters.component.ts;h=344a260dfdd1bae8ecc193f2cd1c0689e1eea134;hb=41eb700fceee1085dd0e1a9ce78ecbd0e111eb6e;hp=8d7f84ac1ba5758b5294ddd2a995c45d5fe7fc0d;hpb=0b4e5fe32708afce54212810738aa4d0c3dc178d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/search/search-filters.component.ts b/client/src/app/search/search-filters.component.ts index 8d7f84ac1..344a260df 100644 --- a/client/src/app/search/search-filters.component.ts +++ b/client/src/app/search/search-filters.component.ts @@ -1,12 +1,10 @@ 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 { ValidatorFn } from '@angular/forms' +import { VideoValidatorsService } from '@app/shared' +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' +import { ServerConfig, VideoConstant } from '../../../../shared' @Component({ selector: 'my-search-filters', @@ -22,6 +20,9 @@ export class SearchFiltersComponent implements OnInit { videoLicences: VideoConstant[] = [] videoLanguages: VideoConstant[] = [] + tagValidators: ValidatorFn[] + tagValidatorsMessages: { [ name: string ]: string } + publishedDateRanges: { id: string, label: string }[] = [] sorts: { id: string, label: string }[] = [] durationRanges: { id: string, label: string }[] = [] @@ -29,11 +30,23 @@ export class SearchFiltersComponent implements OnInit { publishedDateRange: string durationRange: string + 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: undefined, + label: this.i18n('Any') + }, { id: 'today', label: this.i18n('Today') @@ -54,16 +67,20 @@ export class SearchFiltersComponent implements OnInit { this.durationRanges = [ { - id: 'short', - label: this.i18n('Short (< 4 min)') + id: undefined, + 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)') } ] @@ -84,21 +101,62 @@ 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 + } + + 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 @@ -131,6 +189,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