Skip to content

Modular logistics and supply chain operating system (LSOS)

switch dashboard

Turtuvshin520e9771b48b
diff --git a/console/app/components/dashboard.hbs b/console/app/components/dashboard.hbs
index 23f96d9d..1f4a4d7f 100644
--- a/console/app/components/dashboard.hbs
+++ b/console/app/components/dashboard.hbs
@@ -1,15 +1,15 @@
<div class="fleetbase-dashboard-grid flex items-center justify-between mx-2">
<div class="left-section">
- {{!-- Dashboard Title Text --}}
+ {{! Dashboard Title Text }}
<h1 class="text-lg font-bold">{{this.currentDashboard.name}}</h1>
</div>
<div class="right-section ml-4 flex items-center">
- {{!-- Select Dropdown --}}
+ {{! Select Dropdown }}
<div class="fleetbase-model-select fleetbase-power-select ember-model-select h-10">
<PowerSelect
@options={{this.dashboards}}
@selected={{this.currentDashboard}}
- @onChange={{fn (mut this.currentDashboard)}}
+ @onChange={{fn this.selectDashboard}}
@placeholder="Select Dashboard"
@triggerClass="form-select form-input"
as |dashboard|
@@ -17,7 +17,7 @@
{{smart-humanize dashboard.name}}
</PowerSelect>
</div>
- {{!-- Button --}}
+ {{! Button }}
<div class="ml-2 relative h-10">
<DropdownButton class="h-10" @icon="ellipsis-h" @size="sm" @iconPrefix="fas" @triggerClass="hidden md:flex" as |dd|>
diff --git a/console/app/components/dashboard.js b/console/app/components/dashboard.js
index df8aaa52..81501d11 100644
--- a/console/app/components/dashboard.js
+++ b/console/app/components/dashboard.js
@@ -8,6 +8,7 @@ export default class DashboardComponent extends Component {
@service store;
@service notifications;
@service modalsManager;
+ @service fetch;
@tracked dashboards = [];
@tracked currentDashboard;
@@ -24,7 +25,7 @@ export default class DashboardComponent extends Component {
this.dashboards = yield this.store.findAll('dashboard');
if (this.dashboards.length > 0) {
- this.currentDashboard = this.dashboards[0];
+ this.currentDashboard = this.dashboards.find((dashboard) => dashboard.is_default) || this.dashboards[0];
console.log('Current Dashboard: ', this.currentDashboard);
}
@@ -34,7 +35,17 @@ export default class DashboardComponent extends Component {
}
@action selectDashboard(dashboard) {
- this.currentDashboard = dashboard;
+ console.log('Selected dashboard: ', dashboard);
+ this.fetch
+ .post('dashboards/switch', { dashboard_uuid: dashboard.id })
+ .then((response) => {
+ this.store.pushPayload(response);
+ const selectedDashboardId = response.uuid;
+ this.currentDashboard = this.store.peekRecord('dashboard', selectedDashboardId);
+ })
+ .finally(() => {
+ this.isLoading = false;
+ });
}
@action setWidgetSelectorPanelContext(widgetSelectorContext) {
@@ -119,4 +130,10 @@ export default class DashboardComponent extends Component {
...options,
});
}
+
+ setCurrentDashboard(dashboard) {
+ return this.fetch.post('dashboards/switch', { dashboard_uuid: dashboard.id }).then((response) => {
+ this.currentDashboard = response;
+ });
+ }
}
diff --git a/console/app/models/dashboard.js b/console/app/models/dashboard.js
index 0e280a04..28c4e9ae 100644
--- a/console/app/models/dashboard.js
+++ b/console/app/models/dashboard.js
@@ -2,6 +2,8 @@ import Model, { attr, hasMany } from '@ember-data/model';
import { getOwner } from '@ember/application';
export default class DashboardModel extends Model {
+ @attr('string') uuid;
+ @attr('boolean') is_default;
@attr('string') name;
@hasMany('dashboard-widget') widgets;