2021-02-10 11:06:32 +01:00
import { pairwise } from 'rxjs/operators'
2021-05-27 15:59:55 +02:00
import { SelectOptionsItem } from 'src/types/select-options-item.model'
import { Component , Input , OnChanges , OnInit , SimpleChanges } from '@angular/core'
2021-02-10 11:06:32 +01:00
import { FormGroup } from '@angular/forms'
2022-06-16 14:36:51 +02:00
import { MenuService , ThemeService } from '@app/core'
2021-06-04 13:31:41 +02:00
import { HTMLServerConfig } from '@shared/models'
2021-02-10 11:06:32 +01:00
import { ConfigService } from '../shared/config.service'
@Component ( {
selector : 'my-edit-basic-configuration' ,
templateUrl : './edit-basic-configuration.component.html' ,
styleUrls : [ './edit-custom-config.component.scss' ]
} )
2021-05-27 15:59:55 +02:00
export class EditBasicConfigurationComponent implements OnInit , OnChanges {
2021-02-10 11:06:32 +01:00
@Input ( ) form : FormGroup
@Input ( ) formErrors : any
2021-06-04 13:31:41 +02:00
@Input ( ) serverConfig : HTMLServerConfig
2021-02-10 11:06:32 +01:00
signupAlertMessage : string
2021-05-27 15:59:55 +02:00
defaultLandingPageOptions : SelectOptionsItem [ ] = [ ]
2022-06-27 09:59:10 +02:00
availableThemes : SelectOptionsItem [ ]
2021-02-10 11:06:32 +01:00
constructor (
2021-05-27 15:59:55 +02:00
private configService : ConfigService ,
2022-06-16 14:36:51 +02:00
private menuService : MenuService ,
private themeService : ThemeService
2021-02-10 11:06:32 +01:00
) { }
ngOnInit ( ) {
2021-05-27 15:59:55 +02:00
this . buildLandingPageOptions ( )
2021-02-10 11:06:32 +01:00
this . checkSignupField ( )
2022-06-27 09:59:10 +02:00
this . availableThemes = this . themeService . buildAvailableThemes ( )
2021-02-10 11:06:32 +01:00
}
2021-05-27 15:59:55 +02:00
ngOnChanges ( changes : SimpleChanges ) {
if ( changes [ 'serverConfig' ] ) {
this . buildLandingPageOptions ( )
}
}
2021-12-03 17:04:47 +01:00
countExternalAuth ( ) {
return this . serverConfig . plugin . registeredExternalAuths . length
}
2021-02-10 11:06:32 +01:00
getVideoQuotaOptions ( ) {
return this . configService . videoQuotaOptions
}
getVideoQuotaDailyOptions ( ) {
return this . configService . videoQuotaDailyOptions
}
doesTrendingVideosAlgorithmsEnabledInclude ( algorithm : string ) {
const enabled = this . form . value [ 'trending' ] [ 'videos' ] [ 'algorithms' ] [ 'enabled' ]
if ( ! Array . isArray ( enabled ) ) return false
return ! ! enabled . find ( ( e : string ) = > e === algorithm )
}
isSignupEnabled ( ) {
return this . form . value [ 'signup' ] [ 'enabled' ] === true
}
2021-02-10 11:27:36 +01:00
getDisabledSignupClass ( ) {
return { 'disabled-checkbox-extra' : ! this . isSignupEnabled ( ) }
}
hasUnlimitedSignup ( ) {
return this . form . value [ 'signup' ] [ 'limit' ] === - 1
}
2021-02-10 11:06:32 +01:00
isSearchIndexEnabled ( ) {
return this . form . value [ 'search' ] [ 'searchIndex' ] [ 'enabled' ] === true
}
2021-02-10 11:27:36 +01:00
getDisabledSearchIndexClass ( ) {
return { 'disabled-checkbox-extra' : ! this . isSearchIndexEnabled ( ) }
}
2021-02-10 11:06:32 +01:00
isAutoFollowIndexEnabled ( ) {
return this . form . value [ 'followings' ] [ 'instance' ] [ 'autoFollowIndex' ] [ 'enabled' ] === true
}
2021-05-27 15:59:55 +02:00
buildLandingPageOptions ( ) {
this . defaultLandingPageOptions = this . menuService . buildCommonLinks ( this . serverConfig )
2021-06-07 13:16:50 +02:00
. links
2021-05-27 15:59:55 +02:00
. map ( o = > ( {
id : o.path ,
label : o.label ,
description : o.path
} ) )
}
2022-06-16 14:36:51 +02:00
getDefaultThemeLabel ( ) {
return this . themeService . getDefaultThemeLabel ( )
}
2021-02-10 11:06:32 +01:00
private checkSignupField ( ) {
const signupControl = this . form . get ( 'signup.enabled' )
signupControl . valueChanges
. pipe ( pairwise ( ) )
. subscribe ( ( [ oldValue , newValue ] ) = > {
2022-07-28 09:45:15 +02:00
if ( oldValue === false && newValue === true ) {
2021-08-17 14:42:53 +02:00
/* eslint-disable max-len */
2021-02-10 11:06:32 +01:00
this . signupAlertMessage = $localize ` You enabled signup: we automatically enabled the "Block new videos automatically" checkbox of the "Videos" section just below. `
this . form . patchValue ( {
autoBlacklist : {
videos : {
ofUsers : {
enabled : true
}
}
}
} )
}
} )
2022-07-28 09:45:15 +02:00
signupControl . updateValueAndValidity ( )
2021-02-10 11:06:32 +01:00
}
}