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'
10 selector: 'my-edit-basic-configuration',
11 templateUrl: './edit-basic-configuration.component.html',
12 styleUrls: [ './edit-custom-config.component.scss' ]
14 export class EditBasicConfigurationComponent implements OnInit, OnChanges {
15 @Input() form: FormGroup
16 @Input() formErrors: any
18 @Input() serverConfig: HTMLServerConfig
20 signupAlertMessage: string
21 defaultLandingPageOptions: SelectOptionsItem[] = []
24 private configService: ConfigService,
25 private menuService: MenuService
29 this.buildLandingPageOptions()
30 this.checkSignupField()
33 ngOnChanges (changes: SimpleChanges) {
34 if (changes['serverConfig']) {
35 this.buildLandingPageOptions()
39 countExternalAuth () {
40 return this.serverConfig.plugin.registeredExternalAuths.length
43 getVideoQuotaOptions () {
44 return this.configService.videoQuotaOptions
47 getVideoQuotaDailyOptions () {
48 return this.configService.videoQuotaDailyOptions
51 getAvailableThemes () {
52 return this.serverConfig.theme.registered
56 doesTrendingVideosAlgorithmsEnabledInclude (algorithm: string) {
57 const enabled = this.form.value['trending']['videos']['algorithms']['enabled']
58 if (!Array.isArray(enabled)) return false
60 return !!enabled.find((e: string) => e === algorithm)
64 return this.form.value['signup']['enabled'] === true
67 getDisabledSignupClass () {
68 return { 'disabled-checkbox-extra': !this.isSignupEnabled() }
71 hasUnlimitedSignup () {
72 return this.form.value['signup']['limit'] === -1
75 isSearchIndexEnabled () {
76 return this.form.value['search']['searchIndex']['enabled'] === true
79 getDisabledSearchIndexClass () {
80 return { 'disabled-checkbox-extra': !this.isSearchIndexEnabled() }
83 isAutoFollowIndexEnabled () {
84 return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true
87 buildLandingPageOptions () {
88 this.defaultLandingPageOptions = this.menuService.buildCommonLinks(this.serverConfig)
97 private checkSignupField () {
98 const signupControl = this.form.get('signup.enabled')
100 signupControl.valueChanges
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.`
107 this.form.patchValue({