]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
CommitLineData
5f46d28c 1import { pairwise } from 'rxjs/operators'
2539932e
C
2import { SelectOptionsItem } from 'src/types/select-options-item.model'
3import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'
5f46d28c 4import { FormGroup } from '@angular/forms'
5e93a6d1 5import { MenuService, ThemeService } from '@app/core'
2989628b 6import { HTMLServerConfig } from '@shared/models'
5f46d28c
C
7import { 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 14export 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 24 private configService: ConfigService,
5e93a6d1
C
25 private menuService: MenuService,
26 private themeService: ThemeService
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
0bc53e20
C
40 countExternalAuth () {
41 return this.serverConfig.plugin.registeredExternalAuths.length
42 }
43
5f46d28c
C
44 getVideoQuotaOptions () {
45 return this.configService.videoQuotaOptions
46 }
47
48 getVideoQuotaDailyOptions () {
49 return this.configService.videoQuotaDailyOptions
50 }
51
52 getAvailableThemes () {
5e93a6d1 53 return this.themeService.getAvailableThemeLabels()
5f46d28c
C
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
5e93a6d1
C
97 getDefaultThemeLabel () {
98 return this.themeService.getDefaultThemeLabel()
99 }
100
5f46d28c
C
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) {
9df52d66 108 /* eslint-disable max-len */
5f46d28c
C
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}