Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev-v0.2.10 #43

Merged
merged 8 commits into from
May 17, 2024
Next Next commit
parameter passed, changed download method
  • Loading branch information
doljko committed May 15, 2024
commit 0aab9869f60e405c980deaa5ec550f5e72b0a9ec
3 changes: 3 additions & 0 deletions addon/services/crud.js
Original file line number Diff line number Diff line change
@@ -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)}`,
@@ -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}`,
}
)
12 changes: 9 additions & 3 deletions addon/services/fetch.js
Original file line number Diff line number Diff line change
@@ -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);
Loading