@fleetbase/ember-core 0.0.1
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/LICENSE.md +9 -0
- package/README.md +32 -0
- package/addon/adapters/application.js +155 -0
- package/addon/adapters/user.js +19 -0
- package/addon/authenticators/fleetbase.js +72 -0
- package/addon/decorators/fetch-from.js +55 -0
- package/addon/decorators/from-store.js +56 -0
- package/addon/decorators/is-equal.js +15 -0
- package/addon/exports/host-services.js +18 -0
- package/addon/exports/services.js +18 -0
- package/addon/initializers/local-storage-adapter.js +21 -0
- package/addon/serializers/application.js +87 -0
- package/addon/services/app-cache.js +59 -0
- package/addon/services/crud.js +226 -0
- package/addon/services/current-user.js +259 -0
- package/addon/services/fetch.js +648 -0
- package/addon/services/filters.js +183 -0
- package/addon/services/loader.js +136 -0
- package/addon/services/notifications.js +32 -0
- package/addon/services/session.js +221 -0
- package/addon/services/theme.js +200 -0
- package/addon/services/url-search-params.js +92 -0
- package/addon/transforms/array.js +29 -0
- package/addon/transforms/object.js +11 -0
- package/addon/transforms/raw.js +11 -0
- package/addon/utils/api-url.js +11 -0
- package/addon/utils/apply-column-filters.js +3 -0
- package/addon/utils/auto-serialize.js +100 -0
- package/addon/utils/calculate-percentage.js +3 -0
- package/addon/utils/close-sidebar.js +7 -0
- package/addon/utils/console-url.js +56 -0
- package/addon/utils/copy-to-clipboard.js +35 -0
- package/addon/utils/corslite.js +95 -0
- package/addon/utils/download.js +157 -0
- package/addon/utils/env.js +3 -0
- package/addon/utils/extract-coordinates.js +35 -0
- package/addon/utils/extract-latitude.js +28 -0
- package/addon/utils/extract-longitude.js +28 -0
- package/addon/utils/find-closest-waypoint.js +20 -0
- package/addon/utils/first.js +10 -0
- package/addon/utils/frontend-url.js +30 -0
- package/addon/utils/generate-slug.js +11 -0
- package/addon/utils/generate-uuid.js +3 -0
- package/addon/utils/get-length-units.js +44 -0
- package/addon/utils/get-meta-field-types.js +3 -0
- package/addon/utils/get-mime-type.js +25 -0
- package/addon/utils/get-model-name.js +45 -0
- package/addon/utils/get-permission-action.js +47 -0
- package/addon/utils/get-permission-resource.js +16 -0
- package/addon/utils/get-pod-methods.js +7 -0
- package/addon/utils/get-routing-host.js +44 -0
- package/addon/utils/get-service-name.js +21 -0
- package/addon/utils/get-user-options.js +21 -0
- package/addon/utils/get-weight-units.js +32 -0
- package/addon/utils/get-with-default.js +6 -0
- package/addon/utils/group-api-events.js +20 -0
- package/addon/utils/group-by.js +26 -0
- package/addon/utils/has-extension.js +11 -0
- package/addon/utils/has-json-structure.js +10 -0
- package/addon/utils/hason-structure.js +3 -0
- package/addon/utils/haversine.js +59 -0
- package/addon/utils/humanize.js +16 -0
- package/addon/utils/is-electron.js +18 -0
- package/addon/utils/is-email.js +5 -0
- package/addon/utils/is-function.js +3 -0
- package/addon/utils/is-image-file.js +3 -0
- package/addon/utils/is-iterable.js +7 -0
- package/addon/utils/is-json.js +9 -0
- package/addon/utils/is-latitude.js +3 -0
- package/addon/utils/is-letter.js +3 -0
- package/addon/utils/is-longitude.js +3 -0
- package/addon/utils/is-model.js +6 -0
- package/addon/utils/is-not-empty.js +5 -0
- package/addon/utils/is-not-model.js +5 -0
- package/addon/utils/is-numeric.js +3 -0
- package/addon/utils/is-object.js +3 -0
- package/addon/utils/is-proxy.js +5 -0
- package/addon/utils/is-relation-missing.js +21 -0
- package/addon/utils/is-valid-coordinates.js +38 -0
- package/addon/utils/is-video-file.js +3 -0
- package/addon/utils/is-waypoint-record.js +5 -0
- package/addon/utils/ison.js +3 -0
- package/addon/utils/isset.js +10 -0
- package/addon/utils/last.js +23 -0
- package/addon/utils/lazy-load-script.js +25 -0
- package/addon/utils/leaflet-icon.js +13 -0
- package/addon/utils/leaflet-points-from-coordinates.js +3 -0
- package/addon/utils/load-engines.js +37 -0
- package/addon/utils/load-extensions.js +8 -0
- package/addon/utils/macros/group-by.js +28 -0
- package/addon/utils/make-dataset.js +57 -0
- package/addon/utils/map-engines.js +30 -0
- package/addon/utils/mock-response.js +15 -0
- package/addon/utils/numbers-only.js +11 -0
- package/addon/utils/past-tense.js +40 -0
- package/addon/utils/path-to-route.js +10 -0
- package/addon/utils/polyline.js +161 -0
- package/addon/utils/range.js +19 -0
- package/addon/utils/refresh-route.js +3 -0
- package/addon/utils/replace-table-row.js +17 -0
- package/addon/utils/reverse-point.js +3 -0
- package/addon/utils/serialize/normalize-polymorphic-type-within-hash.js +27 -0
- package/addon/utils/serialize/normalize-polymorphic-type.js +13 -0
- package/addon/utils/serialize/normalize-relations-with-hash.js +32 -0
- package/addon/utils/set-column-filter-options.js +3 -0
- package/addon/utils/strip-html.js +3 -0
- package/addon/utils/to-leaflet-bounds.js +6 -0
- package/addon/utils/to-model.js +18 -0
- package/addon/utils/waypoint-label.js +3 -0
- package/addon/utils/with-default-value.js +5 -0
- package/addon/utils/words.js +5 -0
- package/app/adapters/user.js +1 -0
- package/app/authenticators/fleetbase.js +1 -0
- package/app/decorators/fetch-from.js +1 -0
- package/app/decorators/from-store.js +1 -0
- package/app/decorators/is-equal.js +1 -0
- package/app/exports/host-services.js +1 -0
- package/app/exports/services.js +1 -0
- package/app/initializers/local-storage-adapter.js +1 -0
- package/app/serializers/application.js +1 -0
- package/app/services/app-cache.js +1 -0
- package/app/services/crud.js +1 -0
- package/app/services/current-user.js +1 -0
- package/app/services/fetch.js +1 -0
- package/app/services/filters.js +1 -0
- package/app/services/loader.js +1 -0
- package/app/services/notifications.js +1 -0
- package/app/services/session.js +1 -0
- package/app/services/theme.js +1 -0
- package/app/services/url-search-params.js +1 -0
- package/app/storages/local-cache.js +12 -0
- package/app/storages/user-options.js +12 -0
- package/app/transforms/array.js +1 -0
- package/app/transforms/object.js +1 -0
- package/app/transforms/raw.js +1 -0
- package/app/utils/api-url.js +1 -0
- package/app/utils/apply-column-filters.js +1 -0
- package/app/utils/auto-serialize.js +1 -0
- package/app/utils/calculate-percentage.js +1 -0
- package/app/utils/close-sidebar.js +1 -0
- package/app/utils/console-url.js +1 -0
- package/app/utils/copy-to-clipboard.js +1 -0
- package/app/utils/corslite.js +1 -0
- package/app/utils/download.js +1 -0
- package/app/utils/env.js +1 -0
- package/app/utils/extract-coordinates.js +1 -0
- package/app/utils/extract-latitude.js +1 -0
- package/app/utils/extract-longitude.js +1 -0
- package/app/utils/find-closest-waypoint.js +1 -0
- package/app/utils/first.js +1 -0
- package/app/utils/frontend-url.js +1 -0
- package/app/utils/generate-slug.js +1 -0
- package/app/utils/generate-uuid.js +1 -0
- package/app/utils/get-length-units.js +1 -0
- package/app/utils/get-meta-field-types.js +1 -0
- package/app/utils/get-mime-type.js +1 -0
- package/app/utils/get-model-name.js +1 -0
- package/app/utils/get-permission-action.js +1 -0
- package/app/utils/get-permission-resource.js +1 -0
- package/app/utils/get-pod-methods.js +1 -0
- package/app/utils/get-routing-host.js +1 -0
- package/app/utils/get-service-name.js +1 -0
- package/app/utils/get-user-options.js +1 -0
- package/app/utils/get-weight-units.js +1 -0
- package/app/utils/get-with-default.js +1 -0
- package/app/utils/group-api-events.js +1 -0
- package/app/utils/group-by.js +1 -0
- package/app/utils/has-extension.js +1 -0
- package/app/utils/has-json-structure.js +1 -0
- package/app/utils/hason-structure.js +1 -0
- package/app/utils/haversine.js +1 -0
- package/app/utils/humanize.js +1 -0
- package/app/utils/is-electron.js +1 -0
- package/app/utils/is-email.js +1 -0
- package/app/utils/is-function.js +1 -0
- package/app/utils/is-image-file.js +1 -0
- package/app/utils/is-iterable.js +1 -0
- package/app/utils/is-latitude.js +1 -0
- package/app/utils/is-letter.js +1 -0
- package/app/utils/is-longitude.js +1 -0
- package/app/utils/is-model.js +1 -0
- package/app/utils/is-not-empty.js +1 -0
- package/app/utils/is-not-model.js +1 -0
- package/app/utils/is-numeric.js +1 -0
- package/app/utils/is-object.js +1 -0
- package/app/utils/is-proxy.js +1 -0
- package/app/utils/is-relation-missing.js +1 -0
- package/app/utils/is-valid-coordinates.js +1 -0
- package/app/utils/is-video-file.js +1 -0
- package/app/utils/is-waypoint-record.js +1 -0
- package/app/utils/ison.js +1 -0
- package/app/utils/isset.js +1 -0
- package/app/utils/last.js +1 -0
- package/app/utils/lazy-load-script.js +1 -0
- package/app/utils/leaflet-icon.js +1 -0
- package/app/utils/leaflet-points-from-coordinates.js +1 -0
- package/app/utils/load-engines.js +1 -0
- package/app/utils/load-extensions.js +1 -0
- package/app/utils/macros/group-by.js +1 -0
- package/app/utils/make-dataset.js +1 -0
- package/app/utils/map-engines.js +1 -0
- package/app/utils/mock-response.js +1 -0
- package/app/utils/numbers-only.js +1 -0
- package/app/utils/past-tense.js +1 -0
- package/app/utils/path-to-route.js +1 -0
- package/app/utils/polyline.js +1 -0
- package/app/utils/range.js +1 -0
- package/app/utils/refresh-route.js +1 -0
- package/app/utils/replace-table-row.js +1 -0
- package/app/utils/reverse-point.js +1 -0
- package/app/utils/serialize/normalize-polymorphic-type-within-hash.js +1 -0
- package/app/utils/serialize/normalize-polymorphic-type.js +1 -0
- package/app/utils/serialize/normalize-relations-with-hash.js +1 -0
- package/app/utils/set-column-filter-options.js +1 -0
- package/app/utils/strip-html.js +1 -0
- package/app/utils/to-leaflet-bounds.js +1 -0
- package/app/utils/to-model.js +1 -0
- package/app/utils/waypoint-label.js +1 -0
- package/app/utils/with-default-value.js +1 -0
- package/app/utils/words.js +1 -0
- package/config/environment.js +5 -0
- package/index.js +26 -0
- package/package.json +117 -0
- package/pnpm-lock.yaml +12750 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @fleetbase/ember-core
|
|
2
|
+
|
|
3
|
+
Ember Core Services, Utilities and Framework for building Fleetbase Extensions in the Console
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Compatibility
|
|
7
|
+
|
|
8
|
+
* Ember.js v3.24 or above
|
|
9
|
+
* Ember CLI v3.24 or above
|
|
10
|
+
* Node.js v14 or above
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
ember install @fleetbase/ember-core
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
[Longer description of how to use the addon in apps.]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## Contributing
|
|
26
|
+
|
|
27
|
+
See the [Contributing](CONTRIBUTING.md) guide for details.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## License
|
|
31
|
+
|
|
32
|
+
This project is licensed under the [MIT License](LICENSE.md).
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import RESTAdapter from '@ember-data/adapter/rest';
|
|
2
|
+
import { tracked } from '@glimmer/tracking';
|
|
3
|
+
import { inject as service } from '@ember/service';
|
|
4
|
+
import { storageFor } from 'ember-local-storage';
|
|
5
|
+
import { get } from '@ember/object';
|
|
6
|
+
import { isBlank } from '@ember/utils';
|
|
7
|
+
import { dasherize } from '@ember/string';
|
|
8
|
+
import { pluralize } from 'ember-inflector';
|
|
9
|
+
import getUserOptions from '../utils/get-user-options';
|
|
10
|
+
import config from 'ember-get-config';
|
|
11
|
+
|
|
12
|
+
export default class ApplicationAdapter extends RESTAdapter {
|
|
13
|
+
/**
|
|
14
|
+
* Inject the `session` service
|
|
15
|
+
*
|
|
16
|
+
* @var {Service}
|
|
17
|
+
*/
|
|
18
|
+
@service session;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Inject the `currentUser` service
|
|
22
|
+
*
|
|
23
|
+
* @var {Service}
|
|
24
|
+
*/
|
|
25
|
+
@service currentUser;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* User options for setting specific headers
|
|
29
|
+
*
|
|
30
|
+
* @var StorageObject
|
|
31
|
+
*/
|
|
32
|
+
@storageFor('user-options') userOptions;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The default namespace for the adapter
|
|
36
|
+
*
|
|
37
|
+
* @var {String}
|
|
38
|
+
*/
|
|
39
|
+
get host() {
|
|
40
|
+
return get(config, 'API.host');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The default namespace for adapter
|
|
45
|
+
*
|
|
46
|
+
* @var {String}
|
|
47
|
+
*/
|
|
48
|
+
get namespace() {
|
|
49
|
+
return get(config, 'API.namespace');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Credentials
|
|
54
|
+
*
|
|
55
|
+
* @var {String}
|
|
56
|
+
*/
|
|
57
|
+
credentials = 'include';
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Mutable headers property.
|
|
61
|
+
*
|
|
62
|
+
* @var {Array}
|
|
63
|
+
*/
|
|
64
|
+
@tracked _headers;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The headers to send with request.
|
|
68
|
+
*
|
|
69
|
+
* @var {Object}
|
|
70
|
+
*/
|
|
71
|
+
get headers() {
|
|
72
|
+
if (this._headers) {
|
|
73
|
+
return this._headers;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return this.getHeaders();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Setter fucntion to overwrite headers.
|
|
81
|
+
*/
|
|
82
|
+
set headers(headers) {
|
|
83
|
+
this._headers = headers;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Gets headers that should be sent with request.
|
|
88
|
+
*
|
|
89
|
+
* @return {Object}
|
|
90
|
+
*/
|
|
91
|
+
getHeaders() {
|
|
92
|
+
const headers = {};
|
|
93
|
+
const isAuthenticated = this.session.isAuthenticated;
|
|
94
|
+
const userId = this.session.data.authenticated.user;
|
|
95
|
+
const userOptions = getUserOptions();
|
|
96
|
+
const isSandbox = get(userOptions, `${userId}:sandbox`) === true;
|
|
97
|
+
const testKey = get(userOptions, `${userId}:testKey`);
|
|
98
|
+
|
|
99
|
+
headers['Content-Type'] = 'application/json';
|
|
100
|
+
|
|
101
|
+
if (isAuthenticated) {
|
|
102
|
+
headers['Authorization'] = `Bearer ${this.session.data.authenticated.token}`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (isAuthenticated && isSandbox) {
|
|
106
|
+
headers['Access-Console-Sandbox'] = true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (isAuthenticated && !isBlank(testKey)) {
|
|
110
|
+
headers['Access-Console-Sandbox-Key'] = testKey;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return headers;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Gets fresh headers and sets them.
|
|
118
|
+
*
|
|
119
|
+
* @return {Object}
|
|
120
|
+
*/
|
|
121
|
+
refreshHeaders() {
|
|
122
|
+
const headers = this.getHeaders();
|
|
123
|
+
|
|
124
|
+
this.headers = headers;
|
|
125
|
+
|
|
126
|
+
return headers;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Configure AJAX options for request, return as options hash
|
|
131
|
+
*
|
|
132
|
+
* @param {String} url
|
|
133
|
+
* @param {String} type The request type GET, POST, PUT, DELETE etc.
|
|
134
|
+
* @param {Object} options
|
|
135
|
+
*
|
|
136
|
+
* @return {Object}
|
|
137
|
+
*/
|
|
138
|
+
ajaxOptions(url, type, options) {
|
|
139
|
+
this.refreshHeaders();
|
|
140
|
+
|
|
141
|
+
const ajaxOptions = super.ajaxOptions(url, type, options);
|
|
142
|
+
ajaxOptions.credentials = this.credentials;
|
|
143
|
+
|
|
144
|
+
return ajaxOptions;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Dasherize the path for type
|
|
149
|
+
*
|
|
150
|
+
* @param {Object} type
|
|
151
|
+
*/
|
|
152
|
+
pathForType(type) {
|
|
153
|
+
return dasherize(pluralize(type));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import ApplicationAdapter from './application';
|
|
2
|
+
|
|
3
|
+
export default class UserAdapter extends ApplicationAdapter {
|
|
4
|
+
/**
|
|
5
|
+
* Set the URL path for users endpoints
|
|
6
|
+
*
|
|
7
|
+
* @param {object} query
|
|
8
|
+
* @return {String} originalUrl
|
|
9
|
+
*/
|
|
10
|
+
urlForQueryRecord(query) {
|
|
11
|
+
let originalUrl = super.urlForQueryRecord(...arguments);
|
|
12
|
+
if (query.me) {
|
|
13
|
+
delete query.me;
|
|
14
|
+
return `${originalUrl}/me`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return originalUrl;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import Base from 'ember-simple-auth/authenticators/base';
|
|
2
|
+
import { inject as service } from '@ember/service';
|
|
3
|
+
import { get } from '@ember/object';
|
|
4
|
+
|
|
5
|
+
export default class FleetbaseAuthenticator extends Base {
|
|
6
|
+
/**
|
|
7
|
+
* Inject the `fetch` service
|
|
8
|
+
*
|
|
9
|
+
* @var {Service}
|
|
10
|
+
*/
|
|
11
|
+
@service fetch;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Inject the `session` service
|
|
15
|
+
*
|
|
16
|
+
* @var {Service}
|
|
17
|
+
*/
|
|
18
|
+
@service session;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Restore session from server
|
|
22
|
+
*
|
|
23
|
+
* @param {object} data
|
|
24
|
+
* @return {Promise}
|
|
25
|
+
*/
|
|
26
|
+
restore(data) {
|
|
27
|
+
return this.fetch
|
|
28
|
+
.get(
|
|
29
|
+
'auth/session',
|
|
30
|
+
{},
|
|
31
|
+
{
|
|
32
|
+
headers: {
|
|
33
|
+
Authorization: `Bearer ${data.token}`,
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
.then((response) => {
|
|
38
|
+
if (response.restore === false) {
|
|
39
|
+
return Promise.reject(new Error(response.error));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return response;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Authenticates a users credentials
|
|
48
|
+
*
|
|
49
|
+
* @param {object} credentials
|
|
50
|
+
* @param {boolean} remember
|
|
51
|
+
* @param {string} path
|
|
52
|
+
*/
|
|
53
|
+
authenticate(credentials = {}, remember = false, path = 'auth/login') {
|
|
54
|
+
return this.fetch.post(path, { ...credentials, remember }).then((response) => {
|
|
55
|
+
if (response.errors) {
|
|
56
|
+
return Promise.reject(new Error(response.errors.firstObject ?? 'Authentication failed!'));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return response;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Invalidates the current session
|
|
65
|
+
*
|
|
66
|
+
* @param {object} data
|
|
67
|
+
*/
|
|
68
|
+
// eslint-disable-next-line no-unused-vars
|
|
69
|
+
invalidate(data) {
|
|
70
|
+
return this.fetch.post('auth/logout');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { decoratorWithRequiredParams } from '@ember-decorators/utils/decorator';
|
|
2
|
+
import { assert } from '@ember/debug';
|
|
3
|
+
import { getOwner } from '@ember/application';
|
|
4
|
+
import { scheduleOnce } from '@ember/runloop';
|
|
5
|
+
|
|
6
|
+
export default function fetchFrom(endpoint, query = {}, options = {}) {
|
|
7
|
+
assert('The first argument of the @fetchFrom decorator must be a string', typeof endpoint === 'string');
|
|
8
|
+
assert('The second argument of the @fetchFrom decorator must be an object', typeof query === 'object');
|
|
9
|
+
assert('The third argument of the @fetchFrom decorator must be an object', typeof options === 'object');
|
|
10
|
+
|
|
11
|
+
return decoratorWithRequiredParams(function (target, key, desc, params) {
|
|
12
|
+
const symbol = Symbol(`__${key}_fetchFrom`);
|
|
13
|
+
|
|
14
|
+
Object.defineProperty(target, symbol, {
|
|
15
|
+
configurable: true,
|
|
16
|
+
enumerable: false,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: null,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
Object.defineProperty(target, key, {
|
|
22
|
+
configurable: true,
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get() {
|
|
25
|
+
return this[symbol];
|
|
26
|
+
},
|
|
27
|
+
set(value) {
|
|
28
|
+
this[symbol] = value;
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const originalInit = target.init;
|
|
33
|
+
|
|
34
|
+
target.init = function () {
|
|
35
|
+
if (originalInit) {
|
|
36
|
+
originalInit.call(this);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
scheduleOnce('afterRender', this, function () {
|
|
40
|
+
const owner = getOwner(this);
|
|
41
|
+
const fetch = owner.lookup('service:fetch'); // Get the Fleetbase Fetch service
|
|
42
|
+
|
|
43
|
+
// Perform the query and set the result to the property
|
|
44
|
+
fetch
|
|
45
|
+
.get(endpoint, query, options)
|
|
46
|
+
.then((result) => {
|
|
47
|
+
this.set(key, result);
|
|
48
|
+
})
|
|
49
|
+
.catch(() => {
|
|
50
|
+
this.set(key, []);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
}, 'fetchFrom')(endpoint, query, options);
|
|
55
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { decoratorWithRequiredParams } from '@ember-decorators/utils/decorator';
|
|
2
|
+
import { assert } from '@ember/debug';
|
|
3
|
+
import { get } from '@ember/object';
|
|
4
|
+
import { getOwner } from '@ember/application';
|
|
5
|
+
import { scheduleOnce } from '@ember/runloop';
|
|
6
|
+
|
|
7
|
+
export default function fromStore(modelName, query = {}, options = {}) {
|
|
8
|
+
assert('The first argument of the @fromStore decorator must be a string', typeof modelName === 'string');
|
|
9
|
+
assert('The second argument of the @fromStore decorator must be an object', typeof query === 'object');
|
|
10
|
+
assert('The third argument of the @fromStore decorator must be an object', typeof options === 'object');
|
|
11
|
+
|
|
12
|
+
return decoratorWithRequiredParams(function (target, key, desc, params) {
|
|
13
|
+
const symbol = Symbol(`__${key}_fromStore`);
|
|
14
|
+
|
|
15
|
+
Object.defineProperty(target, symbol, {
|
|
16
|
+
configurable: true,
|
|
17
|
+
enumerable: false,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: null,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
Object.defineProperty(target, key, {
|
|
23
|
+
configurable: true,
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get() {
|
|
26
|
+
return this[symbol];
|
|
27
|
+
},
|
|
28
|
+
set(value) {
|
|
29
|
+
this[symbol] = value;
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const originalInit = target.init;
|
|
34
|
+
|
|
35
|
+
target.init = function () {
|
|
36
|
+
if (originalInit) {
|
|
37
|
+
originalInit.call(this);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
scheduleOnce('afterRender', this, function () {
|
|
41
|
+
const owner = getOwner(this);
|
|
42
|
+
const store = owner.lookup('service:store'); // Get the Ember Data store
|
|
43
|
+
|
|
44
|
+
// Perform the query and set the result to the property
|
|
45
|
+
store
|
|
46
|
+
.query(modelName, query, options)
|
|
47
|
+
.then((result) => {
|
|
48
|
+
this.set(key, result);
|
|
49
|
+
})
|
|
50
|
+
.catch(() => {
|
|
51
|
+
this.set(key, []);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
}, 'fromStore')(modelName, query, options);
|
|
56
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { computed } from '@ember/object';
|
|
2
|
+
import { decoratorWithRequiredParams } from '@ember-decorators/utils/decorator';
|
|
3
|
+
import { assert } from '@ember/debug';
|
|
4
|
+
|
|
5
|
+
export function isEqual(propNameA, propNameB) {
|
|
6
|
+
return decoratorWithRequiredParams(function (target, desc, key, params) {
|
|
7
|
+
assert(`The @isEqual decorator requires two property names as parameters`, params.length === 2);
|
|
8
|
+
|
|
9
|
+
let [a, b] = params;
|
|
10
|
+
|
|
11
|
+
return computed(a, b, function () {
|
|
12
|
+
return this.get(a) === this.get(b);
|
|
13
|
+
});
|
|
14
|
+
}, 'isEqual')(propNameA, propNameB);
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const hostServices = [
|
|
2
|
+
'store',
|
|
3
|
+
'session',
|
|
4
|
+
'current-user',
|
|
5
|
+
'fetch',
|
|
6
|
+
'media',
|
|
7
|
+
'app-cache',
|
|
8
|
+
'url-search-params',
|
|
9
|
+
'modals-manager',
|
|
10
|
+
'loader',
|
|
11
|
+
'filters',
|
|
12
|
+
'crud',
|
|
13
|
+
'notifications',
|
|
14
|
+
'fileQueue',
|
|
15
|
+
{ hostRouter: 'router' },
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export default hostServices;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const services = [
|
|
2
|
+
'store',
|
|
3
|
+
'session',
|
|
4
|
+
'current-user',
|
|
5
|
+
'fetch',
|
|
6
|
+
'media',
|
|
7
|
+
'app-cache',
|
|
8
|
+
'url-search-params',
|
|
9
|
+
'modals-manager',
|
|
10
|
+
'loader',
|
|
11
|
+
'filters',
|
|
12
|
+
'crud',
|
|
13
|
+
'notifications',
|
|
14
|
+
'hostRouter',
|
|
15
|
+
'fileQueue',
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export default services;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Store from '@ember-data/store';
|
|
2
|
+
import { importData, exportData } from 'ember-local-storage/helpers/import-export';
|
|
3
|
+
|
|
4
|
+
export function initialize() {
|
|
5
|
+
if (!Store.prototype._emberLocalStoragePatched) {
|
|
6
|
+
Store.reopen({
|
|
7
|
+
_emberLocalStoragePatched: true,
|
|
8
|
+
importData: function (json, options) {
|
|
9
|
+
return importData(this, json, options);
|
|
10
|
+
},
|
|
11
|
+
exportData: function (types, options) {
|
|
12
|
+
return exportData(this, types, options);
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
name: 'local-storage-adapter',
|
|
20
|
+
initialize: initialize,
|
|
21
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import RESTSerializer from '@ember-data/serializer/rest';
|
|
2
|
+
import { isNone } from '@ember/utils';
|
|
3
|
+
import { underscore } from '@ember/string';
|
|
4
|
+
import { isArray } from '@ember/array';
|
|
5
|
+
import normalizePolymorphicTypeWithinHash from '../utils/serialize/normalize-polymorphic-type-within-hash';
|
|
6
|
+
|
|
7
|
+
export default class ApplicationSerializer extends RESTSerializer {
|
|
8
|
+
/**
|
|
9
|
+
* Default primary keys to uuid
|
|
10
|
+
*
|
|
11
|
+
* @var {string}
|
|
12
|
+
*/
|
|
13
|
+
primaryKey = 'uuid';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* keyForPolymorphicType can be used to define a custom key when serializing and deserializing a polymorphic type.
|
|
17
|
+
* By default, the returned key is ${key}Type.
|
|
18
|
+
*
|
|
19
|
+
* @var {String}
|
|
20
|
+
*/
|
|
21
|
+
keyForPolymorphicType(key, typeClass, method) {
|
|
22
|
+
return `${underscore(key)}_type`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Customize serializer so that any attributes that are instances of Models or objects
|
|
27
|
+
* that are to accept and ID get serialized into the id only
|
|
28
|
+
*
|
|
29
|
+
* @param {Snapshot} snapshot
|
|
30
|
+
* @param {Object} options
|
|
31
|
+
* @return {Object} json
|
|
32
|
+
*/
|
|
33
|
+
serialize(snapshot) {
|
|
34
|
+
const json = super.serialize(...arguments);
|
|
35
|
+
|
|
36
|
+
// for each relationship make sure the id is set
|
|
37
|
+
snapshot.eachRelationship((key, relationship) => {
|
|
38
|
+
const { kind } = relationship.meta;
|
|
39
|
+
|
|
40
|
+
if (kind === 'belongsTo') {
|
|
41
|
+
const relationSnapshot = snapshot.belongsTo(key);
|
|
42
|
+
|
|
43
|
+
key = this.keyForRelationship ? this.keyForRelationship(key, 'belongsTo', 'serialize') : key;
|
|
44
|
+
|
|
45
|
+
if (isNone(relationSnapshot)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
json[`${key}_uuid`] = relationSnapshot.id;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return json;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Normalizes a part of the JSON payload returned by the server.
|
|
58
|
+
*
|
|
59
|
+
* @method normalize
|
|
60
|
+
* @param {Model} modelClass
|
|
61
|
+
* @param {Object} resourceHash
|
|
62
|
+
* @param {String} prop
|
|
63
|
+
* @return {Object}
|
|
64
|
+
*/
|
|
65
|
+
normalize(model, hash, prop) {
|
|
66
|
+
hash = normalizePolymorphicTypeWithinHash(hash);
|
|
67
|
+
|
|
68
|
+
return super.normalize(model, hash, prop);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* We only want to save dirty/changed model attributes
|
|
73
|
+
*
|
|
74
|
+
* @param {Snapshot} snapshot
|
|
75
|
+
* @param {Object} json
|
|
76
|
+
* @param {String} key
|
|
77
|
+
* @param {Array} attributes
|
|
78
|
+
*/
|
|
79
|
+
serializeAttribute(snapshot, json, key, attributes) {
|
|
80
|
+
const { modelName } = snapshot;
|
|
81
|
+
const excludedKeys = ['name', 'meta', 'options', 'config', 'excluded_addons', 'translations', 'tags'];
|
|
82
|
+
|
|
83
|
+
if (snapshot.record?.get('isNew') || snapshot.changedAttributes()[key] || isArray(snapshot.attr(key)) || excludedKeys.includes(key)) {
|
|
84
|
+
return super.serializeAttribute(snapshot, json, key, attributes);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import Service from '@ember/service';
|
|
2
|
+
import { inject as service } from '@ember/service';
|
|
3
|
+
import { action } from '@ember/object';
|
|
4
|
+
import { isArray } from '@ember/array';
|
|
5
|
+
import { dasherize } from '@ember/string';
|
|
6
|
+
import { storageFor } from 'ember-local-storage';
|
|
7
|
+
import autoSerialize from '../utils/auto-serialize';
|
|
8
|
+
|
|
9
|
+
export default class AppCacheService extends Service {
|
|
10
|
+
@service currentUser;
|
|
11
|
+
@service store;
|
|
12
|
+
@storageFor('local-cache') localCache;
|
|
13
|
+
|
|
14
|
+
get cachePrefix() {
|
|
15
|
+
return `${this.currentUser.id}:${this.currentUser.companyId}:`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@action setEmberData(key, value, except = []) {
|
|
19
|
+
value = autoSerialize(value, except);
|
|
20
|
+
|
|
21
|
+
return this.set(key, value);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@action getEmberData(key, modelName) {
|
|
25
|
+
const data = this.get(key);
|
|
26
|
+
|
|
27
|
+
if (isArray(data)) {
|
|
28
|
+
return data.map((instance) => this.store.push(this.store.normalize(modelName, instance)));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return this.store.push(this.store.normalize(modelName, data));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@action set(key, value) {
|
|
35
|
+
this.localCache.set(`${this.cachePrefix}${dasherize(key)}`, value);
|
|
36
|
+
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@action get(key) {
|
|
41
|
+
return this.localCache.get(`${this.cachePrefix}${dasherize(key)}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@action has(key) {
|
|
45
|
+
if (isArray(key)) {
|
|
46
|
+
return key.every((k) => this.get(k) !== undefined);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return this.get(key) !== undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@action doesntHave(key) {
|
|
53
|
+
if (isArray(key)) {
|
|
54
|
+
return key.every((k) => this.get(k) === undefined);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return this.get(key) === undefined;
|
|
58
|
+
}
|
|
59
|
+
}
|