@fleetbase/ember-core 0.1.5 → 0.1.6
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/loader.js
CHANGED
|
@@ -2,31 +2,55 @@ import Service from '@ember/service';
|
|
|
2
2
|
import { tracked } from '@glimmer/tracking';
|
|
3
3
|
import { later } from '@ember/runloop';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Service for managing loading overlays.
|
|
7
|
+
*
|
|
8
|
+
* @class LoaderService
|
|
9
|
+
* @extends Service
|
|
10
|
+
*/
|
|
5
11
|
export default class LoaderService extends Service {
|
|
12
|
+
/**
|
|
13
|
+
* Tracks the routes that have been loaded.
|
|
14
|
+
*
|
|
15
|
+
* @type {Array}
|
|
16
|
+
* @tracked
|
|
17
|
+
*/
|
|
6
18
|
@tracked routesLoaded = [];
|
|
7
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Shows the loader based on a condition.
|
|
22
|
+
*
|
|
23
|
+
* @param {String|HTMLElement} target - The loader target.
|
|
24
|
+
* @param {Object} options - Options for controlling the loader.
|
|
25
|
+
* @param {Function|null} condition - The condition to evaluate.
|
|
26
|
+
*/
|
|
8
27
|
showOnCondition(target, options = {}, condition = null) {
|
|
9
|
-
const { loadingMessage, opacity } = options;
|
|
10
|
-
|
|
11
28
|
if (typeof condition === 'function') {
|
|
12
29
|
condition = condition();
|
|
13
30
|
}
|
|
14
31
|
|
|
15
32
|
if (condition) {
|
|
16
|
-
this.showLoader(target,
|
|
33
|
+
this.showLoader(target, options);
|
|
17
34
|
}
|
|
18
35
|
}
|
|
19
36
|
|
|
20
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Shows loader during the initial route transition.
|
|
39
|
+
*
|
|
40
|
+
* @param {Object} transition - The Ember.js transition object.
|
|
41
|
+
* @param {String|HTMLElement} target - The loader target.
|
|
42
|
+
* @param {Object} options - Options for controlling the loader.
|
|
43
|
+
*/
|
|
44
|
+
showOnInitialTransition(transition, target, options = { loadingMessage: 'Loading...', opacity: 0.1 }) {
|
|
21
45
|
const route = transition.to.name;
|
|
22
46
|
const isSameRoute = transition.from ? transition.to.name === transition.from.name : false;
|
|
23
47
|
|
|
24
48
|
if (!this.routesLoaded.includes(route) || !isSameRoute) {
|
|
25
|
-
if (document.querySelectorAll(
|
|
49
|
+
if (document.querySelectorAll('.overloader').length > 0) {
|
|
26
50
|
return;
|
|
27
51
|
}
|
|
28
52
|
|
|
29
|
-
this.showLoader(target,
|
|
53
|
+
this.showLoader(target, options);
|
|
30
54
|
|
|
31
55
|
transition.finally(() => {
|
|
32
56
|
this.removeLoader(target);
|
|
@@ -39,20 +63,25 @@ export default class LoaderService extends Service {
|
|
|
39
63
|
/**
|
|
40
64
|
* Creates an HTML element node for a loading overlay with a message.
|
|
41
65
|
*
|
|
42
|
-
* @param {String|HTMLElement} targetSelector
|
|
43
|
-
* @param {
|
|
44
|
-
* @
|
|
66
|
+
* @param {String|HTMLElement} targetSelector - The loader target.
|
|
67
|
+
* @param {Object} options - Options for controlling the loader.
|
|
68
|
+
* @returns {HTMLElement} - The loader element.
|
|
45
69
|
*/
|
|
46
|
-
showLoader(targetSelector,
|
|
70
|
+
showLoader(targetSelector, options = {}) {
|
|
47
71
|
let target = typeof targetSelector === 'string' ? document.querySelector(targetSelector) : targetSelector;
|
|
48
72
|
|
|
49
73
|
if (!target) {
|
|
50
74
|
target = document.body;
|
|
51
75
|
}
|
|
52
76
|
|
|
77
|
+
const loadingMessage = typeof options.loadingMessage === 'string' ? options.loadingMessage : 'Loading...';
|
|
78
|
+
const opacity = typeof options.opacity === 'number' ? options.opacity : 0.1;
|
|
53
79
|
const isDarkMode = document.body.dataset.theme ? document.body.dataset.theme === 'dark' : true;
|
|
80
|
+
const preserveTargetPosition = options.preserveTargetPosition === true;
|
|
54
81
|
|
|
55
|
-
|
|
82
|
+
if (!preserveTargetPosition) {
|
|
83
|
+
target.style.position = 'relative';
|
|
84
|
+
}
|
|
56
85
|
|
|
57
86
|
let loader = document.createElement('div');
|
|
58
87
|
loader.classList.add('overloader');
|
|
@@ -71,15 +100,21 @@ export default class LoaderService extends Service {
|
|
|
71
100
|
return loader;
|
|
72
101
|
}
|
|
73
102
|
|
|
74
|
-
|
|
75
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Shows a loader on the document body.
|
|
105
|
+
*
|
|
106
|
+
* @param {Object} options - Options for controlling the loader.
|
|
107
|
+
* @returns {HTMLElement} - The loader element.
|
|
108
|
+
*/
|
|
109
|
+
show(options = { loadingMessage: 'Loading...', opacity: 0.1 }) {
|
|
110
|
+
return this.showLoader(document.body, options);
|
|
76
111
|
}
|
|
77
112
|
|
|
78
113
|
/**
|
|
79
|
-
*
|
|
114
|
+
* Removes a loader from a target.
|
|
80
115
|
*
|
|
81
|
-
* @param {String|HTMLElement} targetSelector
|
|
82
|
-
* @
|
|
116
|
+
* @param {String|HTMLElement} targetSelector - The loader target.
|
|
117
|
+
* @returns {Service} - The current service instance.
|
|
83
118
|
*/
|
|
84
119
|
removeLoader(targetSelector) {
|
|
85
120
|
let target = typeof targetSelector === 'string' ? document.querySelector(targetSelector) : targetSelector;
|
|
@@ -114,9 +149,10 @@ export default class LoaderService extends Service {
|
|
|
114
149
|
}
|
|
115
150
|
|
|
116
151
|
/**
|
|
117
|
-
* Removes
|
|
152
|
+
* Removes all loader instances after a delay.
|
|
118
153
|
*
|
|
119
|
-
* @
|
|
154
|
+
* @param {Number} delay - The delay in milliseconds.
|
|
155
|
+
* @returns {Service} - The current service instance.
|
|
120
156
|
*/
|
|
121
157
|
remove(delay = 0) {
|
|
122
158
|
const loaders = document.querySelectorAll(`.overloader`);
|
|
@@ -447,6 +447,14 @@ export default class UniverseService extends Service.extend(Evented) {
|
|
|
447
447
|
// create menu item
|
|
448
448
|
const menuItem = this._createMenuItem(title, route, options);
|
|
449
449
|
|
|
450
|
+
// register menu item
|
|
451
|
+
if (!this[internalRegistryName]) {
|
|
452
|
+
this[internalRegistryName] = {
|
|
453
|
+
menuItems: [],
|
|
454
|
+
menuPanels: [],
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
|
|
450
458
|
// register menu item
|
|
451
459
|
this[internalRegistryName].menuItems.pushObject(menuItem);
|
|
452
460
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getOwner } from '@ember/application';
|
|
2
|
+
|
|
3
|
+
export default function injectEngineService(target, engineName, serviceName, key = null) {
|
|
4
|
+
const owner = getOwner(target);
|
|
5
|
+
const universe = owner.lookup('service:universe');
|
|
6
|
+
const service = universe.getServiceFromEngine(engineName, serviceName);
|
|
7
|
+
const effectiveServiceName = key || serviceName;
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(target, effectiveServiceName, {
|
|
10
|
+
value: service,
|
|
11
|
+
writable: false,
|
|
12
|
+
configurable: true,
|
|
13
|
+
enumerable: true,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '@fleetbase/ember-core/utils/inject-engine-service';
|
package/package.json
CHANGED