From f2a3387c3645f6f5d1b3ed571aa97e786d93e7ee Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Tue, 6 Feb 2024 19:22:00 +0800 Subject: [PATCH 1/4] should register component to application if component definition provided --- addon/services/universe.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/addon/services/universe.js b/addon/services/universe.js index e14cad0..5c04cde 100644 --- a/addon/services/universe.js +++ b/addon/services/universe.js @@ -741,7 +741,19 @@ export default class UniverseService extends Service.extend(Evented) { */ _createDashboardWidget(widget) { // Extract properties from the widget object - const { did, name, description, icon, component, grid_options, options } = widget; + let { did, name, description, icon, component, grid_options, options } = widget; + + // If component is a definition register to host application + if (typeof component === 'function') { + const owner = getOwner(this); + + if (owner) { + owner.register(`component:${component.name}`, component); + + // Update component name + component = component.name; + } + } // Create a new widget object with the extracted properties const newWidget = { From c83c32839aa5751c4b163d95eb84ec705ead7790 Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Tue, 6 Feb 2024 19:46:10 +0800 Subject: [PATCH 2/4] added new method to enable creation of multiple registries --- addon/services/universe.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/addon/services/universe.js b/addon/services/universe.js index 5c04cde..2aa68e8 100644 --- a/addon/services/universe.js +++ b/addon/services/universe.js @@ -268,6 +268,42 @@ export default class UniverseService extends Service.extend(Evented) { return this; } + /** + * Creates multiple registries from a given array of registries. Each registry can be either a string or an array. + * If a registry is an array, it expects two elements: the registry name (string) and registry options (object). + * If a registry is a string, only the registry name is needed. + * + * The function iterates over each element in the `registries` array and creates a registry using the `createRegistry` method. + * It supports two types of registry definitions: + * 1. Array format: [registryName, registryOptions] - where registryOptions is an optional object. + * 2. String format: "registryName" - in this case, only the name is provided and the registry is created with default options. + * + * @param {Array} registries - An array of registries to be created. Each element can be either a string or an array. + * @action + * @memberof YourComponentOrClassName + */ + @action createRegistries(registries = []) { + if (!isArray(registries)) { + throw new Error('`createRegistries()` method must take an array.'); + } + + for (let i = 0; i < registries.length; i++) { + const registry = registries[i]; + + if (isArray(registry) && registry.length === 2) { + let registryName = registry[0]; + let registryOptions = registry[1] ?? {}; + + this.createRegistry(registryName, registryOptions); + continue; + } + + if (typeof registry === 'string') { + this.createRegistry(registry); + } + } + } + /** * Triggers an event on for a universe registry. * From 38c7c5a63472aa0351a5f6c3c39d30ded1a6dcef Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Tue, 6 Feb 2024 19:46:40 +0800 Subject: [PATCH 3/4] bump ember-core version for another release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8554b94..9c45db8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fleetbase/ember-core", - "version": "0.2.2", + "version": "0.2.3", "description": "Provides all the core services, decorators and utilities for building a Fleetbase extension for the Console.", "keywords": [ "fleetbase-core", From e4bad545d8f292ed3bb186d74b7665d288a4909c Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Tue, 6 Feb 2024 19:47:23 +0800 Subject: [PATCH 4/4] fix linter --- addon/services/universe.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/services/universe.js b/addon/services/universe.js index 2aa68e8..c620153 100644 --- a/addon/services/universe.js +++ b/addon/services/universe.js @@ -286,7 +286,7 @@ export default class UniverseService extends Service.extend(Evented) { if (!isArray(registries)) { throw new Error('`createRegistries()` method must take an array.'); } - + for (let i = 0; i < registries.length; i++) { const registry = registries[i];