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/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",