]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/users/user-edit/user-edit.ts
Improving select displays, focus box-shadows for paginators, instructions for index url
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-edit / user-edit.ts
CommitLineData
a95a4cc8 1import { AuthService, ServerService } from '../../../core'
8094a898 2import { FormReactive } from '../../../shared'
ba430d75 3import { ServerConfig, USER_ROLE_LABELS, UserRole, VideoResolution } from '../../../../../../shared'
3827c3b3 4import { ConfigService } from '@app/+admin/config/shared/config.service'
1eddc9a7 5import { UserAdminFlag } from '@shared/models/users/user-flag.model'
ba430d75 6import { OnInit } from '@angular/core'
76314386
RK
7import { User } from '@app/shared/users/user.model'
8import { ScreenService } from '@app/shared/misc/screen.service'
8094a898 9
ba430d75 10export abstract class UserEdit extends FormReactive implements OnInit {
2bc9bd08
RK
11 videoQuotaOptions: { value: string, label: string, disabled?: boolean }[] = []
12 videoQuotaDailyOptions: { value: string, label: string, disabled?: boolean }[] = []
2fbe7f19 13 username: string
76314386 14 user: User
954605a8 15
a31bec51
C
16 roles: { value: string, label: string }[] = []
17
ba430d75
C
18 protected serverConfig: ServerConfig
19
6a84aafd 20 protected abstract serverService: ServerService
3827c3b3 21 protected abstract configService: ConfigService
76314386 22 protected abstract screenService: ScreenService
a95a4cc8 23 protected abstract auth: AuthService
8094a898
C
24 abstract isCreation (): boolean
25 abstract getFormButtonTitle (): string
6a84aafd 26
ba430d75
C
27 ngOnInit (): void {
28 this.serverConfig = this.serverService.getTmpConfig()
29 this.serverService.getConfig()
30 .subscribe(config => this.serverConfig = config)
a31bec51
C
31
32 this.buildRoles()
ba430d75
C
33 }
34
76314386
RK
35 get subscribersCount () {
36 const forAccount = this.user
37 ? this.user.account.followersCount
38 : 0
39 const forChannels = this.user
40 ? this.user.videoChannels.map(c => c.followersCount).reduce((a, b) => a + b, 0)
41 : 0
42 return forAccount + forChannels
43 }
44
45 isInBigView () {
46 return this.screenService.getWindowInnerWidth() > 1600
47 }
48
a31bec51 49 buildRoles () {
a95a4cc8
C
50 const authUser = this.auth.getUser()
51
52 if (authUser.role === UserRole.ADMINISTRATOR) {
a31bec51 53 this.roles = Object.keys(USER_ROLE_LABELS)
a95a4cc8 54 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
a31bec51 55 return
a95a4cc8
C
56 }
57
a31bec51 58 this.roles = [
a95a4cc8
C
59 { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] }
60 ]
61 }
62
6a84aafd
C
63 isTranscodingInformationDisplayed () {
64 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
65
ba430d75 66 return this.serverConfig.transcoding.enabledResolutions.length !== 0 &&
6a84aafd
C
67 formVideoQuota > 0
68 }
69
70 computeQuotaWithTranscoding () {
ba430d75 71 const transcodingConfig = this.serverConfig.transcoding
09209296
C
72
73 const resolutions = transcodingConfig.enabledResolutions
ad3405d0 74 const higherResolution = VideoResolution.H_4K
6a84aafd
C
75 let multiplier = 0
76
77 for (const resolution of resolutions) {
78 multiplier += resolution / higherResolution
79 }
80
09209296
C
81 if (transcodingConfig.hls.enabled) multiplier *= 2
82
6a84aafd
C
83 return multiplier * parseInt(this.form.value['videoQuota'], 10)
84 }
3827c3b3 85
b426edd4
C
86 resetPassword () {
87 return
88 }
89
1eddc9a7
C
90 protected buildAdminFlags (formValue: any) {
91 return formValue.byPassAutoBlacklist ? UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
92 }
93
3827c3b3
C
94 protected buildQuotaOptions () {
95 // These are used by a HTML select, so convert key into strings
96 this.videoQuotaOptions = this.configService
2bc9bd08 97 .videoQuotaOptions.map(q => ({ value: q.value?.toString(), label: q.label, disabled: q.disabled }))
3827c3b3
C
98
99 this.videoQuotaDailyOptions = this.configService
2bc9bd08
RK
100 .videoQuotaDailyOptions.map(q => ({ value: q.value?.toString(), label: q.label, disabled: q.disabled }))
101
102 console.log(
103 this.videoQuotaOptions,
104 this.videoQuotaDailyOptions
105 )
3827c3b3 106 }
8094a898 107}