@fleetbase/ember-core 0.2.9 → 0.2.10
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/crud.js
CHANGED
|
@@ -198,25 +198,29 @@ export default class CrudService extends Service {
|
|
|
198
198
|
|
|
199
199
|
// set the model uri endpoint
|
|
200
200
|
const modelEndpoint = dasherize(pluralize(modelName));
|
|
201
|
+
const exportParams = options.params ?? {};
|
|
201
202
|
|
|
202
203
|
this.modalsManager.show('modals/export-form', {
|
|
203
204
|
title: `Export ${pluralize(modelName)}`,
|
|
204
205
|
acceptButtonText: 'Download',
|
|
205
206
|
modalClass: 'modal-sm',
|
|
207
|
+
format: 'xlsx',
|
|
206
208
|
formatOptions: ['csv', 'xlsx', 'xls', 'html', 'pdf'],
|
|
207
209
|
setFormat: ({ target }) => {
|
|
208
210
|
this.modalsManager.setOption('format', target.value || null);
|
|
209
211
|
},
|
|
210
212
|
confirm: (modal, done) => {
|
|
211
|
-
const format = modal.getOption('format')
|
|
213
|
+
const format = modal.getOption('format') ?? 'xlsx';
|
|
212
214
|
modal.startLoading();
|
|
213
215
|
return this.fetch
|
|
214
216
|
.download(
|
|
215
217
|
`${modelEndpoint}/export`,
|
|
216
218
|
{
|
|
217
219
|
format,
|
|
220
|
+
...exportParams,
|
|
218
221
|
},
|
|
219
222
|
{
|
|
223
|
+
method: 'POST',
|
|
220
224
|
fileName: `${modelEndpoint}-${formatDate(new Date(), 'yyyy-MM-dd-HH:mm')}.${format}`,
|
|
221
225
|
}
|
|
222
226
|
)
|
package/addon/services/fetch.js
CHANGED
|
@@ -15,6 +15,7 @@ import corslite from '../utils/corslite';
|
|
|
15
15
|
import getMimeType from '../utils/get-mime-type';
|
|
16
16
|
import download from '../utils/download';
|
|
17
17
|
import getUserOptions from '../utils/get-user-options';
|
|
18
|
+
import isEmptyObject from '../utils/is-empty-object';
|
|
18
19
|
import fetch from 'fetch';
|
|
19
20
|
|
|
20
21
|
if (isBlank(config.API.host)) {
|
|
@@ -339,7 +340,7 @@ export default class FetchService extends Service {
|
|
|
339
340
|
return this.cachedGet(...arguments);
|
|
340
341
|
}
|
|
341
342
|
|
|
342
|
-
const urlParams = !
|
|
343
|
+
const urlParams = !isEmptyObject(query) ? new URLSearchParams(query).toString() : '';
|
|
343
344
|
|
|
344
345
|
return this.request(`${path}${urlParams ? '?' + urlParams : ''}`, 'GET', {}, options);
|
|
345
346
|
}
|
|
@@ -506,7 +507,7 @@ export default class FetchService extends Service {
|
|
|
506
507
|
let version = options?.version ?? 'v1';
|
|
507
508
|
let host = options?.host ?? `https://${options?.subdomain ?? 'routing'}.fleetbase.io`;
|
|
508
509
|
let route = coordinates.map((coords) => coords.join(',')).join(';');
|
|
509
|
-
let params = !
|
|
510
|
+
let params = !isEmptyObject(query) ? new URLSearchParams(query).toString() : '';
|
|
510
511
|
let path = `${host}/${service}/${version}/${profile}/${route}`;
|
|
511
512
|
let url = `${path}${params ? '?' + params : ''}`;
|
|
512
513
|
|
|
@@ -598,13 +599,25 @@ export default class FetchService extends Service {
|
|
|
598
599
|
*/
|
|
599
600
|
download(path, query = {}, options = {}) {
|
|
600
601
|
const headers = Object.assign(this.getHeaders(), options.headers ?? {});
|
|
602
|
+
const method = options.method ?? 'GET';
|
|
603
|
+
const credentials = options.credentials ?? this.credentials;
|
|
604
|
+
const baseUrl = `${options.host || this.host}/${options.namespace || this.namespace}`;
|
|
605
|
+
const isReadOnlyRequest = ['GET', 'HEAD'].includes(method.toUpperCase());
|
|
606
|
+
const params = isReadOnlyRequest && !isEmptyObject(query) ? `?${new URLSearchParams(query).toString()}` : '';
|
|
607
|
+
const body = !isReadOnlyRequest ? JSON.stringify(query) : {};
|
|
608
|
+
const fetchOptions = {
|
|
609
|
+
method,
|
|
610
|
+
credentials,
|
|
611
|
+
headers,
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
// Only supply body to fetch if not GET or HEAD request
|
|
615
|
+
if (!isReadOnlyRequest) {
|
|
616
|
+
fetchOptions.body = body;
|
|
617
|
+
}
|
|
601
618
|
|
|
602
619
|
return new Promise((resolve, reject) => {
|
|
603
|
-
return fetch(`${
|
|
604
|
-
method: 'GET',
|
|
605
|
-
credentials: options.credentials || this.credentials,
|
|
606
|
-
headers,
|
|
607
|
-
})
|
|
620
|
+
return fetch(`${baseUrl}/${path}${params}`, fetchOptions)
|
|
608
621
|
.then((response) => {
|
|
609
622
|
options.fileName = this.getFilenameFromResponse(response, options.fileName);
|
|
610
623
|
options.mimeType = this.getMimeTypeFromResponse(response, options.mimeType);
|
package/addon/services/loader.js
CHANGED
|
@@ -75,9 +75,10 @@ export default class LoaderService extends Service {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
const loadingMessage = typeof options.loadingMessage === 'string' ? options.loadingMessage : 'Loading...';
|
|
78
|
-
const opacity = typeof options.opacity === 'number' ? options.opacity : 0
|
|
78
|
+
const opacity = typeof options.opacity === 'number' ? options.opacity : 0;
|
|
79
79
|
const isDarkMode = document.body.dataset.theme ? document.body.dataset.theme === 'dark' : true;
|
|
80
80
|
const preserveTargetPosition = options.preserveTargetPosition === true;
|
|
81
|
+
const loaderContainerClass = options.loaderContainerClass ?? '';
|
|
81
82
|
|
|
82
83
|
if (!preserveTargetPosition) {
|
|
83
84
|
target.style.position = 'relative';
|
|
@@ -86,7 +87,7 @@ export default class LoaderService extends Service {
|
|
|
86
87
|
let loader = document.createElement('div');
|
|
87
88
|
loader.classList.add('overloader');
|
|
88
89
|
loader.style.backgroundColor = isDarkMode ? `rgba(128, 128, 128, ${opacity})` : `rgba(249, 250, 251, ${opacity})`;
|
|
89
|
-
loader.innerHTML = `<div class="flex items-center justify-center text-center">
|
|
90
|
+
loader.innerHTML = `<div class="loader-container flex items-center justify-center text-center ${loaderContainerClass}">
|
|
90
91
|
<div>
|
|
91
92
|
<svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg" role="img" focusable="false" aria-hidden="true" data-icon="spinner-third" data-prefix="fad" id="ember240" class="svg-inline--fa fa-spinner-third fa-w-16 fa-spin ember-view text-sky-500 fa-spin-800ms mr-3"><g class="fa-group"><path class="fa-secondary" fill="currentColor" d="M478.71 364.58zm-22 6.11l-27.83-15.9a15.92 15.92 0 0 1-6.94-19.2A184 184 0 1 1 256 72c5.89 0 11.71.29 17.46.83-.74-.07-1.48-.15-2.23-.21-8.49-.69-15.23-7.31-15.23-15.83v-32a16 16 0 0 1 15.34-16C266.24 8.46 261.18 8 256 8 119 8 8 119 8 256s111 248 248 248c98 0 182.42-56.95 222.71-139.42-4.13 7.86-14.23 10.55-22 6.11z"></path><path class="fa-primary" fill="currentColor" d="M271.23 72.62c-8.49-.69-15.23-7.31-15.23-15.83V24.73c0-9.11 7.67-16.78 16.77-16.17C401.92 17.18 504 124.67 504 256a246 246 0 0 1-25 108.24c-4 8.17-14.37 11-22.26 6.45l-27.84-15.9c-7.41-4.23-9.83-13.35-6.2-21.07A182.53 182.53 0 0 0 440 256c0-96.49-74.27-175.63-168.77-183.38z"></path></g>
|
|
92
93
|
</svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '@fleetbase/ember-core/utils/is-empty-object';
|
package/package.json
CHANGED