1
0
mirror of https://github.com/Stirling-Tools/Stirling-PDF.git synced 2024-09-29 16:10:11 +02:00

Fix for ANY values and settings button enablement

This commit is contained in:
Anthony Stirling 2024-01-01 13:57:22 +00:00
parent cd3cc15888
commit 04acdb3b02
2 changed files with 53 additions and 41 deletions

View File

@ -79,7 +79,7 @@ public class ConvertOfficeController {
@Operation( @Operation(
summary = "Convert a file to a PDF using LibreOffice", summary = "Convert a file to a PDF using LibreOffice",
description = description =
"This endpoint converts a given file to a PDF using LibreOffice API Input:Any Output:PDF Type:SISO") "This endpoint converts a given file to a PDF using LibreOffice API Input:ANY Output:PDF Type:SISO")
public ResponseEntity<byte[]> processFileToPDF(@ModelAttribute GeneralFile request) public ResponseEntity<byte[]> processFileToPDF(@ModelAttribute GeneralFile request)
throws Exception { throws Exception {
MultipartFile inputFile = request.getFileInput(); MultipartFile inputFile = request.getFileInput();

View File

@ -243,15 +243,25 @@ document.getElementById('addOperationBtn').addEventListener('click', function()
if (apiDocs[selectedOperation] && apiDocs[selectedOperation].post) { if (apiDocs[selectedOperation] && apiDocs[selectedOperation].post) {
const postMethod = apiDocs[selectedOperation].post; const postMethod = apiDocs[selectedOperation].post;
console.log("hasSettings", hasSettings);
// Check if parameters exist // Check if parameters exist
if (postMethod.parameters && postMethod.parameters.length > 0) { if (postMethod.parameters && postMethod.parameters.length > 0) {
hasSettings = true; hasSettings = true;
console.log("hasSettings2", hasSettings);
} else if (postMethod.requestBody && postMethod.requestBody.content['multipart/form-data']) { } else if (postMethod.requestBody && postMethod.requestBody.content['multipart/form-data']) {
// Extract the reference key // Extract the reference key
const refKey = postMethod.requestBody.content['multipart/form-data'].schema['$ref'].split('/').pop(); const refKey = postMethod.requestBody.content['multipart/form-data'].schema['$ref'].split('/').pop();
// Check if the referenced schema exists and has properties console.log("hasSettings3 ", hasSettings, refKey);
if (apiSchemas[refKey] && Object.keys(apiSchemas[refKey].properties).length > 0) { // Check if the referenced schema exists and has properties more than just its input file
hasSettings = true; if (apiSchemas[refKey]) {
const properties = apiSchemas[refKey].properties;
const propertyKeys = Object.keys(properties);
// Check if there's more than one property or if there's exactly one property and its format is not 'binary'
if (propertyKeys.length > 1 || (propertyKeys.length === 1 && properties[propertyKeys[0]].format !== 'binary')) {
hasSettings = true;
console.log("hasSettings4", hasSettings);
}
} }
} }
} }
@ -430,46 +440,48 @@ document.getElementById('addOperationBtn').addEventListener('click', function()
pipelineSettingsContent.appendChild(parameterDiv); pipelineSettingsContent.appendChild(parameterDiv);
}); });
let saveButton = document.createElement('button'); if(hasSettings) {
saveButton.textContent = "Save Settings"; let saveButton = document.createElement('button');
saveButton.className = "btn btn-primary"; saveButton.textContent = "Save Settings";
saveButton.addEventListener('click', function(event) { saveButton.className = "btn btn-primary";
event.preventDefault(); saveButton.addEventListener('click', function(event) {
let settings = {}; event.preventDefault();
operationData.forEach(parameter => { let settings = {};
if (parameter.name !== "fileInput") { operationData.forEach(parameter => {
let value = document.getElementById(parameter.name).value; if (parameter.name !== "fileInput") {
switch (parameter.schema.type) { let value = document.getElementById(parameter.name).value;
case 'number': switch (parameter.schema.type) {
case 'integer': case 'number':
settings[parameter.name] = Number(value); case 'integer':
break; settings[parameter.name] = Number(value);
case 'boolean': break;
settings[parameter.name] = document.getElementById(parameter.name).checked; case 'boolean':
break; settings[parameter.name] = document.getElementById(parameter.name).checked;
case 'array': break;
case 'object': case 'array':
if (value === null || value === '') { case 'object':
settings[parameter.name] = ''; if (value === null || value === '') {
} else { settings[parameter.name] = '';
try { } else {
settings[parameter.name] = JSON.parse(value); try {
} catch (err) { settings[parameter.name] = JSON.parse(value);
console.error(`Invalid JSON format for ${parameter.name}`); } catch (err) {
console.error(`Invalid JSON format for ${parameter.name}`);
}
} }
} break;
break; default:
default: settings[parameter.name] = value;
settings[parameter.name] = value; }
} }
} });
operationSettings[operation] = settings;
//pipelineSettingsModal.style.display = "none";
}); });
operationSettings[operation] = settings; pipelineSettingsContent.appendChild(saveButton);
//pipelineSettingsModal.style.display = "none"; saveButton.click();
}); }
pipelineSettingsContent.appendChild(saveButton);
saveButton.click();
//pipelineSettingsModal.style.display = "block"; //pipelineSettingsModal.style.display = "block";
//pipelineSettingsModal.getElementsByClassName("close")[0].onclick = function() { //pipelineSettingsModal.getElementsByClassName("close")[0].onclick = function() {