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=3b6dabcb956b86b04563232ec1d1be6ac8e764a9;hb=bee0abffff73804d816b90c7fd599e0a51c09d61;hp=2ab371cbbdc0c2e457d82f9f389ad94fc729565f;hpb=0883b3245bf0deb9106c4041e9afbd3521b79280;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 2ab371cbb..3b6dabcb9 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,19 +1,13 @@ import { Component, OnInit } from '@angular/core' -import { FormBuilder, FormGroup } from '@angular/forms' import { Router } from '@angular/router' import { ConfigService } from '@app/+admin/config/shared/config.service' import { ConfirmService } from '@app/core' import { ServerService } from '@app/core/server/server.service' -import { FormReactive, USER_VIDEO_QUOTA } from '@app/shared' -import { - ADMIN_EMAIL, - CACHE_PREVIEWS_SIZE, - INSTANCE_NAME, INSTANCE_SHORT_DESCRIPTION, - SIGNUP_LIMIT, - TRANSCODING_THREADS -} from '@app/shared/forms/form-validators/custom-config' +import { CustomConfigValidatorsService, FormReactive, UserValidatorsService } from '@app/shared' import { NotificationsService } from 'angular2-notifications' import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model' +import { I18n } from '@ngx-translate/i18n-polyfill' +import { BuildFormDefaultValues, FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' @Component({ selector: 'my-edit-custom-config', @@ -21,10 +15,7 @@ import { CustomConfig } from '../../../../../../shared/models/server/custom-conf styleUrls: [ './edit-custom-config.component.scss' ] }) export class EditCustomConfigComponent extends FormReactive implements OnInit { - customConfig: CustomConfig - resolutions = [ '240p', '360p', '480p', '720p', '1080p' ] - - videoQuotaOptions = [ + static videoQuotaOptions = [ { value: -1, label: 'Unlimited' }, { value: 0, label: '0' }, { value: 100 * 1024 * 1024, label: '100MB' }, @@ -34,48 +25,41 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { { value: 20 * 1024 * 1024 * 1024, label: '20GB' }, { value: 50 * 1024 * 1024 * 1024, label: '50GB' } ] + static videoQuotaDailyOptions = [ + { value: -1, label: 'Unlimited' }, + { value: 0, label: '0' }, + { value: 10 * 1024 * 1024, label: '10MB' }, + { value: 50 * 1024 * 1024, label: '50MB' }, + { value: 100 * 1024 * 1024, label: '100MB' }, + { value: 500 * 1024 * 1024, label: '500MB' }, + { value: 2 * 1024 * 1024 * 1024, label: '2GB' }, + { value: 5 * 1024 * 1024 * 1024, label: '5GB' } + ] + + customConfig: CustomConfig + resolutions = [ '240p', '360p', '480p', '720p', '1080p' ] + transcodingThreadOptions = [ + { value: 0, label: 'Auto (via ffmpeg)' }, { value: 1, label: '1' }, { value: 2, label: '2' }, { value: 4, label: '4' }, { value: 8, label: '8' } ] - form: FormGroup - formErrors = { - instanceName: '', - instanceShortDescription: '', - instanceDescription: '', - instanceTerms: '', - instanceDefaultClientRoute: '', - instanceDefaultNSFWPolicy: '', - cachePreviewsSize: '', - signupLimit: '', - adminEmail: '', - userVideoQuota: '', - transcodingThreads: '', - customizationJavascript: '', - customizationCSS: '' - } - validationMessages = { - instanceShortDescription: INSTANCE_SHORT_DESCRIPTION.MESSAGES, - instanceName: INSTANCE_NAME.MESSAGES, - cachePreviewsSize: CACHE_PREVIEWS_SIZE.MESSAGES, - signupLimit: SIGNUP_LIMIT.MESSAGES, - adminEmail: ADMIN_EMAIL.MESSAGES, - userVideoQuota: USER_VIDEO_QUOTA.MESSAGES - } - private oldCustomJavascript: string private oldCustomCSS: string constructor ( - private formBuilder: FormBuilder, + protected formValidatorService: FormValidatorService, + private customConfigValidatorsService: CustomConfigValidatorsService, + private userValidatorsService: UserValidatorsService, private router: Router, private notificationsService: NotificationsService, private configService: ConfigService, private serverService: ServerService, - private confirmService: ConfirmService + private confirmService: ConfirmService, + private i18n: I18n ) { super() } @@ -84,37 +68,39 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { return 'transcodingResolution' + resolution } - buildForm () { + ngOnInit () { const formGroupData = { - instanceName: [ '', INSTANCE_NAME.VALIDATORS ], - instanceShortDescription: [ '', INSTANCE_SHORT_DESCRIPTION.VALIDATORS ], - instanceDescription: [ '' ], - instanceTerms: [ '' ], - instanceDefaultClientRoute: [ '' ], - instanceDefaultNSFWPolicy: [ '' ], - cachePreviewsSize: [ '', CACHE_PREVIEWS_SIZE.VALIDATORS ], - signupEnabled: [ ], - signupLimit: [ '', SIGNUP_LIMIT.VALIDATORS ], - adminEmail: [ '', ADMIN_EMAIL.VALIDATORS ], - userVideoQuota: [ '', USER_VIDEO_QUOTA.VALIDATORS ], - transcodingThreads: [ '', TRANSCODING_THREADS.VALIDATORS ], - transcodingEnabled: [ ], - customizationJavascript: [ '' ], - customizationCSS: [ '' ] + instanceName: this.customConfigValidatorsService.INSTANCE_NAME, + instanceShortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION, + instanceDescription: null, + instanceTerms: null, + instanceDefaultClientRoute: null, + instanceDefaultNSFWPolicy: null, + servicesTwitterUsername: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME, + servicesTwitterWhitelisted: null, + cachePreviewsSize: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE, + cacheCaptionsSize: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE, + signupEnabled: null, + signupLimit: this.customConfigValidatorsService.SIGNUP_LIMIT, + importVideosHttpEnabled: null, + importVideosTorrentEnabled: null, + adminEmail: this.customConfigValidatorsService.ADMIN_EMAIL, + userVideoQuota: this.userValidatorsService.USER_VIDEO_QUOTA, + userVideoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY, + transcodingThreads: this.customConfigValidatorsService.TRANSCODING_THREADS, + transcodingEnabled: null, + customizationJavascript: null, + customizationCSS: null } + const defaultValues: BuildFormDefaultValues = {} for (const resolution of this.resolutions) { const key = this.getResolutionKey(resolution) - formGroupData[key] = [ false ] + defaultValues[key] = 'false' + formGroupData[key] = null } - this.form = this.formBuilder.group(formGroupData) - - this.form.valueChanges.subscribe(data => this.onValueChanged(data)) - } - - ngOnInit () { - this.buildForm() + this.buildForm(formGroupData) this.configService.getCustomConfig() .subscribe( @@ -129,7 +115,7 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { this.forceCheck() }, - err => this.notificationsService.error('Error', err.message) + err => this.notificationsService.error(this.i18n('Error'), err.message) ) } @@ -152,10 +138,12 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { if (customizations.length !== 0) { const customizationsText = customizations.join('/') - const message = `You set custom ${customizationsText}. ` + - 'This could lead to security issues or bugs if you do not understand it. ' + - 'Are you sure you want to update the configuration?' - const label = `Please type "I understand the ${customizationsText} I set" to confirm.` + // FIXME: i18n service does not support string concatenation + const message = this.i18n('You set custom {{customizationsText}}. ', { customizationsText }) + + this.i18n('This could lead to security issues or bugs if you do not understand it. ') + + this.i18n('Are you sure you want to update the configuration?') + + const label = this.i18n('Please type') + ` "I understand the ${customizationsText} I set" ` + this.i18n('to confirm.') const expectedInputValue = `I understand the ${customizationsText} I set` const confirmRes = await this.confirmService.confirmWithInput(message, label, expectedInputValue) @@ -175,9 +163,18 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { css: this.form.value['customizationCSS'] } }, + services: { + twitter: { + username: this.form.value['servicesTwitterUsername'], + whitelisted: this.form.value['servicesTwitterWhitelisted'] + } + }, cache: { previews: { size: this.form.value['cachePreviewsSize'] + }, + captions: { + size: this.form.value['cacheCaptionsSize'] } }, signup: { @@ -188,7 +185,8 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { email: this.form.value['adminEmail'] }, user: { - videoQuota: this.form.value['userVideoQuota'] + videoQuota: this.form.value['userVideoQuota'], + videoQuotaDaily: this.form.value['userVideoQuotaDaily'] }, transcoding: { enabled: this.form.value['transcodingEnabled'], @@ -200,6 +198,16 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { '720p': this.form.value[this.getResolutionKey('720p')], '1080p': this.form.value[this.getResolutionKey('1080p')] } + }, + import: { + videos: { + http: { + enabled: this.form.value['importVideosHttpEnabled'] + }, + torrent: { + enabled: this.form.value['importVideosTorrentEnabled'] + } + } } } @@ -213,10 +221,10 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { this.updateForm() - this.notificationsService.success('Success', 'Configuration updated.') + this.notificationsService.success(this.i18n('Success'), this.i18n('Configuration updated.')) }, - err => this.notificationsService.error('Error', err.message) + err => this.notificationsService.error(this.i18n('Error'), err.message) ) } @@ -228,15 +236,21 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { instanceTerms: this.customConfig.instance.terms, instanceDefaultClientRoute: this.customConfig.instance.defaultClientRoute, instanceDefaultNSFWPolicy: this.customConfig.instance.defaultNSFWPolicy, + servicesTwitterUsername: this.customConfig.services.twitter.username, + servicesTwitterWhitelisted: this.customConfig.services.twitter.whitelisted, cachePreviewsSize: this.customConfig.cache.previews.size, + cacheCaptionsSize: this.customConfig.cache.captions.size, signupEnabled: this.customConfig.signup.enabled, signupLimit: this.customConfig.signup.limit, adminEmail: this.customConfig.admin.email, userVideoQuota: this.customConfig.user.videoQuota, + userVideoQuotaDaily: this.customConfig.user.videoQuotaDaily, transcodingThreads: this.customConfig.transcoding.threads, transcodingEnabled: this.customConfig.transcoding.enabled, customizationJavascript: this.customConfig.instance.customizations.javascript, - customizationCSS: this.customConfig.instance.customizations.css + customizationCSS: this.customConfig.instance.customizations.css, + importVideosHttpEnabled: this.customConfig.import.videos.http.enabled, + importVideosTorrentEnabled: this.customConfig.import.videos.torrent.enabled } for (const resolution of this.resolutions) {