diff --git a/src/components/Dashboard/context/ApiServerContext.jsx b/src/components/Dashboard/context/ApiServerContext.jsx index f71b9b2..bf4ea75 100644 --- a/src/components/Dashboard/context/ApiServerContext.jsx +++ b/src/components/Dashboard/context/ApiServerContext.jsx @@ -797,6 +797,28 @@ const ApiServerProvider = ({ children }) => { } } + // Update multiple objects + const updateMultipleObjects = async (type, objects) => { + const updateUrl = `${config.backendUrl}/${type.toLowerCase()}s` + logger.debug('Updating multiple objects for ' + type) + try { + const response = await axios.put(updateUrl, objects, { + headers: { + Accept: 'application/json', + Authorization: `Bearer ${token}` + } + }) + logger.debug('Objects updated successfully') + return response.data + } catch (err) { + console.error(err) + showError(err, () => { + updateMultipleObjects(type, objects) + }) + return [] + } + } + // Update filament information const deleteObject = async (id, type) => { const deleteUrl = `${config.backendUrl}/${type.toLowerCase()}s/${id}` @@ -840,6 +862,27 @@ const ApiServerProvider = ({ children }) => { } } + // Call a function on an object + const sendObjectFunction = async (id, type, functionName, value = {}) => { + const url = `${config.backendUrl}/${type.toLowerCase()}s/${id}/${functionName}` + logger.debug(`Calling object function ${functionName} for ${id} at ${url}`) + try { + const response = await axios.post(url, value, { + headers: { + Accept: 'application/json', + Authorization: `Bearer ${token}` + } + }) + return response.data + } catch (err) { + console.error(err) + showError(err, () => { + sendObjectFunction(id, type, functionName, value) + }) + return {} + } + } + // Download GCode file content const fetchFileContent = async (file, download = false) => { try { @@ -1221,7 +1264,9 @@ const ApiServerProvider = ({ children }) => { unlockObject, fetchObjectLock, updateObject, + updateMultipleObjects, createObject, + sendObjectFunction, deleteObject, subscribeToObjectUpdates, subscribeToObjectEvent,