From 650f986d32b2e6a65177506aadf535473ec63261 Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Fri, 27 Oct 2023 04:00:29 +0800 Subject: [PATCH] Added engine service share injection utility, as well as minor updates to the universe service --- addon/services/universe.js | 8 ++++++++ addon/utils/inject-engine-service.js | 15 +++++++++++++++ app/utils/inject-engine-service.js | 1 + tests/unit/utils/inject-engine-service-test.js | 10 ++++++++++ 4 files changed, 34 insertions(+) create mode 100644 addon/utils/inject-engine-service.js create mode 100644 app/utils/inject-engine-service.js create mode 100644 tests/unit/utils/inject-engine-service-test.js diff --git a/addon/services/universe.js b/addon/services/universe.js index ae2551a..fecaca8 100644 --- a/addon/services/universe.js +++ b/addon/services/universe.js @@ -447,6 +447,14 @@ export default class UniverseService extends Service.extend(Evented) { // create menu item const menuItem = this._createMenuItem(title, route, options); + // register menu item + if (!this[internalRegistryName]) { + this[internalRegistryName] = { + menuItems: [], + menuPanels: [], + }; + } + // register menu item this[internalRegistryName].menuItems.pushObject(menuItem); diff --git a/addon/utils/inject-engine-service.js b/addon/utils/inject-engine-service.js new file mode 100644 index 0000000..3d4a21f --- /dev/null +++ b/addon/utils/inject-engine-service.js @@ -0,0 +1,15 @@ +import { getOwner } from '@ember/application'; + +export default function injectEngineService(target, engineName, serviceName, key = null) { + const owner = getOwner(target); + const universe = owner.lookup('service:universe'); + const service = universe.getServiceFromEngine(engineName, serviceName); + const effectiveServiceName = key || serviceName; + + Object.defineProperty(target, effectiveServiceName, { + value: service, + writable: false, + configurable: true, + enumerable: true, + }); +} diff --git a/app/utils/inject-engine-service.js b/app/utils/inject-engine-service.js new file mode 100644 index 0000000..8a3fead --- /dev/null +++ b/app/utils/inject-engine-service.js @@ -0,0 +1 @@ +export { default } from '@fleetbase/ember-core/utils/inject-engine-service'; diff --git a/tests/unit/utils/inject-engine-service-test.js b/tests/unit/utils/inject-engine-service-test.js new file mode 100644 index 0000000..5c2b9b5 --- /dev/null +++ b/tests/unit/utils/inject-engine-service-test.js @@ -0,0 +1,10 @@ +import injectEngineService from 'dummy/utils/inject-engine-service'; +import { module, test } from 'qunit'; + +module('Unit | Utility | inject-engine-service', function () { + // TODO: Replace this with your real tests. + test('it works', function (assert) { + let result = injectEngineService(); + assert.ok(result); + }); +});