1 import { AuthService, ServerService } from '../../../core'
2 import { FormReactive } from '../../../shared'
3 import { ServerConfig, USER_ROLE_LABELS, UserRole, VideoResolution } from '../../../../../../shared'
4 import { ConfigService } from '@app/+admin/config/shared/config.service'
5 import { UserAdminFlag } from '@shared/models/users/user-flag.model'
6 import { OnInit } from '@angular/core'
8 export abstract class UserEdit extends FormReactive implements OnInit {
9 videoQuotaOptions: { value: string, label: string }[] = []
10 videoQuotaDailyOptions: { value: string, label: string }[] = []
14 protected serverConfig: ServerConfig
16 protected abstract serverService: ServerService
17 protected abstract configService: ConfigService
18 protected abstract auth: AuthService
19 abstract isCreation (): boolean
20 abstract getFormButtonTitle (): string
23 this.serverConfig = this.serverService.getTmpConfig()
24 this.serverService.getConfig()
25 .subscribe(config => this.serverConfig = config)
29 const authUser = this.auth.getUser()
31 if (authUser.role === UserRole.ADMINISTRATOR) {
32 return Object.keys(USER_ROLE_LABELS)
33 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
37 { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] }
41 isTranscodingInformationDisplayed () {
42 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
44 return this.serverConfig.transcoding.enabledResolutions.length !== 0 &&
48 computeQuotaWithTranscoding () {
49 const transcodingConfig = this.serverConfig.transcoding
51 const resolutions = transcodingConfig.enabledResolutions
52 const higherResolution = VideoResolution.H_4K
55 for (const resolution of resolutions) {
56 multiplier += resolution / higherResolution
59 if (transcodingConfig.hls.enabled) multiplier *= 2
61 return multiplier * parseInt(this.form.value['videoQuota'], 10)
68 protected buildAdminFlags (formValue: any) {
69 return formValue.byPassAutoBlacklist ? UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
72 protected buildQuotaOptions () {
73 // These are used by a HTML select, so convert key into strings
74 this.videoQuotaOptions = this.configService
75 .videoQuotaOptions.map(q => ({ value: q.value.toString(), label: q.label }))
77 this.videoQuotaDailyOptions = this.configService
78 .videoQuotaDailyOptions.map(q => ({ value: q.value.toString(), label: q.label }))