Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyOplachko committed Jul 5, 2024
1 parent 04e15e9 commit 6dff37f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down
8 changes: 8 additions & 0 deletions src/app/components/dashboard/dashboard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,12 @@ <h1> {{'dashboard.isEmpty' | translate}} </h1>
</button>
</span>
</div>
<div *ngIf="isInvalid" class="no-content">
<span style="text-align: center;">
<h1> {{'dashboard.isInvalid' | translate}} </h1>
<button mat-raised-button class="setting-btn-ok" (click)="onPreference()" [disabled]='isShared'>Open settings
<mat-icon>tune</mat-icon>
</button>
</span>
</div>
</div>
14 changes: 11 additions & 3 deletions src/app/components/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class DashboardComponent implements OnInit, OnDestroy, AfterViewInit {
resizeTimeout: any;
searchTabConfig = {};
brandSrc;
isInvalid = false;
@ViewChildren('widgets') widgets: QueryList<IWidget>;
@ViewChild('customWidget', { static: false }) customWidget: any;
@ViewChild('gridster', { static: false }) gridster: any;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/app/services/dashboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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`));
}
}
3 changes: 2 additions & 1 deletion src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6dff37f

Please sign in to comment.