549 lines
39 KiB
HTML
549 lines
39 KiB
HTML
<!doctype html>
|
|||
|
|
<html lang="en">
|
||
|
|
<head>
|
||
|
|
<meta charset="UTF-8"/>
|
||
|
|
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
|
||
|
|
<title>JSON Infinity Studio</title>
|
||
|
|
<link rel="stylesheet" href="/static/style.css"/>
|
||
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"/>
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div class="app-layout">
|
||
|
|
<div class="sidebar" id="sidebar">
|
||
|
|
<div class="sidebar-header">
|
||
|
|
<div class="sidebar-logo"><i class="fa-solid fa-infinity"></i></div>
|
||
|
|
<h1>JSON Infinity Studio</h1>
|
||
|
|
</div>
|
||
|
|
<div class="sidebar-actions">
|
||
|
|
<button class="btn btn-primary btn-sm" style="flex:1" onclick="showCreateModal()"><i class="fa-solid fa-plus"></i> New</button>
|
||
|
|
<button class="btn btn-ghost btn-sm" style="flex:1" onclick="document.getElementById('fileInput').click()"><i class="fa-solid fa-upload"></i> Load</button>
|
||
|
|
<input type="file" id="fileInput" hidden accept=".json"/>
|
||
|
|
</div>
|
||
|
|
<div class="sidebar-search"><i class="fa-solid fa-search"></i><input type="text" placeholder="Search JSON..." id="searchInput" oninput="handleSearch(this.value)"/></div>
|
||
|
|
<!-- Schema Summary Badge -->
|
||
|
|
<div id="schemaSummary" style="padding:6px 12px;display:none">
|
||
|
|
<div style="font-size:9px;text-transform:uppercase;letter-spacing:1px;color:var(--text-dim);margin-bottom:4px">DETECTED SCHEMA</div>
|
||
|
|
<div id="schemaBadge" style="font-size:11px;color:var(--accent);font-weight:600;font-family:'JetBrains Mono',monospace"></div>
|
||
|
|
</div>
|
||
|
|
<div class="tree-container" id="treeRoot"></div>
|
||
|
|
</div>
|
||
|
|
<div class="main-content">
|
||
|
|
<div class="top-bar">
|
||
|
|
<div class="breadcrumb" id="breadcrumb">
|
||
|
|
<span style="color:var(--text-muted)">Select or create a JSON</span>
|
||
|
|
<span id="dirtyIndicator" class="dirty-dot" style="display:none" title="Unsaved changes">●</span>
|
||
|
|
</div>
|
||
|
|
<div class="top-actions">
|
||
|
|
<button class="btn btn-ghost btn-sm" onclick="showMultiCatAddFieldModal()" title="Add fields across multiple categories"><i class="fa-solid fa-wand-magic-sparkles"></i> Multi-Cat</button>
|
||
|
|
<button class="btn btn-ghost btn-sm" onclick="showCompareOriginal()" title="Compare with original"><i class="fa-solid fa-code-compare"></i> Diff</button>
|
||
|
|
<button class="btn btn-ghost btn-sm" onclick="revertToOriginal()" title="Revert to original"><i class="fa-solid fa-clock-rotate-left"></i> Revert</button>
|
||
|
|
<div style="width:1px;height:20px;background:var(--border);margin:0 4px"></div>
|
||
|
|
<button class="btn-icon" onclick="doUndo()" title="Undo (Ctrl+Z)"><i class="fa-solid fa-rotate-left"></i></button>
|
||
|
|
<button class="btn-icon" onclick="doRedo()" title="Redo (Ctrl+Y)"><i class="fa-solid fa-rotate-right"></i></button>
|
||
|
|
<button class="btn-icon" onclick="toggleRawEditor()" title="Raw JSON"><i class="fa-solid fa-code"></i></button>
|
||
|
|
<div style="width:1px;height:20px;background:var(--border);margin:0 4px"></div>
|
||
|
|
<button class="btn btn-save btn-sm" onclick="saveSession()" title="Save Session & Refresh View (Ctrl+S)"><i class="fa-solid fa-floppy-disk"></i> Save</button>
|
||
|
|
<button class="btn btn-success btn-sm" onclick="downloadFile()"><i class="fa-solid fa-download"></i> Download</button>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="content-area" id="contentArea">
|
||
|
|
<div class="empty-state" id="emptyState">
|
||
|
|
<i class="fa-solid fa-cubes"></i>
|
||
|
|
<p>Create a new JSON or load an existing file to begin</p>
|
||
|
|
<div style="display:flex;gap:8px;margin-top:8px">
|
||
|
|
<button class="btn btn-primary" onclick="showCreateModal()"><i class="fa-solid fa-plus"></i> New JSON</button>
|
||
|
|
<button class="btn btn-ghost" onclick="document.getElementById('fileInput').click()"><i class="fa-solid fa-upload"></i> Load File</button>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div id="editorArea" class="d-none"></div>
|
||
|
|
<div id="rawEditorArea" class="d-none" style="height:100%;padding:0">
|
||
|
|
<textarea class="input" id="rawTextarea" style="height:100%;border-radius:0;border:none;font-family:'JetBrains Mono',monospace;font-size:13px;resize:none"></textarea>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="status-bar">
|
||
|
|
<div class="status-left"><span id="statusPath">No file loaded</span><span id="statusDirty" style="color:var(--warning);display:none"> ● Modified</span><span id="statusCount"></span></div>
|
||
|
|
<div class="status-right"><span id="undoCount"></span><span>Ctrl+Z Undo | Ctrl+S Save | Ctrl+F Search</span></div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="toast-container" id="toastContainer"></div>
|
||
|
|
<div class="ctx-menu" id="ctxMenu" style="display:none"></div>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
// ── State ──
|
||
|
|
let currentPath="",currentNode=null,treeData=[],previewData=[],rawMode=false,currentSchema=null;
|
||
|
|
const D=document,$=s=>D.getElementById(s);
|
||
|
|
const api=async(url,body,isForm)=>{
|
||
|
|
const opts={method:"POST"};
|
||
|
|
if(isForm){opts.body=body}else{opts.headers={"Content-Type":"application/json"};opts.body=JSON.stringify(body||{});}
|
||
|
|
const r=await fetch(url,opts);return r.json();
|
||
|
|
};
|
||
|
|
|
||
|
|
// ── Toast ──
|
||
|
|
function toast(msg,type="success"){
|
||
|
|
const t=D.createElement("div");t.className=`toast toast-${type}`;
|
||
|
|
t.innerHTML=`<i class="fa-solid fa-${type==="success"?"check-circle":type==="error"?"exclamation-circle":"info-circle"}"></i>${msg}`;
|
||
|
|
$("toastContainer").appendChild(t);
|
||
|
|
setTimeout(()=>{t.style.animation="fadeOut .3s ease forwards";setTimeout(()=>t.remove(),300)},2500);
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── Dirty Tracking ──
|
||
|
|
function updateDirtyUI(isDirty){
|
||
|
|
$("dirtyIndicator").style.display=isDirty?"inline":"none";
|
||
|
|
$("statusDirty").style.display=isDirty?"inline":"none";
|
||
|
|
}
|
||
|
|
async function checkDirty(){
|
||
|
|
const r=await fetch("/saved_status").then(r=>r.json());
|
||
|
|
updateDirtyUI(r.is_dirty);
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── File I/O ──
|
||
|
|
$("fileInput").addEventListener("change",async e=>{
|
||
|
|
const fd=new FormData();fd.append("file",e.target.files[0]);
|
||
|
|
const r=await fetch("/upload",{method:"POST",body:fd}).then(r=>r.json());
|
||
|
|
if(r.success){
|
||
|
|
treeData=r.tree;renderTree(r.tree);toast("File loaded — working on a copy!");
|
||
|
|
$("statusPath").textContent=e.target.files[0].name;
|
||
|
|
if(r.schema) setSchemaInfo(r.schema);
|
||
|
|
updateDirtyUI(false);hideEmpty();
|
||
|
|
} else toast(r.error,"error");
|
||
|
|
});
|
||
|
|
|
||
|
|
function showCreateModal(){
|
||
|
|
showModal("Create New JSON",`
|
||
|
|
<label class="label">File Name</label><input class="input" id="mdNewName" value="data.json">
|
||
|
|
<label class="label mt-md">Template</label>
|
||
|
|
<select class="input" id="mdTemplate">
|
||
|
|
<option value="empty">Empty Object {}</option>
|
||
|
|
<option value="array_of_objects">Array of Objects</option>
|
||
|
|
<option value="nested">Nested Categories</option>
|
||
|
|
<option value="config">Config Template</option>
|
||
|
|
<option value="paste">Paste JSON</option>
|
||
|
|
</select>
|
||
|
|
<div id="mdPasteWrap" style="display:none" class="mt-md"><textarea class="input" id="mdPasteContent" rows="5" placeholder='{"key":"value"}'></textarea></div>`,
|
||
|
|
async()=>{
|
||
|
|
const tmpl=$("mdTemplate").value;
|
||
|
|
const body={mode:tmpl==="paste"?"paste":"template",name:$("mdNewName").value,template:tmpl};
|
||
|
|
if(tmpl==="paste")body.content=$("mdPasteContent").value;
|
||
|
|
const r=await api("/create_new",body);
|
||
|
|
if(r.success){treeData=r.tree;renderTree(r.tree);toast("Created!");$("statusPath").textContent=$("mdNewName").value;if(r.schema)setSchemaInfo(r.schema);updateDirtyUI(false);hideEmpty();}
|
||
|
|
else toast(r.error,"error");
|
||
|
|
});
|
||
|
|
$("mdTemplate").onchange=()=>{$("mdPasteWrap").style.display=$("mdTemplate").value==="paste"?"block":"none";};
|
||
|
|
}
|
||
|
|
|
||
|
|
function hideEmpty(){$("emptyState").style.display="none";$("editorArea").classList.remove("d-none");}
|
||
|
|
|
||
|
|
// ── Save Session / Download ──
|
||
|
|
async function saveSession(){
|
||
|
|
// Save = refresh the entire view so you can see all changes
|
||
|
|
const treeR=await fetch("/get_tree").then(r=>r.json());
|
||
|
|
if(treeR.tree){treeData=treeR.tree;renderTree(treeR.tree);}
|
||
|
|
if(currentPath){await loadNode(currentPath);}
|
||
|
|
// Also persist to disk in background so nothing is lost
|
||
|
|
await api("/save");
|
||
|
|
updateDirtyUI(false);
|
||
|
|
toast("Session saved — view updated!");
|
||
|
|
}
|
||
|
|
function downloadFile(){window.location.href="/download";}
|
||
|
|
|
||
|
|
// ── Revert / Compare ──
|
||
|
|
async function revertToOriginal(){
|
||
|
|
if(!confirm("Revert ALL changes back to the original uploaded file? (You can still Undo this)")) return;
|
||
|
|
const r=await api("/revert_original");
|
||
|
|
if(r.success){refreshTree(r.tree);if(currentPath)loadNode(currentPath);toast(r.message,"info");updateDirtyUI(false);}
|
||
|
|
else toast(r.error,"error");
|
||
|
|
}
|
||
|
|
async function showCompareOriginal(){
|
||
|
|
const r=await api("/compare_original");
|
||
|
|
if(!r.success){toast(r.error||"No original to compare","error");return;}
|
||
|
|
const changes=r.changes||[];
|
||
|
|
let bodyHtml=`<div style="max-height:400px;overflow-y:auto">`;
|
||
|
|
if(changes.length===0) bodyHtml+=`<div style="padding:20px;text-align:center;color:var(--success)"><i class="fa-solid fa-check-circle"></i> No changes — data matches original</div>`;
|
||
|
|
else{
|
||
|
|
bodyHtml+=`<div style="padding:6px 10px;background:var(--bg-card);border-radius:var(--radius-sm);margin-bottom:8px;font-size:11px"><strong>${r.total_changes}</strong> change(s) detected</div>`;
|
||
|
|
changes.forEach(c=>{
|
||
|
|
let icon="fa-pen",color="var(--accent)",label="";
|
||
|
|
if(c.type==="added"){icon="fa-plus";color="var(--success)";label=`<strong>Added:</strong> ${c.path}`;}
|
||
|
|
else if(c.type==="removed"){icon="fa-minus";color="var(--danger)";label=`<strong>Removed:</strong> ${c.path}`;}
|
||
|
|
else if(c.type==="value_changed"){icon="fa-pen";color="var(--warning)";label=`<strong>${c.path}</strong>: "${c.from}" → "${c.to}"`;}
|
||
|
|
else if(c.type==="array_size_changed"){icon="fa-layer-group";color="var(--info)";label=`<strong>${c.path}</strong>: ${c.from} → ${c.to} items`;}
|
||
|
|
else if(c.type==="type_changed"){icon="fa-shuffle";color="var(--warning)";label=`<strong>${c.path}</strong>: type ${c.from} → ${c.to}`;}
|
||
|
|
bodyHtml+=`<div class="field-row" style="padding:4px 8px;font-size:11px"><i class="fa-solid ${icon}" style="color:${color};width:14px"></i> ${label}</div>`;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
bodyHtml+=`</div>`;
|
||
|
|
showModal(`<i class="fa-solid fa-code-compare" style="color:var(--accent)"></i> Changes vs Original`,bodyHtml,()=>{});
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── Schema Info ──
|
||
|
|
function setSchemaInfo(schema){
|
||
|
|
currentSchema=schema;
|
||
|
|
const el=$("schemaSummary"),badge=$("schemaBadge");
|
||
|
|
el.style.display="block";
|
||
|
|
const s=schema.schema||schema.type||"unknown";
|
||
|
|
const map={
|
||
|
|
"flat_object":"⚙️ Flat Object","category_container":"📂 Category Container",
|
||
|
|
"nested_categories":"🏗️ Nested Categories","nested_objects":"🏢 Nested Objects",
|
||
|
|
"config_with_data":"📋 Config + Data","config_with_sections":"⚙️ Config + Sections",
|
||
|
|
"mixed_object":"🔀 Mixed Object","array_of_objects":"📊 Array of Objects",
|
||
|
|
"array_of_arrays":"📦 Array of Arrays","mixed_array":"🔀 Mixed Array",
|
||
|
|
"empty_array":"📭 Empty Array","object":"📁 Object","array":"📦 Array",
|
||
|
|
"string":"📝 String","number":"🔢 Number","boolean":"✅ Boolean","null":"⊘ Null"
|
||
|
|
};
|
||
|
|
badge.textContent=map[s]||s;
|
||
|
|
if(schema.key_count) badge.textContent+=` · ${schema.key_count} keys`;
|
||
|
|
else if(schema.count!==undefined) badge.textContent+=` · ${schema.count} items`;
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── Tree ──
|
||
|
|
function renderTree(nodes){
|
||
|
|
const root=$("treeRoot");root.innerHTML="";
|
||
|
|
if(!nodes||!nodes.length){root.innerHTML='<div style="padding:20px;text-align:center;color:var(--text-dim);font-size:12px">Empty — add a node via context menu</div>';return;}
|
||
|
|
root.appendChild(buildTreeDOM(nodes));
|
||
|
|
}
|
||
|
|
function buildTreeDOM(nodes){
|
||
|
|
const wrap=D.createElement("div");
|
||
|
|
nodes.forEach(n=>{
|
||
|
|
const row=D.createElement("div");row.className="tree-node"+(n.path===currentPath?" active":"");
|
||
|
|
const hasKids=n.type==="object"&&n.children&&n.children.length>0;
|
||
|
|
let html="";
|
||
|
|
if(hasKids)html+=`<span class="tree-toggle open"><i class="fa-solid fa-chevron-right"></i></span>`;
|
||
|
|
else html+='<span style="width:14px"></span>';
|
||
|
|
const iconMap={object:"fa-folder text-warning",array:"fa-layer-group text-info",string:"fa-font",number:"fa-hashtag text-accent",boolean:"fa-toggle-on text-warning",null:"fa-ban text-muted",url:"fa-link text-pink",coordinate:"fa-crosshairs text-orange"};
|
||
|
|
html+=`<span class="node-icon"><i class="fa-solid ${iconMap[n.type]||"fa-circle"}"></i></span>`;
|
||
|
|
html+=`<span class="node-label">${n.key}</span>`;
|
||
|
|
if(n.count!==undefined)html+=`<span class="node-badge">${n.count}</span>`;
|
||
|
|
row.innerHTML=html;
|
||
|
|
row.onclick=e=>{e.stopPropagation();if(n.type==="object"||n.type==="array")loadNode(n.path);if(hasKids){const ch=row.nextElementSibling;if(ch&&ch.classList.contains("tree-children"))ch.classList.toggle("collapsed");const tog=row.querySelector(".tree-toggle");if(tog)tog.classList.toggle("open");}};
|
||
|
|
row.oncontextmenu=e=>{e.preventDefault();e.stopPropagation();showContextMenu(e,n);};
|
||
|
|
wrap.appendChild(row);
|
||
|
|
if(hasKids){const childDiv=D.createElement("div");childDiv.className="tree-children";childDiv.appendChild(buildTreeDOM(n.children));wrap.appendChild(childDiv);}
|
||
|
|
});
|
||
|
|
return wrap;
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── Context Menu ──
|
||
|
|
function showContextMenu(e,node){
|
||
|
|
const m=$("ctxMenu");let items=[];
|
||
|
|
if(node.type==="object"){
|
||
|
|
items.push({icon:"fa-plus",label:"Add Child (Object)",action:()=>addNodePrompt(node.path,"object")});
|
||
|
|
items.push({icon:"fa-list",label:"Add Child (Array)",action:()=>addNodePrompt(node.path,"array")});
|
||
|
|
items.push({icon:"fa-font",label:"Add Child (String)",action:()=>addNodePrompt(node.path,"string")});
|
||
|
|
items.push({icon:"fa-hashtag",label:"Add Child (Number)",action:()=>addNodePrompt(node.path,"number")});
|
||
|
|
items.push({icon:"fa-toggle-on",label:"Add Child (Boolean)",action:()=>addNodePrompt(node.path,"boolean")});
|
||
|
|
items.push("sep");
|
||
|
|
}
|
||
|
|
if(node.type==="array"){
|
||
|
|
items.push({icon:"fa-plus",label:"Add Item (Object)",action:()=>addArrayItem(node.path,"object")});
|
||
|
|
items.push({icon:"fa-font",label:"Add Item (String)",action:()=>addArrayItem(node.path,"string")});
|
||
|
|
items.push({icon:"fa-hashtag",label:"Add Item (Number)",action:()=>addArrayItem(node.path,"number")});
|
||
|
|
items.push({icon:"fa-bolt",label:"Bulk Append",action:()=>{loadNode(node.path);setTimeout(()=>showAppendPanel(node.path),300);}});
|
||
|
|
items.push("sep");
|
||
|
|
}
|
||
|
|
items.push({icon:"fa-pen",label:"Rename",action:()=>renamePrompt(node)});
|
||
|
|
items.push({icon:"fa-copy",label:"Duplicate",action:()=>duplicateNode(node.path)});
|
||
|
|
items.push({icon:"fa-arrows-up-down",label:"Move Up",action:()=>moveNode(node.path,"up")});
|
||
|
|
items.push({icon:"fa-arrows-up-down",label:"Move Down",action:()=>moveNode(node.path,"down")});
|
||
|
|
items.push("sep");
|
||
|
|
items.push({icon:"fa-magnifying-glass-chart",label:"Analyze Schema",action:()=>analyzeSchema(node.path)});
|
||
|
|
items.push("sep");
|
||
|
|
items.push({icon:"fa-trash",label:"Delete",action:()=>deleteNode(node.path),danger:true});
|
||
|
|
m.innerHTML=items.map(i=>i==="sep"?'<div class="ctx-sep"></div>':`<div class="ctx-item${i.danger?" danger":""}" onclick="this.action()"><i class="fa-solid ${i.icon}"></i>${i.label}</div>`).join("");
|
||
|
|
m.querySelectorAll(".ctx-item").forEach((el,idx)=>{const item=items.filter(x=>x!=="sep")[idx];if(item)el.onclick=()=>{m.style.display="none";item.action();};});
|
||
|
|
m.style.display="block";m.style.left=Math.min(e.clientX,window.innerWidth-200)+"px";m.style.top=Math.min(e.clientY,window.innerHeight-300)+"px";
|
||
|
|
}
|
||
|
|
D.addEventListener("click",()=>$("ctxMenu").style.display="none");
|
||
|
|
|
||
|
|
// ── Schema Analysis ──
|
||
|
|
async function analyzeSchema(path){
|
||
|
|
const r=await api("/schema/analyze",{path:path||""});
|
||
|
|
if(!r.success){toast(r.error,"error");return;}
|
||
|
|
const s=r.schema;
|
||
|
|
let body=`<div style="max-height:400px;overflow-y:auto;font-size:12px">`;
|
||
|
|
body+=`<div class="field-row" style="background:var(--bg-card);border-radius:var(--radius-sm);padding:8px 12px;margin-bottom:8px">
|
||
|
|
<strong>Type:</strong> <span class="field-type-badge type-${s.type}">${s.type}</span>`;
|
||
|
|
if(s.schema) body+=` | <strong>Schema:</strong> ${s.schema}`;
|
||
|
|
if(s.count!==undefined) body+=` | <strong>Count:</strong> ${s.count}`;
|
||
|
|
if(s.key_count!==undefined) body+=` | <strong>Keys:</strong> ${s.key_count}`;
|
||
|
|
body+=`</div>`;
|
||
|
|
if(s.fields){
|
||
|
|
body+=`<div class="section-title"><i class="fa-solid fa-columns"></i> FIELDS</div>`;
|
||
|
|
for(const[k,f] of Object.entries(s.fields)){
|
||
|
|
const t=f.dominant_type||f.type||"unknown";
|
||
|
|
body+=`<div class="field-row" style="padding:4px 8px"><span class="field-key">${k}</span><span class="field-type-badge type-${t}">${t}</span>`;
|
||
|
|
if(f.type_distribution){body+=`<span style="font-size:9px;color:var(--text-dim);margin-left:6px">${Object.entries(f.type_distribution).map(([tt,c])=>`${tt}:${c}`).join(", ")}</span>`;}
|
||
|
|
if(f.sample!==null&&f.sample!==undefined)body+=`<span style="font-size:10px;color:var(--text-muted);margin-left:8px;max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">${String(f.sample).substring(0,60)}</span>`;
|
||
|
|
body+=`</div>`;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if(s.columns){body+=`<div class="section-title mt-md"><i class="fa-solid fa-table"></i> COLUMNS</div><div style="display:flex;gap:4px;flex-wrap:wrap">${s.columns.map(c=>`<span class="chip">${c}</span>`).join("")}</div>`;}
|
||
|
|
body+=`</div>`;
|
||
|
|
showModal(`<i class="fa-solid fa-magnifying-glass-chart" style="color:var(--accent)"></i> Schema Analysis`,body,()=>{});
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── Node Operations ──
|
||
|
|
async function loadNode(path){
|
||
|
|
currentPath=path;const r=await api("/node/get",{path});
|
||
|
|
if(r.error){toast(r.error,"error");return;}
|
||
|
|
currentNode=r;updateBreadcrumb(path);renderEditor(r,path);checkDirty();
|
||
|
|
D.querySelectorAll(".tree-node").forEach(n=>n.classList.remove("active"));
|
||
|
|
D.querySelectorAll(".tree-node").forEach(n=>{if(n.querySelector(".node-label")?.textContent===path.split("/").pop())n.classList.add("active");});
|
||
|
|
}
|
||
|
|
function updateBreadcrumb(path){
|
||
|
|
const parts=path.split("/");
|
||
|
|
$("breadcrumb").innerHTML='<span onclick="loadNode(\'\')"><i class="fa-solid fa-home"></i></span>'+parts.map((p,i)=>`<span class="sep">/</span><span onclick="loadNode('${parts.slice(0,i+1).join("/")}')">${p}</span>`).join("");
|
||
|
|
$("breadcrumb").innerHTML+=`<span id="dirtyIndicator" class="dirty-dot" style="display:${$("statusDirty")?.style.display==="inline"?"inline":"none"}" title="Unsaved changes">●</span>`;
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── Dynamic Editor Router ──
|
||
|
|
// Auto-detects the JSON type and renders the right editor
|
||
|
|
function renderEditor(data,path){
|
||
|
|
const area=$("editorArea");area.classList.remove("d-none");$("emptyState").style.display="none";
|
||
|
|
if(rawMode)return;
|
||
|
|
|
||
|
|
if(data.type==="object") renderObjectEditor(data,path);
|
||
|
|
else if(data.type==="array"){
|
||
|
|
if(data.view_mode==="table") renderTableEditor(data,path);
|
||
|
|
else if(data.view_mode==="list") renderListEditor(data,path);
|
||
|
|
else renderListEditor(data,path); // fallback
|
||
|
|
}
|
||
|
|
else renderPrimitiveEditor(data,path);
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── Object Editor (works for flat, config, nested objects) ──
|
||
|
|
function renderObjectEditor(data,path){
|
||
|
|
const area=$("editorArea");
|
||
|
|
let html=`<div class="card slide-up"><div class="card-header"><span class="card-title"><i class="fa-solid fa-folder-open"></i> Object · ${data.fields.length} fields</span>
|
||
|
|
<div><button class="btn btn-ghost btn-sm" onclick="showAddFieldModal('${path}')"><i class="fa-solid fa-plus"></i> Add Field</button>
|
||
|
|
<button class="btn btn-ghost btn-sm" onclick="analyzeSchema('${path}')"><i class="fa-solid fa-magnifying-glass-chart"></i></button></div></div>`;
|
||
|
|
data.fields.forEach(f=>{
|
||
|
|
html+=`<div class="field-row"><span class="field-key" ondblclick="renameFieldInline(this,'${path}','${f.key}')">${f.key}</span><span class="field-type-badge type-${f.type||"string"}">${f.type}</span><div class="field-value">`;
|
||
|
|
if(f.is_complex){
|
||
|
|
html+=`<button class="btn btn-ghost btn-sm" onclick="loadNode('${path}/${f.key}')"><i class="fa-solid fa-arrow-right"></i> ${f.type} (${f.child_count} items)</button>`;
|
||
|
|
} else {
|
||
|
|
html+=renderFieldControl(f, path);
|
||
|
|
}
|
||
|
|
html+=`</div><button class="btn-icon btn-sm" onclick="deleteNode('${path}/${f.key}')" title="Delete"><i class="fa-solid fa-trash" style="color:var(--danger)"></i></button></div>`;
|
||
|
|
});
|
||
|
|
html+="</div>";area.innerHTML=html;
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── Dynamic Field Control (renders the right input for any type) ──
|
||
|
|
function renderFieldControl(f, parentPath){
|
||
|
|
const val=f.value;const key=f.key;const fPath=`${parentPath}/${key}`;
|
||
|
|
|
||
|
|
if(f.type==="boolean"){
|
||
|
|
return `<label class="toggle-switch"><input type="checkbox" ${val?"checked":""} onchange="editValue('${fPath}',this.checked,'boolean')"/><span class="toggle-slider"></span></label>
|
||
|
|
<span style="font-size:11px;margin-left:6px;color:${val?'var(--success)':'var(--text-dim)'}">${val}</span>`;
|
||
|
|
}
|
||
|
|
if(f.type==="null"){
|
||
|
|
return `<span style="color:var(--text-dim);font-style:italic">null</span>
|
||
|
|
<button class="btn btn-ghost btn-sm" style="margin-left:8px" onclick="editValue('${fPath}','','string')"><i class="fa-solid fa-pen"></i> Set Value</button>`;
|
||
|
|
}
|
||
|
|
if(f.type==="number"){
|
||
|
|
return `<div style="display:flex;align-items:center;gap:4px">
|
||
|
|
<button class="btn-icon btn-sm" onclick="editValue('${fPath}',${(val||0)-1},'number')"><i class="fa-solid fa-minus"></i></button>
|
||
|
|
<input class="input input-sm" type="number" value="${val!==null&&val!==undefined?val:''}" style="width:100px;text-align:center"
|
||
|
|
onchange="editValue('${fPath}',this.value,'number')"/>
|
||
|
|
<button class="btn-icon btn-sm" onclick="editValue('${fPath}',${(val||0)+1},'number')"><i class="fa-solid fa-plus"></i></button>
|
||
|
|
</div>`;
|
||
|
|
}
|
||
|
|
if(f.type==="url"||f.type==="string"&&typeof val==="string"&&(val.startsWith("http://")||val.startsWith("https://"))){
|
||
|
|
return `<div style="display:flex;align-items:center;gap:6px;flex:1">
|
||
|
|
<input class="input input-sm" value="${String(val||'').replace(/"/g,""")}" onchange="editValue('${fPath}',this.value,'string')" style="flex:1"/>
|
||
|
|
<a href="${val}" target="_blank" class="btn-icon btn-sm" title="Open URL"><i class="fa-solid fa-external-link-alt" style="color:var(--info)"></i></a>
|
||
|
|
</div>`;
|
||
|
|
}
|
||
|
|
if(f.type==="coordinate"){
|
||
|
|
return `<input class="input input-sm font-mono" value="${String(val||'').replace(/"/g,""")}" onchange="editValue('${fPath}',this.value,'string')" style="font-size:11px;color:var(--accent)"/>`;
|
||
|
|
}
|
||
|
|
// Default string/unknown
|
||
|
|
const strVal=val===null?"":val;
|
||
|
|
const displayVal=String(strVal).replace(/"/g,""");
|
||
|
|
if(typeof strVal==="string"&&strVal.length>100){
|
||
|
|
return `<textarea class="input input-sm" style="min-height:50px;font-size:11px" onchange="editValue('${fPath}',this.value,'string')">${displayVal}</textarea>`;
|
||
|
|
}
|
||
|
|
return `<input class="input input-sm" value="${displayVal}" onchange="editValue('${fPath}',this.value,'${f.type||"string"}')"/>`;
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── Table Editor (for arrays of objects — any schema) ──
|
||
|
|
function renderTableEditor(data,path){
|
||
|
|
const area=$("editorArea"),cols=data.columns||[],colTypes=data.column_types||{};
|
||
|
|
let html=`<div class="card slide-up"><div class="card-header"><span class="card-title"><i class="fa-solid fa-table"></i> Array · ${data.total} items · ${cols.length} columns</span>
|
||
|
|
<div style="display:flex;gap:6px;flex-wrap:wrap">
|
||
|
|
<button class="btn btn-ghost btn-sm" onclick="showBulkAddFieldModal('${path}')"><i class="fa-solid fa-columns"></i> Add Col</button>
|
||
|
|
<button class="btn btn-ghost btn-sm" onclick="showBulkRemoveFieldModal('${path}','${cols.join(",")}')"><i class="fa-solid fa-minus"></i> Remove Col</button>
|
||
|
|
<button class="btn btn-ghost btn-sm" onclick="showBulkRenameFieldModal('${path}','${cols.join(",")}')"><i class="fa-solid fa-i-cursor"></i> Rename Col</button>
|
||
|
|
<button class="btn btn-ghost btn-sm" onclick="showBulkEditFieldModal('${path}','${cols.join(",")}')"><i class="fa-solid fa-pen"></i> Bulk Edit</button>
|
||
|
|
<button class="btn btn-primary btn-sm" onclick="showAppendPanel('${path}')"><i class="fa-solid fa-bolt"></i> Bulk Append</button>
|
||
|
|
<button class="btn btn-ghost btn-sm" onclick="analyzeSchema('${path}')"><i class="fa-solid fa-magnifying-glass-chart"></i></button>
|
||
|
|
</div></div>`;
|
||
|
|
html+=`<div class="data-table-wrap" style="max-height:50vh"><table class="data-table"><thead><tr><th class="row-idx">#</th>`;
|
||
|
|
cols.forEach(c=>{const tc=colTypes[c]||"string";html+=`<th>${c} <span class="field-type-badge type-${tc}" style="font-size:8px">${tc}</span></th>`;});
|
||
|
|
html+=`<th style="width:70px">Actions</th></tr></thead><tbody>`;
|
||
|
|
(data.items||[]).forEach((item,idx)=>{
|
||
|
|
html+=`<tr><td class="row-idx">${idx}</td>`;
|
||
|
|
cols.forEach(c=>{
|
||
|
|
const v=item[c];const ct=colTypes[c]||"string";
|
||
|
|
html+=renderTableCell(v,ct,path,idx,c);
|
||
|
|
});
|
||
|
|
html+=`<td><div class="row-actions" style="opacity:1"><button class="btn-icon btn-sm" onclick="editItemModal('${path}',${idx})"><i class="fa-solid fa-pen"></i></button><button class="btn-icon btn-sm" onclick="deleteItem('${path}',${idx})"><i class="fa-solid fa-trash" style="color:var(--danger)"></i></button></div></td></tr>`;
|
||
|
|
});
|
||
|
|
html+=`</tbody></table></div></div><div id="appendPanelWrap"></div>`;
|
||
|
|
area.innerHTML=html;$("statusCount").textContent=`${data.total} items`;
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── Dynamic Table Cell (renders each cell based on its detected type) ──
|
||
|
|
function renderTableCell(v,colType,path,idx,col){
|
||
|
|
if(v===null||v===undefined) return `<td class="cell-editable" style="color:var(--text-dim);font-style:italic" ondblclick="inlineEditCell(this,'${path}',${idx},'${col}')">null</td>`;
|
||
|
|
|
||
|
|
if(typeof v==="boolean") return `<td><input type="checkbox" ${v?"checked":""} onchange="inlineToggleBool('${path}',${idx},'${col}',this.checked)" style="accent-color:var(--accent);cursor:pointer" title="${v}"/></td>`;
|
||
|
|
|
||
|
|
if(typeof v==="object"&&v!==null){
|
||
|
|
const preview=JSON.stringify(v).substring(0,40);
|
||
|
|
return `<td class="cell-editable" style="font-size:10px;color:var(--text-muted);cursor:pointer" onclick="loadNode('${path}/${idx}/${col}')" title='${JSON.stringify(v).replace(/'/g,"'")}'>${Array.isArray(v)?`[${v.length}]`:`{${Object.keys(v).length}}`} <i class="fa-solid fa-arrow-right" style="font-size:8px"></i></td>`;
|
||
|
|
}
|
||
|
|
|
||
|
|
const strV=String(v);
|
||
|
|
if(typeof v==="string"&&(strV.startsWith("http://")||strV.startsWith("https://"))){
|
||
|
|
return `<td class="cell-editable" ondblclick="inlineEditCell(this,'${path}',${idx},'${col}')">
|
||
|
|
<div style="display:flex;align-items:center;width:100%">
|
||
|
|
<span style="flex:1;word-break:break-all;margin-right:6px">${strV}</span>
|
||
|
|
<a href="${v}" target="_blank" class="btn-icon btn-sm" style="color:var(--info);flex-shrink:0" onclick="event.stopPropagation()" title="Open Link"><i class="fa-solid fa-external-link-alt"></i></a>
|
||
|
|
</div>
|
||
|
|
</td>`;
|
||
|
|
}
|
||
|
|
|
||
|
|
const escaped=strV.replace(/"/g,""");
|
||
|
|
// Show full string, let CSS handle wrapping/scroll if needed (user requested no "...")
|
||
|
|
return `<td class="cell-editable" ondblclick="inlineEditCell(this,'${path}',${idx},'${col}')" style="word-break:break-all">${strV}</td>`;
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── Inline Boolean Toggle (for table cells) ──
|
||
|
|
async function inlineToggleBool(path,idx,col,val){
|
||
|
|
const r=await api("/node/get",{path});
|
||
|
|
if(r.items){const item={...r.items[idx]};item[col]=val;await api("/node/edit_item",{path,index:idx,item});loadNode(path);toast("Updated");}
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── List Editor (for arrays of primitives, mixed arrays) ──
|
||
|
|
function renderListEditor(data,path){
|
||
|
|
const area=$("editorArea");
|
||
|
|
let html=`<div class="card slide-up"><div class="card-header"><span class="card-title"><i class="fa-solid fa-list"></i> Array · ${data.total} items</span>
|
||
|
|
<div><button class="btn btn-ghost btn-sm" onclick="addArrayItem('${path}','string')"><i class="fa-solid fa-plus"></i> String</button>
|
||
|
|
<button class="btn btn-ghost btn-sm" onclick="addArrayItem('${path}','number')"><i class="fa-solid fa-plus"></i> Number</button>
|
||
|
|
<button class="btn btn-ghost btn-sm" onclick="addArrayItem('${path}','object')"><i class="fa-solid fa-plus"></i> Object</button>
|
||
|
|
<button class="btn btn-ghost btn-sm" onclick="analyzeSchema('${path}')"><i class="fa-solid fa-magnifying-glass-chart"></i></button></div></div>`;
|
||
|
|
(data.items||[]).forEach((item,idx)=>{
|
||
|
|
const itemType=typeof item;
|
||
|
|
if(item===null){
|
||
|
|
html+=`<div class="field-row"><span class="row-idx">${idx}</span><span class="field-type-badge type-null">null</span><div class="field-value"><span style="color:var(--text-dim);font-style:italic">null</span></div>
|
||
|
|
<button class="btn-icon btn-sm" onclick="deleteItem('${path}',${idx})"><i class="fa-solid fa-trash" style="color:var(--danger)"></i></button></div>`;
|
||
|
|
} else if(typeof item==="object"){
|
||
|
|
const preview=JSON.stringify(item).substring(0,60);
|
||
|
|
html+=`<div class="field-row" style="cursor:pointer" onclick="loadNode('${path}/${idx}')"><span class="row-idx">${idx}</span><span class="field-type-badge type-${Array.isArray(item)?"array":"object"}">${Array.isArray(item)?"array":"object"}</span><div class="field-value"><span style="font-size:11px;color:var(--text-muted)">${preview}${preview.length>=60?"...":""}</span></div>
|
||
|
|
<button class="btn-icon btn-sm" onclick="event.stopPropagation();deleteItem('${path}',${idx})"><i class="fa-solid fa-trash" style="color:var(--danger)"></i></button></div>`;
|
||
|
|
} else if(typeof item==="boolean"){
|
||
|
|
html+=`<div class="field-row"><span class="row-idx">${idx}</span><span class="field-type-badge type-boolean">bool</span><div class="field-value"><label class="toggle-switch"><input type="checkbox" ${item?"checked":""} onchange="editArrayValue('${path}',${idx},this.checked?'true':'false')"/><span class="toggle-slider"></span></label><span style="margin-left:6px;font-size:11px">${item}</span></div>
|
||
|
|
<button class="btn-icon btn-sm" onclick="deleteItem('${path}',${idx})"><i class="fa-solid fa-trash" style="color:var(--danger)"></i></button></div>`;
|
||
|
|
} else {
|
||
|
|
html+=`<div class="field-row"><span class="row-idx">${idx}</span><span class="field-type-badge type-${typeof item==="number"?"number":"string"}">${typeof item}</span><div class="field-value"><input class="input input-sm" value="${String(item).replace(/"/g,""")}" onchange="editArrayValue('${path}',${idx},this.value)"/></div>
|
||
|
|
<button class="btn-icon btn-sm" onclick="deleteItem('${path}',${idx})"><i class="fa-solid fa-trash" style="color:var(--danger)"></i></button></div>`;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
html+="</div>";area.innerHTML=html;
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── Primitive Editor (for individual values) ──
|
||
|
|
function renderPrimitiveEditor(data,path){
|
||
|
|
const area=$("editorArea"),v=data.value===null?"":data.value,t=data.type;
|
||
|
|
let html=`<div class="card slide-up"><div class="card-header"><span class="card-title">Value · <span class="field-type-badge type-${t}">${t}</span></span></div>`;
|
||
|
|
|
||
|
|
if(t==="boolean"){
|
||
|
|
html+=`<div style="display:flex;align-items:center;gap:12px;padding:12px"><label class="toggle-switch"><input type="checkbox" ${v?"checked":""} onchange="editValue('${path}',this.checked,'boolean')"/><span class="toggle-slider"></span></label><span style="font-size:14px;font-weight:600">${v}</span></div>`;
|
||
|
|
} else if(t==="null"){
|
||
|
|
html+=`<div style="padding:20px;text-align:center"><span style="color:var(--text-dim);font-size:16px;font-style:italic">null</span><br>
|
||
|
|
<button class="btn btn-primary btn-sm mt-md" onclick="editValue('${path}','','string')"><i class="fa-solid fa-pen"></i> Set a Value</button></div>`;
|
||
|
|
} else if(t==="number"){
|
||
|
|
html+=`<div style="display:flex;align-items:center;gap:8px;padding:12px">
|
||
|
|
<button class="btn-icon" onclick="editValue('${path}',${(v||0)-1},'number')"><i class="fa-solid fa-minus"></i></button>
|
||
|
|
<input class="input" type="number" id="primVal" value="${v!==null?v:''}" style="width:150px;text-align:center;font-size:18px"/>
|
||
|
|
<button class="btn-icon" onclick="editValue('${path}',${(v||0)+1},'number')"><i class="fa-solid fa-plus"></i></button>
|
||
|
|
</div>
|
||
|
|
<button class="btn btn-primary mt-sm" onclick="editValue('${path}',$('primVal').value,'number')">Save</button>`;
|
||
|
|
} else {
|
||
|
|
const strV=String(v||"").replace(/"/g,""");
|
||
|
|
if(typeof v==="string"&&(v.startsWith("http://")||v.startsWith("https://"))){
|
||
|
|
html+=`<input class="input" id="primVal" value="${strV}"/>
|
||
|
|
<a href="${v}" target="_blank" style="color:var(--info);font-size:12px;margin-top:4px;display:inline-block"><i class="fa-solid fa-external-link-alt"></i> Open Link</a>`;
|
||
|
|
} else if(typeof v==="string"&&v.length>200){
|
||
|
|
html+=`<textarea class="input" id="primVal" rows="6" style="font-family:'JetBrains Mono',monospace;font-size:12px">${strV}</textarea>`;
|
||
|
|
} else {
|
||
|
|
html+=`<input class="input" id="primVal" value="${strV}"/>`;
|
||
|
|
}
|
||
|
|
html+=`<div style="margin-top:10px;display:flex;gap:6px">
|
||
|
|
<select class="input" style="width:120px" id="primType"><option value="string">String</option><option value="number">Number</option><option value="boolean">Boolean</option><option value="null">Null</option></select>
|
||
|
|
<button class="btn btn-primary" onclick="editValue('${path}',$('primVal').value,$('primType').value)">Save</button></div>`;
|
||
|
|
}
|
||
|
|
html+="</div>";area.innerHTML=html;
|
||
|
|
if($("primType"))$("primType").value=t;
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── Inline Cell Edit ──
|
||
|
|
function inlineEditCell(td,path,idx,col){
|
||
|
|
const orig=td.textContent;td.innerHTML=`<input class="input input-sm" value="${orig.replace(/"/g,""")}" style="width:100%" autofocus>`;
|
||
|
|
const inp=td.querySelector("input");inp.focus();inp.select();
|
||
|
|
const save=async()=>{const r=await api("/node/get",{path});if(r.success||r.items){const item={...(r.items||[])[idx]};item[col]=inp.value;await api("/node/edit_item",{path,index:idx,item});loadNode(path);toast("Updated");}};
|
||
|
|
inp.onblur=save;inp.onkeydown=e=>{if(e.key==="Enter")save();if(e.key==="Escape")td.textContent=orig;};
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── API Wrappers ──
|
||
|
|
async function editValue(path,value,type){const r=await api("/node/edit_value",{path,value,value_type:type});if(r.success){toast("Updated");refreshTree(r.tree);if(currentPath)loadNode(currentPath);checkDirty();}else toast(r.error,"error");}
|
||
|
|
async function editArrayValue(path,idx,value){const r=await api("/node/edit_item",{path,index:idx,item:value});if(r.success){toast("Updated");loadNode(path);checkDirty();}else toast(r.error,"error");}
|
||
|
|
async function deleteNode(path){if(!confirm("Delete this node?"))return;const r=await api("/node/delete",{path});if(r.success){toast("Deleted");refreshTree(r.tree);checkDirty();const parent=path.split("/").slice(0,-1).join("/");if(parent)loadNode(parent);else{$("editorArea").innerHTML="";$("editorArea").classList.add("d-none");$("emptyState").style.display="";}}else toast(r.error,"error");}
|
||
|
|
async function deleteItem(path,idx){if(!confirm(`Delete item #${idx}?`))return;const r=await api("/node/delete_item",{path,index:idx});if(r.success){toast("Deleted");refreshTree(r.tree);loadNode(path);checkDirty();}else toast(r.error,"error");}
|
||
|
|
async function duplicateNode(path){const r=await api("/node/duplicate",{path});if(r.success){toast("Duplicated");refreshTree(r.tree);checkDirty();}else toast(r.error,"error");}
|
||
|
|
async function moveNode(path,dir){const r=await api("/node/move",{path,direction:dir});if(r.success){refreshTree(r.tree);toast("Moved");checkDirty();}else toast(r.error,"error");}
|
||
|
|
async function doUndo(){const r=await api("/undo");if(r.success){refreshTree(r.tree);if(currentPath)loadNode(currentPath);toast("Undone","info");checkDirty();}else toast(r.error,"error");}
|
||
|
|
async function doRedo(){const r=await api("/redo");if(r.success){refreshTree(r.tree);if(currentPath)loadNode(currentPath);toast("Redone","info");checkDirty();}else toast(r.error,"error");}
|
||
|
|
function refreshTree(tree){if(tree){treeData=tree;renderTree(tree);}}
|
||
|
|
|
||
|
|
// ── Add Node Prompts ──
|
||
|
|
function addNodePrompt(parentPath,type){
|
||
|
|
showModal("Add "+type.charAt(0).toUpperCase()+type.slice(1),`
|
||
|
|
<label class="label">Key Name</label><input class="input" id="mdAddKey" autofocus>
|
||
|
|
${type==="string"||type==="number"?`<label class="label mt-md">Value</label><input class="input" id="mdAddVal">`:""}`,
|
||
|
|
async()=>{const body={path:parentPath,key:$("mdAddKey").value,value_type:type};if($("mdAddVal"))body.value=$("mdAddVal").value;const r=await api("/node/add",body);if(r.success){refreshTree(r.tree);toast("Added");if(currentPath)loadNode(currentPath);checkDirty();}else toast(r.error,"error");});
|
||
|
|
}
|
||
|
|
async function addArrayItem(path,type){const r=await api("/node/add",{path,value_type:type,value:type==="object"?"{}":type==="number"?"0":""});if(r.success){refreshTree(r.tree);loadNode(path);toast("Item added");checkDirty();}else toast(r.error,"error");}
|
||
|
|
function renamePrompt(node){showModal("Rename",`<label class="label">New Name</label><input class="input" id="mdRename" value="${node.key}">`,async()=>{const r=await api("/node/rename",{path:node.path,new_name:$("mdRename").value});if(r.success){refreshTree(r.tree);toast("Renamed");checkDirty();}else toast(r.error,"error");});}
|
||
|
|
function showAddFieldModal(path){
|
||
|
|
showModal("Add Field",`<label class="label">Key</label><input class="input" id="mdFK">
|
||
|
|
<label class="label mt-md">Type</label><select class="input" id="mdFT"><option value="string">String</option><option value="number">Number</option><option value="boolean">Boolean</option><option value="null">Null</option><option value="object">Object</option><option value="array">Array</option></select>
|
||
|
|
<label class="label mt-md">Value</label><input class="input" id="mdFV">`,
|
||
|
|
async()=>{const r=await api("/node/add",{path,key:$("mdFK").value,value_type:$("mdFT").value,value:$("mdFV").value||null});if(r.success){refreshTree(r.tree);loadNode(path);toast("Field added");checkDirty();}else toast(r.error,"error");});
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── Bulk Modals (simple ones) ──
|
||
|
|
function showBulkAddFieldModal(path){
|
||
|
|
showModal("Add Column to All Items",`<label class="label">Field Name</label><input class="input" id="mdBFK">
|
||
|
|
<label class="label mt-md">Type</label><select class="input" id="mdBFT"><option value="string">String</option><option value="number">Number</option><option value="boolean">Boolean</option></select>
|
||
|
|
<label class="label mt-md">Default Value</label><input class="input" id="mdBFV">`,
|
||
|
|
async()=>{const r=await api("/bulk/add_field",{path,field_name:$("mdBFK").value,field_type:$("mdBFT").value,default_value:$("mdBFV").value});if(r.success){loadNode(path);toast(`Added to ${r.modified} items`);checkDirty();}else toast(r.error,"error");});
|
||
|
|
}
|
||
|
|
function showBulkRemoveFieldModal(path,colsStr){
|
||
|
|
const cols=colsStr.split(",");
|
||
|
|
showModal("Remove Column",`<label class="label">Select Field</label><select class="input" id="mdBRF">${cols.map(c=>`<option value="${c}">${c}</option>`).join("")}</select>`,
|
||
|
|
async()=>{const r=await api("/bulk/remove_field",{path,field_name:$("mdBRF").value});if(r.success){refreshTree(r.tree);loadNode(path);toast(`Removed from ${r.modified} items`);checkDirty();}else toast(r.error,"error");});
|
||
|
|
}
|
||
|
|
function showBulkRenameFieldModal(path,colsStr){
|
||
|
|
const cols=colsStr.split(",");
|
||
|
|
showModal("Rename Column",`<label class="label">Current Name</label><select class="input" id="mdBRnOld">${cols.map(c=>`<option value="${c}">${c}</option>`).join("")}</select>
|
||
|
|
<label class="label mt-md">New Name</label><input class="input" id="mdBRnNew">`,
|
||
|
|
async()=>{const r=await api("/bulk/rename_field",{path,old_name:$("mdBRnOld").value,new_name:$("mdBRnNew").value});if(r.success){refreshTree(r.tree);loadNode(path);toast(`Renamed in ${r.modified} items`);checkDirty();}else toast(r.error,"error");});
|
||
|
|
}
|
||
|
|
</script>
|
||
|
|
<script src="/static/bulk_edit.js"></script>
|
||
|
|
</body>
|
||
|
|
</html>
|