RED-7113: Small license service refactor

This commit is contained in:
Adina Țeudan 2023-07-19 23:32:09 +03:00
parent 98dd16ca0d
commit 031b362951
12 changed files with 75 additions and 61 deletions

View File

@ -16,7 +16,7 @@
<div class="space-between flex-align-items-center">
<span>{{ license.name }}</span>
<div class="mr-10 flex-align-items-center">
<div [class.green]="license.id === licenseService.activeLicenseId" class="dot mr-4"></div>
<div [class.green]="license.id === licenseService.activeLicense.id" class="dot mr-4"></div>
<span class="small-label">{{ getStatus(license.id) | translate | uppercase }}</span>
</div>
</div>

View File

@ -29,7 +29,7 @@ export class LicenseSelectComponent {
constructor(readonly licenseService: LicenseService, private readonly _permissionsService: IqserPermissionsService) {}
getStatus(id) {
return id === this.licenseService.activeLicenseId ? translations.active : translations.inactive;
return id === this.licenseService.activeLicense.id ? translations.active : translations.inactive;
}
async licenseChanged(license: ILicense) {

View File

@ -19,15 +19,15 @@
<div translate="license-info-screen.capacity.all-documents"></div>
<div>
{{ licenseService.currentLicenseReport.totalFilesUploadedBytes | size }}
<ng-container *ngIf="uploadedBytesCapacityPercentage !== -1">
({{ uploadedBytesCapacityPercentage | number : '1.0-2' }}%)
<ng-container *ngIf="licenseService.analyzedPagesPercentageForCurrentLicensePercentage >= 0">
({{ licenseService.uploadedFilesBytesForCurrentLicensePercentage | number : '1.0-2' }}%)
</ng-container>
</div>
</div>
<div class="donut-chart-wrapper pl-20">
<redaction-donut-chart
*ngIf="uploadedBytesCapacityPercentage !== -1"
*ngIf="licenseService.uploadedFilesBytesForCurrentLicensePercentage !== -1"
[config]="donutChartConfig"
[direction]="'row'"
[radius]="80"
@ -50,7 +50,7 @@
</div>
<ng-template #capacitySubtitles>
<span *ngIf="uploadedBytesCapacityPercentage <= 100; else exceeded">
<span *ngIf="licenseService.uploadedFilesBytesForCurrentLicensePercentage <= 100; else exceeded">
{{ 'license-info-screen.capacity.storage-capacity' | translate }}
</span>

View File

@ -16,12 +16,10 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
})
export class LicenseCapacityComponent {
readonly formatSize = size;
uploadedBytesCapacityPercentage = -1;
donutChartConfig: DonutChartConfig[] = [];
readonly data$ = this.licenseService.selectedLicense$.pipe(
map(() => this.licenseService.currentLicenseReport),
tap(license => {
this.uploadedBytesCapacityPercentage = this.#getUploadedBytesCapacityPercentage(license);
this.donutChartConfig = this.#getDonutChartConfig(license);
}),
map(license => ({
@ -33,12 +31,6 @@ export class LicenseCapacityComponent {
constructor(readonly licenseService: LicenseService, private readonly _translateService: TranslateService) {}
#getUploadedBytesCapacityPercentage(license: ILicenseReport): number {
return this.licenseService.uploadedBytesCapacity
? (license.totalFilesUploadedBytes / this.licenseService.uploadedBytesCapacity) * 100
: -1;
}
#getDonutChartConfig(license: ILicenseReport): DonutChartConfig[] {
return [
{

View File

@ -2,10 +2,29 @@
<div class="section-title all-caps-label" translate="license-info-screen.usage-details"></div>
<div class="row">
<div translate="license-info-screen.current-analyzed"></div>
<div translate="license-info-screen.current-volume-analyzed"></div>
<div>
{{ licenseService.analyzedPagesInCurrentLicensingPeriod }}
({{ analysisPercentageOfLicense$ | async | number : '1.0-2' }}%)
{{ licenseService.currentLicenseReport.analysedFilesBytes | size }}
<ng-container *ngIf="licenseService.analyzedFilesBytesForCurrentLicensePercentage >= 0">
({{ licenseService.analyzedFilesBytesForCurrentLicensePercentage | number : '1.0-2' }}%)
</ng-container>
</div>
</div>
<div class="row">
<div translate="license-info-screen.total-volume-analyzed"></div>
<div>
{{ licenseService.allLicensesReport.analysedFilesBytes | size }}
</div>
</div>
<div class="row">
<div translate="license-info-screen.current-analyzed-pages"></div>
<div>
{{ licenseService.currentLicenseReport.numberOfAnalyzedPages }}
<ng-container *ngIf="licenseService.analyzedPagesPercentageForCurrentLicensePercentage >= 0">
({{ licenseService.analyzedPagesPercentageForCurrentLicensePercentage | number : '1.0-2' }}%)
</ng-container>
</div>
</div>

View File

@ -13,7 +13,6 @@ import { TranslateService } from '@ngx-translate/core';
styleUrls: ['./license-usage.component.scss'],
})
export class LicenseUsageComponent {
readonly analysisPercentageOfLicense$ = this.licenseService.selectedLicense$.pipe(map(() => this.getAnalysisPercentageOfLicense()));
readonly data$ = this.licenseService.selectedLicense$.pipe(
map(() => this.licenseService.currentLicenseReport),
map(license => ({
@ -24,12 +23,6 @@ export class LicenseUsageComponent {
constructor(readonly licenseService: LicenseService, private readonly _translateService: TranslateService) {}
getAnalysisPercentageOfLicense() {
const totalLicensedNumberOfPages = this.licenseService.totalLicensedNumberOfPages;
const numberOfAnalyzedPages = this.licenseService.analyzedPagesInCurrentLicensingPeriod;
return totalLicensedNumberOfPages > 0 ? (numberOfAnalyzedPages / totalLicensedNumberOfPages) * 100 : 100;
}
#getDatasets(license: ILicenseReport): ChartDataset[] {
const monthlyData = license.monthlyData;

View File

@ -2,7 +2,7 @@ import { inject, Injectable } from '@angular/core';
import { GenericService, Toaster } from '@iqser/common-ui';
import { ILicense, ILicenseReport, ILicenseReportRequest, ILicenses } from '@red/domain';
import { BehaviorSubject, firstValueFrom, Observable, of } from 'rxjs';
import { catchError, filter, tap } from 'rxjs/operators';
import { catchError, filter } from 'rxjs/operators';
import dayjs from 'dayjs';
import { NGXLogger } from 'ngx-logger';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
@ -42,12 +42,8 @@ const defaultOnError: ILicenses = {
export class LicenseService extends GenericService<ILicenseReport> {
readonly licenseData$: Observable<ILicenses>;
readonly selectedLicense$: Observable<ILicense>;
activeLicenseId: string;
totalLicensedNumberOfPages = 0;
currentLicenseReport: ILicenseReport = {};
allLicensesReport: ILicenseReport = {};
unlicensedPages = 0;
analyzedPagesInCurrentLicensingPeriod = 0;
protected readonly _defaultModelPath = 'report';
readonly #licenseData$ = new BehaviorSubject<ILicenses | undefined>(undefined);
readonly #selectedLicense$ = new BehaviorSubject<ILicense | undefined>(undefined);
@ -81,47 +77,53 @@ export class LicenseService extends GenericService<ILicenseReport> {
return activeLicense.features.find(f => f.name === 'pdftron').value;
}
get totalLicensedNumberOfPages(): number {
const processingPagesFeature = this.selectedLicense.features?.find(f => f.name === 'processingPages');
return Number(processingPagesFeature?.value ?? '0');
}
get analyzedPagesPercentageForCurrentLicensePercentage(): number {
return this.totalLicensedNumberOfPages
? (this.currentLicenseReport.numberOfAnalyzedPages / this.totalLicensedNumberOfPages) * 100
: -1;
}
get totalBytesCapacity(): number {
const capacityFeature = this.selectedLicense.features?.find(f => f.name === 'uploadedBytesCapacity');
return Number(capacityFeature?.value ?? '0');
}
get analyzedFilesBytesForCurrentLicensePercentage(): number {
return this.totalBytesCapacity ? (this.currentLicenseReport.analysedFilesBytes / this.totalBytesCapacity) * 100 : -1;
}
get uploadedFilesBytesForCurrentLicensePercentage(): number {
return this.totalBytesCapacity ? (this.currentLicenseReport.totalFilesUploadedBytes / this.totalBytesCapacity) * 100 : -1;
}
get unlicensedPages(): number {
return Math.max(0, this.currentLicenseReport.numberOfAnalyzedPages - this.totalLicensedNumberOfPages);
}
constructor() {
super();
this.selectedLicense$ = this.#selectedLicense$.pipe(filter(license => !!license));
this.licenseData$ = this.#licenseData$.pipe(
filter(licenses => !!licenses),
tap(data => (this.activeLicenseId = data.activeLicense)),
);
this.licenseData$ = this.#licenseData$.pipe(filter(licenses => !!licenses));
}
async loadLicenseData(license: ILicense = this.selectedLicense) {
this.totalLicensedNumberOfPages = this.getTotalLicensedNumberOfPages(license);
const startDate = dayjs(license.validFrom);
const endDate = dayjs(license.validUntil);
const currentLicenseConfig = {
this.currentLicenseReport = await this.getReport({
startDate: startDate.toDate(),
endDate: endDate.toDate(),
};
});
const allLicensesConfig = {
this.allLicensesReport = await this.getReport({
startDate: '2020-01-01T00:00:00.000Z',
endDate: '2023-12-31T00:00:00.000Z',
};
const configs = [currentLicenseConfig, allLicensesConfig];
const reports = configs.map(config => this.getReport(config));
[this.currentLicenseReport, this.allLicensesReport] = await Promise.all(reports);
if (this.currentLicenseReport.numberOfAnalyzedPages > this.totalLicensedNumberOfPages) {
this.unlicensedPages = this.currentLicenseReport.numberOfAnalyzedPages - this.totalLicensedNumberOfPages;
} else {
this.unlicensedPages = 0;
}
this.analyzedPagesInCurrentLicensingPeriod = this.currentLicenseReport.numberOfAnalyzedPages;
}
getTotalLicensedNumberOfPages(license: ILicense) {
const processingPagesFeature = license.features?.find(f => f.name === 'processingPages');
return Number(processingPagesFeature?.value ?? '0');
});
}
setDefaultSelectedLicense() {

View File

@ -1650,7 +1650,8 @@
},
"copyright-claim-text": "Copyright © 2020 - {currentYear} knecon AG (powered by IQSER)",
"copyright-claim-title": "Copyright",
"current-analyzed": "In aktuellem Lizenzzeitraum analysierte Seiten",
"current-analyzed-pages": "In aktuellem Lizenzzeitraum analysierte Seiten",
"current-volume-analyzed": "",
"custom-app-title": "Name der Anwendung",
"email-report": "E-Mail-Bericht",
"email": {
@ -1680,6 +1681,7 @@
},
"total-analyzed": "Seit {date} insgesamt analysierte Seiten",
"total-ocr-analyzed": "",
"total-volume-analyzed": "",
"unlicensed-analyzed": "Über Lizenz hinaus analysierte Seiten",
"usage-details": "Nutzungsdetails"
},

View File

@ -1650,7 +1650,8 @@
},
"copyright-claim-text": "Copyright © 2020 - {currentYear} knecon AG (powered by IQSER)",
"copyright-claim-title": "Copyright Claim",
"current-analyzed": "Analyzed Pages in Licensing Period",
"current-analyzed-pages": "Analyzed Pages in Licensing Period",
"current-volume-analyzed": "Data Volume Analyzed in Licensing Period",
"custom-app-title": "Custom Application Title",
"email-report": "Email Report",
"email": {
@ -1680,6 +1681,7 @@
},
"total-analyzed": "Total Analyzed Pages",
"total-ocr-analyzed": "Total OCR Processed Pages",
"total-volume-analyzed": "Total Data Volume Analyzed",
"unlicensed-analyzed": "Unlicensed Analyzed Pages",
"usage-details": "Page Usage Details"
},

View File

@ -1650,7 +1650,8 @@
},
"copyright-claim-text": "Copyright © 2020 - {currentYear} knecon AG (powered by IQSER)",
"copyright-claim-title": "Copyright",
"current-analyzed": "In aktuellem Lizenzzeitraum analysierte Seiten",
"current-analyzed-pages": "In aktuellem Lizenzzeitraum analysierte Seiten",
"current-volume-analyzed": "",
"custom-app-title": "Name der Anwendung",
"email-report": "E-Mail-Bericht",
"email": {
@ -1680,6 +1681,7 @@
},
"total-analyzed": "Seit {date} insgesamt analysierte Seiten",
"total-ocr-analyzed": "",
"total-volume-analyzed": "",
"unlicensed-analyzed": "Über Lizenz hinaus analysierte Seiten",
"usage-details": "Nutzungsdetails"
},

View File

@ -1650,7 +1650,8 @@
},
"copyright-claim-text": "Copyright © 2020 - {currentYear} knecon AG (powered by IQSER)",
"copyright-claim-title": "Copyright Claim",
"current-analyzed": "Analyzed Pages in Licensing Period",
"current-analyzed-pages": "Analyzed Pages in Licensing Period",
"current-volume-analyzed": "Data Volume Analyzed in Licensing Period",
"custom-app-title": "Custom Application Title",
"email-report": "Email Report",
"email": {
@ -1680,6 +1681,7 @@
},
"total-analyzed": "Total Analyzed Pages Since {date}",
"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"
},

View File

@ -5,6 +5,7 @@ export interface ILicenseData {
trashFilesUploadedBytes?: number;
numberOfAnalyzedPages?: number;
numberOfOcrPages?: number;
analysedFilesBytes?: number;
startDate?: Date;
endDate?: Date;
}
@ -15,6 +16,5 @@ export interface ILicenseReport extends ILicenseData {
numberOfAnalyzedFiles?: number;
numberOfDossiers?: number;
numberOfOcrFiles?: number;
offset?: number;
monthlyData?: ILicenseData[];
}