@fleetbase/ember-core 0.2.17 → 0.2.19
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/current-user.js +23 -5
- package/addon/services/fetch.js +12 -1
- package/addon/services/session.js +14 -8
- package/addon/services/theme.js +1 -1
- package/addon/services/universe.js +636 -119
- package/addon/services/url-search-params.js +189 -35
- package/addon/utils/inject-engine-service.js +7 -2
- package/addon/utils/is-empty-object.js +7 -1
- package/addon/utils/register-component.js +8 -0
- package/addon/utils/register-helper.js +8 -0
- package/addon/utils/serialize/normalize-relations-with-hash.js +0 -5
- package/app/utils/register-component.js +1 -0
- package/app/utils/register-helper.js +1 -0
- package/package.json +1 -1
|
@@ -32,6 +32,8 @@ export default class CurrentUserService extends Service.extend(Evented) {
|
|
|
32
32
|
@alias('user.is_admin') isAdmin;
|
|
33
33
|
@alias('user.company_uuid') companyId;
|
|
34
34
|
@alias('user.company_name') companyName;
|
|
35
|
+
@alias('user.role_name') roleName;
|
|
36
|
+
@alias('user.role') role;
|
|
35
37
|
|
|
36
38
|
@computed('id') get optionsPrefix() {
|
|
37
39
|
return `${this.id}:`;
|
|
@@ -94,8 +96,18 @@ export default class CurrentUserService extends Service.extend(Evented) {
|
|
|
94
96
|
// Set environment from user option
|
|
95
97
|
this.theme.setEnvironment();
|
|
96
98
|
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
+
// Set locale
|
|
100
|
+
if (user.locale) {
|
|
101
|
+
this.setLocale(user.locale);
|
|
102
|
+
} else {
|
|
103
|
+
await this.loadLocale();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Load user whois data
|
|
107
|
+
await this.loadWhois();
|
|
108
|
+
|
|
109
|
+
// Load user organizations
|
|
110
|
+
await this.loadOrganizations();
|
|
99
111
|
|
|
100
112
|
// Optional callback
|
|
101
113
|
if (typeof options?.onUserResolved === 'function') {
|
|
@@ -118,9 +130,7 @@ export default class CurrentUserService extends Service.extend(Evented) {
|
|
|
118
130
|
async loadLocale() {
|
|
119
131
|
try {
|
|
120
132
|
const { locale } = await this.fetch.get('users/locale');
|
|
121
|
-
this.
|
|
122
|
-
this.intl.setLocale(locale);
|
|
123
|
-
this.locale = locale;
|
|
133
|
+
this.setLocale(locale);
|
|
124
134
|
|
|
125
135
|
return locale;
|
|
126
136
|
} catch (error) {
|
|
@@ -207,6 +217,14 @@ export default class CurrentUserService extends Service.extend(Evented) {
|
|
|
207
217
|
return this.getWhoisProperty(key);
|
|
208
218
|
}
|
|
209
219
|
|
|
220
|
+
setLocale(locale) {
|
|
221
|
+
this.setOption('locale', locale);
|
|
222
|
+
this.intl.setLocale(locale);
|
|
223
|
+
this.locale = locale;
|
|
224
|
+
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
227
|
+
|
|
210
228
|
setOption(key, value) {
|
|
211
229
|
key = `${this.optionsPrefix}${dasherize(key)}`;
|
|
212
230
|
|
package/addon/services/fetch.js
CHANGED
|
@@ -360,6 +360,7 @@ export default class FetchService extends Service {
|
|
|
360
360
|
const pathKeyVersion = new Date().toISOString();
|
|
361
361
|
|
|
362
362
|
const request = () => {
|
|
363
|
+
delete options.fromCache;
|
|
363
364
|
return this.get(path, query, options).then((response) => {
|
|
364
365
|
// cache the response
|
|
365
366
|
this.localCache.set(pathKey, response);
|
|
@@ -392,7 +393,7 @@ export default class FetchService extends Service {
|
|
|
392
393
|
// if the version is older than 3 days clear it
|
|
393
394
|
if (!version || shouldExpire || options.clearData === true) {
|
|
394
395
|
this.flushRequestCache(path);
|
|
395
|
-
return request();
|
|
396
|
+
return request().then(resolve);
|
|
396
397
|
}
|
|
397
398
|
|
|
398
399
|
if (options.normalizeToEmberData) {
|
|
@@ -408,6 +409,11 @@ export default class FetchService extends Service {
|
|
|
408
409
|
return request();
|
|
409
410
|
}
|
|
410
411
|
|
|
412
|
+
/**
|
|
413
|
+
* Flushes the local cache for a specific path by setting its value and version to undefined.
|
|
414
|
+
*
|
|
415
|
+
* @param {string} path - The path for which the cache should be flushed.
|
|
416
|
+
*/
|
|
411
417
|
flushRequestCache(path) {
|
|
412
418
|
const pathKey = dasherize(path);
|
|
413
419
|
|
|
@@ -415,6 +421,11 @@ export default class FetchService extends Service {
|
|
|
415
421
|
this.localCache.set(`${pathKey}-version`, undefined);
|
|
416
422
|
}
|
|
417
423
|
|
|
424
|
+
/**
|
|
425
|
+
* Determines whether the cache should be reset by comparing the current version
|
|
426
|
+
* of the console with the cached version. If they differ, the cache is cleared
|
|
427
|
+
* and the new version is saved.
|
|
428
|
+
*/
|
|
418
429
|
shouldResetCache() {
|
|
419
430
|
const consoleVersion = this.localCache.get('console-version');
|
|
420
431
|
|
|
@@ -2,12 +2,14 @@ import SimpleAuthSessionService from 'ember-simple-auth/services/session';
|
|
|
2
2
|
import { tracked } from '@glimmer/tracking';
|
|
3
3
|
import { inject as service } from '@ember/service';
|
|
4
4
|
import { later } from '@ember/runloop';
|
|
5
|
+
import { debug } from '@ember/debug';
|
|
5
6
|
import getWithDefault from '../utils/get-with-default';
|
|
6
7
|
|
|
7
8
|
export default class SessionService extends SimpleAuthSessionService {
|
|
8
9
|
@service router;
|
|
9
10
|
@service currentUser;
|
|
10
11
|
@service fetch;
|
|
12
|
+
@service notifications;
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Set where to transition to
|
|
@@ -52,10 +54,7 @@ export default class SessionService extends SimpleAuthSessionService {
|
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
const loaderNode = this.showLoader('Starting session...');
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
await this.router.transitionTo(this.redirectTo);
|
|
57
|
+
const removeLoaderNode = () => {
|
|
59
58
|
later(
|
|
60
59
|
this,
|
|
61
60
|
() => {
|
|
@@ -63,11 +62,18 @@ export default class SessionService extends SimpleAuthSessionService {
|
|
|
63
62
|
document.body.removeChild(loaderNode);
|
|
64
63
|
this.isLoaderNodeOpen = false;
|
|
65
64
|
},
|
|
66
|
-
600 *
|
|
65
|
+
600 * 3
|
|
67
66
|
);
|
|
67
|
+
};
|
|
68
|
+
this.isLoaderNodeOpen = true;
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
await this.router.transitionTo(this.redirectTo);
|
|
68
72
|
} catch (error) {
|
|
69
|
-
|
|
73
|
+
debug(`Session's handleAuthentication() failed to transition: ${error.message}`);
|
|
70
74
|
}
|
|
75
|
+
|
|
76
|
+
removeLoaderNode();
|
|
71
77
|
}
|
|
72
78
|
|
|
73
79
|
/**
|
|
@@ -114,6 +120,7 @@ export default class SessionService extends SimpleAuthSessionService {
|
|
|
114
120
|
if (transition) {
|
|
115
121
|
transition.abort();
|
|
116
122
|
}
|
|
123
|
+
|
|
117
124
|
await invalidateWithLoader(error.message ?? 'Session authentication failed...');
|
|
118
125
|
throw error;
|
|
119
126
|
}
|
|
@@ -154,8 +161,7 @@ export default class SessionService extends SimpleAuthSessionService {
|
|
|
154
161
|
}
|
|
155
162
|
|
|
156
163
|
const loaderNode = this.showLoader(loadingMessage);
|
|
157
|
-
|
|
158
|
-
this.isLoaderNodeOpen = false;
|
|
164
|
+
this.isLoaderNodeOpen = true;
|
|
159
165
|
|
|
160
166
|
return this.session.invalidate().then(() => {
|
|
161
167
|
later(
|
package/addon/services/theme.js
CHANGED