]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/users/user-edit/user-edit.ts
Fix quota translations
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-edit / user-edit.ts
1 import { ServerService } from '../../../core'
2 import { FormReactive } from '../../../shared'
3 import { USER_ROLE_LABELS, VideoResolution } from '../../../../../../shared'
4 import { EditCustomConfigComponent } from '../../../+admin/config/edit-custom-config/'
5 import { ConfigService } from '@app/+admin/config/shared/config.service'
6
7 export abstract class UserEdit extends FormReactive {
8
9 videoQuotaOptions: { value: string, label: string }[] = []
10 videoQuotaDailyOptions: { value: string, label: string }[] = []
11 roles = Object.keys(USER_ROLE_LABELS).map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
12
13 protected abstract serverService: ServerService
14 protected abstract configService: ConfigService
15 abstract isCreation (): boolean
16 abstract getFormButtonTitle (): string
17
18 isTranscodingInformationDisplayed () {
19 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
20
21 return this.serverService.getConfig().transcoding.enabledResolutions.length !== 0 &&
22 formVideoQuota > 0
23 }
24
25 computeQuotaWithTranscoding () {
26 const resolutions = this.serverService.getConfig().transcoding.enabledResolutions
27 const higherResolution = VideoResolution.H_1080P
28 let multiplier = 0
29
30 for (const resolution of resolutions) {
31 multiplier += resolution / higherResolution
32 }
33
34 return multiplier * parseInt(this.form.value['videoQuota'], 10)
35 }
36
37 protected buildQuotaOptions () {
38 // These are used by a HTML select, so convert key into strings
39 this.videoQuotaOptions = this.configService
40 .videoQuotaOptions.map(q => ({ value: q.value.toString(), label: q.label }))
41
42 this.videoQuotaDailyOptions = this.configService
43 .videoQuotaDailyOptions.map(q => ({ value: q.value.toString(), label: q.label }))
44 }
45 }