@fleetbase/ember-core 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,6 +29,10 @@ export default class UniverseService extends Service.extend(Evented) {
29
29
  menuItems: A([]),
30
30
  menuPanels: A([]),
31
31
  };
32
+ @tracked dashboardWidgets = {
33
+ defaultWidgets: A([]),
34
+ widgets: A([]),
35
+ };
32
36
 
33
37
  /**
34
38
  * Computed property that returns all administrative menu items.
@@ -656,6 +660,103 @@ export default class UniverseService extends Service.extend(Evented) {
656
660
  this.registerMenuPanel('settings', title, items, options);
657
661
  }
658
662
 
663
+ /**
664
+ * Registers a new dashboard widget in the universe service.
665
+ *
666
+ * @method registerDashboardWidgets
667
+ * @public
668
+ * @memberof UniverseService
669
+ * @param {Object} widget - The widget object containing name, component, gridOptions, and options.
670
+ * @property {String} name - The name of the widget.
671
+ * @property {String} icon - The iron of the widget.
672
+ * @property {Function} component - The component associated with the widget.
673
+ * @property {Object} gridOptions - The grid options for the widget.
674
+ * @property {Object} options - Additional options for the widget.
675
+ */
676
+ registerDashboardWidgets(widget) {
677
+ if (isArray(widget)) {
678
+ widget.forEach((w) => this.registerDashboardWidgets(w));
679
+ return;
680
+ }
681
+
682
+ const newWidget = this._createDashboardWidget(widget);
683
+ this.dashboardWidgets.widgets.pushObject(newWidget);
684
+ this.trigger('widget.registered', newWidget);
685
+ }
686
+
687
+ /**
688
+ * Retrieves the widgets registered in the universe service.
689
+ *
690
+ * @method getDashboardWidgets
691
+ * @public
692
+ * @memberof UniverseService
693
+ * @returns {Array} An array of registered widgets
694
+ */
695
+ getDashboardWidgets() {
696
+ return this.dashboardWidgets.widgets;
697
+ }
698
+
699
+ /**
700
+ * Registers a new dashboard widget in the universe service.
701
+ *
702
+ * @method registerDefaultDashboardWidgets
703
+ * @public
704
+ * @memberof UniverseService
705
+ * @param {Object} widget - The widget object containing name, component, gridOptions, and options.
706
+ * @property {String} name - The name of the widget.
707
+ * @property {String} icon - The iron of the widget.
708
+ * @property {Function} component - The component associated with the widget.
709
+ * @property {Object} gridOptions - The grid options for the widget.
710
+ * @property {Object} options - Additional options for the widget.
711
+ */
712
+ registerDefaultDashboardWidgets(widget) {
713
+ if (isArray(widget)) {
714
+ widget.forEach((w) => this.registerDefaultDashboardWidgets(w));
715
+ return;
716
+ }
717
+
718
+ const newWidget = this._createDashboardWidget(widget);
719
+ this.dashboardWidgets.defaultWidgets.pushObject(newWidget);
720
+ this.trigger('widget.registered', newWidget);
721
+ }
722
+
723
+ /**
724
+ * Retrieves the widgets registered in the universe service.
725
+ *
726
+ * @method getDefaultDashboardWidgets
727
+ * @public
728
+ * @memberof UniverseService
729
+ * @returns {Array} An array of registered widgets
730
+ */
731
+ getDefaultDashboardWidgets() {
732
+ return this.dashboardWidgets.defaultWidgets;
733
+ }
734
+
735
+ /**
736
+ * Creates a dashboard widget object
737
+ *
738
+ * @param {Object} widget
739
+ * @return {Widgetobject}
740
+ * @memberof UniverseService
741
+ */
742
+ _createDashboardWidget(widget) {
743
+ // Extract properties from the widget object
744
+ const { did, name, description, icon, component, grid_options, options } = widget;
745
+
746
+ // Create a new widget object with the extracted properties
747
+ const newWidget = {
748
+ did,
749
+ name,
750
+ description,
751
+ icon,
752
+ component,
753
+ grid_options,
754
+ options,
755
+ };
756
+
757
+ return newWidget;
758
+ }
759
+
659
760
  /**
660
761
  * Registers a new settings menu item.
661
762
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fleetbase/ember-core",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Provides all the core services, decorators and utilities for building a Fleetbase extension for the Console.",
5
5
  "keywords": [
6
6
  "fleetbase-core",