]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/users/user-edit/user-edit.ts
Lazy load static objects
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-edit / user-edit.ts
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'
7
8 export abstract class UserEdit extends FormReactive implements OnInit {
9 videoQuotaOptions: { value: string, label: string }[] = []
10 videoQuotaDailyOptions: { value: string, label: string }[] = []
11 username: string
12 userId: number
13
14 protected serverConfig: ServerConfig
15
16 protected abstract serverService: ServerService
17 protected abstract configService: ConfigService
18 protected abstract auth: AuthService
19 abstract isCreation (): boolean
20 abstract getFormButtonTitle (): string
21
22 ngOnInit (): void {
23 this.serverConfig = this.serverService.getTmpConfig()
24 this.serverService.getConfig()
25 .subscribe(config => this.serverConfig = config)
26 }
27
28 getRoles () {
29 const authUser = this.auth.getUser()
30
31 if (authUser.role === UserRole.ADMINISTRATOR) {
32 return Object.keys(USER_ROLE_LABELS)
33 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
34 }
35
36 return [
37 { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] }
38 ]
39 }
40
41 isTranscodingInformationDisplayed () {
42 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
43
44 return this.serverConfig.transcoding.enabledResolutions.length !== 0 &&
45 formVideoQuota > 0
46 }
47
48 computeQuotaWithTranscoding () {
49 const transcodingConfig = this.serverConfig.transcoding
50
51 const resolutions = transcodingConfig.enabledResolutions
52 const higherResolution = VideoResolution.H_4K
53 let multiplier = 0
54
55 for (const resolution of resolutions) {
56 multiplier += resolution / higherResolution
57 }
58
59 if (transcodingConfig.hls.enabled) multiplier *= 2
60
61 return multiplier * parseInt(this.form.value['videoQuota'], 10)
62 }
63
64 resetPassword () {
65 return
66 }
67
68 protected buildAdminFlags (formValue: any) {
69 return formValue.byPassAutoBlacklist ? UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
70 }
71
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 }))
76
77 this.videoQuotaDailyOptions = this.configService
78 .videoQuotaDailyOptions.map(q => ({ value: q.value.toString(), label: q.label }))
79 }
80 }