import os with open("core/templates/core/project_detail.html", "r") as f: html = f.read() # Replace the node clicked block old_block = """ const nodeId = params.nodes[0]; const node = data.nodes.get(nodeId); detailsPanel.innerHTML = `
${node.label}
${node.category}

Summary:
${node.summary}

`; """ new_block = """ const nodeId = params.nodes[0]; const node = data.nodes.get(nodeId); // remove emoji from label for editing const cleanLabel = node.label.replace(/^.*? /, ''); detailsPanel.innerHTML = `
${cleanLabel}
${node.category}

Summary:
${node.summary}

`; """ html = html.replace(old_block, new_block) new_scripts = """ function editNodeUI(nodeId) { document.getElementById(`node-view-${nodeId}`).classList.add('d-none'); document.getElementById(`node-edit-${nodeId}`).classList.remove('d-none'); } function cancelEditNode(nodeId) { document.getElementById(`node-edit-${nodeId}`).classList.add('d-none'); document.getElementById(`node-view-${nodeId}`).classList.remove('d-none'); } function saveNode(nodeId, event) { const title = document.getElementById(`edit-node-title-${nodeId}`).value; const category = document.getElementById(`edit-node-category-${nodeId}`).value; const summary = document.getElementById(`edit-node-summary-${nodeId}`).value; const saveBtn = event.target; saveBtn.disabled = true; saveBtn.innerText = 'Saving...'; let csrfToken = ''; const csrfInput = document.querySelector('[name=csrfmiddlewaretoken]'); if (csrfInput) { csrfToken = csrfInput.value; } else { // fallback, get from form if present elsewhere console.warn("CSRF token not found via input name. Ensure it exists on the page."); } const url = "{% url 'edit_node' project.pk 0 %}".replace('/0/', '/' + nodeId + '/'); fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRFToken': csrfToken }, body: JSON.stringify({ title: title, category: category, summary: summary }) }) .then(response => response.json()) .then(res => { if (res.status === 'success') { const node = res.node; const emoji = getNodeEmoji(node.category); const color = getNodeColor(node.category); data.nodes.update({ id: node.id, label: emoji + " " + node.title, title: `${node.title}
${node.summary}
Category: ${node.category}`, summary: node.summary, category: node.category, color: color }); // re-render details network.emit('click', { nodes: [nodeId], edges: [] }); } else { alert('Error saving node: ' + res.message); saveBtn.disabled = false; saveBtn.innerText = 'Save'; } }) .catch(err => { alert('Error saving node'); saveBtn.disabled = false; saveBtn.innerText = 'Save'; }); } """ html = html.replace(' // AI Chat Handler', new_scripts + '\n // AI Chat Handler') with open("core/templates/core/project_detail.html", "w") as f: f.write(html)