2017-10-19 17:33:32 +02:00
|
|
|
import { ServerService } from '../../../core'
|
2017-09-05 21:29:39 +02:00
|
|
|
import { FormReactive } from '../../../shared'
|
2017-10-27 16:55:03 +02:00
|
|
|
import { USER_ROLE_LABELS, VideoResolution } from '../../../../../../shared'
|
2018-09-26 14:46:54 +02:00
|
|
|
import { ConfigService } from '@app/+admin/config/shared/config.service'
|
2019-04-15 10:49:46 +02:00
|
|
|
import { UserAdminFlag } from '@shared/models/users/user-flag.model'
|
2017-09-05 21:29:39 +02:00
|
|
|
|
|
|
|
export abstract class UserEdit extends FormReactive {
|
2018-09-26 14:46:54 +02:00
|
|
|
videoQuotaOptions: { value: string, label: string }[] = []
|
|
|
|
videoQuotaDailyOptions: { value: string, label: string }[] = []
|
2019-06-06 14:45:57 +02:00
|
|
|
roles = Object.keys(USER_ROLE_LABELS)
|
|
|
|
.map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
|
2018-11-15 09:24:56 +01:00
|
|
|
username: string
|
2019-02-11 09:30:29 +01:00
|
|
|
userId: number
|
2017-10-27 16:55:03 +02:00
|
|
|
|
2017-10-19 17:33:32 +02:00
|
|
|
protected abstract serverService: ServerService
|
2018-09-26 14:46:54 +02:00
|
|
|
protected abstract configService: ConfigService
|
2017-09-05 21:29:39 +02:00
|
|
|
abstract isCreation (): boolean
|
|
|
|
abstract getFormButtonTitle (): string
|
2017-10-19 17:33:32 +02:00
|
|
|
|
|
|
|
isTranscodingInformationDisplayed () {
|
|
|
|
const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
|
|
|
|
|
|
|
|
return this.serverService.getConfig().transcoding.enabledResolutions.length !== 0 &&
|
|
|
|
formVideoQuota > 0
|
|
|
|
}
|
|
|
|
|
|
|
|
computeQuotaWithTranscoding () {
|
2019-01-29 08:37:25 +01:00
|
|
|
const transcodingConfig = this.serverService.getConfig().transcoding
|
|
|
|
|
|
|
|
const resolutions = transcodingConfig.enabledResolutions
|
2019-06-06 14:45:57 +02:00
|
|
|
const higherResolution = VideoResolution.H_4K
|
2017-10-19 17:33:32 +02:00
|
|
|
let multiplier = 0
|
|
|
|
|
|
|
|
for (const resolution of resolutions) {
|
|
|
|
multiplier += resolution / higherResolution
|
|
|
|
}
|
|
|
|
|
2019-01-29 08:37:25 +01:00
|
|
|
if (transcodingConfig.hls.enabled) multiplier *= 2
|
|
|
|
|
2017-10-19 17:33:32 +02:00
|
|
|
return multiplier * parseInt(this.form.value['videoQuota'], 10)
|
|
|
|
}
|
2018-09-26 14:46:54 +02:00
|
|
|
|
2019-02-11 09:30:29 +01:00
|
|
|
resetPassword () {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-04-15 10:49:46 +02:00
|
|
|
protected buildAdminFlags (formValue: any) {
|
|
|
|
return formValue.byPassAutoBlacklist ? UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
|
|
|
|
}
|
|
|
|
|
2018-09-26 14:46:54 +02:00
|
|
|
protected buildQuotaOptions () {
|
|
|
|
// These are used by a HTML select, so convert key into strings
|
|
|
|
this.videoQuotaOptions = this.configService
|
|
|
|
.videoQuotaOptions.map(q => ({ value: q.value.toString(), label: q.label }))
|
|
|
|
|
|
|
|
this.videoQuotaDailyOptions = this.configService
|
|
|
|
.videoQuotaDailyOptions.map(q => ({ value: q.value.toString(), label: q.label }))
|
|
|
|
}
|
2017-09-05 21:29:39 +02:00
|
|
|
}
|