Skip to content

Commit

Permalink
parameter passed, changed download method
Browse files Browse the repository at this point in the history
  • Loading branch information
doljko committed May 15, 2024
1 parent a068790 commit 0aab986
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions addon/services/crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export default class CrudService extends Service {

// set the model uri endpoint
const modelEndpoint = dasherize(pluralize(modelName));
const exportParams = options.params ?? {};

this.modalsManager.show('modals/export-form', {
title: `Export ${pluralize(modelName)}`,
Expand All @@ -215,8 +216,10 @@ export default class CrudService extends Service {
`${modelEndpoint}/export`,
{
format,
...exportParams,
},
{
method: 'POST',
fileName: `${modelEndpoint}-${formatDate(new Date(), 'yyyy-MM-dd-HH:mm')}.${format}`,
}
)
Expand Down
12 changes: 9 additions & 3 deletions addon/services/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,12 +598,18 @@ export default class FetchService extends Service {
*/
download(path, query = {}, options = {}) {
const headers = Object.assign(this.getHeaders(), options.headers ?? {});
const method = options.method ?? 'GET';
const credentials = options.credentials ?? this.credentials;
const baseUrl = `${options.host || this.host}/${options.namespace || this.namespace}`;
const params = method.toUpperCase() === 'GET' ? `?${!isBlank(query) ? new URLSearchParams(query).toString() : ''}` : '';
const body = method.toUpperCase() !== 'GET' ? JSON.stringify(query) : {};

return new Promise((resolve, reject) => {
return fetch(`${options.host || this.host}/${options.namespace || this.namespace}/${path}?${!isBlank(query) ? new URLSearchParams(query).toString() : ''}`, {
method: 'GET',
credentials: options.credentials || this.credentials,
return fetch(`${baseUrl}/${path}${params}`, {
method,
credentials,
headers,
body,
})
.then((response) => {
options.fileName = this.getFilenameFromResponse(response, options.fileName);
Expand Down

0 comments on commit 0aab986

Please sign in to comment.