Skip to content

Commit

Permalink
Merge pull request #29 from fleetbase/dev-v0.2.2
Browse files Browse the repository at this point in the history
v0.2.2
  • Loading branch information
roncodes authored Feb 6, 2024
2 parents 54a45bb + 12d907c commit 2499869
Show file tree
Hide file tree
Showing 3 changed files with 447 additions and 507 deletions.
101 changes: 101 additions & 0 deletions addon/services/universe.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export default class UniverseService extends Service.extend(Evented) {
menuItems: A([]),
menuPanels: A([]),
};
@tracked dashboardWidgets = {
defaultWidgets: A([]),
widgets: A([]),
};

/**
* Computed property that returns all administrative menu items.
Expand Down Expand Up @@ -656,6 +660,103 @@ export default class UniverseService extends Service.extend(Evented) {
this.registerMenuPanel('settings', title, items, options);
}

/**
* Registers a new dashboard widget in the universe service.
*
* @method registerDashboardWidgets
* @public
* @memberof UniverseService
* @param {Object} widget - The widget object containing name, component, gridOptions, and options.
* @property {String} name - The name of the widget.
* @property {String} icon - The iron of the widget.
* @property {Function} component - The component associated with the widget.
* @property {Object} gridOptions - The grid options for the widget.
* @property {Object} options - Additional options for the widget.
*/
registerDashboardWidgets(widget) {
if (isArray(widget)) {
widget.forEach((w) => this.registerDashboardWidgets(w));
return;
}

const newWidget = this._createDashboardWidget(widget);
this.dashboardWidgets.widgets.pushObject(newWidget);
this.trigger('widget.registered', newWidget);
}

/**
* Retrieves the widgets registered in the universe service.
*
* @method getDashboardWidgets
* @public
* @memberof UniverseService
* @returns {Array} An array of registered widgets
*/
getDashboardWidgets() {
return this.dashboardWidgets.widgets;
}

/**
* Registers a new dashboard widget in the universe service.
*
* @method registerDefaultDashboardWidgets
* @public
* @memberof UniverseService
* @param {Object} widget - The widget object containing name, component, gridOptions, and options.
* @property {String} name - The name of the widget.
* @property {String} icon - The iron of the widget.
* @property {Function} component - The component associated with the widget.
* @property {Object} gridOptions - The grid options for the widget.
* @property {Object} options - Additional options for the widget.
*/
registerDefaultDashboardWidgets(widget) {
if (isArray(widget)) {
widget.forEach((w) => this.registerDefaultDashboardWidgets(w));
return;
}

const newWidget = this._createDashboardWidget(widget);
this.dashboardWidgets.defaultWidgets.pushObject(newWidget);
this.trigger('widget.registered', newWidget);
}

/**
* Retrieves the widgets registered in the universe service.
*
* @method getDefaultDashboardWidgets
* @public
* @memberof UniverseService
* @returns {Array} An array of registered widgets
*/
getDefaultDashboardWidgets() {
return this.dashboardWidgets.defaultWidgets;
}

/**
* Creates a dashboard widget object
*
* @param {Object} widget
* @return {Widgetobject}
* @memberof UniverseService
*/
_createDashboardWidget(widget) {
// Extract properties from the widget object
const { did, name, description, icon, component, grid_options, options } = widget;

// Create a new widget object with the extracted properties
const newWidget = {
did,
name,
description,
icon,
component,
grid_options,
options,
};

return newWidget;
}

/**
* Registers a new settings menu item.
*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleetbase/ember-core",
"version": "0.2.1",
"version": "0.2.2",
"description": "Provides all the core services, decorators and utilities for building a Fleetbase extension for the Console.",
"keywords": [
"fleetbase-core",
Expand Down
Loading

0 comments on commit 2499869

Please sign in to comment.