]>
Commit | Line | Data |
---|---|---|
5f46d28c | 1 | import { pairwise } from 'rxjs/operators' |
2539932e C |
2 | import { SelectOptionsItem } from 'src/types/select-options-item.model' |
3 | import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core' | |
5f46d28c | 4 | import { FormGroup } from '@angular/forms' |
5e93a6d1 | 5 | import { MenuService, ThemeService } from '@app/core' |
49602b3a | 6 | import { HTMLServerConfig } from '@shared/models' |
5f46d28c C |
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 | }) | |
2539932e | 14 | export class EditBasicConfigurationComponent implements OnInit, OnChanges { |
5f46d28c C |
15 | @Input() form: FormGroup |
16 | @Input() formErrors: any | |
17 | ||
2989628b | 18 | @Input() serverConfig: HTMLServerConfig |
5f46d28c C |
19 | |
20 | signupAlertMessage: string | |
2539932e | 21 | defaultLandingPageOptions: SelectOptionsItem[] = [] |
00fe5d61 | 22 | availableThemes: SelectOptionsItem[] |
5f46d28c C |
23 | |
24 | constructor ( | |
2539932e | 25 | private configService: ConfigService, |
5e93a6d1 C |
26 | private menuService: MenuService, |
27 | private themeService: ThemeService | |
2a491182 | 28 | ) {} |
5f46d28c C |
29 | |
30 | ngOnInit () { | |
2539932e | 31 | this.buildLandingPageOptions() |
5f46d28c | 32 | this.checkSignupField() |
2a491182 | 33 | this.checkImportSyncField() |
00fe5d61 C |
34 | |
35 | this.availableThemes = this.themeService.buildAvailableThemes() | |
5f46d28c C |
36 | } |
37 | ||
2539932e C |
38 | ngOnChanges (changes: SimpleChanges) { |
39 | if (changes['serverConfig']) { | |
40 | this.buildLandingPageOptions() | |
41 | } | |
42 | } | |
43 | ||
0bc53e20 C |
44 | countExternalAuth () { |
45 | return this.serverConfig.plugin.registeredExternalAuths.length | |
46 | } | |
47 | ||
5f46d28c C |
48 | getVideoQuotaOptions () { |
49 | return this.configService.videoQuotaOptions | |
50 | } | |
51 | ||
52 | getVideoQuotaDailyOptions () { | |
53 | return this.configService.videoQuotaDailyOptions | |
54 | } | |
55 | ||
5f46d28c C |
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 | ||
f67ac646 C |
63 | getUserVideoQuota () { |
64 | return this.form.value['user']['videoQuota'] | |
65 | } | |
66 | ||
5f46d28c C |
67 | isSignupEnabled () { |
68 | return this.form.value['signup']['enabled'] === true | |
69 | } | |
70 | ||
70e33515 C |
71 | getDisabledSignupClass () { |
72 | return { 'disabled-checkbox-extra': !this.isSignupEnabled() } | |
73 | } | |
74 | ||
2a491182 F |
75 | isImportVideosHttpEnabled (): boolean { |
76 | return this.form.value['import']['videos']['http']['enabled'] === true | |
77 | } | |
78 | ||
79 | importSynchronizationChecked () { | |
80 | return this.isImportVideosHttpEnabled() && this.form.value['import']['videoChannelSynchronization']['enabled'] | |
81 | } | |
82 | ||
70e33515 C |
83 | hasUnlimitedSignup () { |
84 | return this.form.value['signup']['limit'] === -1 | |
85 | } | |
86 | ||
5f46d28c C |
87 | isSearchIndexEnabled () { |
88 | return this.form.value['search']['searchIndex']['enabled'] === true | |
89 | } | |
90 | ||
70e33515 C |
91 | getDisabledSearchIndexClass () { |
92 | return { 'disabled-checkbox-extra': !this.isSearchIndexEnabled() } | |
93 | } | |
94 | ||
5f46d28c C |
95 | isAutoFollowIndexEnabled () { |
96 | return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true | |
97 | } | |
98 | ||
2539932e C |
99 | buildLandingPageOptions () { |
100 | this.defaultLandingPageOptions = this.menuService.buildCommonLinks(this.serverConfig) | |
8beea2d3 | 101 | .links |
2539932e C |
102 | .map(o => ({ |
103 | id: o.path, | |
104 | label: o.label, | |
105 | description: o.path | |
106 | })) | |
107 | } | |
108 | ||
5e93a6d1 C |
109 | getDefaultThemeLabel () { |
110 | return this.themeService.getDefaultThemeLabel() | |
111 | } | |
112 | ||
2a491182 F |
113 | private checkImportSyncField () { |
114 | const importSyncControl = this.form.get('import.videoChannelSynchronization.enabled') | |
115 | const importVideosHttpControl = this.form.get('import.videos.http.enabled') | |
116 | ||
117 | importVideosHttpControl.valueChanges | |
118 | .subscribe((httpImportEnabled) => { | |
119 | importSyncControl.setValue(httpImportEnabled && importSyncControl.value) | |
120 | if (httpImportEnabled) { | |
121 | importSyncControl.enable() | |
122 | } else { | |
123 | importSyncControl.disable() | |
124 | } | |
125 | }) | |
126 | } | |
127 | ||
5f46d28c C |
128 | private checkSignupField () { |
129 | const signupControl = this.form.get('signup.enabled') | |
130 | ||
131 | signupControl.valueChanges | |
132 | .pipe(pairwise()) | |
133 | .subscribe(([ oldValue, newValue ]) => { | |
8224e13d | 134 | if (oldValue === false && newValue === true) { |
9df52d66 | 135 | /* eslint-disable max-len */ |
5f46d28c C |
136 | this.signupAlertMessage = $localize`You enabled signup: we automatically enabled the "Block new videos automatically" checkbox of the "Videos" section just below.` |
137 | ||
138 | this.form.patchValue({ | |
139 | autoBlacklist: { | |
140 | videos: { | |
141 | ofUsers: { | |
142 | enabled: true | |
143 | } | |
144 | } | |
145 | } | |
146 | }) | |
147 | } | |
148 | }) | |
8224e13d C |
149 | |
150 | signupControl.updateValueAndValidity() | |
5f46d28c C |
151 | } |
152 | } |