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