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, ThemeService } 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[] = []
22 availableThemes: SelectOptionsItem[]
25 private configService: ConfigService,
26 private menuService: MenuService,
27 private themeService: ThemeService
31 this.buildLandingPageOptions()
32 this.checkSignupField()
34 this.availableThemes = this.themeService.buildAvailableThemes()
37 ngOnChanges (changes: SimpleChanges) {
38 if (changes['serverConfig']) {
39 this.buildLandingPageOptions()
43 countExternalAuth () {
44 return this.serverConfig.plugin.registeredExternalAuths.length
47 getVideoQuotaOptions () {
48 return this.configService.videoQuotaOptions
51 getVideoQuotaDailyOptions () {
52 return this.configService.videoQuotaDailyOptions
55 doesTrendingVideosAlgorithmsEnabledInclude (algorithm: string) {
56 const enabled = this.form.value['trending']['videos']['algorithms']['enabled']
57 if (!Array.isArray(enabled)) return false
59 return !!enabled.find((e: string) => e === algorithm)
63 return this.form.value['signup']['enabled'] === true
66 getDisabledSignupClass () {
67 return { 'disabled-checkbox-extra': !this.isSignupEnabled() }
70 hasUnlimitedSignup () {
71 return this.form.value['signup']['limit'] === -1
74 isSearchIndexEnabled () {
75 return this.form.value['search']['searchIndex']['enabled'] === true
78 getDisabledSearchIndexClass () {
79 return { 'disabled-checkbox-extra': !this.isSearchIndexEnabled() }
82 isAutoFollowIndexEnabled () {
83 return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true
86 buildLandingPageOptions () {
87 this.defaultLandingPageOptions = this.menuService.buildCommonLinks(this.serverConfig)
96 getDefaultThemeLabel () {
97 return this.themeService.getDefaultThemeLabel()
100 private checkSignupField () {
101 const signupControl = this.form.get('signup.enabled')
103 signupControl.valueChanges
105 .subscribe(([ oldValue, newValue ]) => {
106 if (oldValue !== true && newValue === true) {
107 /* eslint-disable max-len */
108 this.signupAlertMessage = $localize`You enabled signup: we automatically enabled the "Block new videos automatically" checkbox of the "Videos" section just below.`
110 this.form.patchValue({