This commit is contained in:
+26
-12
@@ -62,7 +62,6 @@ function autoDetectArrayPath(obj) {
|
||||
return bestPath || ".";
|
||||
}
|
||||
|
||||
|
||||
function processPreview() {
|
||||
let headers = [];
|
||||
let rows = [];
|
||||
@@ -72,7 +71,6 @@ function processPreview() {
|
||||
const parsed = JSON.parse(currentRawData);
|
||||
const findings = getNestedValue(parsed, pathInput.value);
|
||||
|
||||
|
||||
if (!Array.isArray(findings) || findings.length === 0) {
|
||||
const rawPreview = JSON.stringify(parsed, null, 2).substring(0, 1500) + "\n\n... (file truncated for preview)";
|
||||
|
||||
@@ -140,8 +138,8 @@ function populateDropdowns(headers) {
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById('adapter-form').onsubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
// Reusable save function mapped to the API
|
||||
async function saveAdapterToAPI() {
|
||||
const data = {
|
||||
name: document.getElementById('name').value,
|
||||
source_name: document.getElementById('source_name').value,
|
||||
@@ -165,12 +163,28 @@ document.getElementById('adapter-form').onsubmit = async (e) => {
|
||||
} else {
|
||||
alert("Failed to save adapter: " + await resp.text());
|
||||
}
|
||||
}
|
||||
|
||||
// Bound to the primary "Save & Enable Adapter" submit button
|
||||
document.getElementById('adapter-form').onsubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
await saveAdapterToAPI();
|
||||
};
|
||||
|
||||
// Bound to the secondary "Save to Database" button
|
||||
window.saveAdapter = async function() {
|
||||
const form = document.getElementById('adapter-form');
|
||||
// Ensure HTML validations (like 'required') are checked before saving
|
||||
if (form.reportValidity()) {
|
||||
await saveAdapterToAPI();
|
||||
}
|
||||
};
|
||||
|
||||
window.exportAdapterJSON = function() {
|
||||
const name = document.getElementById("adapterName").value.trim();
|
||||
const sourceName = document.getElementById("sourceName").value.trim();
|
||||
const rootPath = document.getElementById("rootPath").value.trim();
|
||||
// Fixed mismatched Element IDs
|
||||
const name = document.getElementById("name").value.trim();
|
||||
const sourceName = document.getElementById("source_name").value.trim();
|
||||
const rootPath = document.getElementById("findings_path").value.trim();
|
||||
|
||||
if (!name || !sourceName) {
|
||||
return alert("Adapter Name and Source Name are required to export.");
|
||||
@@ -180,11 +194,11 @@ window.exportAdapterJSON = function() {
|
||||
name: name,
|
||||
source_name: sourceName,
|
||||
findings_path: rootPath,
|
||||
mapping_title: document.getElementById("mapTitle").value.trim(),
|
||||
mapping_asset: document.getElementById("mapAsset").value.trim(),
|
||||
mapping_severity: document.getElementById("mapSeverity").value.trim(),
|
||||
mapping_description: document.getElementById("mapDesc").value.trim(),
|
||||
mapping_remediation: document.getElementById("mapRem").value.trim()
|
||||
mapping_title: document.getElementById("mapping_title").value.trim(),
|
||||
mapping_asset: document.getElementById("mapping_asset").value.trim(),
|
||||
mapping_severity: document.getElementById("mapping_severity").value.trim(),
|
||||
mapping_description: document.getElementById("mapping_description").value.trim(),
|
||||
mapping_remediation: document.getElementById("mapping_remediation").value.trim()
|
||||
};
|
||||
|
||||
// Create a downloadable JSON blob
|
||||
|
||||
Reference in New Issue
Block a user