diff options
Diffstat (limited to 'client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts')
-rw-r--r-- | client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts new file mode 100644 index 000000000..9a19c2913 --- /dev/null +++ b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts | |||
@@ -0,0 +1,83 @@ | |||
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 | |||
53 | isSearchIndexEnabled () { | ||
54 | return this.form.value['search']['searchIndex']['enabled'] === true | ||
55 | } | ||
56 | |||
57 | isAutoFollowIndexEnabled () { | ||
58 | return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true | ||
59 | } | ||
60 | |||
61 | private checkSignupField () { | ||
62 | const signupControl = this.form.get('signup.enabled') | ||
63 | |||
64 | signupControl.valueChanges | ||
65 | .pipe(pairwise()) | ||
66 | .subscribe(([ oldValue, newValue ]) => { | ||
67 | if (oldValue !== true && newValue === true) { | ||
68 | // tslint:disable:max-line-length | ||
69 | this.signupAlertMessage = $localize`You enabled signup: we automatically enabled the "Block new videos automatically" checkbox of the "Videos" section just below.` | ||
70 | |||
71 | this.form.patchValue({ | ||
72 | autoBlacklist: { | ||
73 | videos: { | ||
74 | ofUsers: { | ||
75 | enabled: true | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | }) | ||
80 | } | ||
81 | }) | ||
82 | } | ||
83 | } | ||