]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts
Improve theme label
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / config / edit-custom-config / edit-basic-configuration.component.ts
1 import { pairwise } from 'rxjs/operators'
2 import { SelectOptionsItem } from 'src/types/select-options-item.model'
3 import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'
4 import { FormGroup } from '@angular/forms'
5 import { MenuService, ThemeService } from '@app/core'
6 import { HTMLServerConfig } from '@shared/models'
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 })
14 export class EditBasicConfigurationComponent implements OnInit, OnChanges {
15 @Input() form: FormGroup
16 @Input() formErrors: any
17
18 @Input() serverConfig: HTMLServerConfig
19
20 signupAlertMessage: string
21 defaultLandingPageOptions: SelectOptionsItem[] = []
22
23 constructor (
24 private configService: ConfigService,
25 private menuService: MenuService,
26 private themeService: ThemeService
27 ) { }
28
29 ngOnInit () {
30 this.buildLandingPageOptions()
31 this.checkSignupField()
32 }
33
34 ngOnChanges (changes: SimpleChanges) {
35 if (changes['serverConfig']) {
36 this.buildLandingPageOptions()
37 }
38 }
39
40 countExternalAuth () {
41 return this.serverConfig.plugin.registeredExternalAuths.length
42 }
43
44 getVideoQuotaOptions () {
45 return this.configService.videoQuotaOptions
46 }
47
48 getVideoQuotaDailyOptions () {
49 return this.configService.videoQuotaDailyOptions
50 }
51
52 getAvailableThemes () {
53 return this.themeService.getAvailableThemeLabels()
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
67 getDisabledSignupClass () {
68 return { 'disabled-checkbox-extra': !this.isSignupEnabled() }
69 }
70
71 hasUnlimitedSignup () {
72 return this.form.value['signup']['limit'] === -1
73 }
74
75 isSearchIndexEnabled () {
76 return this.form.value['search']['searchIndex']['enabled'] === true
77 }
78
79 getDisabledSearchIndexClass () {
80 return { 'disabled-checkbox-extra': !this.isSearchIndexEnabled() }
81 }
82
83 isAutoFollowIndexEnabled () {
84 return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true
85 }
86
87 buildLandingPageOptions () {
88 this.defaultLandingPageOptions = this.menuService.buildCommonLinks(this.serverConfig)
89 .links
90 .map(o => ({
91 id: o.path,
92 label: o.label,
93 description: o.path
94 }))
95 }
96
97 getDefaultThemeLabel () {
98 return this.themeService.getDefaultThemeLabel()
99 }
100
101 private checkSignupField () {
102 const signupControl = this.form.get('signup.enabled')
103
104 signupControl.valueChanges
105 .pipe(pairwise())
106 .subscribe(([ oldValue, newValue ]) => {
107 if (oldValue !== true && newValue === true) {
108 /* eslint-disable max-len */
109 this.signupAlertMessage = $localize`You enabled signup: we automatically enabled the "Block new videos automatically" checkbox of the "Videos" section just below.`
110
111 this.form.patchValue({
112 autoBlacklist: {
113 videos: {
114 ofUsers: {
115 enabled: true
116 }
117 }
118 }
119 })
120 }
121 })
122 }
123 }