@fleetbase/ember-core 0.2.3 → 0.2.4
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.
- package/addon/services/universe.js +38 -7
- package/package.json +1 -1
|
@@ -769,31 +769,39 @@ export default class UniverseService extends Service.extend(Evented) {
|
|
|
769
769
|
}
|
|
770
770
|
|
|
771
771
|
/**
|
|
772
|
-
* Creates a dashboard widget object
|
|
772
|
+
* Creates a dashboard widget object from the given widget configuration.
|
|
773
773
|
*
|
|
774
|
-
* @param {Object} widget
|
|
775
|
-
* @
|
|
774
|
+
* @param {Object} widget - The widget configuration object.
|
|
775
|
+
* @param {string} widget.widgetId - The unique identifier for the widget.
|
|
776
|
+
* @param {string} widget.name - The name of the widget.
|
|
777
|
+
* @param {string} widget.description - The description of the widget.
|
|
778
|
+
* @param {string} widget.icon - The icon for the widget.
|
|
779
|
+
* @param {(Function|string)} widget.component - The component class or name for the widget.
|
|
780
|
+
* @param {Object} widget.grid_options - Grid options for the widget layout.
|
|
781
|
+
* @param {Object} widget.options - Additional options for the widget.
|
|
782
|
+
* @returns {Object} A new widget object with properties derived from the input configuration.
|
|
776
783
|
* @memberof UniverseService
|
|
777
784
|
*/
|
|
778
785
|
_createDashboardWidget(widget) {
|
|
779
786
|
// Extract properties from the widget object
|
|
780
|
-
let {
|
|
787
|
+
let { widgetId, name, description, icon, component, grid_options, options } = widget;
|
|
781
788
|
|
|
782
789
|
// If component is a definition register to host application
|
|
783
790
|
if (typeof component === 'function') {
|
|
784
791
|
const owner = getOwner(this);
|
|
792
|
+
const widgetId = component.widgetId || widgetId || this._createUniqueWidgetHashFromDefinition(component);
|
|
785
793
|
|
|
786
794
|
if (owner) {
|
|
787
|
-
owner.register(`component:${
|
|
795
|
+
owner.register(`component:${widgetId}`, component);
|
|
788
796
|
|
|
789
797
|
// Update component name
|
|
790
|
-
component =
|
|
798
|
+
component = widgetId;
|
|
791
799
|
}
|
|
792
800
|
}
|
|
793
801
|
|
|
794
802
|
// Create a new widget object with the extracted properties
|
|
795
803
|
const newWidget = {
|
|
796
|
-
|
|
804
|
+
widgetId,
|
|
797
805
|
name,
|
|
798
806
|
description,
|
|
799
807
|
icon,
|
|
@@ -805,6 +813,29 @@ export default class UniverseService extends Service.extend(Evented) {
|
|
|
805
813
|
return newWidget;
|
|
806
814
|
}
|
|
807
815
|
|
|
816
|
+
/**
|
|
817
|
+
* Creates a unique hash from a component's definition. This hash is used as an identifier
|
|
818
|
+
* for the component when a direct identifier (widgetId) or a name is not available.
|
|
819
|
+
*
|
|
820
|
+
* @param {Function} component - The component class or constructor function.
|
|
821
|
+
* @returns {string} A unique hash string representing the component's definition.
|
|
822
|
+
* @memberof UniverseService
|
|
823
|
+
*/
|
|
824
|
+
_createUniqueWidgetHashFromDefinition(component) {
|
|
825
|
+
if (typeof component.toString === 'function') {
|
|
826
|
+
let definition = component.toString();
|
|
827
|
+
let hash = 0;
|
|
828
|
+
for (let i = 0; i < definition.length; i++) {
|
|
829
|
+
const char = definition.charCodeAt(i);
|
|
830
|
+
hash = (hash << 5) - hash + char;
|
|
831
|
+
hash |= 0;
|
|
832
|
+
}
|
|
833
|
+
return hash.toString(16);
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
return component.name;
|
|
837
|
+
}
|
|
838
|
+
|
|
808
839
|
/**
|
|
809
840
|
* Registers a new settings menu item.
|
|
810
841
|
*
|
package/package.json
CHANGED