]>
Commit | Line | Data |
---|---|---|
5f46d28c C |
1 | |
2 | import { pairwise } from 'rxjs/operators' | |
2539932e C |
3 | import { SelectOptionsItem } from 'src/types/select-options-item.model' |
4 | import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core' | |
5f46d28c | 5 | import { FormGroup } from '@angular/forms' |
2539932e | 6 | import { MenuService } from '@app/core' |
5f46d28c C |
7 | import { ServerConfig } from '@shared/models' |
8 | import { ConfigService } from '../shared/config.service' | |
9 | ||
10 | @Component({ | |
11 | selector: 'my-edit-basic-configuration', | |
12 | templateUrl: './edit-basic-configuration.component.html', | |
13 | styleUrls: [ './edit-custom-config.component.scss' ] | |
14 | }) | |
2539932e | 15 | export class EditBasicConfigurationComponent implements OnInit, OnChanges { |
5f46d28c C |
16 | @Input() form: FormGroup |
17 | @Input() formErrors: any | |
18 | ||
19 | @Input() serverConfig: ServerConfig | |
20 | ||
21 | signupAlertMessage: string | |
2539932e | 22 | defaultLandingPageOptions: SelectOptionsItem[] = [] |
5f46d28c C |
23 | |
24 | constructor ( | |
2539932e C |
25 | private configService: ConfigService, |
26 | private menuService: MenuService | |
5f46d28c C |
27 | ) { } |
28 | ||
29 | ngOnInit () { | |
2539932e | 30 | this.buildLandingPageOptions() |
5f46d28c C |
31 | this.checkSignupField() |
32 | } | |
33 | ||
2539932e C |
34 | ngOnChanges (changes: SimpleChanges) { |
35 | if (changes['serverConfig']) { | |
36 | this.buildLandingPageOptions() | |
37 | } | |
38 | } | |
39 | ||
5f46d28c C |
40 | getVideoQuotaOptions () { |
41 | return this.configService.videoQuotaOptions | |
42 | } | |
43 | ||
44 | getVideoQuotaDailyOptions () { | |
45 | return this.configService.videoQuotaDailyOptions | |
46 | } | |
47 | ||
48 | getAvailableThemes () { | |
49 | return this.serverConfig.theme.registered | |
50 | .map(t => t.name) | |
51 | } | |
52 | ||
53 | doesTrendingVideosAlgorithmsEnabledInclude (algorithm: string) { | |
54 | const enabled = this.form.value['trending']['videos']['algorithms']['enabled'] | |
55 | if (!Array.isArray(enabled)) return false | |
56 | ||
57 | return !!enabled.find((e: string) => e === algorithm) | |
58 | } | |
59 | ||
60 | isSignupEnabled () { | |
61 | return this.form.value['signup']['enabled'] === true | |
62 | } | |
63 | ||
70e33515 C |
64 | getDisabledSignupClass () { |
65 | return { 'disabled-checkbox-extra': !this.isSignupEnabled() } | |
66 | } | |
67 | ||
68 | hasUnlimitedSignup () { | |
69 | return this.form.value['signup']['limit'] === -1 | |
70 | } | |
71 | ||
5f46d28c C |
72 | isSearchIndexEnabled () { |
73 | return this.form.value['search']['searchIndex']['enabled'] === true | |
74 | } | |
75 | ||
70e33515 C |
76 | getDisabledSearchIndexClass () { |
77 | return { 'disabled-checkbox-extra': !this.isSearchIndexEnabled() } | |
78 | } | |
79 | ||
5f46d28c C |
80 | isAutoFollowIndexEnabled () { |
81 | return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true | |
82 | } | |
83 | ||
2539932e C |
84 | buildLandingPageOptions () { |
85 | this.defaultLandingPageOptions = this.menuService.buildCommonLinks(this.serverConfig) | |
86 | .map(o => ({ | |
87 | id: o.path, | |
88 | label: o.label, | |
89 | description: o.path | |
90 | })) | |
91 | } | |
92 | ||
5f46d28c C |
93 | private checkSignupField () { |
94 | const signupControl = this.form.get('signup.enabled') | |
95 | ||
96 | signupControl.valueChanges | |
97 | .pipe(pairwise()) | |
98 | .subscribe(([ oldValue, newValue ]) => { | |
99 | if (oldValue !== true && newValue === true) { | |
100 | // tslint:disable:max-line-length | |
101 | this.signupAlertMessage = $localize`You enabled signup: we automatically enabled the "Block new videos automatically" checkbox of the "Videos" section just below.` | |
102 | ||
103 | this.form.patchValue({ | |
104 | autoBlacklist: { | |
105 | videos: { | |
106 | ofUsers: { | |
107 | enabled: true | |
108 | } | |
109 | } | |
110 | } | |
111 | }) | |
112 | } | |
113 | }) | |
114 | } | |
115 | } |