]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts
Put video quota info in its own component
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / config / edit-custom-config / edit-basic-configuration.component.ts
index 74fdb87a18c663f3669b4115bb18a612769b13f0..f7de4c7decaec6bccb03bc995cdf444c65fcfeb1 100644 (file)
@@ -2,8 +2,8 @@ import { pairwise } from 'rxjs/operators'
 import { SelectOptionsItem } from 'src/types/select-options-item.model'
 import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'
 import { FormGroup } from '@angular/forms'
-import { MenuService } from '@app/core'
-import { ServerConfig } from '@shared/models'
+import { MenuService, ThemeService } from '@app/core'
+import { HTMLServerConfig, VideoResolution } from '@shared/models'
 import { ConfigService } from '../shared/config.service'
 
 @Component({
@@ -15,19 +15,24 @@ export class EditBasicConfigurationComponent implements OnInit, OnChanges {
   @Input() form: FormGroup
   @Input() formErrors: any
 
-  @Input() serverConfig: ServerConfig
+  @Input() serverConfig: HTMLServerConfig
 
   signupAlertMessage: string
   defaultLandingPageOptions: SelectOptionsItem[] = []
+  availableThemes: SelectOptionsItem[]
 
   constructor (
     private configService: ConfigService,
-    private menuService: MenuService
-  ) { }
+    private menuService: MenuService,
+    private themeService: ThemeService
+  ) {}
 
   ngOnInit () {
     this.buildLandingPageOptions()
     this.checkSignupField()
+    this.checkImportSyncField()
+
+    this.availableThemes = this.themeService.buildAvailableThemes()
   }
 
   ngOnChanges (changes: SimpleChanges) {
@@ -36,6 +41,10 @@ export class EditBasicConfigurationComponent implements OnInit, OnChanges {
     }
   }
 
+  countExternalAuth () {
+    return this.serverConfig.plugin.registeredExternalAuths.length
+  }
+
   getVideoQuotaOptions () {
     return this.configService.videoQuotaOptions
   }
@@ -44,11 +53,6 @@ export class EditBasicConfigurationComponent implements OnInit, OnChanges {
     return this.configService.videoQuotaDailyOptions
   }
 
-  getAvailableThemes () {
-    return this.serverConfig.theme.registered
-      .map(t => t.name)
-  }
-
   doesTrendingVideosAlgorithmsEnabledInclude (algorithm: string) {
     const enabled = this.form.value['trending']['videos']['algorithms']['enabled']
     if (!Array.isArray(enabled)) return false
@@ -56,6 +60,10 @@ export class EditBasicConfigurationComponent implements OnInit, OnChanges {
     return !!enabled.find((e: string) => e === algorithm)
   }
 
+  getUserVideoQuota () {
+    return this.form.value['user']['videoQuota']
+  }
+
   isSignupEnabled () {
     return this.form.value['signup']['enabled'] === true
   }
@@ -64,6 +72,14 @@ export class EditBasicConfigurationComponent implements OnInit, OnChanges {
     return { 'disabled-checkbox-extra': !this.isSignupEnabled() }
   }
 
+  isImportVideosHttpEnabled (): boolean {
+    return this.form.value['import']['videos']['http']['enabled'] === true
+  }
+
+  importSynchronizationChecked () {
+    return this.isImportVideosHttpEnabled() && this.form.value['import']['videoChannelSynchronization']['enabled']
+  }
+
   hasUnlimitedSignup () {
     return this.form.value['signup']['limit'] === -1
   }
@@ -82,6 +98,7 @@ export class EditBasicConfigurationComponent implements OnInit, OnChanges {
 
   buildLandingPageOptions () {
     this.defaultLandingPageOptions = this.menuService.buildCommonLinks(this.serverConfig)
+      .links
       .map(o => ({
         id: o.path,
         label: o.label,
@@ -89,14 +106,33 @@ export class EditBasicConfigurationComponent implements OnInit, OnChanges {
       }))
   }
 
+  getDefaultThemeLabel () {
+    return this.themeService.getDefaultThemeLabel()
+  }
+
+  private checkImportSyncField () {
+    const importSyncControl = this.form.get('import.videoChannelSynchronization.enabled')
+    const importVideosHttpControl = this.form.get('import.videos.http.enabled')
+
+    importVideosHttpControl.valueChanges
+      .subscribe((httpImportEnabled) => {
+        importSyncControl.setValue(httpImportEnabled && importSyncControl.value)
+        if (httpImportEnabled) {
+          importSyncControl.enable()
+        } else {
+          importSyncControl.disable()
+        }
+      })
+  }
+
   private checkSignupField () {
     const signupControl = this.form.get('signup.enabled')
 
     signupControl.valueChanges
       .pipe(pairwise())
       .subscribe(([ oldValue, newValue ]) => {
-        if (oldValue !== true && newValue === true) {
-          // tslint:disable:max-line-length
+        if (oldValue === false && newValue === true) {
+          /* eslint-disable max-len */
           this.signupAlertMessage = $localize`You enabled signup: we automatically enabled the "Block new videos automatically" checkbox of the "Videos" section just below.`
 
           this.form.patchValue({
@@ -110,5 +146,7 @@ export class EditBasicConfigurationComponent implements OnInit, OnChanges {
           })
         }
       })
+
+    signupControl.updateValueAndValidity()
   }
 }