]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts
Load server config on app init
[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'
2539932e 5import { MenuService } from '@app/core'
5f46d28c
C
6import { ServerConfig } from '@shared/models'
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
18 @Input() serverConfig: ServerConfig
19
20 signupAlertMessage: string
2539932e 21 defaultLandingPageOptions: SelectOptionsItem[] = []
5f46d28c
C
22
23 constructor (
2539932e
C
24 private configService: ConfigService,
25 private menuService: MenuService
5f46d28c
C
26 ) { }
27
28 ngOnInit () {
2539932e 29 this.buildLandingPageOptions()
5f46d28c
C
30 this.checkSignupField()
31 }
32
2539932e
C
33 ngOnChanges (changes: SimpleChanges) {
34 if (changes['serverConfig']) {
35 this.buildLandingPageOptions()
36 }
37 }
38
5f46d28c
C
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
70e33515
C
63 getDisabledSignupClass () {
64 return { 'disabled-checkbox-extra': !this.isSignupEnabled() }
65 }
66
67 hasUnlimitedSignup () {
68 return this.form.value['signup']['limit'] === -1
69 }
70
5f46d28c
C
71 isSearchIndexEnabled () {
72 return this.form.value['search']['searchIndex']['enabled'] === true
73 }
74
70e33515
C
75 getDisabledSearchIndexClass () {
76 return { 'disabled-checkbox-extra': !this.isSearchIndexEnabled() }
77 }
78
5f46d28c
C
79 isAutoFollowIndexEnabled () {
80 return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true
81 }
82
2539932e
C
83 buildLandingPageOptions () {
84 this.defaultLandingPageOptions = this.menuService.buildCommonLinks(this.serverConfig)
85 .map(o => ({
86 id: o.path,
87 label: o.label,
88 description: o.path
89 }))
90 }
91
5f46d28c
C
92 private checkSignupField () {
93 const signupControl = this.form.get('signup.enabled')
94
95 signupControl.valueChanges
96 .pipe(pairwise())
97 .subscribe(([ oldValue, newValue ]) => {
98 if (oldValue !== true && newValue === true) {
99 // tslint:disable:max-line-length
100 this.signupAlertMessage = $localize`You enabled signup: we automatically enabled the "Block new videos automatically" checkbox of the "Videos" section just below.`
101
102 this.form.patchValue({
103 autoBlacklist: {
104 videos: {
105 ofUsers: {
106 enabled: true
107 }
108 }
109 }
110 })
111 }
112 })
113 }
114}