]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts
Instance homepage support (#4007)
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / config / edit-custom-config / edit-basic-configuration.component.ts
1
2 import { pairwise } from 'rxjs/operators'
3 import { SelectOptionsItem } from 'src/types/select-options-item.model'
4 import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'
5 import { FormGroup } from '@angular/forms'
6 import { MenuService } from '@app/core'
7 import { ServerConfig } from '@shared/models'
8 import { ConfigService } from '../shared/config.service'
9
10 @Component({
11 selector: 'my-edit-basic-configuration',
12 templateUrl: './edit-basic-configuration.component.html',
13 styleUrls: [ './edit-custom-config.component.scss' ]
14 })
15 export class EditBasicConfigurationComponent implements OnInit, OnChanges {
16 @Input() form: FormGroup
17 @Input() formErrors: any
18
19 @Input() serverConfig: ServerConfig
20
21 signupAlertMessage: string
22 defaultLandingPageOptions: SelectOptionsItem[] = []
23
24 constructor (
25 private configService: ConfigService,
26 private menuService: MenuService
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 getVideoQuotaOptions () {
41 return this.configService.videoQuotaOptions
42 }
43
44 getVideoQuotaDailyOptions () {
45 return this.configService.videoQuotaDailyOptions
46 }
47
48 getAvailableThemes () {
49 return this.serverConfig.theme.registered
50 .map(t => t.name)
51 }
52
53 doesTrendingVideosAlgorithmsEnabledInclude (algorithm: string) {
54 const enabled = this.form.value['trending']['videos']['algorithms']['enabled']
55 if (!Array.isArray(enabled)) return false
56
57 return !!enabled.find((e: string) => e === algorithm)
58 }
59
60 isSignupEnabled () {
61 return this.form.value['signup']['enabled'] === true
62 }
63
64 getDisabledSignupClass () {
65 return { 'disabled-checkbox-extra': !this.isSignupEnabled() }
66 }
67
68 hasUnlimitedSignup () {
69 return this.form.value['signup']['limit'] === -1
70 }
71
72 isSearchIndexEnabled () {
73 return this.form.value['search']['searchIndex']['enabled'] === true
74 }
75
76 getDisabledSearchIndexClass () {
77 return { 'disabled-checkbox-extra': !this.isSearchIndexEnabled() }
78 }
79
80 isAutoFollowIndexEnabled () {
81 return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true
82 }
83
84 buildLandingPageOptions () {
85 this.defaultLandingPageOptions = this.menuService.buildCommonLinks(this.serverConfig)
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 }