aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-01-10 09:58:08 +0100
committerChocobozzz <me@florianbigard.com>2019-01-10 11:32:38 +0100
commit3866f1a02f73665541468fbadcc3cd2cc459aef2 (patch)
treefc653d6a43fad579b4de3f0628b07a5cdf80aa76 /client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts
parenta4101923e699e49ceb9ff36e971c75417fafc9f0 (diff)
downloadPeerTube-3866f1a02f73665541468fbadcc3cd2cc459aef2.tar.gz
PeerTube-3866f1a02f73665541468fbadcc3cd2cc459aef2.tar.zst
PeerTube-3866f1a02f73665541468fbadcc3cd2cc459aef2.zip
Add contact form checkbox in admin form
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.ts203
1 files changed, 70 insertions, 133 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
index ee877ee31..654a076b0 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
@@ -18,9 +18,6 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
18 resolutions: string[] = [] 18 resolutions: string[] = []
19 transcodingThreadOptions: { label: string, value: number }[] = [] 19 transcodingThreadOptions: { label: string, value: number }[] = []
20 20
21 private oldCustomJavascript: string
22 private oldCustomCSS: string
23
24 constructor ( 21 constructor (
25 protected formValidatorService: FormValidatorService, 22 protected formValidatorService: FormValidatorService,
26 private customConfigValidatorsService: CustomConfigValidatorsService, 23 private customConfigValidatorsService: CustomConfigValidatorsService,
@@ -58,41 +55,78 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
58 } 55 }
59 56
60 getResolutionKey (resolution: string) { 57 getResolutionKey (resolution: string) {
61 return 'transcodingResolution' + resolution 58 return 'transcoding.resolutions.' + resolution
62 } 59 }
63 60
64 ngOnInit () { 61 ngOnInit () {
65 const formGroupData: { [key: string]: any } = { 62 const formGroupData: { [key in keyof CustomConfig ]: any } = {
66 instanceName: this.customConfigValidatorsService.INSTANCE_NAME, 63 instance: {
67 instanceShortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION, 64 name: this.customConfigValidatorsService.INSTANCE_NAME,
68 instanceDescription: null, 65 shortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION,
69 instanceTerms: null, 66 description: null,
70 instanceDefaultClientRoute: null, 67 terms: null,
71 instanceDefaultNSFWPolicy: null, 68 defaultClientRoute: null,
72 servicesTwitterUsername: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME, 69 defaultNSFWPolicy: null,
73 servicesTwitterWhitelisted: null, 70 customizations: {
74 cachePreviewsSize: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE, 71 javascript: null,
75 cacheCaptionsSize: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE, 72 css: null
76 signupEnabled: null, 73 }
77 signupLimit: this.customConfigValidatorsService.SIGNUP_LIMIT, 74 },
78 signupRequiresEmailVerification: null, 75 services: {
79 importVideosHttpEnabled: null, 76 twitter: {
80 importVideosTorrentEnabled: null, 77 username: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME,
81 adminEmail: this.customConfigValidatorsService.ADMIN_EMAIL, 78 whitelisted: null
82 userVideoQuota: this.userValidatorsService.USER_VIDEO_QUOTA, 79 }
83 userVideoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY, 80 },
84 transcodingThreads: this.customConfigValidatorsService.TRANSCODING_THREADS, 81 cache: {
85 transcodingAllowAdditionalExtensions: null, 82 previews: {
86 transcodingEnabled: null, 83 size: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE
87 customizationJavascript: null, 84 },
88 customizationCSS: null 85 captions: {
86 size: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE
87 }
88 },
89 signup: {
90 enabled: null,
91 limit: this.customConfigValidatorsService.SIGNUP_LIMIT,
92 requiresEmailVerification: null
93 },
94 import: {
95 videos: {
96 http: {
97 enabled: null
98 },
99 torrent: {
100 enabled: null
101 }
102 }
103 },
104 admin: {
105 email: this.customConfigValidatorsService.ADMIN_EMAIL
106 },
107 contactForm: {
108 enabled: null
109 },
110 user: {
111 videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
112 videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY
113 },
114 transcoding: {
115 enabled: null,
116 threads: this.customConfigValidatorsService.TRANSCODING_THREADS,
117 allowAdditionalExtensions: null,
118 resolutions: {}
119 }
89 } 120 }
90 121
91 const defaultValues: BuildFormDefaultValues = {} 122 const defaultValues = {
123 transcoding: {
124 resolutions: {}
125 }
126 }
92 for (const resolution of this.resolutions) { 127 for (const resolution of this.resolutions) {
93 const key = this.getResolutionKey(resolution) 128 defaultValues.transcoding.resolutions[resolution] = 'false'
94 defaultValues[key] = 'false' 129 formGroupData.transcoding.resolutions[resolution] = null
95 formGroupData[key] = null
96 } 130 }
97 131
98 this.buildForm(formGroupData) 132 this.buildForm(formGroupData)
@@ -102,9 +136,6 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
102 res => { 136 res => {
103 this.customConfig = res 137 this.customConfig = res
104 138
105 this.oldCustomCSS = this.customConfig.instance.customizations.css
106 this.oldCustomJavascript = this.customConfig.instance.customizations.javascript
107
108 this.updateForm() 139 this.updateForm()
109 // Force form validation 140 // Force form validation
110 this.forceCheck() 141 this.forceCheck()
@@ -115,78 +146,15 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
115 } 146 }
116 147
117 isTranscodingEnabled () { 148 isTranscodingEnabled () {
118 return this.form.value['transcodingEnabled'] === true 149 return this.form.value['transcoding']['enabled'] === true
119 } 150 }
120 151
121 isSignupEnabled () { 152 isSignupEnabled () {
122 return this.form.value['signupEnabled'] === true 153 return this.form.value['signup']['enabled'] === true
123 } 154 }
124 155
125 async formValidated () { 156 async formValidated () {
126 const data: CustomConfig = { 157 this.configService.updateCustomConfig(this.form.value)
127 instance: {
128 name: this.form.value['instanceName'],
129 shortDescription: this.form.value['instanceShortDescription'],
130 description: this.form.value['instanceDescription'],
131 terms: this.form.value['instanceTerms'],
132 defaultClientRoute: this.form.value['instanceDefaultClientRoute'],
133 defaultNSFWPolicy: this.form.value['instanceDefaultNSFWPolicy'],
134 customizations: {
135 javascript: this.form.value['customizationJavascript'],
136 css: this.form.value['customizationCSS']
137 }
138 },
139 services: {
140 twitter: {
141 username: this.form.value['servicesTwitterUsername'],
142 whitelisted: this.form.value['servicesTwitterWhitelisted']
143 }
144 },
145 cache: {
146 previews: {
147 size: this.form.value['cachePreviewsSize']
148 },
149 captions: {
150 size: this.form.value['cacheCaptionsSize']
151 }
152 },
153 signup: {
154 enabled: this.form.value['signupEnabled'],
155 limit: this.form.value['signupLimit'],
156 requiresEmailVerification: this.form.value['signupRequiresEmailVerification']
157 },
158 admin: {
159 email: this.form.value['adminEmail']
160 },
161 user: {
162 videoQuota: this.form.value['userVideoQuota'],
163 videoQuotaDaily: this.form.value['userVideoQuotaDaily']
164 },
165 transcoding: {
166 enabled: this.form.value['transcodingEnabled'],
167 allowAdditionalExtensions: this.form.value['transcodingAllowAdditionalExtensions'],
168 threads: this.form.value['transcodingThreads'],
169 resolutions: {
170 '240p': this.form.value[this.getResolutionKey('240p')],
171 '360p': this.form.value[this.getResolutionKey('360p')],
172 '480p': this.form.value[this.getResolutionKey('480p')],
173 '720p': this.form.value[this.getResolutionKey('720p')],
174 '1080p': this.form.value[this.getResolutionKey('1080p')]
175 }
176 },
177 import: {
178 videos: {
179 http: {
180 enabled: this.form.value['importVideosHttpEnabled']
181 },
182 torrent: {
183 enabled: this.form.value['importVideosTorrentEnabled']
184 }
185 }
186 }
187 }
188
189 this.configService.updateCustomConfig(data)
190 .subscribe( 158 .subscribe(
191 res => { 159 res => {
192 this.customConfig = res 160 this.customConfig = res
@@ -204,38 +172,7 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
204 } 172 }
205 173
206 private updateForm () { 174 private updateForm () {
207 const data: { [key: string]: any } = { 175 this.form.patchValue(this.customConfig)
208 instanceName: this.customConfig.instance.name,
209 instanceShortDescription: this.customConfig.instance.shortDescription,
210 instanceDescription: this.customConfig.instance.description,
211 instanceTerms: this.customConfig.instance.terms,
212 instanceDefaultClientRoute: this.customConfig.instance.defaultClientRoute,
213 instanceDefaultNSFWPolicy: this.customConfig.instance.defaultNSFWPolicy,
214 servicesTwitterUsername: this.customConfig.services.twitter.username,
215 servicesTwitterWhitelisted: this.customConfig.services.twitter.whitelisted,
216 cachePreviewsSize: this.customConfig.cache.previews.size,
217 cacheCaptionsSize: this.customConfig.cache.captions.size,
218 signupEnabled: this.customConfig.signup.enabled,
219 signupLimit: this.customConfig.signup.limit,
220 signupRequiresEmailVerification: this.customConfig.signup.requiresEmailVerification,
221 adminEmail: this.customConfig.admin.email,
222 userVideoQuota: this.customConfig.user.videoQuota,
223 userVideoQuotaDaily: this.customConfig.user.videoQuotaDaily,
224 transcodingThreads: this.customConfig.transcoding.threads,
225 transcodingEnabled: this.customConfig.transcoding.enabled,
226 transcodingAllowAdditionalExtensions: this.customConfig.transcoding.allowAdditionalExtensions,
227 customizationJavascript: this.customConfig.instance.customizations.javascript,
228 customizationCSS: this.customConfig.instance.customizations.css,
229 importVideosHttpEnabled: this.customConfig.import.videos.http.enabled,
230 importVideosTorrentEnabled: this.customConfig.import.videos.torrent.enabled
231 }
232
233 for (const resolution of this.resolutions) {
234 const key = this.getResolutionKey(resolution)
235 data[key] = this.customConfig.transcoding.resolutions[resolution]
236 }
237
238 this.form.patchValue(data)
239 } 176 }
240 177
241} 178}