]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts
Merge branch 'release/4.0.0' into develop
[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 countExternalAuth () {
40 return this.serverConfig.plugin.registeredExternalAuths.length
41 }
42
43 getVideoQuotaOptions () {
44 return this.configService.videoQuotaOptions
45 }
46
47 getVideoQuotaDailyOptions () {
48 return this.configService.videoQuotaDailyOptions
49 }
50
51 getAvailableThemes () {
52 return this.serverConfig.theme.registered
53 .map(t => t.name)
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
67 getDisabledSignupClass () {
68 return { 'disabled-checkbox-extra': !this.isSignupEnabled() }
69 }
70
71 hasUnlimitedSignup () {
72 return this.form.value['signup']['limit'] === -1
73 }
74
75 isSearchIndexEnabled () {
76 return this.form.value['search']['searchIndex']['enabled'] === true
77 }
78
79 getDisabledSearchIndexClass () {
80 return { 'disabled-checkbox-extra': !this.isSearchIndexEnabled() }
81 }
82
83 isAutoFollowIndexEnabled () {
84 return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true
85 }
86
87 buildLandingPageOptions () {
88 this.defaultLandingPageOptions = this.menuService.buildCommonLinks(this.serverConfig)
89 .links
90 .map(o => ({
91 id: o.path,
92 label: o.label,
93 description: o.path
94 }))
95 }
96
97 private checkSignupField () {
98 const signupControl = this.form.get('signup.enabled')
99
100 signupControl.valueChanges
101 .pipe(pairwise())
102 .subscribe(([ oldValue, newValue ]) => {
103 if (oldValue !== true && newValue === true) {
104 /* eslint-disable max-len */
105 this.signupAlertMessage = $localize`You enabled signup: we automatically enabled the "Block new videos automatically" checkbox of the "Videos" section just below.`
106
107 this.form.patchValue({
108 autoBlacklist: {
109 videos: {
110 ofUsers: {
111 enabled: true
112 }
113 }
114 }
115 })
116 }
117 })
118 }
119 }