@fleetbase/ember-core 0.2.2 → 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 +84 -5
- package/package.json +1 -1
|
@@ -268,6 +268,42 @@ export default class UniverseService extends Service.extend(Evented) {
|
|
|
268
268
|
return this;
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
+
/**
|
|
272
|
+
* Creates multiple registries from a given array of registries. Each registry can be either a string or an array.
|
|
273
|
+
* If a registry is an array, it expects two elements: the registry name (string) and registry options (object).
|
|
274
|
+
* If a registry is a string, only the registry name is needed.
|
|
275
|
+
*
|
|
276
|
+
* The function iterates over each element in the `registries` array and creates a registry using the `createRegistry` method.
|
|
277
|
+
* It supports two types of registry definitions:
|
|
278
|
+
* 1. Array format: [registryName, registryOptions] - where registryOptions is an optional object.
|
|
279
|
+
* 2. String format: "registryName" - in this case, only the name is provided and the registry is created with default options.
|
|
280
|
+
*
|
|
281
|
+
* @param {Array} registries - An array of registries to be created. Each element can be either a string or an array.
|
|
282
|
+
* @action
|
|
283
|
+
* @memberof YourComponentOrClassName
|
|
284
|
+
*/
|
|
285
|
+
@action createRegistries(registries = []) {
|
|
286
|
+
if (!isArray(registries)) {
|
|
287
|
+
throw new Error('`createRegistries()` method must take an array.');
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
for (let i = 0; i < registries.length; i++) {
|
|
291
|
+
const registry = registries[i];
|
|
292
|
+
|
|
293
|
+
if (isArray(registry) && registry.length === 2) {
|
|
294
|
+
let registryName = registry[0];
|
|
295
|
+
let registryOptions = registry[1] ?? {};
|
|
296
|
+
|
|
297
|
+
this.createRegistry(registryName, registryOptions);
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (typeof registry === 'string') {
|
|
302
|
+
this.createRegistry(registry);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
271
307
|
/**
|
|
272
308
|
* Triggers an event on for a universe registry.
|
|
273
309
|
*
|
|
@@ -733,19 +769,39 @@ export default class UniverseService extends Service.extend(Evented) {
|
|
|
733
769
|
}
|
|
734
770
|
|
|
735
771
|
/**
|
|
736
|
-
* Creates a dashboard widget object
|
|
772
|
+
* Creates a dashboard widget object from the given widget configuration.
|
|
737
773
|
*
|
|
738
|
-
* @param {Object} widget
|
|
739
|
-
* @
|
|
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.
|
|
740
783
|
* @memberof UniverseService
|
|
741
784
|
*/
|
|
742
785
|
_createDashboardWidget(widget) {
|
|
743
786
|
// Extract properties from the widget object
|
|
744
|
-
|
|
787
|
+
let { widgetId, name, description, icon, component, grid_options, options } = widget;
|
|
788
|
+
|
|
789
|
+
// If component is a definition register to host application
|
|
790
|
+
if (typeof component === 'function') {
|
|
791
|
+
const owner = getOwner(this);
|
|
792
|
+
const widgetId = component.widgetId || widgetId || this._createUniqueWidgetHashFromDefinition(component);
|
|
793
|
+
|
|
794
|
+
if (owner) {
|
|
795
|
+
owner.register(`component:${widgetId}`, component);
|
|
796
|
+
|
|
797
|
+
// Update component name
|
|
798
|
+
component = widgetId;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
745
801
|
|
|
746
802
|
// Create a new widget object with the extracted properties
|
|
747
803
|
const newWidget = {
|
|
748
|
-
|
|
804
|
+
widgetId,
|
|
749
805
|
name,
|
|
750
806
|
description,
|
|
751
807
|
icon,
|
|
@@ -757,6 +813,29 @@ export default class UniverseService extends Service.extend(Evented) {
|
|
|
757
813
|
return newWidget;
|
|
758
814
|
}
|
|
759
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
|
+
|
|
760
839
|
/**
|
|
761
840
|
* Registers a new settings menu item.
|
|
762
841
|
*
|
package/package.json
CHANGED