]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts
dc7802b2c6dd699b61843a7c7b7433ad555f52a4
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / config / edit-custom-config / edit-basic-configuration.component.ts
1 import { pairwise } from 'rxjs/operators'
2 import { SelectOptionsItem } from 'src/types/select-options-item.model'
3 import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'
4 import { FormGroup } from '@angular/forms'
5 import { MenuService, ThemeService } from '@app/core'
6 import { HTMLServerConfig, VideoResolution } from '@shared/models'
7 import { ConfigService } from '../shared/config.service'
8
9 @Component({
10 selector: 'my-edit-basic-configuration',
11 templateUrl: './edit-basic-configuration.component.html',
12 styleUrls: [ './edit-custom-config.component.scss' ]
13 })
14 export class EditBasicConfigurationComponent implements OnInit, OnChanges {
15 @Input() form: FormGroup
16 @Input() formErrors: any
17
18 @Input() serverConfig: HTMLServerConfig
19
20 signupAlertMessage: string
21 defaultLandingPageOptions: SelectOptionsItem[] = []
22 availableThemes: SelectOptionsItem[]
23
24 constructor (
25 private configService: ConfigService,
26 private menuService: MenuService,
27 private themeService: ThemeService
28 ) {}
29
30 ngOnInit () {
31 this.buildLandingPageOptions()
32 this.checkSignupField()
33 this.checkImportSyncField()
34
35 this.availableThemes = this.themeService.buildAvailableThemes()
36 }
37
38 ngOnChanges (changes: SimpleChanges) {
39 if (changes['serverConfig']) {
40 this.buildLandingPageOptions()
41 }
42 }
43
44 countExternalAuth () {
45 return this.serverConfig.plugin.registeredExternalAuths.length
46 }
47
48 getVideoQuotaOptions () {
49 return this.configService.videoQuotaOptions
50 }
51
52 getVideoQuotaDailyOptions () {
53 return this.configService.videoQuotaDailyOptions
54 }
55
56 doesTrendingVideosAlgorithmsEnabledInclude (algorithm: string) {
57 const enabled = this.form.value['trending']['videos']['algorithms']['enabled']
58 if (!Array.isArray(enabled)) return false
59
60 return !!enabled.find((e: string) => e === algorithm)
61 }
62
63 isSignupEnabled () {
64 return this.form.value['signup']['enabled'] === true
65 }
66
67 getDisabledSignupClass () {
68 return { 'disabled-checkbox-extra': !this.isSignupEnabled() }
69 }
70
71 isImportVideosHttpEnabled (): boolean {
72 return this.form.value['import']['videos']['http']['enabled'] === true
73 }
74
75 importSynchronizationChecked () {
76 return this.isImportVideosHttpEnabled() && this.form.value['import']['videoChannelSynchronization']['enabled']
77 }
78
79 hasUnlimitedSignup () {
80 return this.form.value['signup']['limit'] === -1
81 }
82
83 isSearchIndexEnabled () {
84 return this.form.value['search']['searchIndex']['enabled'] === true
85 }
86
87 getDisabledSearchIndexClass () {
88 return { 'disabled-checkbox-extra': !this.isSearchIndexEnabled() }
89 }
90
91 isAutoFollowIndexEnabled () {
92 return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true
93 }
94
95 computeQuotaWithTranscoding () {
96 const transcodingConfig = this.serverConfig.transcoding
97
98 const resolutions = transcodingConfig.enabledResolutions
99 const higherResolution = VideoResolution.H_4K
100 let multiplier = 0
101
102 for (const resolution of resolutions) {
103 multiplier += resolution / higherResolution
104 }
105
106 if (transcodingConfig.hls.enabled) multiplier *= 2
107
108 return multiplier * parseInt(this.form.value['user']['videoQuota'], 10)
109 }
110
111 isTranscodingInformationDisplayed () {
112 const formVideoQuota = parseInt(this.form.value['user']['videoQuota'], 10)
113 return this.serverConfig.transcoding.enabledResolutions.length !== 0 &&
114 formVideoQuota > 0
115 }
116
117 buildLandingPageOptions () {
118 this.defaultLandingPageOptions = this.menuService.buildCommonLinks(this.serverConfig)
119 .links
120 .map(o => ({
121 id: o.path,
122 label: o.label,
123 description: o.path
124 }))
125 }
126
127 getDefaultThemeLabel () {
128 return this.themeService.getDefaultThemeLabel()
129 }
130
131 private checkImportSyncField () {
132 const importSyncControl = this.form.get('import.videoChannelSynchronization.enabled')
133 const importVideosHttpControl = this.form.get('import.videos.http.enabled')
134
135 importVideosHttpControl.valueChanges
136 .subscribe((httpImportEnabled) => {
137 importSyncControl.setValue(httpImportEnabled && importSyncControl.value)
138 if (httpImportEnabled) {
139 importSyncControl.enable()
140 } else {
141 importSyncControl.disable()
142 }
143 })
144 }
145
146 private checkSignupField () {
147 const signupControl = this.form.get('signup.enabled')
148
149 signupControl.valueChanges
150 .pipe(pairwise())
151 .subscribe(([ oldValue, newValue ]) => {
152 if (oldValue === false && newValue === true) {
153 /* eslint-disable max-len */
154 this.signupAlertMessage = $localize`You enabled signup: we automatically enabled the "Block new videos automatically" checkbox of the "Videos" section just below.`
155
156 this.form.patchValue({
157 autoBlacklist: {
158 videos: {
159 ofUsers: {
160 enabled: true
161 }
162 }
163 }
164 })
165 }
166 })
167
168 signupControl.updateValueAndValidity()
169 }
170 }