Skip to content

Modular logistics and supply chain operating system (LSOS)

patches for dashboards

Ronald A. Richardson52bf61b3bef5
diff --git a/console/app/components/dashboard.hbs b/console/app/components/dashboard.hbs
index 30762aba..c5031e25 100644
--- a/console/app/components/dashboard.hbs
+++ b/console/app/components/dashboard.hbs
@@ -78,7 +78,7 @@
</div>
{{#if this.dashboard.isEditingDashboard}}
<div class="ml-2 h-10">
- <Button @type="magic" @icon="save" @helpText={{"Save Dashboard"}} @onClick={{fn this.onChangeEdit false}} class="h-10" />
+ <Button @type="magic" @icon="save" @helpText={{t "component.dashboard.save-dashboard"}} @onClick={{fn this.onChangeEdit false}} class="h-10" />
</div>
{{/if}}
</div>
diff --git a/console/app/components/dashboard.js b/console/app/components/dashboard.js
index 698a4b0a..2ed1e62b 100644
--- a/console/app/components/dashboard.js
+++ b/console/app/components/dashboard.js
@@ -2,30 +2,84 @@ import Component from '@glimmer/component';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
+/**
+ * DashboardComponent for managing dashboards in an Ember application.
+ * This component handles actions such as selecting, creating, deleting dashboards,
+ * and managing widget selectors and dashboard editing states.
+ *
+ * @extends Component
+ */
export default class DashboardComponent extends Component {
+ /**
+ * Ember Data store service.
+ * @type {Service}
+ */
@service store;
+
+ /**
+ * Internationalization service for managing translations.
+ * @type {Service}
+ */
+ @service intl;
+
+ /**
+ * Notifications service for displaying alerts or confirmations.
+ * @type {Service}
+ */
@service notifications;
+
+ /**
+ * Modals manager service for handling modal dialogs.
+ * @type {Service}
+ */
@service modalsManager;
+
+ /**
+ * Fetch service for handling HTTP requests.
+ * @type {Service}
+ */
@service fetch;
+
+ /**
+ * Dashboard service for business logic related to dashboards.
+ * @type {Service}
+ */
@service dashboard;
+ /**
+ * Creates an instance of DashboardComponent.
+ * @memberof DashboardComponent
+ */
constructor() {
super(...arguments);
this.dashboard.loadDashboards.perform();
}
+ /**
+ * Action to select a dashboard.
+ * @param {Object} dashboard - The dashboard to be selected.
+ */
@action selectDashboard(dashboard) {
this.dashboard.selectDashboard.perform(dashboard);
}
+ /**
+ * Sets the context for the widget selector panel.
+ * @param {Object} widgetSelectorContext - The context object for the widget selector.
+ */
@action setWidgetSelectorPanelContext(widgetSelectorContext) {
this.widgetSelectorContext = widgetSelectorContext;
}
+ /**
+ * Creates a new dashboard.
+ * @param {Object} dashboard - The dashboard to be created.
+ * @param {Object} [options={}] - Optional parameters for dashboard creation.
+ */
@action createDashboard(dashboard, options = {}) {
this.modalsManager.show('modals/create-dashboard', {
- title: `Create a new dashboard`,
- acceptButtonText: 'Save Changes',
+ title: this.intl.t('component.dashboard.create-a-new-dashboard'),
+ acceptButtonText: this.intl.t('component.dashboard.confirm-create-dashboard'),
confirm: async (modal, done) => {
modal.startLoading();
@@ -39,13 +93,18 @@ export default class DashboardComponent extends Component {
});
}
+ /**
+ * Deletes a dashboard.
+ * @param {Object} dashboard - The dashboard to be deleted.
+ * @param {Object} [options={}] - Optional parameters for dashboard deletion.
+ */
@action deleteDashboard(dashboard, options = {}) {
if (this.dashboard.dashboards?.length === 1) {
- return this.notifications.error('You cannot delete the last dashboard.');
+ return this.notifications.error(this.intl.t('component.dashboard.you-cannot-delete-this-dashboard'));
}
this.modalsManager.confirm({
- title: `Are you sure to delete this ${dashboard.name}?`,
+ title: this.intl.t('component.dashboard.are-you-sure-you-want-delete-dashboard', { dashboardName: dashboard.name }),
confirm: async (modal, done) => {
modal.startLoading();
await this.dashboard.deleteDashboard.perform(dashboard);
@@ -55,15 +114,27 @@ export default class DashboardComponent extends Component {
});
}
+ /**
+ * Action to handle the addition of a widget.
+ * @param {boolean} [state=true] - The state to set for adding a widget.
+ */
@action onAddingWidget(state = true) {
this.dashboard.onAddingWidget(state);
}
- setCurrentDashboard(dashboard) {
+ /**
+ * Sets the current dashboard.
+ * @param {Object} dashboard - The dashboard to be set as current.
+ */
+ @action setCurrentDashboard(dashboard) {
this.dashboard.setCurrentDashboard.perform(dashboard);
}
- onChangeEdit(state = true) {
+ /**
+ * Changes the editing state of the dashboard.
+ * @param {boolean} [state=true] - The state to set for editing the dashboard.
+ */
+ @action onChangeEdit(state = true) {
this.dashboard.onChangeEdit(state);
}
}
diff --git a/console/app/components/dashboard/create.hbs b/console/app/components/dashboard/create.hbs
index 486a9eb8..d9378291 100644
--- a/console/app/components/dashboard/create.hbs
+++ b/console/app/components/dashboard/create.hbs
@@ -1,7 +1,7 @@
<div class="fleetbase-dashboard-grid" ...attributes>
<GridStack @options={{this.gridOptions}} @onChange={{this.onChangeGrid}}>
{{#each @dashboard.widgets as |widget|}}
- <GridStackItem @options={{spread-widget-options (hash id=widget.uuid options=widget.grid_options)}} class="relative">
+ <GridStackItem id={{widget.id}} @options={{spread-widget-options (hash id=widget.id options=widget.grid_options)}} class="relative">
{{component widget.component options=widget.options}}
{{#if @isEdit}}
<div class="absolute top-2 right-2">
diff --git a/console/app/components/dashboard/create.js b/console/app/components/dashboard/create.js
index 5dc4bdb0..cbad60cd 100644
--- a/console/app/components/dashboard/create.js
+++ b/console/app/components/dashboard/create.js
@@ -1,24 +1,51 @@
-import { action, computed } from '@ember/object';
import Component from '@glimmer/component';
+import { tracked } from '@glimmer/tracking';
+import { action, computed } from '@ember/object';
import { inject as service } from '@ember/service';
+/**
+ * Component responsible for creating and managing the dashboard layout.
+ * Provides functionalities such as toggling widget float, changing grid layout, and removing widgets.
+ *
+ * @extends Component
+ */
export default class DashboardCreateComponent extends Component {
+ /**
+ * Notifications service for displaying alerts or errors.
+ * @type {Service}
+ */
@service notifications;
+ /**
+ * Tracked array to keep track of widgets that have been updated.
+ * @type {Array}
+ */
+ @tracked updatedWidgets = [];
+
+ /**
+ * Action to toggle the floating state of widgets on the grid.
+ */
@action toggleFloat() {
this.shouldFloat = !this.shouldFloat;
}
+ /**
+ * Handles changes to the grid layout, such as repositioning or resizing widgets.
+ * Iterates over each widget event detail and updates the corresponding widget's properties if necessary.
+ *
+ * @param {Event} event - Event containing details about the grid change.
+ * @action
+ */
@action onChangeGrid(event) {
- const updatedWidgets = [];
+ const { dashboard } = this.args;
event.detail.forEach((currentWidgetEvent) => {
- const alreadyUpdated = updatedWidgets.find((item) => item.uuid === currentWidgetEvent.id);
- if (alreadyUpdated) {
- return; // Skip updating if already updated
+ const alreadyUpdated = this.updatedWidgets.find((item) => item.id === currentWidgetEvent.id);
+ if (alreadyUpdated || !this.dashboard) {
+ return;
}
- const changedWidget = this.args.dashboard.widgets.find((widget) => widget.id === currentWidgetEvent.id);
+ const changedWidget = dashboard.widgets.find((widget) => widget.id === currentWidgetEvent.id);
if (!changedWidget) {
return;
}
@@ -28,17 +55,35 @@ export default class DashboardCreateComponent extends Component {
grid_options: { x, y, w, h },
});
if (response) {
- updatedWidgets.push(changedWidget);
+ this.updatedWidgets.push(changedWidget);
}
});
}
+ /**
+ * Removes a specified widget from the dashboard.
+ * Performs a removal operation on the dashboard and handles any errors that occur during the process.
+ *
+ * @param {Object} widget - The widget object to be removed.
+ * @action
+ */
@action removeWidget(widget) {
- this.args.dashboard.removeWidget(widget.id).catch((error) => {
- this.notifications.serverError(error);
- });
+ const { dashboard } = this.args;
+
+ if (dashboard) {
+ dashboard.removeWidget(widget.id).catch((error) => {
+ this.notifications.serverError(error);
+ });
+ }
}
+ /**
+ * Computed property that returns grid options based on the current edit state.
+ * Configures grid behavior such as floating, animation, and drag and resize capabilities.
+ *
+ * @computed
+ * @returns {Object} An object containing grid configuration options.
+ */
@computed('args.isEdit') get gridOptions() {
return {
float: true,
diff --git a/console/app/services/dashboard.js b/console/app/services/dashboard.js
index 142ccc44..cb60fab4 100644
--- a/console/app/services/dashboard.js
+++ b/console/app/services/dashboard.js
@@ -74,10 +74,15 @@ export default class DashboardService extends Service {
if (isArray(dashboards)) {
this.dashboards = dashboards.toArray();
- this.dashboards.unshiftObject(this._createDefaultDashboard());
+
+ // insert default dashboard if it's not loaded
+ const defaultDashboard = this._createDefaultDashboard();
+ if (this._isDefaultDashboardNotLoaded()) {
+ this.dashboards.unshiftObject(defaultDashboard);
+ }
// Set the current dashboard
- this.currentDashboard = this.dashboards.find((dashboard) => dashboard.is_default) || this.dashboards[0];
+ this.currentDashboard = this._getNextDashboard();
if (this.currentDashboard && this.currentDashboard.widgets.length === 0) {
this.onAddingWidget(true);
}
@@ -101,10 +106,6 @@ export default class DashboardService extends Service {
if (currentDashboard) {
this.currentDashboard = currentDashboard;
-
- if (this.currentDashboard && this.currentDashboard.widgets.length === 0) {
- this.onChangeEdit(true);
- }
}
}
@@ -122,7 +123,6 @@ export default class DashboardService extends Service {
this.notifications.success(this.intl.t('services.dashboard-service.create-dashboard-success-notification', { dashboardName: dashboard.name }));
this.selectDashboard.perform(dashboard);
this.dashboards.pushObject(dashboard);
- this.isEditingDashboard = true;
}
}
@@ -141,7 +141,8 @@ export default class DashboardService extends Service {
});
this.notifications.success(this.intl.t('services.dashboard-service.delete-dashboard-success-notification', { dashboardName: dashboard.name }));
- this.loadDashboards.perform();
+ yield this.loadDashboards.perform();
+ yield this.selectDashboard.perform(this._getNextDashboard());
if (typeof options.callback === 'function') {
options.callback(this.currentDashboard);
@@ -184,8 +185,21 @@ export default class DashboardService extends Service {
* @returns {Object} The default dashboard object.
*/
_createDefaultDashboard() {
- const defaultDashboard = this.store.createRecord('dashboard', {
+ let defaultDashboard;
+
+ // check store for default dashboard
+ const loadedDashboars = this.store.peekAll('dashboard');
+
+ // check for default dashboard loaded in store
+ defaultDashboard = loadedDashboars.find((dashboard) => dashboard.id === 'system');
+ if (defaultDashboard) {
+ return defaultDashboard;
+ }
+
+ // create new default dashboard
+ defaultDashboard = this.store.createRecord('dashboard', {
id: 'system',
+ uuid: 'system',
name: 'Default Dashboard',
is_default: false,
user_uuid: 'system',
@@ -207,4 +221,35 @@ export default class DashboardService extends Service {
return widgets;
}
+
+ /**
+ * Checks if default dashboard is already loaded.
+ * @private
+ * @return {Boolean}
+ * @memberof DashboardService
+ */
+ _isDefaultDashboardLoaded() {
+ const defaultDashboard = this._createDefaultDashboard();
+ return this.dashboards.some((dashboard) => dashboard.id === defaultDashboard.id);
+ }
+
+ /**
+ * Checks if default dashboard is not already loaded.
+ * @private
+ * @return {Boolean}
+ * @memberof DashboardService
+ */
+ _isDefaultDashboardNotLoaded() {
+ return !this._isDefaultDashboardLoaded();
+ }
+
+ /**
+ * Gets the current dasbhoard or next available dashboard.
+ *
+ * @return {DashboardModel}
+ * @memberof DashboardService
+ */
+ _getNextDashboard() {
+ return this.dashboards.find((dashboard) => dashboard.is_default) || this.dashboards[0];
+ }
}
diff --git a/console/translations/en-us.yaml b/console/translations/en-us.yaml
index 664e5b5f..4958ef3f 100644
--- a/console/translations/en-us.yaml
+++ b/console/translations/en-us.yaml
@@ -91,9 +91,14 @@ component:
dashboard:
select-dashboard: Select Dashboard
create-new-dashboard: Create new Dashboard
+ create-a-new-dashboard: Create a new Dashboard
+ confirm-create-dashboard: Create Dashboard!
edit-layout: Edit layout
add-widgets: Add widgets
delete-dashboard: Delete dashboard
+ save-dashboard: Save Dashboard
+ you-cannot-delete-this-dashboard: You cannot delete this dashboard.
+ are-you-sure-you-want-delete-dashboard: Are you sure to delete this {dashboardName}?
dashboard-widget-panel:
widget-name: >-
{widgetName} Widget