]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Put video quota info in its own component
authorChocobozzz <me@florianbigard.com>
Wed, 28 Sep 2022 11:59:23 +0000 (13:59 +0200)
committerChocobozzz <chocobozzz@cpy.re>
Wed, 28 Sep 2022 12:04:06 +0000 (14:04 +0200)
12 files changed:
client/src/app/+admin/admin.module.ts
client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html
client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts
client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.scss
client/src/app/+admin/overview/users/user-edit/user-edit.component.html
client/src/app/+admin/overview/users/user-edit/user-edit.component.scss
client/src/app/+admin/overview/users/user-edit/user-edit.ts
client/src/app/+admin/shared/index.ts [new file with mode: 0644]
client/src/app/+admin/shared/shared-admin.module.ts [new file with mode: 0644]
client/src/app/+admin/shared/user-real-quota-info.component.html [new file with mode: 0644]
client/src/app/+admin/shared/user-real-quota-info.component.scss [new file with mode: 0644]
client/src/app/+admin/shared/user-real-quota-info.component.ts [new file with mode: 0644]

index 366e29883c29d9e15dfd4b0a42278181ee50459a..f01967ea6c27ee5a49d59cc8625a92f4eb5cb0b6 100644 (file)
@@ -49,6 +49,7 @@ import {
   PluginSearchComponent,
   PluginShowInstalledComponent
 } from './plugins'
+import { SharedAdminModule } from './shared'
 import { JobService, LogsComponent, LogsService } from './system'
 import { DebugComponent, DebugService } from './system/debug'
 import { JobsComponent } from './system/jobs/jobs.component'
@@ -69,6 +70,7 @@ import { JobsComponent } from './system/jobs/jobs.component'
     SharedVideoMiniatureModule,
     SharedTablesModule,
     SharedUsersModule,
+    SharedAdminModule,
 
     TableModule,
     ChartModule
index 728185195098d18adf199828061c5e46189d72af..43f1438e0cabe6b77ad4865a88e93e99c6428a44 100644 (file)
             [clearable]="false"
           ></my-select-custom-value>
 
-          <div i18n class="transcoding-information" *ngIf="isTranscodingInformationDisplayed()">
-            Transcoding is enabled. The video quota only takes into account <strong>original</strong> video size. <br />
-            At most, a user could upload ~ {{ computeQuotaWithTranscoding() | bytes: 0 }}.
-          </div>
+          <my-user-real-quota-info [videoQuota]="getUserVideoQuota()"></my-user-real-quota-info>
 
           <div *ngIf="formErrors.user.videoQuota" class="form-error">{{ formErrors.user.videoQuota }}</div>
         </div>
index dc7802b2c6dd699b61843a7c7b7433ad555f52a4..f7de4c7decaec6bccb03bc995cdf444c65fcfeb1 100644 (file)
@@ -60,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
   }
@@ -92,28 +96,6 @@ export class EditBasicConfigurationComponent implements OnInit, OnChanges {
     return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true
   }
 
-  computeQuotaWithTranscoding () {
-    const transcodingConfig = this.serverConfig.transcoding
-
-    const resolutions = transcodingConfig.enabledResolutions
-    const higherResolution = VideoResolution.H_4K
-    let multiplier = 0
-
-    for (const resolution of resolutions) {
-      multiplier += resolution / higherResolution
-    }
-
-    if (transcodingConfig.hls.enabled) multiplier *= 2
-
-    return multiplier * parseInt(this.form.value['user']['videoQuota'], 10)
-  }
-
-  isTranscodingInformationDisplayed () {
-    const formVideoQuota = parseInt(this.form.value['user']['videoQuota'], 10)
-    return this.serverConfig.transcoding.enabledResolutions.length !== 0 &&
-           formVideoQuota > 0
-  }
-
   buildLandingPageOptions () {
     this.defaultLandingPageOptions = this.menuService.buildCommonLinks(this.serverConfig)
       .links
index dda5d0b5ed6275406fe746db1658aab346e31727..764e626ec3b51e403bd3e60beb1618c1ba2f67bd 100644 (file)
@@ -150,3 +150,9 @@ ngb-tabset:not(.previews) ::ng-deep {
     padding: 0 .3em;
   }
 }
+
+my-user-real-quota-info {
+  display: block;
+  margin-top: 5px;
+  font-size: 11px;
+}
index e484ab8b02304378fe46edb51dd94457e479c765..da5879a36fb1ae1850d9a2b95d67d0519cb021ce 100644 (file)
             [clearable]="false"
           ></my-select-custom-value>
 
-          <div i18n class="transcoding-information" *ngIf="isTranscodingInformationDisplayed()">
-            Transcoding is enabled. The video quota only takes into account <strong>original</strong> video size. <br />
-            At most, this user could upload ~ {{ computeQuotaWithTranscoding() | bytes: 0 }}.
-          </div>
+          <my-user-real-quota-info [videoQuota]="getUserVideoQuota()"></my-user-real-quota-info>
 
           <div *ngIf="formErrors.videoQuota" class="form-error">
             {{ formErrors.videoQuota }}
index 254286ae3660fa0a4686c99a260932cf55905329..68fa1215fccc15cc9f0686c4246bde7bd3ed0669 100644 (file)
@@ -41,7 +41,8 @@ button {
   margin-top: 10px;
 }
 
