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()
33 this.checkImportSyncField()
35 this.availableThemes = this.themeService.buildAvailableThemes()
38 ngOnChanges (changes: SimpleChanges) {
39 if (changes['serverConfig']) {
40 this.buildLandingPageOptions()
44 countExternalAuth () {
45 return this.serverConfig.plugin.registeredExternalAuths.length
48 getVideoQuotaOptions () {
49 return this.configService.videoQuotaOptions
52 getVideoQuotaDailyOptions () {
53 return this.configService.videoQuotaDailyOptions
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)
63 getUserVideoQuota () {
64 return this.form.value['user']['videoQuota']
68 return this.form.value['signup']['enabled'] === true
71 getDisabledSignupClass () {
72 return { 'disabled-checkbox-extra': !this.isSignupEnabled() }
75 isImportVideosHttpEnabled (): boolean {
76 return this.form.value['import']['videos']['http']['enabled'] === true
79 importSynchronizationChecked () {
80 return this.isImportVideosHttpEnabled() && this.form.value['import']['videoChannelSynchronization']['enabled']
83 hasUnlimitedSignup () {
84 return this.form.value['signup']['limit'] === -1
87 isSearchIndexEnabled () {
88 return this.form.value['search']['searchIndex']['enabled'] === true
91 getDisabledSearchIndexClass () {
92 return { 'disabled-checkbox-extra': !this.isSearchIndexEnabled() }
95 isAutoFollowIndexEnabled () {
96 return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true
99 buildLandingPageOptions () {
100 this.defaultLandingPageOptions = this.menuService.buildCommonLinks(this.serverConfig)
109 getDefaultThemeLabel () {
110 return this.themeService.getDefaultThemeLabel()
113 private checkImportSyncField () {
114 const importSyncControl = this.form.get('import.videoChannelSynchronization.enabled')
115 const importVideosHttpControl = this.form.get('import.videos.http.enabled')
117 importVideosHttpControl.valueChanges
118 .subscribe((httpImportEnabled) => {
119 importSyncControl.setValue(httpImportEnabled && importSyncControl.value)
120 if (httpImportEnabled) {
121 importSyncControl.enable()
123 importSyncControl.disable()
128 private checkSignupField () {
129 const signupControl = this.form.get('signup.enabled')
131 signupControl.valueChanges
133 .subscribe(([ oldValue, newValue ]) => {
134 if (oldValue === false && newValue === true) {
135 /* eslint-disable max-len */
136 this.signupAlertMessage = $localize`You enabled signup: we automatically enabled the "Block new videos automatically" checkbox of the "Videos" section just below.`
138 this.form.patchValue({
150 signupControl.updateValueAndValidity()