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[] = []
24 private configService: ConfigService,
25 private menuService: MenuService,
26 private themeService: ThemeService
30 this.buildLandingPageOptions()
31 this.checkSignupField()
34 ngOnChanges (changes: SimpleChanges) {
35 if (changes['serverConfig']) {
36 this.buildLandingPageOptions()
40 countExternalAuth () {
41 return this.serverConfig.plugin.registeredExternalAuths.length
44 getVideoQuotaOptions () {
45 return this.configService.videoQuotaOptions
48 getVideoQuotaDailyOptions () {
49 return this.configService.videoQuotaDailyOptions
52 getAvailableThemes () {
53 return this.themeService.getAvailableThemeLabels()
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 getDefaultThemeLabel () {
98 return this.themeService.getDefaultThemeLabel()
101 private checkSignupField () {
102 const signupControl = this.form.get('signup.enabled')
104 signupControl.valueChanges
106 .subscribe(([ oldValue, newValue ]) => {
107 if (oldValue !== true && newValue === true) {
108 /* eslint-disable max-len */
109 this.signupAlertMessage = $localize`You enabled signup: we automatically enabled the "Block new videos automatically" checkbox of the "Videos" section just below.`
111 this.form.patchValue({