-.transcoding-information {
+my-user-real-quota-info {
+  display: block;
   margin-top: 5px;
   font-size: 11px;
 }
index 395d0742370142d248e46eb7c16e27171f10a244..0ba517edbb1c8d66baf97d18698db487cb8c3cfe 100644 (file)
@@ -60,33 +60,14 @@ export abstract class UserEdit extends FormReactive implements OnInit {
     ]
   }
 
-  isTranscodingInformationDisplayed () {
-    const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
-
-    return this.serverConfig.transcoding.enabledResolutions.length !== 0 &&
-           formVideoQuota > 0
-  }
-
-  computeQuotaWithTranscoding () {
-    const transcodingConfig = this.serverConfig.transcoding
-
-    const resolutions = transcodingConfig.enabledResolutions
-    const higherResolution = VideoResolution.H_4K
-    let multiplier = 0
-
-    for (const resolution of resolutions) {
-      multiplier += resolution / higherResolution
-    }
-
-    if (transcodingConfig.hls.enabled) multiplier *= 2
-
-    return multiplier * parseInt(this.form.value['videoQuota'], 10)
-  }
-
   resetPassword () {
     return
   }
 
+  getUserVideoQuota () {
+    return this.form.value['videoQuota']
+  }
+
   protected buildAdminFlags (formValue: any) {
     return formValue.byPassAutoBlock ? UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
   }
diff --git a/client/src/app/+admin/shared/index.ts b/client/src/app/+admin/shared/index.ts
new file mode 100644 (file)
index 0000000..9e3834a
--- /dev/null
@@ -0,0 +1,3 @@
+export * from './user-real-quota-info.component'
+
+export * from './shared-admin.module'
diff --git a/client/src/app/+admin/shared/shared-admin.module.ts b/client/src/app/+admin/shared/shared-admin.module.ts
new file mode 100644 (file)
index 0000000..bef7d54
--- /dev/null
@@ -0,0 +1,20 @@
+import { NgModule } from '@angular/core'
+import { SharedMainModule } from '../../shared/shared-main/shared-main.module'
+import { UserRealQuotaInfoComponent } from './user-real-quota-info.component'
+
+@NgModule({
+  imports: [
+    SharedMainModule
+  ],
+
+  declarations: [
+    UserRealQuotaInfoComponent
+  ],
+
+  exports: [
+    UserRealQuotaInfoComponent
+  ],
+
+  providers: []
+})
+export class SharedAdminModule { }
diff --git a/client/src/app/+admin/shared/user-real-quota-info.component.html b/client/src/app/+admin/shared/user-real-quota-info.component.html
new file mode 100644 (file)
index 0000000..b975ab1
--- /dev/null
@@ -0,0 +1,4 @@
+<div i18n class="transcoding-information" *ngIf="isTranscodingInformationDisplayed()">
+  The video quota only takes into account <strong>original</strong> video size. <br />
+  Since transcoding is enabled, videos size can be at most ~ {{ computeQuotaWithTranscoding() | bytes: 0 }}.
+</div>
diff --git a/client/src/app/+admin/shared/user-real-quota-info.component.scss b/client/src/app/+admin/shared/user-real-quota-info.component.scss
new file mode 100644 (file)
index 0000000..40083be
--- /dev/null
@@ -0,0 +1,2 @@
+@use '_variables' as *;
+@use '_mixins' as *;
diff --git a/client/src/app/+admin/shared/user-real-quota-info.component.ts b/client/src/app/+admin/shared/user-real-quota-info.component.ts
new file mode 100644 (file)
index 0000000..069eeba
--- /dev/null
@@ -0,0 +1,44 @@
+import { Component, Input, OnInit } from '@angular/core'
+import { ServerService } from '@app/core'
+import { HTMLServerConfig, VideoResolution } from '@shared/models/index'
+
+@Component({
+  selector: 'my-user-real-quota-info',
+  templateUrl: './user-real-quota-info.component.html',
+  styleUrls: [ './user-real-quota-info.component.scss' ]
+})
+export class UserRealQuotaInfoComponent implements OnInit {
+  @Input() videoQuota: number | string
+
+  private serverConfig: HTMLServerConfig
+
+  constructor (private server: ServerService) { }
+
+  ngOnInit () {
+    this.serverConfig = this.server.getHTMLConfig()
+  }
+
+  isTranscodingInformationDisplayed () {
+    return this.serverConfig.transcoding.enabledResolutions.length !== 0 && this.getQuotaAsNumber() > 0
+  }
+
+  computeQuotaWithTranscoding () {
+    const transcodingConfig = this.serverConfig.transcoding
+
+    const resolutions = transcodingConfig.enabledResolutions
+    const higherResolution = VideoResolution.H_4K
+    let multiplier = 0
+
+    for (const resolution of resolutions) {
+      multiplier += resolution / higherResolution
+    }
+
+    if (transcodingConfig.hls.enabled) multiplier *= 2
+
+    return multiplier * this.getQuotaAsNumber()
+  }
+
+  private getQuotaAsNumber () {
+    return parseInt(this.videoQuota + '', 10)
+  }
+}