@fleetbase/ember-core 0.1.5 → 0.1.7
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.
|
@@ -6,6 +6,7 @@ import { isBlank } from '@ember/utils';
|
|
|
6
6
|
import { computed, action, set, get } from '@ember/object';
|
|
7
7
|
import { getOwner } from '@ember/application';
|
|
8
8
|
import { format } from 'date-fns';
|
|
9
|
+
import getWithDefault from '../utils/get-with-default';
|
|
9
10
|
|
|
10
11
|
export default class FiltersService extends Service {
|
|
11
12
|
@service router;
|
|
@@ -74,7 +75,7 @@ export default class FiltersService extends Service {
|
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
@action apply(controller) {
|
|
77
|
-
const currentQueryParams = this.getQueryParams();
|
|
78
|
+
const currentQueryParams = this.getQueryParams(controller);
|
|
78
79
|
const updatableQueryParams = { ...currentQueryParams, ...this.pendingQueryParams };
|
|
79
80
|
|
|
80
81
|
for (let queryParam in updatableQueryParams) {
|
|
@@ -88,8 +89,10 @@ export default class FiltersService extends Service {
|
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
@action reset(controller) {
|
|
91
|
-
this.
|
|
92
|
-
|
|
92
|
+
const queryParams = this.getQueryParams(controller);
|
|
93
|
+
|
|
94
|
+
Object.keys(queryParams).forEach((queryParam) => {
|
|
95
|
+
this.removeFromController(controller, queryParam, undefined);
|
|
93
96
|
});
|
|
94
97
|
}
|
|
95
98
|
|
|
@@ -103,20 +106,18 @@ export default class FiltersService extends Service {
|
|
|
103
106
|
return this.clear(queryParam, callback);
|
|
104
107
|
}
|
|
105
108
|
|
|
106
|
-
if (isBlank(queryParam)) {
|
|
109
|
+
if (isBlank(queryParam) && Object.keys(currentQueryParams).length > 0) {
|
|
107
110
|
return Object.keys(currentQueryParams).forEach((qp) => this.clear(callback, qp));
|
|
108
111
|
}
|
|
109
112
|
|
|
110
|
-
if (isArray(queryParam)) {
|
|
113
|
+
if (isArray(queryParam) && !isBlank(queryParam)) {
|
|
111
114
|
return queryParam.forEach((qp) => this.clear(callback, qp));
|
|
112
115
|
}
|
|
113
116
|
|
|
114
|
-
if (typeof queryParam
|
|
115
|
-
|
|
117
|
+
if (typeof queryParam === 'string') {
|
|
118
|
+
set(this.pendingQueryParams, queryParam, undefined);
|
|
116
119
|
}
|
|
117
120
|
|
|
118
|
-
set(this.pendingQueryParams, queryParam, undefined);
|
|
119
|
-
|
|
120
121
|
if (typeof callback == 'function') {
|
|
121
122
|
callback(queryParam);
|
|
122
123
|
}
|
|
@@ -153,10 +154,29 @@ export default class FiltersService extends Service {
|
|
|
153
154
|
return currentRoute.queryParams;
|
|
154
155
|
}
|
|
155
156
|
|
|
156
|
-
@action getQueryParams() {
|
|
157
|
+
@action getQueryParams(controller) {
|
|
158
|
+
const queryParams = {};
|
|
159
|
+
|
|
160
|
+
if (controller) {
|
|
161
|
+
const controllerQueryParams = getWithDefault(controller, 'queryParams', []);
|
|
162
|
+
|
|
163
|
+
if (isArray(controllerQueryParams)) {
|
|
164
|
+
for (let i = 0; i < controllerQueryParams.length; i++) {
|
|
165
|
+
const qp = controllerQueryParams.objectAt(i);
|
|
166
|
+
|
|
167
|
+
if (this.managedQueryParams.includes(qp)) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
queryParams[qp] = get(controller, qp);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return queryParams;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
157
178
|
const currentRoute = this.lookupCurrentRoute();
|
|
158
179
|
const currentRouteQueryParams = Object.keys(currentRoute.queryParams);
|
|
159
|
-
const queryParams = {};
|
|
160
180
|
|
|
161
181
|
for (let i = 0; i < currentRouteQueryParams.length; i++) {
|
|
162
182
|
const queryParam = currentRouteQueryParams.objectAt(i);
|
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