@fleetbase/ember-core 0.1.0 → 0.1.2
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.
|
@@ -40,25 +40,21 @@ export default class ApplicationAdapter extends RESTAdapter {
|
|
|
40
40
|
*
|
|
41
41
|
* @var {String}
|
|
42
42
|
*/
|
|
43
|
-
|
|
44
|
-
return get(config, 'API.host');
|
|
45
|
-
}
|
|
43
|
+
@tracked host;
|
|
46
44
|
|
|
47
45
|
/**
|
|
48
46
|
* The default namespace for adapter
|
|
49
47
|
*
|
|
50
48
|
* @var {String}
|
|
51
49
|
*/
|
|
52
|
-
|
|
53
|
-
return get(config, 'API.namespace');
|
|
54
|
-
}
|
|
50
|
+
@tracked namespace;
|
|
55
51
|
|
|
56
52
|
/**
|
|
57
53
|
* Credentials
|
|
58
54
|
*
|
|
59
55
|
* @var {String}
|
|
60
56
|
*/
|
|
61
|
-
credentials = 'include';
|
|
57
|
+
@tracked credentials = 'include';
|
|
62
58
|
|
|
63
59
|
/**
|
|
64
60
|
* Mutable headers property.
|
|
@@ -68,31 +64,23 @@ export default class ApplicationAdapter extends RESTAdapter {
|
|
|
68
64
|
@tracked _headers;
|
|
69
65
|
|
|
70
66
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* @var {Object}
|
|
67
|
+
* Creates an instance of ApplicationAdapter.
|
|
68
|
+
* @memberof ApplicationAdapter
|
|
74
69
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return this._headers;
|
|
78
|
-
}
|
|
70
|
+
constructor() {
|
|
71
|
+
super(...arguments);
|
|
79
72
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Setter fucntion to overwrite headers.
|
|
85
|
-
*/
|
|
86
|
-
set headers(headers) {
|
|
87
|
-
this._headers = headers;
|
|
73
|
+
this.host = get(config, 'API.host');
|
|
74
|
+
this.namespace = get(config, 'API.namespace');
|
|
75
|
+
this.headers = this.setupHeaders();
|
|
88
76
|
}
|
|
89
77
|
|
|
90
78
|
/**
|
|
91
|
-
*
|
|
79
|
+
* Setup headers that should be sent with request.
|
|
92
80
|
*
|
|
93
81
|
* @return {Object}
|
|
94
82
|
*/
|
|
95
|
-
|
|
83
|
+
setupHeaders() {
|
|
96
84
|
const headers = {};
|
|
97
85
|
const userId = this.session.data.authenticated.user;
|
|
98
86
|
const userOptions = getUserOptions();
|
|
@@ -127,20 +115,8 @@ export default class ApplicationAdapter extends RESTAdapter {
|
|
|
127
115
|
headers['Access-Console-Sandbox-Key'] = testKey;
|
|
128
116
|
}
|
|
129
117
|
|
|
130
|
-
return headers;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Gets fresh headers and sets them.
|
|
135
|
-
*
|
|
136
|
-
* @return {Object}
|
|
137
|
-
*/
|
|
138
|
-
refreshHeaders() {
|
|
139
|
-
const headers = this.getHeaders();
|
|
140
|
-
|
|
141
118
|
this.headers = headers;
|
|
142
|
-
|
|
143
|
-
return headers;
|
|
119
|
+
return this.headers;
|
|
144
120
|
}
|
|
145
121
|
|
|
146
122
|
/**
|
|
@@ -153,7 +129,7 @@ export default class ApplicationAdapter extends RESTAdapter {
|
|
|
153
129
|
* @return {Object}
|
|
154
130
|
*/
|
|
155
131
|
ajaxOptions(url, type, options) {
|
|
156
|
-
this.
|
|
132
|
+
this.setupHeaders();
|
|
157
133
|
|
|
158
134
|
const ajaxOptions = super.ajaxOptions(url, type, options);
|
|
159
135
|
ajaxOptions.credentials = this.credentials;
|
package/addon/services/theme.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Service from '@ember/service';
|
|
2
2
|
import { tracked } from '@glimmer/tracking';
|
|
3
3
|
import { inject as service } from '@ember/service';
|
|
4
|
+
import { computed } from '@ember/object';
|
|
4
5
|
import { dasherize } from '@ember/string';
|
|
5
6
|
import { isArray } from '@ember/array';
|
|
6
7
|
import { getOwner } from '@ember/application';
|
|
@@ -32,19 +33,23 @@ export default class ThemeService extends Service {
|
|
|
32
33
|
*
|
|
33
34
|
* @var {String}
|
|
34
35
|
*/
|
|
35
|
-
get activeTheme() {
|
|
36
|
+
@computed('currentTheme', 'initialTheme') get activeTheme() {
|
|
36
37
|
const userSetTheme = this.currentUser.getOption(`theme`);
|
|
37
38
|
|
|
38
39
|
if (userSetTheme) {
|
|
39
40
|
return userSetTheme;
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
if (this.initialTheme) {
|
|
44
|
+
return this.initialTheme;
|
|
45
|
+
}
|
|
46
|
+
|
|
42
47
|
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
43
48
|
return 'dark';
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
// default to dark theme
|
|
47
|
-
return
|
|
52
|
+
return this.currentTheme;
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
/**
|
|
@@ -56,12 +61,19 @@ export default class ThemeService extends Service {
|
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
/**
|
|
59
|
-
* Current theme, defaults to
|
|
64
|
+
* Current theme, defaults to dark, active theme represents the theme set by user OS
|
|
60
65
|
*
|
|
61
66
|
* @var {String}
|
|
62
67
|
*/
|
|
63
68
|
@tracked currentTheme = 'dark';
|
|
64
69
|
|
|
70
|
+
/**
|
|
71
|
+
* The initially set theme
|
|
72
|
+
*
|
|
73
|
+
* @var {String}
|
|
74
|
+
*/
|
|
75
|
+
@tracked initialTheme;
|
|
76
|
+
|
|
65
77
|
/**
|
|
66
78
|
* The current route name as style class
|
|
67
79
|
*
|
|
@@ -116,6 +128,7 @@ export default class ThemeService extends Service {
|
|
|
116
128
|
* @void
|
|
117
129
|
*/
|
|
118
130
|
initialize(options = {}) {
|
|
131
|
+
this.initialTheme = options?.theme;
|
|
119
132
|
this.setTheme(this.activeTheme);
|
|
120
133
|
this.setEnvironment();
|
|
121
134
|
this.resetScroll();
|
|
@@ -125,6 +138,19 @@ export default class ThemeService extends Service {
|
|
|
125
138
|
// remove route class as exiting
|
|
126
139
|
this.router.on('routeWillChange', this.routeWillChange.bind(this));
|
|
127
140
|
// remove console-loader
|
|
141
|
+
this.removeConsoleLoader();
|
|
142
|
+
// run a `onInit` callback if provided
|
|
143
|
+
if (typeof options.onInit === 'function') {
|
|
144
|
+
options.onInit(this);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Remove the console-loader
|
|
150
|
+
*
|
|
151
|
+
* @memberof ThemeService
|
|
152
|
+
*/
|
|
153
|
+
removeConsoleLoader() {
|
|
128
154
|
const consoleLoader = document.getElementById(`console-loader`);
|
|
129
155
|
if (consoleLoader) {
|
|
130
156
|
consoleLoader.remove();
|
|
@@ -12,6 +12,7 @@ import RSVP from 'rsvp';
|
|
|
12
12
|
|
|
13
13
|
export default class UniverseService extends Service.extend(Evented) {
|
|
14
14
|
@service router;
|
|
15
|
+
@service intl;
|
|
15
16
|
@tracked headerMenuItems = [];
|
|
16
17
|
@tracked organizationMenuItems = [];
|
|
17
18
|
@tracked userMenuItems = [];
|
|
@@ -527,4 +528,13 @@ export default class UniverseService extends Service.extend(Evented) {
|
|
|
527
528
|
return engineInstance;
|
|
528
529
|
});
|
|
529
530
|
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Alias for intl service `t`
|
|
534
|
+
*
|
|
535
|
+
* @memberof UniverseService
|
|
536
|
+
*/
|
|
537
|
+
t() {
|
|
538
|
+
this.intl.t(...arguments);
|
|
539
|
+
}
|
|
530
540
|
}
|
|
@@ -2,55 +2,39 @@ import config from '@fleetbase/console/config/environment';
|
|
|
2
2
|
import { isBlank } from '@ember/utils';
|
|
3
3
|
|
|
4
4
|
const isDevelopment = ['local', 'development'].includes(config.environment);
|
|
5
|
-
const isProduction = ['production'].includes(config.environment);
|
|
6
5
|
|
|
7
|
-
function queryString(params) {
|
|
6
|
+
export function queryString(params) {
|
|
8
7
|
return Object.keys(params)
|
|
9
|
-
.map((key) => `${key}=${params[key]}`)
|
|
8
|
+
.map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
|
|
10
9
|
.join('&');
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
function extractHostAndPort(url) {
|
|
12
|
+
export function extractHostAndPort(url) {
|
|
14
13
|
try {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const port = parsedUrl.port;
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
host: host,
|
|
21
|
-
port: port || null,
|
|
22
|
-
};
|
|
14
|
+
const { hostname: host, port = null } = new URL(url);
|
|
15
|
+
return { host, port };
|
|
23
16
|
} catch (error) {
|
|
24
|
-
|
|
25
|
-
return null;
|
|
17
|
+
return { host: null, port: null };
|
|
26
18
|
}
|
|
27
19
|
}
|
|
28
20
|
|
|
29
|
-
export default function consoleUrl(path = '', queryParams = {}, subdomain =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (!isProduction && !isDevelopment) {
|
|
40
|
-
url += `${config.environment}.`;
|
|
21
|
+
export default function consoleUrl(path = '', queryParams = {}, subdomain = null, host = null) {
|
|
22
|
+
if (subdomain === null || host === null) {
|
|
23
|
+
const { hostname, host: currentHost } = window.location;
|
|
24
|
+
if (subdomain === null) {
|
|
25
|
+
const parts = hostname.split('.');
|
|
26
|
+
subdomain = parts.length > 2 ? parts[0] : null;
|
|
27
|
+
}
|
|
28
|
+
if (host === null) {
|
|
29
|
+
host = currentHost;
|
|
30
|
+
}
|
|
41
31
|
}
|
|
42
32
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
url += `/${path}`;
|
|
50
|
-
|
|
51
|
-
if (urlParams) {
|
|
52
|
-
url += `?${urlParams}`;
|
|
53
|
-
}
|
|
33
|
+
const { host: parsedHost, port } = extractHostAndPort(host);
|
|
34
|
+
const protocol = isDevelopment ? 'http://' : 'https://';
|
|
35
|
+
const urlParams = !isBlank(queryParams) ? queryString(queryParams) : '';
|
|
36
|
+
const portSegment = port ? `:${port}` : '';
|
|
37
|
+
const pathSegment = path.startsWith('/') ? path : `/${path}`;
|
|
54
38
|
|
|
55
|
-
return
|
|
39
|
+
return `${protocol}${subdomain ? subdomain + '.' : ''}${parsedHost}${portSegment}${pathSegment}${urlParams ? '?' + urlParams : ''}`;
|
|
56
40
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fleetbase/ember-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Provides all the core services, decorators and utilities for building a Fleetbase extension for the Console.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fleetbase-core",
|
|
@@ -27,10 +27,13 @@
|
|
|
27
27
|
"start": "ember serve",
|
|
28
28
|
"test": "npm-run-all lint test:*",
|
|
29
29
|
"test:ember": "ember test",
|
|
30
|
-
"test:ember-compatibility": "ember try:each"
|
|
30
|
+
"test:ember-compatibility": "ember try:each",
|
|
31
|
+
"publish:npm": "npm config set registry https://registry.npmjs.org/ && npm publish",
|
|
32
|
+
"publish:github": "npm config set '@fleetbase:registry' https://npm.pkg.github.com/ && npm publish"
|
|
31
33
|
},
|
|
32
34
|
"dependencies": {
|
|
33
|
-
"date-fns": "^2.
|
|
35
|
+
"date-fns": "^2.30.0",
|
|
36
|
+
"ember-intl": "^6.0.0-beta.6",
|
|
34
37
|
"ember-auto-import": "^2.4.2",
|
|
35
38
|
"ember-cli-babel": "^7.26.11",
|
|
36
39
|
"ember-cli-htmlbars": "^6.1.0",
|