RED-6364: fix licenses infos
This commit is contained in:
parent
5bd1fae73f
commit
1c6a02b539
@ -75,23 +75,23 @@
|
||||
|
||||
<div class="row">
|
||||
<div
|
||||
*ngIf="licenseService.totalInfo.startDate | date : 'longDate' as startDate"
|
||||
*ngIf="licenseService.annualInfo.startDate | date : 'longDate' as startDate"
|
||||
[innerHTML]="'license-info-screen.total-analyzed' | translate : { date: startDate }"
|
||||
></div>
|
||||
<div>{{ licenseService.totalInfo.numberOfAnalyzedPages }}</div>
|
||||
<div>{{ licenseService.annualInfo.numberOfAnalyzedPages }}</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div translate="license-info-screen.current-analyzed"></div>
|
||||
<div>
|
||||
{{ licenseService.currentInfo.numberOfAnalyzedPages }}
|
||||
{{ licenseService.analyzedPagesInCurrentLicensingPeriod }}
|
||||
({{ analysisPercentageOfLicense$ | async | number : '1.0-2' }}%)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div *ngIf="!!licenseService.unlicensedInfo" class="row">
|
||||
<div *ngIf="!!licenseService.unlicensedPages" class="row">
|
||||
<div translate="license-info-screen.unlicensed-analyzed"></div>
|
||||
<div>{{ licenseService.unlicensedInfo.numberOfAnalyzedPages }}</div>
|
||||
<div>{{ licenseService.unlicensedPages }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@ -50,7 +50,7 @@ export class LicenseScreenComponent {
|
||||
|
||||
getAnalysisPercentageOfLicense() {
|
||||
const totalLicensedNumberOfPages = this.licenseService.totalLicensedNumberOfPages;
|
||||
const numberOfAnalyzedPages = this.licenseService.currentInfo.numberOfAnalyzedPages;
|
||||
const numberOfAnalyzedPages = this.licenseService.analyzedPagesInCurrentLicensingPeriod;
|
||||
return totalLicensedNumberOfPages > 0 ? (numberOfAnalyzedPages / totalLicensedNumberOfPages) * 100 : 100;
|
||||
}
|
||||
|
||||
|
||||
@ -51,20 +51,16 @@ export class LicenseService extends GenericService<ILicenseReport> {
|
||||
activeLicenseId: string;
|
||||
totalLicensedNumberOfPages = 0;
|
||||
currentInfo: ILicenseReport = {};
|
||||
totalInfo: ILicenseReport = {};
|
||||
unlicensedInfo: ILicenseReport = {};
|
||||
annualInfo: ILicenseReport = {};
|
||||
unlicensedPages = 0;
|
||||
analyzedPagesInCurrentLicensingPeriod = 0;
|
||||
protected readonly _defaultModelPath = 'report';
|
||||
readonly #licenseData$ = new BehaviorSubject<ILicenses | undefined>(undefined);
|
||||
readonly #selectedLicense$ = new BehaviorSubject<ILicense | undefined>(undefined);
|
||||
|
||||
constructor(private readonly _logger: NGXLogger) {
|
||||
super();
|
||||
this.selectedLicense$ = this.#selectedLicense$.pipe(
|
||||
filter(license => !!license),
|
||||
tap(license => {
|
||||
this.totalLicensedNumberOfPages = this.getTotalLicensedNumberOfPages(license);
|
||||
}),
|
||||
);
|
||||
this.selectedLicense$ = this.#selectedLicense$.pipe(filter(license => !!license));
|
||||
this.licenseData$ = this.#licenseData$.pipe(
|
||||
filter(licenses => !!licenses),
|
||||
tap(data => (this.activeLicenseId = data.activeLicense)),
|
||||
@ -95,6 +91,8 @@ export class LicenseService extends GenericService<ILicenseReport> {
|
||||
}
|
||||
|
||||
async loadLicenseData(license: ILicense = this.selectedLicense) {
|
||||
this.totalLicensedNumberOfPages = this.getTotalLicensedNumberOfPages(license);
|
||||
|
||||
const startDate = dayjs(license.validFrom);
|
||||
const endDate = dayjs(license.validUntil);
|
||||
|
||||
@ -102,16 +100,23 @@ export class LicenseService extends GenericService<ILicenseReport> {
|
||||
startDate: startDate.toDate(),
|
||||
endDate: endDate.toDate(),
|
||||
};
|
||||
const reports: Promise<ILicenseReport>[] = [this.getReport(currentConfig), this.getReport({})];
|
||||
|
||||
if (endDate.isBefore(dayjs())) {
|
||||
const unlicensedConfig = {
|
||||
startDate: endDate.toDate(),
|
||||
};
|
||||
reports.push(this.getReport(unlicensedConfig));
|
||||
const thisYearConfig = {
|
||||
startDate: `${startDate.year()}-01-01T00:00:00.000Z`,
|
||||
endDate: `${startDate.year()}-12-31T00:00:00.000Z`,
|
||||
};
|
||||
const configs = [currentConfig, thisYearConfig];
|
||||
const reports = configs.map(config => this.getReport(config));
|
||||
|
||||
[this.currentInfo, this.annualInfo] = await Promise.all(reports);
|
||||
|
||||
if (this.currentInfo.numberOfAnalyzedPages > this.totalLicensedNumberOfPages) {
|
||||
this.unlicensedPages = this.currentInfo.numberOfAnalyzedPages - this.totalLicensedNumberOfPages;
|
||||
this.analyzedPagesInCurrentLicensingPeriod = this.totalLicensedNumberOfPages;
|
||||
} else {
|
||||
this.unlicensedPages = 0;
|
||||
this.analyzedPagesInCurrentLicensingPeriod = this.currentInfo.numberOfAnalyzedPages;
|
||||
}
|
||||
|
||||
[this.currentInfo, this.totalInfo, this.unlicensedInfo] = await Promise.all(reports);
|
||||
}
|
||||
|
||||
getTotalLicensedNumberOfPages(license: ILicense) {
|
||||
|
||||
@ -2,7 +2,7 @@ import { List } from '@iqser/common-ui';
|
||||
|
||||
export interface ILicenseReportRequest {
|
||||
dossierIds?: List;
|
||||
endDate?: Date;
|
||||
endDate?: Date | string;
|
||||
requestId?: string;
|
||||
startDate?: Date;
|
||||
startDate?: Date | string;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user