Merge branch 'develop' into pr/1217
[oweals/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   videoQuotaOptions: { value: string, label: string }[] = []
8   videoQuotaDailyOptions: { value: string, label: string }[] = []
9   roles = Object.keys(USER_ROLE_LABELS).map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
10   username: string
11   userId: number
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 transcodingConfig = this.serverService.getConfig().transcoding
27
28     const resolutions = transcodingConfig.enabledResolutions
29     const higherResolution = VideoResolution.H_1080P
30     let multiplier = 0
31
32     for (const resolution of resolutions) {
33       multiplier += resolution / higherResolution
34     }
35
36     if (transcodingConfig.hls.enabled) multiplier *= 2
37
38     return multiplier * parseInt(this.form.value['videoQuota'], 10)
39   }
40
41   resetPassword () {
42     return
43   }
44
45   protected buildQuotaOptions () {
46     // These are used by a HTML select, so convert key into strings
47     this.videoQuotaOptions = this.configService
48                                  .videoQuotaOptions.map(q => ({ value: q.value.toString(), label: q.label }))
49
50     this.videoQuotaDailyOptions = this.configService
51                                       .videoQuotaDailyOptions.map(q => ({ value: q.value.toString(), label: q.label }))
52   }
53 }