RED-4596: wipe stored license reports if number of pages mismatch
This commit is contained in:
parent
b983418370
commit
140ce5f708
@ -87,6 +87,10 @@ export class LicenseChartComponent {
|
||||
}
|
||||
}
|
||||
|
||||
if (cumulativePages !== this._licenseService.currentInfo.numberOfAnalyzedPages) {
|
||||
this._licenseService.wipeStoredReportsAndReloadSelectedLicenseData();
|
||||
}
|
||||
|
||||
return cumulativePagesSeries;
|
||||
}
|
||||
|
||||
@ -120,11 +124,9 @@ export class LicenseChartComponent {
|
||||
}
|
||||
|
||||
#totalLicensedPagesSeries(dateRanges: List<IDateRange>) {
|
||||
const processingPages = this._licenseService.processingPages;
|
||||
|
||||
return dateRanges.map(dateRange => ({
|
||||
name: verboseDate(dateRange),
|
||||
value: processingPages,
|
||||
value: this._licenseService.totalLicensedNumberOfPages,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@
|
||||
<div class="row">
|
||||
<div class="flex align-center" translate="license-info-screen.license-title"></div>
|
||||
<div>
|
||||
<redaction-license-select (valueChanges)="licenseChanged($event)"></redaction-license-select>
|
||||
<redaction-license-select></redaction-license-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -58,36 +58,42 @@
|
||||
|
||||
<div class="row">
|
||||
<div>{{ 'license-info-screen.licensed-page-count' | translate }}</div>
|
||||
<div>{{ totalLicensedNumberOfPages }}</div>
|
||||
<div>{{ licenseService.totalLicensedNumberOfPages }}</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div translate="license-info-screen.analyzed-pages"></div>
|
||||
<div>{{ currentInfo.numberOfAnalyzedPages }}</div>
|
||||
<div>{{ licenseService.currentInfo.numberOfAnalyzedPages }}</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div translate="license-info-screen.ocr-analyzed-pages"></div>
|
||||
<div>{{ currentInfo.numberOfOcrPages }}</div>
|
||||
<div>{{ licenseService.currentInfo.numberOfOcrPages }}</div>
|
||||
</div>
|
||||
|
||||
<div class="section-title all-caps-label" translate="license-info-screen.usage-details"></div>
|
||||
|
||||
<div class="row">
|
||||
<div>
|
||||
{{ 'license-info-screen.total-analyzed' | translate: { date: totalInfo.startDate | date: 'longDate' } }}
|
||||
{{
|
||||
'license-info-screen.total-analyzed'
|
||||
| translate: { date: licenseService.totalInfo.startDate | date: 'longDate' }
|
||||
}}
|
||||
</div>
|
||||
<div>{{ totalInfo.numberOfAnalyzedPages }}</div>
|
||||
<div>{{ licenseService.totalInfo.numberOfAnalyzedPages }}</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div translate="license-info-screen.current-analyzed"></div>
|
||||
<div>{{ currentInfo.numberOfAnalyzedPages }} ({{ analysisPercentageOfLicense | number: '1.0-2' }}%)</div>
|
||||
<div>
|
||||
{{ licenseService.currentInfo.numberOfAnalyzedPages }}
|
||||
({{ analysisPercentageOfLicense$ | async | number: '1.0-2' }}%)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div *ngIf="!!unlicensedInfo" class="row">
|
||||
<div *ngIf="!!licenseService.unlicensedInfo" class="row">
|
||||
<div translate="license-info-screen.unlicensed-analyzed"></div>
|
||||
<div>{{ unlicensedInfo.numberOfAnalyzedPages }}</div>
|
||||
<div>{{ licenseService.unlicensedInfo.numberOfAnalyzedPages }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@ -6,10 +6,8 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { UserService } from '@services/user.service';
|
||||
import { RouterHistoryService } from '@services/router-history.service';
|
||||
import { LicenseService } from '../../../../../services/license.service';
|
||||
import { ILicense, ILicenseReport } from '@red/domain';
|
||||
import dayjs from 'dayjs';
|
||||
import { UserPreferenceService } from '@services/user-preference.service';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
templateUrl: './license-screen.component.html',
|
||||
@ -26,11 +24,7 @@ export class LicenseScreenComponent implements OnInit {
|
||||
},
|
||||
];
|
||||
|
||||
currentInfo: ILicenseReport = {};
|
||||
totalInfo: ILicenseReport = {};
|
||||
unlicensedInfo: ILicenseReport = {};
|
||||
analysisPercentageOfLicense = 100;
|
||||
totalLicensedNumberOfPages: number;
|
||||
readonly analysisPercentageOfLicense$ = this.licenseService.selectedLicense$.pipe(map(() => this.getAnalysisPercentageOfLicense()));
|
||||
|
||||
constructor(
|
||||
readonly configService: ConfigService,
|
||||
@ -45,31 +39,13 @@ export class LicenseScreenComponent implements OnInit {
|
||||
}
|
||||
|
||||
async ngOnInit() {
|
||||
await firstValueFrom(this.licenseService.loadLicense());
|
||||
this.totalLicensedNumberOfPages = this.licenseService.processingPages;
|
||||
await this.loadLicenseData(this.licenseService.selectedLicense);
|
||||
await this.licenseService.loadLicenseData();
|
||||
}
|
||||
|
||||
async loadLicenseData(license: ILicense) {
|
||||
const startDate = dayjs(license.validFrom);
|
||||
const endDate = dayjs(license.validUntil);
|
||||
|
||||
const currentConfig = {
|
||||
startDate: startDate.toDate(),
|
||||
endDate: endDate.toDate(),
|
||||
};
|
||||
const reports: Promise<ILicenseReport>[] = [this.licenseService.getReport(currentConfig), this.licenseService.getReport({})];
|
||||
|
||||
if (endDate.isBefore(dayjs())) {
|
||||
const unlicensedConfig = {
|
||||
startDate: endDate.toDate(),
|
||||
};
|
||||
reports.push(this.licenseService.getReport(unlicensedConfig));
|
||||
}
|
||||
|
||||
[this.currentInfo, this.totalInfo, this.unlicensedInfo] = await Promise.all(reports);
|
||||
this.analysisPercentageOfLicense =
|
||||
this.totalLicensedNumberOfPages > 0 ? (this.currentInfo.numberOfAnalyzedPages / this.totalLicensedNumberOfPages) * 100 : 100;
|
||||
getAnalysisPercentageOfLicense() {
|
||||
const totalLicensedNumberOfPages = this.licenseService.totalLicensedNumberOfPages;
|
||||
const numberOfAnalyzedPages = this.licenseService.currentInfo.numberOfAnalyzedPages;
|
||||
return totalLicensedNumberOfPages > 0 ? (numberOfAnalyzedPages / totalLicensedNumberOfPages) * 100 : 100;
|
||||
}
|
||||
|
||||
sendMail(): void {
|
||||
@ -80,18 +56,13 @@ export class LicenseScreenComponent implements OnInit {
|
||||
const lineBreak = '%0D%0A';
|
||||
const body = [
|
||||
this._translateService.instant('license-info-screen.email.body.analyzed', {
|
||||
pages: this.currentInfo.numberOfAnalyzedPages,
|
||||
pages: this.licenseService.currentInfo.numberOfAnalyzedPages,
|
||||
}),
|
||||
this._translateService.instant('license-info-screen.email.body.licensed', {
|
||||
pages: this.totalLicensedNumberOfPages,
|
||||
pages: this.licenseService.totalLicensedNumberOfPages,
|
||||
}),
|
||||
].join(lineBreak);
|
||||
const mail = this.licenseService.selectedLicense.licensedToEmail;
|
||||
window.location.href = `mailto:${mail}?subject=${subject}&body=${body}`;
|
||||
}
|
||||
|
||||
licenseChanged(license: ILicense) {
|
||||
this.totalLicensedNumberOfPages = this.licenseService.processingPages;
|
||||
return this.loadLicenseData(license);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Component, EventEmitter, Output } from '@angular/core';
|
||||
import { Component } from '@angular/core';
|
||||
import { LicenseService } from '@services/license.service';
|
||||
import { ILicense } from '@red/domain';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
@ -15,7 +15,6 @@ const translations = {
|
||||
styleUrls: ['./license-select.component.scss'],
|
||||
})
|
||||
export class LicenseSelectComponent {
|
||||
@Output() readonly valueChanges = new EventEmitter<ILicense>();
|
||||
value: ILicense;
|
||||
licenses$ = this.licenseService.licenseData$.pipe(
|
||||
map(data => data.licenses),
|
||||
@ -32,8 +31,8 @@ export class LicenseSelectComponent {
|
||||
return id === this.licenseService.activeLicenseId ? translations.active : translations.inactive;
|
||||
}
|
||||
|
||||
licenseChanged($event: ILicense) {
|
||||
this.valueChanges.emit($event);
|
||||
this.licenseService.setSelectedLicense($event);
|
||||
async licenseChanged(license: ILicense) {
|
||||
await this.licenseService.loadLicenseData(license);
|
||||
this.licenseService.setSelectedLicense(license);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ import { NgModule } from '@angular/core';
|
||||
import { LicenseScreenComponent } from './license-screen/license-screen.component';
|
||||
import { LicenseSelectComponent } from './license-select/license-select.component';
|
||||
import { LicenseChartComponent } from './license-chart/license-chart.component';
|
||||
import { LicenseService } from '../../../../services/license.service';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
@ -36,6 +35,5 @@ const routes: Routes = [
|
||||
NgxChartsModule,
|
||||
IqserListingModule,
|
||||
],
|
||||
providers: [LicenseService],
|
||||
})
|
||||
export class LicenseModule {}
|
||||
|
||||
@ -4,6 +4,8 @@ import { ILicense, ILicenseReport, ILicenseReportRequest, ILicenses } from '@red
|
||||
import { BehaviorSubject, firstValueFrom, Observable, of } from 'rxjs';
|
||||
import { catchError, filter, tap } from 'rxjs/operators';
|
||||
import { LICENSE_STORAGE_KEY } from '../modules/admin/screens/license/utils/constants';
|
||||
import dayjs from 'dayjs';
|
||||
import { NGXLogger } from 'ngx-logger';
|
||||
|
||||
export function getStoredReports() {
|
||||
const rawStoredReports = localStorage.getItem(LICENSE_STORAGE_KEY);
|
||||
@ -47,13 +49,22 @@ export class LicenseService extends GenericService<ILicenseReport> {
|
||||
readonly licenseData$: Observable<ILicenses>;
|
||||
readonly selectedLicense$: Observable<ILicense>;
|
||||
activeLicenseId: string;
|
||||
totalLicensedNumberOfPages = 0;
|
||||
currentInfo: ILicenseReport = {};
|
||||
totalInfo: ILicenseReport = {};
|
||||
unlicensedInfo: ILicenseReport = {};
|
||||
protected readonly _defaultModelPath = 'report';
|
||||
readonly #licenseData$ = new BehaviorSubject<ILicenses | undefined>(undefined);
|
||||
readonly #selectedLicense$ = new BehaviorSubject<ILicense | undefined>(undefined);
|
||||
|
||||
constructor() {
|
||||
constructor(private readonly _logger: NGXLogger) {
|
||||
super();
|
||||
this.selectedLicense$ = this.#selectedLicense$.pipe(filter(license => !!license));
|
||||
this.selectedLicense$ = this.#selectedLicense$.pipe(
|
||||
filter(license => !!license),
|
||||
tap(license => {
|
||||
this.totalLicensedNumberOfPages = this.getTotalLicensedNumberOfPages(license);
|
||||
}),
|
||||
);
|
||||
this.licenseData$ = this.#licenseData$.pipe(
|
||||
filter(licenses => !!licenses),
|
||||
tap(data => (this.activeLicenseId = data.activeLicense)),
|
||||
@ -64,11 +75,6 @@ export class LicenseService extends GenericService<ILicenseReport> {
|
||||
return this.#selectedLicense$.value;
|
||||
}
|
||||
|
||||
get processingPages() {
|
||||
const processingPagesFeature = this.#selectedLicense$.value?.features?.find(f => f.name === 'processingPages');
|
||||
return Number(processingPagesFeature?.value ?? '0');
|
||||
}
|
||||
|
||||
get activeLicense() {
|
||||
if (!this.#licenseData$.value) {
|
||||
return undefined;
|
||||
@ -82,6 +88,37 @@ export class LicenseService extends GenericService<ILicenseReport> {
|
||||
return this.activeLicense.features.find(f => f.name === 'pdftron').value;
|
||||
}
|
||||
|
||||
wipeStoredReportsAndReloadSelectedLicenseData() {
|
||||
this._logger.info('[LICENSE] Wiping stored reports and reloading license data');
|
||||
this.storedReports = {};
|
||||
this.setSelectedLicense(this.selectedLicense);
|
||||
}
|
||||
|
||||
async loadLicenseData(license: ILicense = this.selectedLicense) {
|
||||
const startDate = dayjs(license.validFrom);
|
||||
const endDate = dayjs(license.validUntil);
|
||||
|
||||
const currentConfig = {
|
||||
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));
|
||||
}
|
||||
|
||||
[this.currentInfo, this.totalInfo, this.unlicensedInfo] = await Promise.all(reports);
|
||||
}
|
||||
|
||||
getTotalLicensedNumberOfPages(license: ILicense) {
|
||||
const processingPagesFeature = license.features?.find(f => f.name === 'processingPages');
|
||||
return Number(processingPagesFeature?.value ?? '0');
|
||||
}
|
||||
|
||||
setDefaultSelectedLicense() {
|
||||
this.setSelectedLicense(this.activeLicense);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user