diff --git a/src/app/components/dashboard/add-dashboard-dialog/add-dashboard-dialog.component.ts b/src/app/components/dashboard/add-dashboard-dialog/add-dashboard-dialog.component.ts index c99a9b95..7b3667f6 100644 --- a/src/app/components/dashboard/add-dashboard-dialog/add-dashboard-dialog.component.ts +++ b/src/app/components/dashboard/add-dashboard-dialog/add-dashboard-dialog.component.ts @@ -149,11 +149,14 @@ export class AddDashboardDialogComponent this.data = {}; } const text = (await file?.text()) || '{}'; - const dashboard = Functions.JSON_parse(text); - this.nameNewPanel.setValue(dashboard?.data?.name); - this.data.type = dashboard?.data?.type || 1; - this.data.param = dashboard?.data?.param || ''; - this.data.dashboard = dashboard?.data; + let dashboard = Functions.JSON_parse(text); + if (dashboard.data) { + dashboard = dashboard.data; + } + this.nameNewPanel.setValue(dashboard?.name); + this.data.type = dashboard?.type || 1; + this.data.param = dashboard?.param || ''; + this.data.dashboard = dashboard; delete this.data.dashboard.alias; delete this.data.dashboard.id; delete this.data.dashboard.dashboardId; @@ -169,13 +172,13 @@ export class AddDashboardDialogComponent (a, b) => [...a, $e.target.files[b].name], [] ); - if ($e.dataTransfer) { - const dataTransferFiles = Object?.keys($e?.dataTransfer?.files)?.reduce( - (a, b) => [...a, $e?.dataTransfer?.files[b].name], - [] - ); - files = files.concat(dataTransferFiles) - } + if ($e.dataTransfer) { + const dataTransferFiles = Object?.keys($e?.dataTransfer?.files)?.reduce( + (a, b) => [...a, $e?.dataTransfer?.files[b].name], + [] + ); + files = files.concat(dataTransferFiles) + } this.fileNames = [...files]; this.cdr.detectChanges(); } diff --git a/src/app/components/dashboard/dashboard.component.html b/src/app/components/dashboard/dashboard.component.html index 1607baa8..280d821a 100644 --- a/src/app/components/dashboard/dashboard.component.html +++ b/src/app/components/dashboard/dashboard.component.html @@ -193,4 +193,12 @@

{{'dashboard.isEmpty' | translate}}

+
+ +

{{'dashboard.isInvalid' | translate}}

