]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts
Add ability to filter menu links
[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 } 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 ) { }
27
28 ngOnInit () {
29 this.buildLandingPageOptions()
30 this.checkSignupField()
31 }
32
33 ngOnChanges (changes: SimpleChanges) {
34 if (changes['serverConfig']) {
35 this.buildLandingPageOptions()
36 }
37 }
38
39 getVideoQuotaOptions () {
40 return this.configService.videoQuotaOptions
41 }
42
43 getVideoQuotaDailyOptions () {
44 return this.configService.videoQuotaDailyOptions
45 }
46
47 getAvailableThemes () {
48 return this.serverConfig.theme.registered
49 .map(t => t.name)
50 }
51
52 doesTrendingVideosAlgorithmsEnabledInclude (algorithm: string) {
53 const enabled = this.form.value['trending']['videos']['algorithms']['enabled']
54 if (!Array.isArray(enabled)) return false
55
56 return !!enabled.find((e: string) => e === algorithm)
57 }
58
59 isSignupEnabled () {
60 return this.form.value['signup']['enabled'] === true
61 }
62
63 getDisabledSignupClass () {
64 return { 'disabled-checkbox-extra': !this.isSignupEnabled() }
65 }
66
67 hasUnlimitedSignup () {
68 return this.form.value['signup']['limit'] === -1
69 }
70
71 isSearchIndexEnabled () {
72 return this.form.value['search']['searchIndex']['enabled'] === true
73 }
74
75 getDisabledSearchIndexClass () {
76 return { 'disabled-checkbox-extra': !this.isSearchIndexEnabled() }
77 }
78
79 isAutoFollowIndexEnabled () {
80 return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true
81 }
82
83 buildLandingPageOptions () {
84 this.defaultLandingPageOptions = this.menuService.buildCommonLinks(this.serverConfig)
85 .links
86 .map(o => ({
87 id: o.path,
88 label: o.label,
89 description: o.path
90 }))
91 }
92
93 private checkSignupField () {
94 const signupControl = this.form.get('signup.enabled')
95
96 signupControl.valueChanges
97 .pipe(pairwise())
98 .subscribe(([ oldValue, newValue ]) => {
99 if (oldValue !== true && newValue === true) {
100 // tslint:disable:max-line-length
101 this.signupAlertMessage = $localize`You enabled signup: we automatically enabled the "Block new videos automatically" checkbox of the "Videos" section just below.`
102
103 this.form.patchValue({
104 autoBlacklist: {
105 videos: {
106 ofUsers: {
107 enabled: true
108 }
109 }
110 }
111 })
112 }
113 })
114 }
115 }