Skip to content

Modular logistics and supply chain operating system (LSOS)

fixed default dashboard actions and remove widget function

Turtuvshine67149db892a
diff --git a/console/app/components/dashboard.hbs b/console/app/components/dashboard.hbs
index 8b1ab009..5c241bb1 100644
--- a/console/app/components/dashboard.hbs
+++ b/console/app/components/dashboard.hbs
@@ -9,7 +9,7 @@
<DropdownButton
class="h-10"
- @text="Select Dashboard"
+ @text={{if this.dashboard.currentDashboard.name this.dashboard.currentDashboard.name "Select Dashboard"}}
@textClass="text-sm mr-2"
@buttonClass="flex-row-reverse"
@icon="caret-down"
@@ -45,19 +45,29 @@
</div>
<span>Create new Dashboard</span>
</a>
- <a href="javascript:;" class="next-dd-item" {{on "click" (dropdown-fn dd this.onChangeEdit true)}}>
- <div class="w-6">
- <FaIcon @icon="edit" />
- </div>
- <span>Edit dashboard</span>
- </a>
- <a href="javascript:;" class="next-dd-item" {{on "click" (dropdown-fn dd this.deleteDashboard this.dashboard.currentDashboard)}}>
- <div class="w-6">
- <FaIcon @icon="trash" />
- </div>
- <span>Delete dashboard</span>
- </a>
+ {{#unless (eq this.dashboard.currentDashboard.owner_uuid "system")}}
+ <a href="javascript:;" class="next-dd-item" {{on "click" (dropdown-fn dd this.onChangeEdit true)}}>
+ <div class="w-6">
+ <FaIcon @icon="edit" />
+ </div>
+ <span>Edit layout</span>
+ </a>
+ <a href="javascript:;" class="next-dd-item" {{on "click" (dropdown-fn dd this.onAddingWidget true)}}>
+ <div class="w-6">
+ <FaIcon @icon="add" />
+ </div>
+ <span>Add widgets</span>
+ </a>
+
+ <a href="javascript:;" class="next-dd-item" {{on "click" (dropdown-fn dd this.deleteDashboard this.dashboard.currentDashboard)}}>
+ <div class="w-6">
+ <FaIcon @icon="trash" />
+ </div>
+ <span>Delete dashboard</span>
+ </a>
+ {{/unless}}
+
</div>
</div>
</DropdownButton>
@@ -71,11 +81,11 @@
</div>
<div class="px-10">
- <Dashboard::Create @isEdit={{this.dashboard.isEditingDashboard}} @dashboard={{this.dashboard.currentDashboard}} />
- {{#if this.dashboard.isEditingDashboard}}
+ <Dashboard::Create @isEdit={{this.dashboard.isEditingDashboard}} @isAddingWidget={{this.dashboard.isAddingWidget}} @dashboard={{this.dashboard.currentDashboard}} />
+ {{#if this.dashboard.isAddingWidget}}
<EmberWormhole @to="console-home-wormhole">
<Dashboard::WidgetPanel
- @isOpen={{this.dashboard.isEditingDashboard}}
+ @isOpen={{this.dashboard.isAddingWidget}}
@onLoad={{this.setWidgetSelectorPanelContext}}
@dashboard={{this.dashboard.currentDashboard}}
@onClose={{fn this.onChangeEdit false}}
diff --git a/console/app/components/dashboard.js b/console/app/components/dashboard.js
index 0684637d..2633fec7 100644
--- a/console/app/components/dashboard.js
+++ b/console/app/components/dashboard.js
@@ -77,4 +77,8 @@ export default class DashboardComponent extends Component {
onChangeEdit(state = true) {
this.dashboard.onChangeEdit(state);
}
+
+ onAddingWidget(state = true) {
+ this.dashboard.onAddingWidget(state);
+ }
}
diff --git a/console/app/helpers/spread-widget-options.js b/console/app/helpers/spread-widget-options.js
index 2a815ad2..8f2e1358 100644
--- a/console/app/helpers/spread-widget-options.js
+++ b/console/app/helpers/spread-widget-options.js
@@ -2,5 +2,6 @@ import { helper } from '@ember/component/helper';
export default helper(function spreadWidgetOptions([params]) {
const { id, options } = params;
- return { id, ...options };
+ const gridOptions = { id, ...options };
+ return gridOptions;
});
diff --git a/console/app/models/dashboard.js b/console/app/models/dashboard.js
index 3c98ed58..c7a54d10 100644
--- a/console/app/models/dashboard.js
+++ b/console/app/models/dashboard.js
@@ -66,27 +66,25 @@ export default class DashboardModel extends Model {
});
}
- /** @methods */
- addWidget(widget) {
+ removeWidget(widget) {
const owner = getOwner(this);
const store = owner.lookup('service:store');
- const widgetRecord = store.createRecord('dashboard-widget', widget);
+ const widgetRecord = store.peekRecord('dashboard-widget', widget);
- widgetRecord.dashboard = this;
- console.log(widgetRecord);
- return new Promise((resolve, reject) => {
- widgetRecord
- .save()
- .then((widgetRecord) => {
- this.widgets.pushObject(widgetRecord);
- resolve(widgetRecord);
- })
- .catch((error) => {
- store.unloadRecord(widgetRecord);
- reject(error);
- });
- });
+ if (widgetRecord) {
+ return new Promise((resolve, reject) => {
+ widgetRecord
+ .destroyRecord()
+ .then(() => {
+ this.widgets.removeObject(widgetRecord);
+ resolve();
+ })
+ .catch((error) => {
+ reject(error);
+ });
+ });
+ }
}
updateWidget(widget) {
diff --git a/console/app/services/dashboard.js b/console/app/services/dashboard.js
index 2a56e1a2..d07da83f 100644
--- a/console/app/services/dashboard.js
+++ b/console/app/services/dashboard.js
@@ -35,6 +35,10 @@ export default class DashboardService extends Service {
@task *selectDashboard(dashboard) {
try {
+ if (dashboard.owner_uuid === 'system') {
+ this.currentDashboard = dashboard;
+ return;
+ }
const response = yield this.fetch.post('dashboards/switch', { dashboard_uuid: dashboard.id });
this.store.pushPayload(response);
const selectedDashboardId = response.uuid;
@@ -107,6 +111,7 @@ export default class DashboardService extends Service {
const defaultDashboard = this.store.createRecord('dashboard', {
name: 'Default Dashboard',
is_default: false,
+ owner_uuid: 'system',
widgets: this._createDefaultDashboardWidgets(),
});