@fleetbase/ember-core 0.2.1 → 0.2.3
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 +149 -0
- package/package.json +1 -1
|
@@ -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.
|
|
@@ -264,6 +268,42 @@ export default class UniverseService extends Service.extend(Evented) {
|
|
|
264
268
|
return this;
|
|
265
269
|
}
|
|
266
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
|
+
|
|
267
307
|
/**
|
|
268
308
|
* Triggers an event on for a universe registry.
|
|
269
309
|
*
|
|
@@ -656,6 +696,115 @@ export default class UniverseService extends Service.extend(Evented) {
|
|
|
656
696
|
this.registerMenuPanel('settings', title, items, options);
|
|
657
697
|
}
|
|
658
698
|
|
|
699
|
+
/**
|
|
700
|
+
* Registers a new dashboard widget in the universe service.
|
|
701
|
+
*
|
|
702
|
+
* @method registerDashboardWidgets
|
|
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
|
+
registerDashboardWidgets(widget) {
|
|
713
|
+
if (isArray(widget)) {
|
|
714
|
+
widget.forEach((w) => this.registerDashboardWidgets(w));
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
const newWidget = this._createDashboardWidget(widget);
|
|
719
|
+
this.dashboardWidgets.widgets.pushObject(newWidget);
|
|
720
|
+
this.trigger('widget.registered', newWidget);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* Retrieves the widgets registered in the universe service.
|
|
725
|
+
*
|
|
726
|
+
* @method getDashboardWidgets
|
|
727
|
+
* @public
|
|
728
|
+
* @memberof UniverseService
|
|
729
|
+
* @returns {Array} An array of registered widgets
|
|
730
|
+
*/
|
|
731
|
+
getDashboardWidgets() {
|
|
732
|
+
return this.dashboardWidgets.widgets;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Registers a new dashboard widget in the universe service.
|
|
737
|
+
*
|
|
738
|
+
* @method registerDefaultDashboardWidgets
|
|
739
|
+
* @public
|
|
740
|
+
* @memberof UniverseService
|
|
741
|
+
* @param {Object} widget - The widget object containing name, component, gridOptions, and options.
|
|
742
|
+
* @property {String} name - The name of the widget.
|
|
743
|
+
* @property {String} icon - The iron of the widget.
|
|
744
|
+
* @property {Function} component - The component associated with the widget.
|
|
745
|
+
* @property {Object} gridOptions - The grid options for the widget.
|
|
746
|
+
* @property {Object} options - Additional options for the widget.
|
|
747
|
+
*/
|
|
748
|
+
registerDefaultDashboardWidgets(widget) {
|
|
749
|
+
if (isArray(widget)) {
|
|
750
|
+
widget.forEach((w) => this.registerDefaultDashboardWidgets(w));
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
const newWidget = this._createDashboardWidget(widget);
|
|
755
|
+
this.dashboardWidgets.defaultWidgets.pushObject(newWidget);
|
|
756
|
+
this.trigger('widget.registered', newWidget);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* Retrieves the widgets registered in the universe service.
|
|
761
|
+
*
|
|
762
|
+
* @method getDefaultDashboardWidgets
|
|
763
|
+
* @public
|
|
764
|
+
* @memberof UniverseService
|
|
765
|
+
* @returns {Array} An array of registered widgets
|
|
766
|
+
*/
|
|
767
|
+
getDefaultDashboardWidgets() {
|
|
768
|
+
return this.dashboardWidgets.defaultWidgets;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* Creates a dashboard widget object
|
|
773
|
+
*
|
|
774
|
+
* @param {Object} widget
|
|
775
|
+
* @return {Widgetobject}
|
|
776
|
+
* @memberof UniverseService
|
|
777
|
+
*/
|
|
778
|
+
_createDashboardWidget(widget) {
|
|
779
|
+
// Extract properties from the widget object
|
|
780
|
+
let { did, name, description, icon, component, grid_options, options } = widget;
|
|
781
|
+
|
|
782
|
+
// If component is a definition register to host application
|
|
783
|
+
if (typeof component === 'function') {
|
|
784
|
+
const owner = getOwner(this);
|
|
785
|
+
|
|
786
|
+
if (owner) {
|
|
787
|
+
owner.register(`component:${component.name}`, component);
|
|
788
|
+
|
|
789
|
+
// Update component name
|
|
790
|
+
component = component.name;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
// Create a new widget object with the extracted properties
|
|
795
|
+
const newWidget = {
|
|
796
|
+
did,
|
|
797
|
+
name,
|
|
798
|
+
description,
|
|
799
|
+
icon,
|
|
800
|
+
component,
|
|
801
|
+
grid_options,
|
|
802
|
+
options,
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
return newWidget;
|
|
806
|
+
}
|
|
807
|
+
|
|
659
808
|
/**
|
|
660
809
|
* Registers a new settings menu item.
|
|
661
810
|
*
|
package/package.json
CHANGED