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 import { UserAdminFlag } from '@shared/models/users/user-flag.model'
7 export abstract class UserEdit extends FormReactive {
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] }))
14 protected abstract serverService: ServerService
15 protected abstract configService: ConfigService
16 abstract isCreation (): boolean
17 abstract getFormButtonTitle (): string
19 isTranscodingInformationDisplayed () {
20 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
22 return this.serverService.getConfig().transcoding.enabledResolutions.length !== 0 &&
26 computeQuotaWithTranscoding () {
27 const transcodingConfig = this.serverService.getConfig().transcoding
29 const resolutions = transcodingConfig.enabledResolutions
30 const higherResolution = VideoResolution.H_1080P
33 for (const resolution of resolutions) {
34 multiplier += resolution / higherResolution
37 if (transcodingConfig.hls.enabled) multiplier *= 2
39 return multiplier * parseInt(this.form.value['videoQuota'], 10)
46 protected buildAdminFlags (formValue: any) {
47 return formValue.byPassAutoBlacklist ? UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
50 protected buildQuotaOptions () {
51 // These are used by a HTML select, so convert key into strings
52 this.videoQuotaOptions = this.configService
53 .videoQuotaOptions.map(q => ({ value: q.value.toString(), label: q.label }))
55 this.videoQuotaDailyOptions = this.configService
56 .videoQuotaDailyOptions.map(q => ({ value: q.value.toString(), label: q.label }))