From 2e7f262724dd64a209e0bad5930ba29bb4f801c3 Mon Sep 17 00:00:00 2001 From: Kim <1877318+kimsible@users.noreply.github.com> Date: Fri, 24 Jul 2020 08:53:25 +0200 Subject: Display user quota progress bars above upload form (#2981) * Move user-quota to my-user-quota shared component * Add user-quota to upload form * Increase progress bar height and make it focusable * Correct syntax parenthesis * Add explicit title to user-quota bars + tooltip with quota values * Hide user-quota in second upload step * Customize focus styles on user-quota Co-authored-by: kimsible --- .../app/shared/shared-main/shared-main.module.ts | 4 +- client/src/app/shared/shared-main/users/index.ts | 1 + .../shared-main/users/user-quota.component.html | 21 +++++++ .../shared-main/users/user-quota.component.scss | 31 ++++++++++ .../shared-main/users/user-quota.component.ts | 68 ++++++++++++++++++++++ 5 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 client/src/app/shared/shared-main/users/user-quota.component.html create mode 100644 client/src/app/shared/shared-main/users/user-quota.component.scss create mode 100644 client/src/app/shared/shared-main/users/user-quota.component.ts (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/shared-main/shared-main.module.ts b/client/src/app/shared/shared-main/shared-main.module.ts index 732914e34..22a207e51 100644 --- a/client/src/app/shared/shared-main/shared-main.module.ts +++ b/client/src/app/shared/shared-main/shared-main.module.ts @@ -26,7 +26,7 @@ import { DateToggleComponent } from './date' import { FeedComponent } from './feeds' import { LoaderComponent, SmallLoaderComponent } from './loaders' import { HelpComponent, ListOverflowComponent, TopMenuDropdownComponent } from './misc' -import { UserHistoryService, UserNotificationsComponent, UserNotificationService } from './users' +import { UserHistoryService, UserNotificationsComponent, UserNotificationService, UserQuotaComponent } from './users' import { RedundancyService, VideoImportService, VideoOwnershipService, VideoService } from './video' import { VideoCaptionService } from './video-caption' import { VideoChannelService } from './video-channel' @@ -83,6 +83,7 @@ import { AUTH_INTERCEPTOR_PROVIDER } from './auth' ListOverflowComponent, TopMenuDropdownComponent, + UserQuotaComponent, UserNotificationsComponent ], @@ -132,6 +133,7 @@ import { AUTH_INTERCEPTOR_PROVIDER } from './auth' ListOverflowComponent, TopMenuDropdownComponent, + UserQuotaComponent, UserNotificationsComponent ], diff --git a/client/src/app/shared/shared-main/users/index.ts b/client/src/app/shared/shared-main/users/index.ts index 83401ab52..130082af6 100644 --- a/client/src/app/shared/shared-main/users/index.ts +++ b/client/src/app/shared/shared-main/users/index.ts @@ -2,3 +2,4 @@ export * from './user-history.service' export * from './user-notification.model' export * from './user-notification.service' export * from './user-notifications.component' +export * from './user-quota.component' diff --git a/client/src/app/shared/shared-main/users/user-quota.component.html b/client/src/app/shared/shared-main/users/user-quota.component.html new file mode 100644 index 000000000..f9fb32133 --- /dev/null +++ b/client/src/app/shared/shared-main/users/user-quota.component.html @@ -0,0 +1,21 @@ +
+
+ Total video quota +
+
+ {{ userVideoQuotaUsed | bytes: 0 }}
+ {{ userVideoQuota }} +
+
+ +
+ Daily video quota +
+
+ {{ userVideoQuotaUsedDaily | bytes: 0 }}
+ {{ userVideoQuotaDaily }} +
+
+
\ No newline at end of file diff --git a/client/src/app/shared/shared-main/users/user-quota.component.scss b/client/src/app/shared/shared-main/users/user-quota.component.scss new file mode 100644 index 000000000..904add0f4 --- /dev/null +++ b/client/src/app/shared/shared-main/users/user-quota.component.scss @@ -0,0 +1,31 @@ +@import '_variables'; +@import '_mixins'; + +.user-quota { + font-size: 15px; + margin-top: 20px; + + label { + margin-right: 5px; + } + + &, .progress { + width: 100% !important; + } + + .user-quota-title, .progress { + @include disable-outline; + @include button-focus(pvar(--mainColorLightest)); + } + + .progress { + @include progressbar; + + height: 2rem; + + span { + align-self: center; + } + } +} + diff --git a/client/src/app/shared/shared-main/users/user-quota.component.ts b/client/src/app/shared/shared-main/users/user-quota.component.ts new file mode 100644 index 000000000..a8f56e4d6 --- /dev/null +++ b/client/src/app/shared/shared-main/users/user-quota.component.ts @@ -0,0 +1,68 @@ +import { Subject } from 'rxjs' +import { BytesPipe } from 'ngx-pipes' +import { Component, Input, OnInit } from '@angular/core' +import { User, UserService } from '@app/core' +import { I18n } from '@ngx-translate/i18n-polyfill' + +@Component({ + selector: 'my-user-quota', + templateUrl: './user-quota.component.html', + styleUrls: ['./user-quota.component.scss'] +}) + +export class UserQuotaComponent implements OnInit { + @Input() user: User = null + @Input() userInformationLoaded: Subject + + userVideoQuota = '0' + userVideoQuotaUsed = 0 + userVideoQuotaPercentage = 15 + + userVideoQuotaDaily = '0' + userVideoQuotaUsedDaily = 0 + userVideoQuotaDailyPercentage = 15 + + constructor ( + private userService: UserService, + private i18n: I18n + ) { } + + ngOnInit () { + this.userInformationLoaded.subscribe( + () => { + if (this.user.videoQuota !== -1) { + this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString() + } else { + this.userVideoQuota = this.i18n('Unlimited') + } + + if (this.user.videoQuotaDaily !== -1) { + this.userVideoQuotaDaily = new BytesPipe().transform(this.user.videoQuotaDaily, 0).toString() + } else { + this.userVideoQuotaDaily = this.i18n('Unlimited') + } + } + ) + + this.userService.getMyVideoQuotaUsed() + .subscribe(data => { + this.userVideoQuotaUsed = data.videoQuotaUsed + this.userVideoQuotaPercentage = this.userVideoQuotaUsed * 100 / this.user.videoQuota + + this.userVideoQuotaUsedDaily = data.videoQuotaUsedDaily + this.userVideoQuotaDailyPercentage = this.userVideoQuotaUsedDaily * 100 / this.user.videoQuotaDaily + }) + } + + hasDailyQuota () { + return this.user.videoQuotaDaily !== -1 + } + + titleVideoQuota () { + return `${new BytesPipe().transform(this.userVideoQuotaUsed, 0).toString()} / ${this.userVideoQuota}` + } + + titleVideoQuotaDaily () { + return `${new BytesPipe().transform(this.userVideoQuotaUsedDaily, 0).toString()} / ${this.userVideoQuotaDaily}` + } +} -- cgit v1.2.3