diff options
Diffstat (limited to 'client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts')
-rw-r--r-- | client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts | 174 |
1 files changed, 174 insertions, 0 deletions
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 new file mode 100644 index 000000000..1b3522786 --- /dev/null +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts | |||
@@ -0,0 +1,174 @@ | |||
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' | ||
7 | import { ADMIN_EMAIL, CACHE_PREVIEWS_SIZE, SIGNUP_LIMIT, TRANSCODING_THREADS } from '@app/shared/forms/form-validators/custom-config' | ||
8 | import { NotificationsService } from 'angular2-notifications' | ||
9 | import { CustomConfig } from '../../../../../../shared/models/config/custom-config.model' | ||
10 | |||
11 | @Component({ | ||
12 | selector: 'my-edit-custom-config', | ||
13 | templateUrl: './edit-custom-config.component.html', | ||
14 | styleUrls: [ './edit-custom-config.component.scss' ] | ||
15 | }) | ||
16 | export class EditCustomConfigComponent extends FormReactive implements OnInit { | ||
17 | customConfig: CustomConfig | ||
18 | resolutions = [ '240p', '360p', '480p', '720p', '1080p' ] | ||
19 | |||
20 | videoQuotaOptions = [ | ||
21 | { value: -1, label: 'Unlimited' }, | ||
22 | { value: 0, label: '0' }, | ||
23 | { value: 100 * 1024 * 1024, label: '100MB' }, | ||
24 | { value: 500 * 1024 * 1024, label: '500MB' }, | ||
25 | { value: 1024 * 1024 * 1024, label: '1GB' }, | ||
26 | { value: 5 * 1024 * 1024 * 1024, label: '5GB' }, | ||
27 | { value: 20 * 1024 * 1024 * 1024, label: '20GB' }, | ||
28 | { value: 50 * 1024 * 1024 * 1024, label: '50GB' } | ||
29 | ] | ||
30 | transcodingThreadOptions = [ | ||
31 | { value: 1, label: '1' }, | ||
32 | { value: 2, label: '2' }, | ||
33 | { value: 4, label: '4' }, | ||
34 | { value: 8, label: '8' } | ||
35 | ] | ||
36 | |||
37 | form: FormGroup | ||
38 | formErrors = { | ||
39 | cachePreviewsSize: '', | ||
40 | signupLimit: '', | ||
41 | adminEmail: '', | ||
42 | userVideoQuota: '', | ||
43 | transcodingThreads: '' | ||
44 | } | ||
45 | validationMessages = { | ||
46 | cachePreviewsSize: CACHE_PREVIEWS_SIZE.MESSAGES, | ||
47 | signupLimit: SIGNUP_LIMIT.MESSAGES, | ||
48 | adminEmail: ADMIN_EMAIL.MESSAGES, | ||
49 | userVideoQuota: USER_VIDEO_QUOTA.MESSAGES | ||
50 | } | ||
51 | |||
52 | constructor ( | ||
53 | private formBuilder: FormBuilder, | ||
54 | private router: Router, | ||
55 | private notificationsService: NotificationsService, | ||
56 | private configService: ConfigService, | ||
57 | private serverService: ServerService | ||
58 | ) { | ||
59 | super() | ||
60 | } | ||
61 | |||
62 | getResolutionKey (resolution: string) { | ||
63 | return 'transcodingResolution' + resolution | ||
64 | } | ||
65 | |||
66 | buildForm () { | ||
67 | const formGroupData = { | ||
68 | cachePreviewsSize: [ '', CACHE_PREVIEWS_SIZE.VALIDATORS ], | ||
69 | signupEnabled: [ ], | ||
70 | signupLimit: [ '', SIGNUP_LIMIT.VALIDATORS ], | ||
71 | adminEmail: [ '', ADMIN_EMAIL.VALIDATORS ], | ||
72 | userVideoQuota: [ '', USER_VIDEO_QUOTA.VALIDATORS ], | ||
73 | transcodingThreads: [ '', TRANSCODING_THREADS.VALIDATORS ], | ||
74 | transcodingEnabled: [ ] | ||
75 | } | ||
76 | |||
77 | for (const resolution of this.resolutions) { | ||
78 | const key = this.getResolutionKey(resolution) | ||
79 | formGroupData[key] = [ false ] | ||
80 | } | ||
81 | |||
82 | this.form = this.formBuilder.group(formGroupData) | ||
83 | |||
84 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)) | ||
85 | } | ||
86 | |||
87 | ngOnInit () { | ||
88 | this.buildForm() | ||
89 | |||
90 | this.configService.getCustomConfig() | ||
91 | .subscribe( | ||
92 | res => { | ||
93 | this.customConfig = res | ||
94 | |||
95 | this.updateForm() | ||
96 | }, | ||
97 | |||
98 | err => this.notificationsService.error('Error', err.message) | ||
99 | ) | ||
100 | } | ||
101 | |||
102 | isTranscodingEnabled () { | ||
103 | return this.form.value['transcodingEnabled'] === true | ||
104 | } | ||
105 | |||
106 | isSignupEnabled () { | ||
107 | return this.form.value['signupEnabled'] === true | ||
108 | } | ||
109 | |||
110 | formValidated () { | ||
111 | const data = { | ||
112 | cache: { | ||
113 | previews: { | ||
114 | size: this.form.value['cachePreviewsSize'] | ||
115 | } | ||
116 | }, | ||
117 | signup: { | ||
118 | enabled: this.form.value['signupEnabled'], | ||
119 | limit: this.form.value['signupLimit'] | ||
120 | }, | ||
121 | admin: { | ||
122 | email: this.form.value['adminEmail'] | ||
123 | }, | ||
124 | user: { | ||
125 | videoQuota: this.form.value['userVideoQuota'] | ||
126 | }, | ||
127 | transcoding: { | ||
128 | enabled: this.form.value['transcodingEnabled'], | ||
129 | threads: this.form.value['transcodingThreads'], | ||
130 | resolutions: { | ||
131 | '240p': this.form.value[this.getResolutionKey('240p')], | ||
132 | '360p': this.form.value[this.getResolutionKey('360p')], | ||
133 | '480p': this.form.value[this.getResolutionKey('480p')], | ||
134 | '720p': this.form.value[this.getResolutionKey('720p')], | ||
135 | '1080p': this.form.value[this.getResolutionKey('1080p')] | ||
136 | } | ||
137 | } | ||
138 | } | ||
139 | |||
140 | this.configService.updateCustomConfig(data) | ||
141 | .subscribe( | ||
142 | res => { | ||
143 | this.customConfig = res | ||
144 | |||
145 | // Reload general configuration | ||
146 | this.serverService.loadConfig() | ||
147 | |||
148 | this.updateForm() | ||
149 | }, | ||
150 | |||
151 | err => this.notificationsService.error('Error', err.message) | ||
152 | ) | ||
153 | } | ||
154 | |||
155 | private updateForm () { | ||
156 | const data = { | ||
157 | cachePreviewsSize: this.customConfig.cache.previews.size, | ||
158 | signupEnabled: this.customConfig.signup.enabled, | ||
159 | signupLimit: this.customConfig.signup.limit, | ||
160 | adminEmail: this.customConfig.admin.email, | ||
161 | userVideoQuota: this.customConfig.user.videoQuota, | ||
162 | transcodingThreads: this.customConfig.transcoding.threads, | ||
163 | transcodingEnabled: this.customConfig.transcoding.enabled | ||
164 | } | ||
165 | |||
166 | for (const resolution of this.resolutions) { | ||
167 | const key = this.getResolutionKey(resolution) | ||
168 | data[key] = this.customConfig.transcoding.resolutions[resolution] | ||
169 | } | ||
170 | |||
171 | this.form.patchValue(data) | ||
172 | } | ||
173 | |||
174 | } | ||