1 import { Component, OnInit } from '@angular/core'
2 import { FormBuilder, FormGroup } from '@angular/forms'
3 import { Router } from '@angular/router'
4 import { ConfigService } from '@app/+admin/config/shared/config.service'
5 import { ServerService } from '@app/core/server/server.service'
6 import { FormReactive, USER_VIDEO_QUOTA } from '@app/shared'
13 } from '@app/shared/forms/form-validators/custom-config'
14 import { NotificationsService } from 'angular2-notifications'
15 import { CustomConfig } from '../../../../../../shared/models/config/custom-config.model'
18 selector: 'my-edit-custom-config',
19 templateUrl: './edit-custom-config.component.html',
20 styleUrls: [ './edit-custom-config.component.scss' ]
22 export class EditCustomConfigComponent extends FormReactive implements OnInit {
23 customConfig: CustomConfig
24 resolutions = [ '240p', '360p', '480p', '720p', '1080p' ]
27 { value: -1, label: 'Unlimited' },
28 { value: 0, label: '0' },
29 { value: 100 * 1024 * 1024, label: '100MB' },
30 { value: 500 * 1024 * 1024, label: '500MB' },
31 { value: 1024 * 1024 * 1024, label: '1GB' },
32 { value: 5 * 1024 * 1024 * 1024, label: '5GB' },
33 { value: 20 * 1024 * 1024 * 1024, label: '20GB' },
34 { value: 50 * 1024 * 1024 * 1024, label: '50GB' }
36 transcodingThreadOptions = [
37 { value: 1, label: '1' },
38 { value: 2, label: '2' },
39 { value: 4, label: '4' },
40 { value: 8, label: '8' }
46 instanceDescription: '',
48 cachePreviewsSize: '',
52 transcodingThreads: '',
53 customizationJavascript: '',
56 validationMessages = {
57 instanceName: INSTANCE_NAME.MESSAGES,
58 cachePreviewsSize: CACHE_PREVIEWS_SIZE.MESSAGES,
59 signupLimit: SIGNUP_LIMIT.MESSAGES,
60 adminEmail: ADMIN_EMAIL.MESSAGES,
61 userVideoQuota: USER_VIDEO_QUOTA.MESSAGES
65 private formBuilder: FormBuilder,
66 private router: Router,
67 private notificationsService: NotificationsService,
68 private configService: ConfigService,
69 private serverService: ServerService
74 getResolutionKey (resolution: string) {
75 return 'transcodingResolution' + resolution
79 const formGroupData = {
80 instanceName: [ '', INSTANCE_NAME.VALIDATORS ],
81 instanceDescription: [ '' ],
82 instanceTerms: [ '' ],
83 cachePreviewsSize: [ '', CACHE_PREVIEWS_SIZE.VALIDATORS ],
85 signupLimit: [ '', SIGNUP_LIMIT.VALIDATORS ],
86 adminEmail: [ '', ADMIN_EMAIL.VALIDATORS ],
87 userVideoQuota: [ '', USER_VIDEO_QUOTA.VALIDATORS ],
88 transcodingThreads: [ '', TRANSCODING_THREADS.VALIDATORS ],
89 transcodingEnabled: [ ],
90 customizationJavascript: [ '' ],
91 customizationCSS: [ '' ]
94 for (const resolution of this.resolutions) {
95 const key = this.getResolutionKey(resolution)
96 formGroupData[key] = [ false ]
99 this.form = this.formBuilder.group(formGroupData)
101 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
107 this.configService.getCustomConfig()
110 this.customConfig = res
115 err => this.notificationsService.error('Error', err.message)
119 isTranscodingEnabled () {
120 return this.form.value['transcodingEnabled'] === true
124 return this.form.value['signupEnabled'] === true
130 name: this.form.value['instanceName'],
131 description: this.form.value['instanceDescription'],
132 terms: this.form.value['instanceTerms'],
134 javascript: this.form.value['customizationJavascript'],
135 css: this.form.value['customizationCSS']
140 size: this.form.value['cachePreviewsSize']
144 enabled: this.form.value['signupEnabled'],
145 limit: this.form.value['signupLimit']
148 email: this.form.value['adminEmail']
151 videoQuota: this.form.value['userVideoQuota']
154 enabled: this.form.value['transcodingEnabled'],
155 threads: this.form.value['transcodingThreads'],
157 '240p': this.form.value[this.getResolutionKey('240p')],
158 '360p': this.form.value[this.getResolutionKey('360p')],
159 '480p': this.form.value[this.getResolutionKey('480p')],
160 '720p': this.form.value[this.getResolutionKey('720p')],
161 '1080p': this.form.value[this.getResolutionKey('1080p')]
166 this.configService.updateCustomConfig(data)
169 this.customConfig = res
171 // Reload general configuration
172 this.serverService.loadConfig()
176 this.notificationsService.success('Success', 'Configuration updated.')
179 err => this.notificationsService.error('Error', err.message)
183 private updateForm () {
185 instanceName: this.customConfig.instance.name,
186 instanceDescription: this.customConfig.instance.description,
187 instanceTerms: this.customConfig.instance.terms,
188 cachePreviewsSize: this.customConfig.cache.previews.size,
189 signupEnabled: this.customConfig.signup.enabled,
190 signupLimit: this.customConfig.signup.limit,
191 adminEmail: this.customConfig.admin.email,
192 userVideoQuota: this.customConfig.user.videoQuota,
193 transcodingThreads: this.customConfig.transcoding.threads,
194 transcodingEnabled: this.customConfig.transcoding.enabled,
195 customizationJavascript: this.customConfig.instance.customizations.javascript,
196 customizationCSS: this.customConfig.instance.customizations.css
199 for (const resolution of this.resolutions) {
200 const key = this.getResolutionKey(resolution)
201 data[key] = this.customConfig.transcoding.resolutions[resolution]
204 this.form.patchValue(data)