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