From f67ac646a2c081e02b28a7ab1dc856db6ee20e2f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 28 Sep 2022 13:59:23 +0200 Subject: Put video quota info in its own component --- client/src/app/+admin/admin.module.ts | 2 + .../edit-basic-configuration.component.html | 5 +-- .../edit-basic-configuration.component.ts | 26 ++----------- .../edit-custom-config.component.scss | 6 +++ .../users/user-edit/user-edit.component.html | 5 +-- .../users/user-edit/user-edit.component.scss | 3 +- .../+admin/overview/users/user-edit/user-edit.ts | 27 ++----------- client/src/app/+admin/shared/index.ts | 3 ++ .../src/app/+admin/shared/shared-admin.module.ts | 20 ++++++++++ .../shared/user-real-quota-info.component.html | 4 ++ .../shared/user-real-quota-info.component.scss | 2 + .../shared/user-real-quota-info.component.ts | 44 ++++++++++++++++++++++ 12 files changed, 93 insertions(+), 54 deletions(-) create mode 100644 client/src/app/+admin/shared/index.ts create mode 100644 client/src/app/+admin/shared/shared-admin.module.ts create mode 100644 client/src/app/+admin/shared/user-real-quota-info.component.html create mode 100644 client/src/app/+admin/shared/user-real-quota-info.component.scss create mode 100644 client/src/app/+admin/shared/user-real-quota-info.component.ts (limited to 'client') diff --git a/client/src/app/+admin/admin.module.ts b/client/src/app/+admin/admin.module.ts index 366e29883..f01967ea6 100644 --- a/client/src/app/+admin/admin.module.ts +++ b/client/src/app/+admin/admin.module.ts @@ -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 diff --git a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html index 728185195..43f1438e0 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html +++ b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html @@ -218,10 +218,7 @@ [clearable]="false" > -
- Transcoding is enabled. The video quota only takes into account original video size.
- At most, a user could upload ~ {{ computeQuotaWithTranscoding() | bytes: 0 }}. -
+
{{ formErrors.user.videoQuota }}
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts index dc7802b2c..f7de4c7de 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts +++ b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts @@ -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 diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.scss b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.scss index dda5d0b5e..764e626ec 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.scss +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.scss @@ -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; +} diff --git a/client/src/app/+admin/overview/users/user-edit/user-edit.component.html b/client/src/app/+admin/overview/users/user-edit/user-edit.component.html index e484ab8b0..da5879a36 100644 --- a/client/src/app/+admin/overview/users/user-edit/user-edit.component.html +++ b/client/src/app/+admin/overview/users/user-edit/user-edit.component.html @@ -152,10 +152,7 @@ [clearable]="false" > -
- Transcoding is enabled. The video quota only takes into account original video size.
- At most, this user could upload ~ {{ computeQuotaWithTranscoding() | bytes: 0 }}. -
+
{{ formErrors.videoQuota }} diff --git a/client/src/app/+admin/overview/users/user-edit/user-edit.component.scss b/client/src/app/+admin/overview/users/user-edit/user-edit.component.scss index 254286ae3..68fa1215f 100644 --- a/client/src/app/+admin/overview/users/user-edit/user-edit.component.scss +++ b/client/src/app/+admin/overview/users/user-edit/user-edit.component.scss @@ -41,7 +41,8 @@ button { margin-top: 10px; } -.transcoding-information { +my-user-real-quota-info { + display: block; margin-top: 5px; font-size: 11px; } diff --git a/client/src/app/+admin/overview/users/user-edit/user-edit.ts b/client/src/app/+admin/overview/users/user-edit/user-edit.ts index 395d07423..0ba517edb 100644 --- a/client/src/app/+admin/overview/users/user-edit/user-edit.ts +++ b/client/src/app/+admin/overview/users/user-edit/user-edit.ts @@ -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 index 000000000..9e3834aae --- /dev/null +++ b/client/src/app/+admin/shared/index.ts @@ -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 index 000000000..bef7d54ef --- /dev/null +++ b/client/src/app/+admin/shared/shared-admin.module.ts @@ -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 index 000000000..b975ab17f --- /dev/null +++ b/client/src/app/+admin/shared/user-real-quota-info.component.html @@ -0,0 +1,4 @@ +
+ The video quota only takes into account original video size.
+ Since transcoding is enabled, videos size can be at most ~ {{ computeQuotaWithTranscoding() | bytes: 0 }}. +
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 index 000000000..40083bed3 --- /dev/null +++ b/client/src/app/+admin/shared/user-real-quota-info.component.scss @@ -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 index 000000000..069eeba12 --- /dev/null +++ b/client/src/app/+admin/shared/user-real-quota-info.component.ts @@ -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) + } +} -- cgit v1.2.3