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 roles: { value: string, label: string }[] = []
16 protected serverConfig: ServerConfig
18 protected abstract serverService: ServerService
19 protected abstract configService: ConfigService
20 protected abstract auth: AuthService
21 abstract isCreation (): boolean
22 abstract getFormButtonTitle (): string
25 this.serverConfig = this.serverService.getTmpConfig()
26 this.serverService.getConfig()
27 .subscribe(config => this.serverConfig = config)
33 const authUser = this.auth.getUser()
35 if (authUser.role === UserRole.ADMINISTRATOR) {
36 this.roles = Object.keys(USER_ROLE_LABELS)
37 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
42 { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] }
46 isTranscodingInformationDisplayed () {
47 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
49 return this.serverConfig.transcoding.enabledResolutions.length !== 0 &&
53 computeQuotaWithTranscoding () {
54 const transcodingConfig = this.serverConfig.transcoding
56 const resolutions = transcodingConfig.enabledResolutions
57 const higherResolution = VideoResolution.H_4K
60 for (const resolution of resolutions) {
61 multiplier += resolution / higherResolution
64 if (transcodingConfig.hls.enabled) multiplier *= 2
66 return multiplier * parseInt(this.form.value['videoQuota'], 10)
73 protected buildAdminFlags (formValue: any) {
74 return formValue.byPassAutoBlacklist ? UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
77 protected buildQuotaOptions () {
78 // These are used by a HTML select, so convert key into strings
79 this.videoQuotaOptions = this.configService
80 .videoQuotaOptions.map(q => ({ value: q.value.toString(), label: q.label }))
82 this.videoQuotaDailyOptions = this.configService
83 .videoQuotaDailyOptions.map(q => ({ value: q.value.toString(), label: q.label }))