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