X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Badmin%2Fconfig%2Fedit-custom-config%2Fedit-custom-config.component.ts;h=de1cf46b141114aac523cb1b3805b87119a80685;hb=a056ca4813c82f490dcd31ac97a64d6bf76d3dcc;hp=c3eac68bbf419474aa73826577d49da65e021b6d;hpb=45e0d6697c107d77dce73d8e354867dc1959741d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts index c3eac68bb..de1cf46b1 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts @@ -1,16 +1,25 @@ -import { Component, OnInit, AfterViewChecked, ViewChild } from '@angular/core' -import { ConfigService } from '@app/+admin/config/shared/config.service' -import { ServerService } from '@app/core/server/server.service' -import { CustomConfigValidatorsService, FormReactive, UserValidatorsService } from '@app/shared' -import { Notifier } from '@app/core' -import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model' -import { I18n } from '@ngx-translate/i18n-polyfill' -import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' -import { SelectItem } from 'primeng/api' import { forkJoin } from 'rxjs' -import { ServerConfig } from '@shared/models' import { ViewportScroller } from '@angular/common' -import { NgbTabset } from '@ng-bootstrap/ng-bootstrap' +import { AfterViewChecked, Component, OnInit, ViewChild } from '@angular/core' +import { ConfigService } from '@app/+admin/config/shared/config.service' +import { Notifier } from '@app/core' +import { ServerService } from '@app/core/server/server.service' +import { + ADMIN_EMAIL_VALIDATOR, + CACHE_CAPTIONS_SIZE_VALIDATOR, + CACHE_PREVIEWS_SIZE_VALIDATOR, + INDEX_URL_VALIDATOR, + INSTANCE_NAME_VALIDATOR, + INSTANCE_SHORT_DESCRIPTION_VALIDATOR, + SEARCH_INDEX_URL_VALIDATOR, + SERVICES_TWITTER_USERNAME_VALIDATOR, + SIGNUP_LIMIT_VALIDATOR, + TRANSCODING_THREADS_VALIDATOR +} from '@app/shared/form-validators/custom-config-validators' +import { USER_VIDEO_QUOTA_DAILY_VALIDATOR, USER_VIDEO_QUOTA_VALIDATOR } from '@app/shared/form-validators/user-validators' +import { FormReactive, FormValidatorService, SelectOptionsItem } from '@app/shared/shared-forms' +import { NgbNav } from '@ng-bootstrap/ng-bootstrap' +import { CustomConfig, ServerConfig } from '@shared/models' @Component({ selector: 'my-edit-custom-config', @@ -18,70 +27,80 @@ import { NgbTabset } from '@ng-bootstrap/ng-bootstrap' styleUrls: [ './edit-custom-config.component.scss' ] }) export class EditCustomConfigComponent extends FormReactive implements OnInit, AfterViewChecked { - @ViewChild('tabs') private tabs: NgbTabset + // FIXME: use built-in router + @ViewChild('nav') nav: NgbNav initDone = false customConfig: CustomConfig resolutions: { id: string, label: string, description?: string }[] = [] + liveResolutions: { id: string, label: string, description?: string }[] = [] transcodingThreadOptions: { label: string, value: number }[] = [] + liveMaxDurationOptions: { label: string, value: number }[] = [] - languageItems: SelectItem[] = [] - categoryItems: SelectItem[] = [] + languageItems: SelectOptionsItem[] = [] + categoryItems: SelectOptionsItem[] = [] private serverConfig: ServerConfig constructor ( private viewportScroller: ViewportScroller, protected formValidatorService: FormValidatorService, - private customConfigValidatorsService: CustomConfigValidatorsService, - private userValidatorsService: UserValidatorsService, private notifier: Notifier, private configService: ConfigService, - private serverService: ServerService, - private i18n: I18n + private serverService: ServerService ) { super() this.resolutions = [ { id: '0p', - label: this.i18n('Audio-only'), - description: this.i18n('A .mp4 that keeps the original audio track, with no video') + label: $localize`Audio-only`, + description: $localize`A .mp4 that keeps the original audio track, with no video` }, { id: '240p', - label: this.i18n('240p') + label: $localize`240p` }, { id: '360p', - label: this.i18n('360p') + label: $localize`360p` }, { id: '480p', - label: this.i18n('480p') + label: $localize`480p` }, { id: '720p', - label: this.i18n('720p') + label: $localize`720p` }, { id: '1080p', - label: this.i18n('1080p') + label: $localize`1080p` }, { id: '2160p', - label: this.i18n('2160p') + label: $localize`2160p` } ] + this.liveResolutions = this.resolutions.filter(r => r.id !== '0p') + this.transcodingThreadOptions = [ - { value: 0, label: this.i18n('Auto (via ffmpeg)') }, + { value: 0, label: $localize`Auto (via ffmpeg)` }, { value: 1, label: '1' }, { value: 2, label: '2' }, { value: 4, label: '4' }, { value: 8, label: '8' } ] + + this.liveMaxDurationOptions = [ + { value: 0, label: $localize`No limit` }, + { value: 1000 * 3600, label: $localize`1 hour` }, + { value: 1000 * 3600 * 3, label: $localize`3 hours` }, + { value: 1000 * 3600 * 5, label: $localize`5 hours` }, + { value: 1000 * 3600 * 10, label: $localize`10 hours` } + ] } get videoQuotaOptions () { @@ -104,12 +123,14 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit, A ngOnInit () { this.serverConfig = this.serverService.getTmpConfig() this.serverService.getConfig() - .subscribe(config => this.serverConfig = config) + .subscribe(config => { + this.serverConfig = config + }) const formGroupData: { [key in keyof CustomConfig ]: any } = { instance: { - name: this.customConfigValidatorsService.INSTANCE_NAME, - shortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION, + name: INSTANCE_NAME_VALIDATOR, + shortDescription: INSTANCE_SHORT_DESCRIPTION_VALIDATOR, description: null, isNSFW: false, @@ -141,21 +162,21 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit, A }, services: { twitter: { - username: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME, + username: SERVICES_TWITTER_USERNAME_VALIDATOR, whitelisted: null } }, cache: { previews: { - size: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE + size: CACHE_PREVIEWS_SIZE_VALIDATOR }, captions: { - size: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE + size: CACHE_CAPTIONS_SIZE_VALIDATOR } }, signup: { enabled: null, - limit: this.customConfigValidatorsService.SIGNUP_LIMIT, + limit: SIGNUP_LIMIT_VALIDATOR, requiresEmailVerification: null }, import: { @@ -169,18 +190,18 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit, A } }, admin: { - email: this.customConfigValidatorsService.ADMIN_EMAIL + email: ADMIN_EMAIL_VALIDATOR }, contactForm: { enabled: null }, user: { - videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA, - videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY + videoQuota: USER_VIDEO_QUOTA_VALIDATOR, + videoQuotaDaily: USER_VIDEO_QUOTA_DAILY_VALIDATOR }, transcoding: { enabled: null, - threads: this.customConfigValidatorsService.TRANSCODING_THREADS, + threads: TRANSCODING_THREADS_VALIDATOR, allowAdditionalExtensions: null, allowAudioFiles: null, resolutions: {}, @@ -191,6 +212,20 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit, A enabled: null } }, + live: { + enabled: null, + + maxDuration: null, + maxInstanceLives: null, + maxUserLives: null, + allowReplay: null, + + transcoding: { + enabled: null, + threads: TRANSCODING_THREADS_VALIDATOR, + resolutions: {} + } + }, autoBlacklist: { videos: { ofUsers: { @@ -211,22 +246,51 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit, A }, autoFollowIndex: { enabled: null, - indexUrl: this.customConfigValidatorsService.INDEX_URL + indexUrl: INDEX_URL_VALIDATOR } } + }, + broadcastMessage: { + enabled: null, + level: null, + dismissable: null, + message: null + }, + search: { + remoteUri: { + users: null, + anonymous: null + }, + searchIndex: { + enabled: null, + url: SEARCH_INDEX_URL_VALIDATOR, + disableLocalSearch: null, + isDefaultSearch: null + } } } const defaultValues = { transcoding: { resolutions: {} + }, + live: { + transcoding: { + resolutions: {} + } } } + for (const resolution of this.resolutions) { defaultValues.transcoding.resolutions[resolution.id] = 'false' formGroupData.transcoding.resolutions[resolution.id] = null } + for (const resolution of this.liveResolutions) { + defaultValues.live.transcoding.resolutions[resolution.id] = 'false' + formGroupData.live.transcoding.resolutions[resolution.id] = null + } + this.buildForm(formGroupData) this.loadForm() this.checkTranscodingFields() @@ -243,10 +307,22 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit, A return this.form.value['transcoding']['enabled'] === true } + isLiveEnabled () { + return this.form.value['live']['enabled'] === true + } + + isLiveTranscodingEnabled () { + return this.form.value['live']['transcoding']['enabled'] === true + } + isSignupEnabled () { return this.form.value['signup']['enabled'] === true } + isSearchIndexEnabled () { + return this.form.value['search']['searchIndex']['enabled'] === true + } + isAutoFollowIndexEnabled () { return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true } @@ -262,39 +338,37 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit, A this.updateForm() - this.notifier.success(this.i18n('Configuration updated.')) + this.notifier.success($localize`Configuration updated.`) }, err => this.notifier.error(err.message) ) } - getSelectedLanguageLabel () { - return this.i18n('{{\'{0} languages selected') - } + gotoAnchor () { + const hashToNav = { + 'customizations': 'advanced-configuration' + } + const hash = window.location.hash.replace('#', '') - getDefaultLanguageLabel () { - return this.i18n('No language') + if (hash && Object.keys(hashToNav).includes(hash)) { + this.nav.select(hashToNav[hash]) + setTimeout(() => this.viewportScroller.scrollToAnchor(hash), 100) + } } - getSelectedCategoryLabel () { - return this.i18n('{{\'{0} categories selected') - } + hasConsistentOptions () { + if (this.hasLiveAllowReplayConsistentOptions()) return true - getDefaultCategoryLabel () { - return this.i18n('No category') + return false } - gotoAnchor () { - const hashToTab = { - 'customizations': 'advanced-configuration' + hasLiveAllowReplayConsistentOptions () { + if (this.isTranscodingEnabled() === false && this.isLiveEnabled() && this.form.value['live']['allowReplay'] === true) { + return false } - const hash = window.location.hash.replace('#', '') - if (hash && Object.keys(hashToTab).includes(hash)) { - this.tabs.select(hashToTab[hash]) - setTimeout(() => this.viewportScroller.scrollToAnchor(hash), 100) - } + return true } private updateForm () { @@ -310,8 +384,8 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit, A ([ config, languages, categories ]) => { this.customConfig = config - this.languageItems = languages.map(l => ({ label: l.label, value: l.id })) - this.categoryItems = categories.map(l => ({ label: l.label, value: l.id })) + this.languageItems = languages.map(l => ({ label: l.label, id: l.id })) + this.categoryItems = categories.map(l => ({ label: l.label, id: l.id + '' })) this.updateForm() // Force form validation