Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Zorin95670 committed Sep 9, 2024
1 parent cecf089 commit 82e6ac2
Show file tree
Hide file tree
Showing 11 changed files with 633 additions and 245 deletions.
4 changes: 3 additions & 1 deletion global.config.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"backendUrl": "https://localhost:8443"
}
355 changes: 197 additions & 158 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
"plugin:uninstall": "node node_modules/@ditrit/leto-modelizer-plugin-cli/src/index.js uninstall"
},
"dependencies": {
"@ditrit/leto-modelizer-plugin-core": "=0.28.0",
"@ditrit/terrator-plugin": "^0.12.2",
"@quasar/extras": "=1.16.9",
"axios": "=1.6.2",
"browserfs": "=1.4.3",
"core-js": "=3.34.0",
"crypto-js": "^4.2.0",
"isomorphic-git": "=1.25.1",
"@ditrit/leto-modelizer-plugin-core": "=0.28.0",
"monaco-editor": "=0.45.0",
"monaco-editor-webpack-plugin": "=7.1.0",
"pako": "^2.1.0",
"pinia": "=2.1.7",
"quasar": "=2.13.0",
"rxjs": "=7.8.1",
Expand Down
45 changes: 44 additions & 1 deletion src/boot/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,43 @@ api.interceptors.response.use(
},
);

/**
* Make a filter request (GET) to the specified URL using the provided API.
* @param {object} apiInstance - The API object used to make the request.
* @param {string} url - The URL to make the filter request to.
* @returns {Promise<object>} The response data of the filter request.
*/
async function makeFilterRequest(apiInstance, url) {
return apiInstance.get(url).then((data) => {
if (data.totalPages > 0 && data.pageable.pageNumber + 1 > data.totalPages) {
// TODO : for now we don't have any entity attribute name that ends with 'page'.
// Be careful if this case arises, you'll need to adjust the regex.
const newUrl = url.replace(/page=\d+/, `page=${data.totalPages - 1}`);
return makeFilterRequest(apiInstance, newUrl);
}

return data;
});
}

/**
* Transform filters into query parameters string.
* @param {object} filters - API Filters.
* @returns {string} Formatted string to put in url, works even if there are no filters.
*/
function prepareQueryParameters(filters = {}) {
const queryParameters = Object.keys(filters)
.map((key) => ({ key, value: `${filters[key]}` }))
.filter(({ value }) => value?.length > 0)
.map(({ key, value }) => `${key}=${encodeURIComponent(value)}`);

if (queryParameters.length === 0) {
return '';
}

return `?${queryParameters.join('&')}`;
}

/**
* Asynchronously prepares a request by ensuring the availability of a valid CSRF token.
*
Expand All @@ -65,4 +102,10 @@ async function prepareApiRequest() {
return api;
}

export { api, prepareApiRequest, templateLibraryApiClient };
export {
api,
prepareApiRequest,
templateLibraryApiClient,
prepareQueryParameters,
makeFilterRequest,
};
Loading

0 comments on commit 82e6ac2

Please sign in to comment.