From 4d761adc0da1784b678b64fef335c142ccaa924d Mon Sep 17 00:00:00 2001 From: Timo Bejan Date: Tue, 13 Jun 2023 11:51:58 +0300 Subject: [PATCH] HotFix - license screen --- .../license-chart/license-chart.component.ts | 7 ++++- .../admin/screens/license/utils/functions.ts | 4 +-- .../src/app/services/license.service.ts | 29 ++++++++++--------- .../app/utils/configuration.initializer.ts | 2 +- apps/red-ui/src/assets/config/config.json | 4 +-- libs/red-domain/src/lib/license/date-range.ts | 2 ++ 6 files changed, 28 insertions(+), 20 deletions(-) diff --git a/apps/red-ui/src/app/modules/admin/screens/license/license-chart/license-chart.component.ts b/apps/red-ui/src/app/modules/admin/screens/license/license-chart/license-chart.component.ts index 30cf658d3..8133a66bd 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/license-chart/license-chart.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/license/license-chart/license-chart.component.ts @@ -38,6 +38,7 @@ export class LicenseChartComponent { async #getLicenseData(license: ILicense): Promise { const startDate = dayjs(license.validFrom); const endDate = dayjs(license.validUntil); + const startDay: number = startDate.date(); const startMonth: number = startDate.month(); const startYear: number = startDate.year(); @@ -48,6 +49,9 @@ export class LicenseChartComponent { dateRanges.push({ startMonth: dt.month(), startYear: dt.year(), endMonth: end.month(), endYear: end.year() }); } + if (dateRanges.length > 0) { + dateRanges[0].startDay = startDay; + } const reports = await this.#getReports(dateRanges, license.id); return this.#mapRangesToReports(startMonth, startYear, dateRanges, reports); @@ -101,6 +105,7 @@ export class LicenseChartComponent { } #getReports(dateRanges: List, id: string) { + console.log(dateRanges); const reports = dateRanges.map(range => { const startMonth = range.startMonth + 1; const endMonth = range.endMonth + 1; @@ -111,7 +116,7 @@ export class LicenseChartComponent { return existingReport; } - const startDate = toDate(startMonth, range.startYear); + const startDate = toDate(startMonth, range.startYear, range.startDay); const endDate = toDate(endMonth, range.endYear); const requestedReport = this._licenseService.getReport({ startDate, endDate }); return requestedReport.then(report => this.#storeReportIfNotCurrentMonth(range, report, key)); diff --git a/apps/red-ui/src/app/modules/admin/screens/license/utils/functions.ts b/apps/red-ui/src/app/modules/admin/screens/license/utils/functions.ts index 1c29ba8b2..0dd196237 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/utils/functions.ts +++ b/apps/red-ui/src/app/modules/admin/screens/license/utils/functions.ts @@ -1,8 +1,8 @@ import dayjs from 'dayjs'; import { IDateRange } from '@red/domain'; -export function toDate(month: number, year: number) { - return dayjs(`01-${month}-${year}`, 'D-M-YYYY').toDate(); +export function toDate(month: number, year: number, day: number = 1) { + return dayjs(`${day}-${month}-${year}`, 'D-M-YYYY').toDate(); } export function isCurrentMonth(month: number, year: number) { diff --git a/apps/red-ui/src/app/services/license.service.ts b/apps/red-ui/src/app/services/license.service.ts index e8d7dd1a6..b613e9a84 100644 --- a/apps/red-ui/src/app/services/license.service.ts +++ b/apps/red-ui/src/app/services/license.service.ts @@ -1,11 +1,13 @@ import { Injectable } from '@angular/core'; -import { GenericService, QueryParam, RequiredParam, Validate } from '@iqser/common-ui'; +import { GenericService, QueryParam } 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 { LICENSE_STORAGE_KEY } from '../modules/admin/screens/license/utils/constants'; import dayjs from 'dayjs'; import { NGXLogger } from 'ngx-logger'; +import { UI } from '@pdftron/webviewer'; +import off = UI.Hotkeys.off; export function getStoredReports() { const rawStoredReports = localStorage.getItem(LICENSE_STORAGE_KEY); @@ -90,7 +92,11 @@ export class LicenseService extends GenericService { this.setSelectedLicense(this.selectedLicense); } + x = null; async loadLicenseData(license: ILicense = this.selectedLicense) { + if (this.x) { + return; + } this.totalLicensedNumberOfPages = this.getTotalLicensedNumberOfPages(license); const startDate = dayjs(license.validFrom); @@ -117,6 +123,7 @@ export class LicenseService extends GenericService { this.unlicensedPages = 0; } this.analyzedPagesInCurrentLicensingPeriod = this.currentLicenseInfo.numberOfAnalyzedPages; + this.x = '100'; } getTotalLicensedNumberOfPages(license: ILicense) { @@ -128,8 +135,7 @@ export class LicenseService extends GenericService { this.setSelectedLicense(this.activeLicense); } - @Validate() - getReport$(@RequiredParam() body: ILicenseReportRequest, limit?: number, offset?: number) { + getReport(body: ILicenseReportRequest, limit?: number, offset?: number) { const queryParams: QueryParam[] = []; if (limit) { queryParams.push({ key: 'limit', value: limit }); @@ -139,19 +145,14 @@ export class LicenseService extends GenericService { queryParams.push({ key: 'offset', value: offset }); } - return this._post(body, `${this._defaultModelPath}/license`, queryParams); + return firstValueFrom(this._post(body, `${this._defaultModelPath}/license`, queryParams)); } - getReport(body: ILicenseReportRequest, limit?: number, offset?: number) { - return firstValueFrom(this.getReport$(body, limit, offset)); - } - - loadLicense() { - return this._http.get('/license').pipe( - catchError(() => of(defaultOnError)), - tap(licenses => this.#licenseData$.next(licenses)), - tap(() => this.setDefaultSelectedLicense()), - ); + async loadLicenses() { + const licenses$ = this._http.get('/license').pipe(catchError(() => of(defaultOnError))); + const licenses = await firstValueFrom(licenses$); + this.#licenseData$.next(licenses); + this.setDefaultSelectedLicense(); } setSelectedLicense($event: ILicense) { diff --git a/apps/red-ui/src/app/utils/configuration.initializer.ts b/apps/red-ui/src/app/utils/configuration.initializer.ts index 7a2f34965..3e1327a5c 100644 --- a/apps/red-ui/src/app/utils/configuration.initializer.ts +++ b/apps/red-ui/src/app/utils/configuration.initializer.ts @@ -51,7 +51,7 @@ export function configurationInitializer( lastDossierTemplateRedirect(baseHref.replace('/', ''), userPreferenceService); }), switchMap(() => languageService.setInitialLanguage()), - switchMap(() => licenseService.loadLicense()), + switchMap(() => licenseService.loadLicenses()), ); return () => firstValueFrom(setup); } diff --git a/apps/red-ui/src/assets/config/config.json b/apps/red-ui/src/assets/config/config.json index 6db60fee3..830a385a0 100644 --- a/apps/red-ui/src/assets/config/config.json +++ b/apps/red-ui/src/assets/config/config.json @@ -1,7 +1,7 @@ { "ADMIN_CONTACT_NAME": null, "ADMIN_CONTACT_URL": null, - "API_URL": "https://red-staging.iqser.cloud/redaction-gateway-v1", + "API_URL": "https://basf.redactmanager.com/redaction-gateway-v1", "APP_NAME": "RedactManager", "AUTO_READ_TIME": 3, "BACKEND_APP_VERSION": "4.4.40", @@ -11,7 +11,7 @@ "MAX_RETRIES_ON_SERVER_ERROR": 3, "OAUTH_CLIENT_ID": "redaction", "OAUTH_IDP_HINT": null, - "OAUTH_URL": "https://red-staging.iqser.cloud/auth/realms/redaction", + "OAUTH_URL": "https://basf.redactmanager.com/auth/realms/redaction", "RECENT_PERIOD_IN_HOURS": 24, "SELECTION_MODE": "structural", "MANUAL_BASE_URL": "https://docs.redactmanager.com/preview", diff --git a/libs/red-domain/src/lib/license/date-range.ts b/libs/red-domain/src/lib/license/date-range.ts index c18962cd6..7a8de5a86 100644 --- a/libs/red-domain/src/lib/license/date-range.ts +++ b/libs/red-domain/src/lib/license/date-range.ts @@ -1,6 +1,8 @@ export interface IDateRange { + readonly startDay: number; readonly startMonth: number; readonly startYear: number; readonly endMonth: number; readonly endYear: number; + readonly endDay: number; }