]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts
Fix setting theme in client
[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[] = []
00fe5d61 22 availableThemes: SelectOptionsItem[]
5f46d28c
C
23
24 constructor (
2539932e 25 private configService: ConfigService,
5e93a6d1
C
26 private menuService: MenuService,
27 private themeService: ThemeService
5f46d28c
C
28 ) { }
29
30 ngOnInit () {
2539932e 31 this.buildLandingPageOptions()
5f46d28c 32 this.checkSignupField()
00fe5d61
C
33
34 this.availableThemes = this.themeService.buildAvailableThemes()
5f46d28c
C
35 }
36
2539932e
C
37 ngOnChanges (changes: SimpleChanges) {
38 if (changes['serverConfig']) {
39 this.buildLandingPageOptions()
40 }
41 }
42
0bc53e20
C
43 countExternalAuth () {
44 return this.serverConfig.plugin.registeredExternalAuths.length
45 }
46
5f46d28c
C
47 getVideoQuotaOptions () {
48 return this.configService.videoQuotaOptions
49 }
50
51 getVideoQuotaDailyOptions () {
52 return this.configService.videoQuotaDailyOptions
53 }
54
5f46d28c
C
55 doesTrendingVideosAlgorithmsEnabledInclude (algorithm: string) {
56 const enabled = this.form.value['trending']['videos']['algorithms']['enabled']
57 if (!Array.isArray(enabled)) return false
58
59 return !!enabled.find((e: string) => e === algorithm)
60 }
61
62 isSignupEnabled () {
63 return this.form.value['signup']['enabled'] === true
64 }
65
70e33515
C
66 getDisabledSignupClass () {
67 return { 'disabled-checkbox-extra': !this.isSignupEnabled() }
68 }
69
70 hasUnlimitedSignup () {
71 return this.form.value['signup']['limit'] === -1
72 }
73
5f46d28c
C
74 isSearchIndexEnabled () {
75 return this.form.value['search']['searchIndex']['enabled'] === true
76 }
77
70e33515
C
78 getDisabledSearchIndexClass () {
79 return { 'disabled-checkbox-extra': !this.isSearchIndexEnabled() }
80 }
81
5f46d28c
C
82 isAutoFollowIndexEnabled () {
83 return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true
84 }
85
2539932e
C
86 buildLandingPageOptions () {
87 this.defaultLandingPageOptions = this.menuService.buildCommonLinks(this.serverConfig)
8beea2d3 88 .links
2539932e
C
89 .map(o => ({
90 id: o.path,
91 label: o.label,
92 description: o.path
93 }))
94 }
95
5e93a6d1
C
96 getDefaultThemeLabel () {
97 return this.themeService.getDefaultThemeLabel()
98 }
99
5f46d28c
C
100 private checkSignupField () {
101 const signupControl = this.form.get('signup.enabled')
102
103 signupControl.valueChanges
104 .pipe(pairwise())
105 .subscribe(([ oldValue, newValue ]) => {
106 if (oldValue !== true && newValue === true) {
9df52d66 107 /* eslint-disable max-len */
5f46d28c
C
108 this.signupAlertMessage = $localize`You enabled signup: we automatically enabled the "Block new videos automatically" checkbox of the "Videos" section just below.`
109
110 this.form.patchValue({
111 autoBlacklist: {
112 videos: {
113 ofUsers: {
114 enabled: true
115 }
116 }
117 }
118 })
119 }
120 })
121 }
122}