From ac238d0f5fba0cb9bce26f91cf186b87f4abe8a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Wed, 16 Aug 2023 02:18:51 +0300 Subject: [PATCH] RED-7204: Show License Information depending on license features --- .../license-capacity.component.html | 16 +++---- .../license-capacity.component.ts | 2 +- .../license-usage.component.html | 14 +++---- .../license-usage/license-usage.component.ts | 32 +++++++++----- .../license-screen.component.html | 2 +- .../license-screen.component.ts | 7 +++- .../admin/screens/license/utils/constants.ts | 6 +++ .../src/app/services/license.service.ts | 42 +++++++++---------- apps/red-ui/src/assets/i18n/redact/en.json | 2 +- apps/red-ui/src/assets/i18n/scm/en.json | 2 +- 10 files changed, 74 insertions(+), 51 deletions(-) diff --git a/apps/red-ui/src/app/modules/admin/screens/license/components/license-storage/license-capacity.component.html b/apps/red-ui/src/app/modules/admin/screens/license/components/license-storage/license-capacity.component.html index 31b8bb2f2..a1028921f 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/components/license-storage/license-capacity.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/license/components/license-storage/license-capacity.component.html @@ -3,31 +3,31 @@
-
{{ licenseService.currentLicenseReport.activeFilesUploadedBytes | size }}
+
{{ licenseService.selectedLicenseReport.activeFilesUploadedBytes | size }}
-
{{ licenseService.currentLicenseReport.archivedFilesUploadedBytes | size }}
+
{{ licenseService.selectedLicenseReport.archivedFilesUploadedBytes | size }}
-
{{ licenseService.currentLicenseReport.trashFilesUploadedBytes | size }}
+
{{ licenseService.selectedLicenseReport.trashFilesUploadedBytes | size }}
- {{ licenseService.currentLicenseReport.totalFilesUploadedBytes | size }} - - ({{ licenseService.uploadedFilesBytesForCurrentLicensePercentage | number : '1.0-2' }}%) + {{ licenseService.selectedLicenseReport.totalFilesUploadedBytes | size }} + + ({{ licenseService.uploadedFilesBytesForSelectedLicensePercentage | number : '1.0-2' }}%)
- + {{ 'license-info-screen.capacity.storage-capacity' | translate }} diff --git a/apps/red-ui/src/app/modules/admin/screens/license/components/license-storage/license-capacity.component.ts b/apps/red-ui/src/app/modules/admin/screens/license/components/license-storage/license-capacity.component.ts index a1943b15f..dffab4001 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/components/license-storage/license-capacity.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/license/components/license-storage/license-capacity.component.ts @@ -18,7 +18,7 @@ export class LicenseCapacityComponent { readonly formatSize = size; donutChartConfig: DonutChartConfig[] = []; readonly data$ = this.licenseService.selectedLicense$.pipe( - map(() => this.licenseService.currentLicenseReport), + map(() => this.licenseService.selectedLicenseReport), tap(license => { this.donutChartConfig = this.#getDonutChartConfig(license); }), diff --git a/apps/red-ui/src/app/modules/admin/screens/license/components/license-usage/license-usage.component.html b/apps/red-ui/src/app/modules/admin/screens/license/components/license-usage/license-usage.component.html index ae0f382ee..fe2fcc7cc 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/components/license-usage/license-usage.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/license/components/license-usage/license-usage.component.html @@ -4,9 +4,9 @@
- {{ licenseService.currentLicenseReport.analysedFilesBytes | size }} - - ({{ licenseService.analyzedFilesBytesForCurrentLicensePercentage | number : '1.0-2' }}%) + {{ licenseService.selectedLicenseReport.analysedFilesBytes | size }} + + ({{ licenseService.analyzedFilesBytesForSelectedLicensePercentage | number : '1.0-2' }}%)
@@ -21,16 +21,16 @@
- {{ licenseService.currentLicenseReport.numberOfAnalyzedPages }} - - ({{ licenseService.analyzedPagesPercentageForCurrentLicensePercentage | number : '1.0-2' }}%) + {{ licenseService.selectedLicenseReport.numberOfAnalyzedPages }} + + ({{ licenseService.analyzedPagesPercentageForSelectedLicensePercentage | number : '1.0-2' }}%)
-
{{ licenseService.currentLicenseReport.numberOfOcrPages }}
+
{{ licenseService.selectedLicenseReport.numberOfOcrPages }}
diff --git a/apps/red-ui/src/app/modules/admin/screens/license/components/license-usage/license-usage.component.ts b/apps/red-ui/src/app/modules/admin/screens/license/components/license-usage/license-usage.component.ts index f676005c9..d1e04cc57 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/components/license-usage/license-usage.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/license/components/license-usage/license-usage.component.ts @@ -1,11 +1,11 @@ -import { Component } from '@angular/core'; +import { Component, OnDestroy } from '@angular/core'; import { LicenseService } from '@services/license.service'; import { map } from 'rxjs/operators'; import { ChartDataset } from 'chart.js'; -import { ChartBlue, ChartGreen, ChartRed } from '../../utils/constants'; +import { ChartBlue, ChartGreen, ChartRed, LicenseFeatures } from '../../utils/constants'; import { getLabelsFromLicense, getLineConfig } from '../../utils/functions'; import { TranslateService } from '@ngx-translate/core'; -import { BehaviorSubject, combineLatest } from 'rxjs'; +import { BehaviorSubject, combineLatest, Subscription } from 'rxjs'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { size } from '@iqser/common-ui/lib/utils'; @@ -19,13 +19,25 @@ enum ViewMode { templateUrl: './license-usage.component.html', styleUrls: ['./license-usage.component.scss'], }) -export class LicenseUsageComponent { +export class LicenseUsageComponent implements OnDestroy { readonly viewModes = ViewMode; - activeViewMode$ = new BehaviorSubject(ViewMode.VOLUME); - + readonly activeViewMode$ = new BehaviorSubject( + this.licenseService.getFeature(LicenseFeatures.UPLOADED_BYTES_CAPACITY) ? ViewMode.VOLUME : ViewMode.PAGES, + ); readonly data$ = combineLatest([this.licenseService.selectedLicense$, this.activeViewMode$]).pipe(map(() => this.#getData())); + private _subscription: Subscription; - constructor(readonly licenseService: LicenseService, private readonly _translateService: TranslateService) {} + constructor(readonly licenseService: LicenseService, private readonly _translateService: TranslateService) { + this._subscription = this.licenseService.selectedLicense$ + .pipe(map(() => this.licenseService.getFeature(LicenseFeatures.UPLOADED_BYTES_CAPACITY) !== undefined)) + .subscribe(hasCapacity => { + this.switchView(hasCapacity ? ViewMode.VOLUME : ViewMode.PAGES); + }); + } + + ngOnDestroy() { + this._subscription.unsubscribe(); + } switchView(mode: ViewMode): void { this.activeViewMode$.next(mode); @@ -44,7 +56,7 @@ export class LicenseUsageComponent { return { datasets: isVolume ? this.#getVolumeDatasets() : this.#getPagesDatasets(), - labels: getLabelsFromLicense(this.licenseService.currentLicenseReport), + labels: getLabelsFromLicense(this.licenseService.selectedLicenseReport), yAxisLabel: this._translateService.instant(yAxisLabel), yAxisLabelRight: this._translateService.instant(yAxisLabelRight), valueFormatter: isVolume ? value => size(value) : undefined, @@ -52,7 +64,7 @@ export class LicenseUsageComponent { } #getPagesDatasets(): ChartDataset[] { - const monthlyData = this.licenseService.currentLicenseReport.monthlyData; + const monthlyData = this.licenseService.selectedLicenseReport.monthlyData; return [ { @@ -85,7 +97,7 @@ export class LicenseUsageComponent { } #getVolumeDatasets(): ChartDataset[] { - const monthlyData = this.licenseService.currentLicenseReport.monthlyData; + const monthlyData = this.licenseService.selectedLicenseReport.monthlyData; const datasets: ChartDataset[] = [ { diff --git a/apps/red-ui/src/app/modules/admin/screens/license/license-screen/license-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/license/license-screen/license-screen.component.html index 4c210d01e..4585f72c6 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/license-screen/license-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/license/license-screen/license-screen.component.html @@ -68,7 +68,7 @@
- +
diff --git a/apps/red-ui/src/app/modules/admin/screens/license/license-screen/license-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/license/license-screen/license-screen.component.ts index e2665814e..45b58b688 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/license-screen/license-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/license/license-screen/license-screen.component.ts @@ -8,6 +8,7 @@ import { LicenseService } from '@services/license.service'; import { Roles } from '@users/roles'; import type { User } from '@red/domain'; import { getCurrentUser } from '@iqser/common-ui/lib/users'; +import { LicenseFeatures } from '../utils/constants'; @Component({ templateUrl: './license-screen.component.html', @@ -27,6 +28,10 @@ export class LicenseScreenComponent { }, ]; + get showCapacity(): boolean { + return this.licenseService.getFeature(LicenseFeatures.UPLOADED_BYTES_CAPACITY) !== undefined; + } + constructor( readonly configService: ConfigService, readonly licenseService: LicenseService, @@ -43,7 +48,7 @@ export class LicenseScreenComponent { const lineBreak = '%0D%0A'; const body = [ this._translateService.instant('license-info-screen.email.body.analyzed', { - pages: this.licenseService.currentLicenseReport.numberOfAnalyzedPages, + pages: this.licenseService.selectedLicenseReport.numberOfAnalyzedPages, }), this._translateService.instant('license-info-screen.email.body.licensed', { pages: this.licenseService.totalLicensedNumberOfPages, diff --git a/apps/red-ui/src/app/modules/admin/screens/license/utils/constants.ts b/apps/red-ui/src/app/modules/admin/screens/license/utils/constants.ts index 2b7c99a2a..d3c28aa95 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/utils/constants.ts +++ b/apps/red-ui/src/app/modules/admin/screens/license/utils/constants.ts @@ -3,3 +3,9 @@ export const ChartGreen = '#5ce594'; export const ChartBlue = '#0389ec'; export const ChartGrey = '#ccced3'; // grey-5 export const ChartBlack = '#283241'; // grey-1 + +export enum LicenseFeatures { + PROCESSING_PAGES = 'processingPages', + PDFTRON = 'pdftron', + UPLOADED_BYTES_CAPACITY = 'uploadedBytesCapacity', +} diff --git a/apps/red-ui/src/app/services/license.service.ts b/apps/red-ui/src/app/services/license.service.ts index ea13361b9..4d2559a08 100644 --- a/apps/red-ui/src/app/services/license.service.ts +++ b/apps/red-ui/src/app/services/license.service.ts @@ -1,11 +1,12 @@ import { inject, Injectable } from '@angular/core'; import { GenericService, Toaster } from '@iqser/common-ui'; -import { ILicense, ILicenseReport, ILicenseReportRequest, ILicenses } from '@red/domain'; +import { ILicense, ILicenseFeature, ILicenseReport, ILicenseReportRequest, ILicenses } from '@red/domain'; import { BehaviorSubject, firstValueFrom, Observable, of } from 'rxjs'; import { catchError, filter } from 'rxjs/operators'; import dayjs from 'dayjs'; import { NGXLogger } from 'ngx-logger'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; +import { LicenseFeatures } from '../modules/admin/screens/license/utils/constants'; const defaultOnError: ILicenses = { activeLicense: 'err', @@ -20,12 +21,12 @@ const defaultOnError: ILicenses = { validUntil: '01-01-2023', features: [ { - name: 'processingPages', + name: LicenseFeatures.PROCESSING_PAGES, type: 'NUMBER', value: '2000000', }, { - name: 'pdftron', + name: LicenseFeatures.PDFTRON, type: 'STRING', value: 'S25lY29uIEFHKGVuLmtuZWNvbi5zd2lzcyk6T0VNOkREQS1SOjpCKzpBTVMoMj' + @@ -42,7 +43,7 @@ const defaultOnError: ILicenses = { export class LicenseService extends GenericService { readonly licenseData$: Observable; readonly selectedLicense$: Observable; - currentLicenseReport: ILicenseReport = {}; + selectedLicenseReport: ILicenseReport = {}; allLicensesReport: ILicenseReport = {}; protected readonly _defaultModelPath = 'report'; readonly #licenseData$ = new BehaviorSubject(undefined); @@ -54,11 +55,6 @@ export class LicenseService extends GenericService { return this.#selectedLicense$.value; } - get uploadedBytesCapacity(): number { - const uploadedBytesCapacity = this.selectedLicense.features.find(f => f.name === 'uploadedBytesCapacity')?.value || '0'; - return parseInt(uploadedBytesCapacity, 10); - } - get activeLicense() { if (!this.#licenseData$.value) { return undefined; @@ -74,35 +70,35 @@ export class LicenseService extends GenericService { return ''; } - return activeLicense.features.find(f => f.name === 'pdftron').value; + return activeLicense.features.find(f => f.name === LicenseFeatures.PDFTRON).value; } get totalLicensedNumberOfPages(): number { - const processingPagesFeature = this.selectedLicense.features?.find(f => f.name === 'processingPages'); + const processingPagesFeature = this.getFeature(LicenseFeatures.PROCESSING_PAGES); return Number(processingPagesFeature?.value ?? '0'); } - get analyzedPagesPercentageForCurrentLicensePercentage(): number { + get analyzedPagesPercentageForSelectedLicensePercentage(): number { return this.totalLicensedNumberOfPages - ? (this.currentLicenseReport.numberOfAnalyzedPages / this.totalLicensedNumberOfPages) * 100 + ? (this.selectedLicenseReport.numberOfAnalyzedPages / this.totalLicensedNumberOfPages) * 100 : -1; } - get totalBytesCapacity(): number { - const capacityFeature = this.selectedLicense.features?.find(f => f.name === 'uploadedBytesCapacity'); + get uploadedBytesCapacity(): number { + const capacityFeature = this.getFeature(LicenseFeatures.UPLOADED_BYTES_CAPACITY); return Number(capacityFeature?.value ?? '0'); } - get analyzedFilesBytesForCurrentLicensePercentage(): number { - return this.totalBytesCapacity ? (this.currentLicenseReport.analysedFilesBytes / this.totalBytesCapacity) * 100 : -1; + get analyzedFilesBytesForSelectedLicensePercentage(): number { + return this.uploadedBytesCapacity ? (this.selectedLicenseReport.analysedFilesBytes / this.uploadedBytesCapacity) * 100 : -1; } - get uploadedFilesBytesForCurrentLicensePercentage(): number { - return this.totalBytesCapacity ? (this.currentLicenseReport.totalFilesUploadedBytes / this.totalBytesCapacity) * 100 : -1; + get uploadedFilesBytesForSelectedLicensePercentage(): number { + return this.uploadedBytesCapacity ? (this.selectedLicenseReport.totalFilesUploadedBytes / this.uploadedBytesCapacity) * 100 : -1; } get unlicensedPages(): number { - return Math.max(0, this.currentLicenseReport.numberOfAnalyzedPages - this.totalLicensedNumberOfPages); + return Math.max(0, this.selectedLicenseReport.numberOfAnalyzedPages - this.totalLicensedNumberOfPages); } constructor() { @@ -111,11 +107,15 @@ export class LicenseService extends GenericService { this.licenseData$ = this.#licenseData$.pipe(filter(licenses => !!licenses)); } + getFeature(name: string): ILicenseFeature | undefined { + return this.selectedLicense.features?.find(f => f.name === name); + } + async loadLicenseData(license: ILicense = this.selectedLicense) { const startDate = dayjs(license.validFrom); const endDate = dayjs(license.validUntil); - this.currentLicenseReport = await this.getReport({ + this.selectedLicenseReport = await this.getReport({ startDate: startDate.toDate(), endDate: endDate.toDate(), }); diff --git a/apps/red-ui/src/assets/i18n/redact/en.json b/apps/red-ui/src/assets/i18n/redact/en.json index 5e89ea950..2d1e94022 100644 --- a/apps/red-ui/src/assets/i18n/redact/en.json +++ b/apps/red-ui/src/assets/i18n/redact/en.json @@ -1773,7 +1773,7 @@ "total-ocr-analyzed": "Total OCR Processed Pages", "total-volume-analyzed": "Total Data Volume Analyzed", "unlicensed-analyzed": "Unlicensed Analyzed Pages", - "usage-details": "Page Usage Details" + "usage-details": "Usage Details" }, "license-information": "License Information", "load-all-annotations-success": "All annotations were loaded and are now visible in the document thumbnails", diff --git a/apps/red-ui/src/assets/i18n/scm/en.json b/apps/red-ui/src/assets/i18n/scm/en.json index 048521ff9..f0835dc62 100644 --- a/apps/red-ui/src/assets/i18n/scm/en.json +++ b/apps/red-ui/src/assets/i18n/scm/en.json @@ -1773,7 +1773,7 @@ "total-ocr-analyzed": "Total OCR Processed Pages Since {date}", "total-volume-analyzed": "Total Data Volume Analyzed", "unlicensed-analyzed": "Unlicensed Analyzed Pages", - "usage-details": "Page Usage Details" + "usage-details": "Usage Details" }, "license-information": "License Information", "load-all-annotations-success": "All annotations were loaded and are now visible in the document thumbnails",