]>
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' |
2539932e | 5 | import { MenuService } from '@app/core' |
2989628b | 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[] = [] |
5f46d28c C |
22 | |
23 | constructor ( | |
2539932e C |
24 | private configService: ConfigService, |
25 | private menuService: MenuService | |
5f46d28c C |
26 | ) { } |
27 | ||
28 | ngOnInit () { | |
2539932e | 29 | this.buildLandingPageOptions() |
5f46d28c C |
30 | this.checkSignupField() |
31 | } | |
32 | ||
2539932e C |
33 | ngOnChanges (changes: SimpleChanges) { |
34 | if (changes['serverConfig']) { | |
35 | this.buildLandingPageOptions() | |
36 | } | |
37 | } | |
38 | ||
0bc53e20 C |
39 | countExternalAuth () { |
40 | return this.serverConfig.plugin.registeredExternalAuths.length | |
41 | } | |
42 | ||
5f46d28c C |
43 | getVideoQuotaOptions () { |
44 | return this.configService.videoQuotaOptions | |
45 | } | |
46 | ||
47 | getVideoQuotaDailyOptions () { | |
48 | return this.configService.videoQuotaDailyOptions | |
49 | } | |
50 | ||
51 | getAvailableThemes () { | |
52 | return this.serverConfig.theme.registered | |
53 | .map(t => t.name) | |
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 | ||
70e33515 C |
67 | getDisabledSignupClass () { |
68 | return { 'disabled-checkbox-extra': !this.isSignupEnabled() } | |
69 | } | |
70 | ||
71 | hasUnlimitedSignup () { | |
72 | return this.form.value['signup']['limit'] === -1 | |
73 | } | |
74 | ||
5f46d28c C |
75 | isSearchIndexEnabled () { |
76 | return this.form.value['search']['searchIndex']['enabled'] === true | |
77 | } | |
78 | ||
70e33515 C |
79 | getDisabledSearchIndexClass () { |
80 | return { 'disabled-checkbox-extra': !this.isSearchIndexEnabled() } | |
81 | } | |
82 | ||
5f46d28c C |
83 | isAutoFollowIndexEnabled () { |
84 | return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true | |
85 | } | |
86 | ||
2539932e C |
87 | buildLandingPageOptions () { |
88 | this.defaultLandingPageOptions = this.menuService.buildCommonLinks(this.serverConfig) | |
8beea2d3 | 89 | .links |
2539932e C |
90 | .map(o => ({ |
91 | id: o.path, | |
92 | label: o.label, | |
93 | description: o.path | |
94 | })) | |
95 | } | |
96 | ||
5f46d28c C |
97 | private checkSignupField () { |
98 | const signupControl = this.form.get('signup.enabled') | |
99 | ||
100 | signupControl.valueChanges | |
101 | .pipe(pairwise()) | |
102 | .subscribe(([ oldValue, newValue ]) => { | |
103 | if (oldValue !== true && newValue === true) { | |
9df52d66 | 104 | /* eslint-disable max-len */ |
5f46d28c C |
105 | this.signupAlertMessage = $localize`You enabled signup: we automatically enabled the "Block new videos automatically" checkbox of the "Videos" section just below.` |
106 | ||
107 | this.form.patchValue({ | |
108 | autoBlacklist: { | |
109 | videos: { | |
110 | ofUsers: { | |
111 | enabled: true | |
112 | } | |
113 | } | |
114 | } | |
115 | }) | |
116 | } | |
117 | }) | |
118 | } | |
119 | } |