2 import { pairwise } from 'rxjs/operators'
3 import { SelectOptionsItem } from 'src/types/select-options-item.model'
4 import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'
5 import { FormGroup } from '@angular/forms'
6 import { MenuService } from '@app/core'
7 import { ServerConfig } from '@shared/models'
8 import { ConfigService } from '../shared/config.service'
11 selector: 'my-edit-basic-configuration',
12 templateUrl: './edit-basic-configuration.component.html',
13 styleUrls: [ './edit-custom-config.component.scss' ]
15 export class EditBasicConfigurationComponent implements OnInit, OnChanges {
16 @Input() form: FormGroup
17 @Input() formErrors: any
19 @Input() serverConfig: ServerConfig
21 signupAlertMessage: string
22 defaultLandingPageOptions: SelectOptionsItem[] = []
25 private configService: ConfigService,
26 private menuService: MenuService
30 this.buildLandingPageOptions()
31 this.checkSignupField()
34 ngOnChanges (changes: SimpleChanges) {
35 if (changes['serverConfig']) {
36 this.buildLandingPageOptions()
40 getVideoQuotaOptions () {
41 return this.configService.videoQuotaOptions
44 getVideoQuotaDailyOptions () {
45 return this.configService.videoQuotaDailyOptions
48 getAvailableThemes () {
49 return this.serverConfig.theme.registered
53 doesTrendingVideosAlgorithmsEnabledInclude (algorithm: string) {
54 const enabled = this.form.value['trending']['videos']['algorithms']['enabled']
55 if (!Array.isArray(enabled)) return false
57 return !!enabled.find((e: string) => e === algorithm)
61 return this.form.value['signup']['enabled'] === true
64 getDisabledSignupClass () {
65 return { 'disabled-checkbox-extra': !this.isSignupEnabled() }
68 hasUnlimitedSignup () {
69 return this.form.value['signup']['limit'] === -1
72 isSearchIndexEnabled () {
73 return this.form.value['search']['searchIndex']['enabled'] === true
76 getDisabledSearchIndexClass () {
77 return { 'disabled-checkbox-extra': !this.isSearchIndexEnabled() }
80 isAutoFollowIndexEnabled () {
81 return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true
84 buildLandingPageOptions () {
85 this.defaultLandingPageOptions = this.menuService.buildCommonLinks(this.serverConfig)
93 private checkSignupField () {
94 const signupControl = this.form.get('signup.enabled')
96 signupControl.valueChanges
98 .subscribe(([ oldValue, newValue ]) => {
99 if (oldValue !== true && newValue === true) {
100 // tslint:disable:max-line-length
101 this.signupAlertMessage = $localize`You enabled signup: we automatically enabled the "Block new videos automatically" checkbox of the "Videos" section just below.`
103 this.form.patchValue({