]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/users/user-edit/user-edit.ts
Merge branch 'master' into develop
[github/Chocobozzz/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 import { UserAdminFlag } from '@shared/models/users/user-flag.model'
6
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] }))
11 username: string
12 userId: number
13
14 protected abstract serverService: ServerService
15 protected abstract configService: ConfigService
16 abstract isCreation (): boolean
17 abstract getFormButtonTitle (): string
18
19 isTranscodingInformationDisplayed () {
20 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
21
22 return this.serverService.getConfig().transcoding.enabledResolutions.length !== 0 &&
23 formVideoQuota > 0
24 }
25
26 computeQuotaWithTranscoding () {
27 const transcodingConfig = this.serverService.getConfig().transcoding
28
29 const resolutions = transcodingConfig.enabledResolutions
30 const higherResolution = VideoResolution.H_1080P
31 let multiplier = 0
32
33 for (const resolution of resolutions) {
34 multiplier += resolution / higherResolution
35 }
36
37 if (transcodingConfig.hls.enabled) multiplier *= 2
38
39 return multiplier * parseInt(this.form.value['videoQuota'], 10)
40 }
41
42 resetPassword () {
43 return
44 }
45
46 protected buildAdminFlags (formValue: any) {
47 return formValue.byPassAutoBlacklist ? UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
48 }
49
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 }))
54
55 this.videoQuotaDailyOptions = this.configService
56 .videoQuotaDailyOptions.map(q => ({ value: q.value.toString(), label: q.label }))
57 }
58 }