Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/dashboard issues #639

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 => {
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/app/helpers/http-get-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(url: string, delay = HttpGetBuffer.delay): Observable<T> {
console.log(HttpGetBuffer._buffer);
if (delay === 0) {
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
Loading