]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
CommitLineData
6a84aafd 1import { ServerService } from '../../../core'
8094a898 2import { FormReactive } from '../../../shared'
954605a8 3import { USER_ROLE_LABELS, VideoResolution } from '../../../../../../shared'
3827c3b3 4import { ConfigService } from '@app/+admin/config/shared/config.service'
1eddc9a7 5import { UserAdminFlag } from '@shared/models/users/user-flag.model'
8094a898
C
6
7export abstract class UserEdit extends FormReactive {
3827c3b3
C
8 videoQuotaOptions: { value: string, label: string }[] = []
9 videoQuotaDailyOptions: { value: string, label: string }[] = []
c199c427 10 roles = Object.keys(USER_ROLE_LABELS).map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
2fbe7f19 11 username: string
b426edd4 12 userId: number
954605a8 13
6a84aafd 14 protected abstract serverService: ServerService
3827c3b3 15 protected abstract configService: ConfigService
8094a898
C
16 abstract isCreation (): boolean
17 abstract getFormButtonTitle (): string
6a84aafd
C
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 () {
09209296
C
27 const transcodingConfig = this.serverService.getConfig().transcoding
28
29 const resolutions = transcodingConfig.enabledResolutions
6a84aafd
C
30 const higherResolution = VideoResolution.H_1080P
31 let multiplier = 0
32
33 for (const resolution of resolutions) {
34 multiplier += resolution / higherResolution
35 }
36
09209296
C
37 if (transcodingConfig.hls.enabled) multiplier *= 2
38
6a84aafd
C
39 return multiplier * parseInt(this.form.value['videoQuota'], 10)
40 }
3827c3b3 41
b426edd4
C
42 resetPassword () {
43 return
44 }
45
1eddc9a7
C
46 protected buildAdminFlags (formValue: any) {
47 return formValue.byPassAutoBlacklist ? UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
48 }
49
3827c3b3
C
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 }
8094a898 58}