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: ''
54 validationMessages = {
55 instanceName: INSTANCE_NAME.MESSAGES,
56 cachePreviewsSize: CACHE_PREVIEWS_SIZE.MESSAGES,
57 signupLimit: SIGNUP_LIMIT.MESSAGES,
58 adminEmail: ADMIN_EMAIL.MESSAGES,
59 userVideoQuota: USER_VIDEO_QUOTA.MESSAGES
63 private formBuilder: FormBuilder,
64 private router: Router,
65 private notificationsService: NotificationsService,
66 private configService: ConfigService,
67 private serverService: ServerService
72 getResolutionKey (resolution: string) {
73 return 'transcodingResolution' + resolution
77 const formGroupData = {
78 instanceName: [ '', INSTANCE_NAME.VALIDATORS ],
79 instanceDescription: [ '' ],
80 instanceTerms: [ '' ],
81 cachePreviewsSize: [ '', CACHE_PREVIEWS_SIZE.VALIDATORS ],
83 signupLimit: [ '', SIGNUP_LIMIT.VALIDATORS ],
84 adminEmail: [ '', ADMIN_EMAIL.VALIDATORS ],
85 userVideoQuota: [ '', USER_VIDEO_QUOTA.VALIDATORS ],
86 transcodingThreads: [ '', TRANSCODING_THREADS.VALIDATORS ],
87 transcodingEnabled: [ ]
90 for (const resolution of this.resolutions) {
91 const key = this.getResolutionKey(resolution)
92 formGroupData[key] = [ false ]
95 this.form = this.formBuilder.group(formGroupData)
97 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
103 this.configService.getCustomConfig()
106 this.customConfig = res
111 err => this.notificationsService.error('Error', err.message)
115 isTranscodingEnabled () {
116 return this.form.value['transcodingEnabled'] === true
120 return this.form.value['signupEnabled'] === true
126 name: this.form.value['instanceName'],
127 description: this.form.value['instanceDescription'],
128 terms: this.form.value['instanceTerms']
132 size: this.form.value['cachePreviewsSize']
136 enabled: this.form.value['signupEnabled'],
137 limit: this.form.value['signupLimit']
140 email: this.form.value['adminEmail']
143 videoQuota: this.form.value['userVideoQuota']
146 enabled: this.form.value['transcodingEnabled'],
147 threads: this.form.value['transcodingThreads'],
149 '240p': this.form.value[this.getResolutionKey('240p')],
150 '360p': this.form.value[this.getResolutionKey('360p')],
151 '480p': this.form.value[this.getResolutionKey('480p')],
152 '720p': this.form.value[this.getResolutionKey('720p')],
153 '1080p': this.form.value[this.getResolutionKey('1080p')]
158 this.configService.updateCustomConfig(data)
161 this.customConfig = res
163 // Reload general configuration
164 this.serverService.loadConfig()
168 this.notificationsService.success('Success', 'Configuration updated.')
171 err => this.notificationsService.error('Error', err.message)
175 private updateForm () {
177 instanceName: this.customConfig.instance.name,
178 instanceDescription: this.customConfig.instance.description,
179 instanceTerms: this.customConfig.instance.terms,
180 cachePreviewsSize: this.customConfig.cache.previews.size,
181 signupEnabled: this.customConfig.signup.enabled,
182 signupLimit: this.customConfig.signup.limit,
183 adminEmail: this.customConfig.admin.email,
184 userVideoQuota: this.customConfig.user.videoQuota,
185 transcodingThreads: this.customConfig.transcoding.threads,
186 transcodingEnabled: this.customConfig.transcoding.enabled
189 for (const resolution of this.resolutions) {
190 const key = this.getResolutionKey(resolution)
191 data[key] = this.customConfig.transcoding.resolutions[resolution]
194 this.form.patchValue(data)