+ +
+
diff --git a/src/app/components/dashboard/dashboard.component.ts b/src/app/components/dashboard/dashboard.component.ts index 184f3662..e4c9ffae 100644 --- a/src/app/components/dashboard/dashboard.component.ts +++ b/src/app/components/dashboard/dashboard.component.ts @@ -113,6 +113,7 @@ export class DashboardComponent implements OnInit, OnDestroy, AfterViewInit { resizeTimeout: any; searchTabConfig = {}; brandSrc; + isInvalid = false; @ViewChildren('widgets') widgets: QueryList; @ViewChild('customWidget', { static: false }) customWidget: any; @ViewChild('gridster', { static: false }) gridster: any; @@ -428,12 +429,17 @@ export class DashboardComponent implements OnInit, OnDestroy, AfterViewInit { this.isHome = params?.id === 'home'; const dashboard = await this.dashboardService.getDashboardStore(this.dashboardService.getCurrentDashBoardId()).toPromise(); + console.log(dashboard); if (dashboard == null) { return; } this.dashboardCollection = dashboard; this.dashboardService.dbs.currentDashboardType = dashboard.data?.type; - this.dashboardService.setWidgetListCurrentDashboard(this.dashboardCollection.data.widgets); + if (typeof this.dashboardCollection.data?.widgets === 'undefined') { + this.isInvalid = true; + } else { + this.dashboardService.setWidgetListCurrentDashboard(this.dashboardCollection.data.widgets); + } if (dashboard.data.shared === 0 && dashboard.owner === username) { dashboard.data.shared = false; } @@ -919,7 +925,9 @@ export class DashboardComponent implements OnInit, OnDestroy, AfterViewInit { // this.dashboardArray[this.dashboardArray.map(i => i.id).indexOf(id)].config = config; this.save(); } - + onPreference() { + this.router.navigate([`preference/reset`]); + } async onDashboardAdd(tabGroup: string = null) { const data = await this.dialog.open(AddDialogComponent, { width: '600px', data: {} }).afterClosed().toPromise(); @@ -1012,7 +1020,7 @@ export class DashboardComponent implements OnInit, OnDestroy, AfterViewInit { } onDownloadDashboardSettings() { - Functions.saveToFile(JSON.stringify(this.dashboardCollection, null, 2), `${this.dashboardTitle}.json`); + Functions.saveToFile(JSON.stringify(this.dashboardCollection.data, null, 2), `${this.dashboardTitle}.json`); } async onShareQrLink() { diff --git a/src/app/components/preference/pages/page-reset/page-reset.component.ts b/src/app/components/preference/pages/page-reset/page-reset.component.ts index 5d8689ce..8182326c 100644 --- a/src/app/components/preference/pages/page-reset/page-reset.component.ts +++ b/src/app/components/preference/pages/page-reset/page-reset.component.ts @@ -6,6 +6,7 @@ import { DialogDeleteAlertComponent } from '../../dialogs'; import { AlertService, AuthenticationService, DashboardService, PreferenceMappingProtocolService, SessionStorageService } from '@app/services'; import { MatDialog } from '@angular/material/dialog'; import { TranslateService } from '@ngx-translate/core'; +import { HttpGetBuffer } from '@app/helpers/http-get-buffer'; @Component({ selector: 'app-page-reset', @@ -27,7 +28,8 @@ export class PageResetComponent implements OnInit { private dialog: MatDialog, private cdr: ChangeDetectorRef, private _pmps: PreferenceMappingProtocolService, - private translateService: TranslateService + private translateService: TranslateService, + private _httpBuffer: HttpGetBuffer ) { this.translateService.get('notifications').subscribe(res => { @@ -93,8 +95,13 @@ export class PageResetComponent implements OnInit { const data = { page: 'Dashboard', message: 'reset' }; this.openDialog(DialogDeleteAlertComponent, data, (result) => { if (result && result === true) { - const resData: any = this.dashboardService.resetDashboard().toPromise(); - this.alertService.success(this.localDictionary.success.dashboardReset); + this.dashboardService.resetDashboard().then(() => { + this.alertService.success(this.localDictionary.success.dashboardReset); + this._httpBuffer.removeAllSubPathsFromBuffer('dashboard'); + }, () => { + + this.alertService.error(this.localDictionary.error.dashboardReset); + }) } else { this.alertService.error(this.localDictionary.error.dashboardReset); return; diff --git a/src/app/helpers/http-get-buffer.ts b/src/app/helpers/http-get-buffer.ts index dd213286..44dddf97 100644 --- a/src/app/helpers/http-get-buffer.ts +++ b/src/app/helpers/http-get-buffer.ts @@ -36,6 +36,13 @@ export class HttpGetBuffer { public removeFromBuffer(url: string) { HttpGetBuffer._buffer = HttpGetBuffer._buffer.filter(request => request.url !== url) } + // Expects subpath as parameter, i.e. if you want to remove all Dashboard store requests + // http://localhost:9080/api/v3/dashboard/store/home, http://localhost:9080/api/v3/dashboard/store/smartsearch + // You pass 'dashboard' and it removes them + public removeAllSubPathsFromBuffer(subpath: string) { + HttpGetBuffer._buffer = HttpGetBuffer._buffer.filter(request => !request.url.includes(`/${subpath}/`)); + console.log(HttpGetBuffer._buffer); + } public get(url: string, delay = HttpGetBuffer.delay): Observable { console.log(HttpGetBuffer._buffer); if (delay === 0) { diff --git a/src/app/services/dashboard.service.ts b/src/app/services/dashboard.service.ts index 71ddfb47..8ced5efd 100644 --- a/src/app/services/dashboard.service.ts +++ b/src/app/services/dashboard.service.ts @@ -3,7 +3,7 @@ import { HttpGetBuffer } from '@app/helpers/http-get-buffer'; import { ConstValue, UserConstValue } from '@app/models'; import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; -import { Observable, BehaviorSubject } from 'rxjs'; +import { Observable, BehaviorSubject, lastValueFrom } from 'rxjs'; import { environment } from '@environments/environment'; export interface DashboardEventData { @@ -180,6 +180,6 @@ export class DashboardService { return this._httpBuffer.get(`${this.url}/info`, delayBuffer); } resetDashboard() { - return this._http.get(`${this.url}/reset`); + return lastValueFrom(this._http.get(`${this.url}/reset`)); } } diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 147b5ea2..76b2b148 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -390,7 +390,8 @@ "setting": "@LINK.widget@ Settings", "delete": "Delete @LINK.widget@" }, - "isEmpty": "@LINK.dashboard@ is empty" + "isEmpty": "@LINK.dashboard@ is empty", + "isInvalid": "@LINK.dashboard@ is invalid, please try resetting it if it's Home or deleting it otherwise" }, "cellTypes": { "lastError": "Last Error",