From 8c49e7396ee16c9aa928c0cd3efbe7eac06dcbac Mon Sep 17 00:00:00 2001 From: marwin Date: Fri, 16 May 2025 20:04:36 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20enhance=20mindmap=20update?= =?UTF-8?q?=20functionality=20in=20update=5Fmindmap.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/js/update_mindmap.js | 154 +++++++++++++++++++++++++++++++++++- 1 file changed, 153 insertions(+), 1 deletion(-) diff --git a/static/js/update_mindmap.js b/static/js/update_mindmap.js index 2541013..cec0a86 100644 --- a/static/js/update_mindmap.js +++ b/static/js/update_mindmap.js @@ -1755,4 +1755,156 @@ editingStyles.textContent = ` opacity: 0.8; } `; -document.head.appendChild(editingStyles); \ No newline at end of file +document.head.appendChild(editingStyles); + +// Funktion zum Laden der Subthemen +async function loadSubthemes(node) { + try { + const mindmapData = await loadMindmapData(node.id()); + if (!mindmapData) return; + + showUINotification('Lade Subthemen...', 'info'); + + const mindmapContainer = document.querySelector('.mindmap-container'); + const newPage = document.createElement('div'); + newPage.className = 'mindmap-page'; + newPage.style.display = 'none'; + + const header = document.createElement('div'); + header.className = 'mindmap-header'; + header.innerHTML = ` + +

${node.data('label')}

+ `; + + const newContainer = document.createElement('div'); + newContainer.id = `cy-${node.id()}`; + newContainer.className = 'mindmap-view'; + + newPage.appendChild(header); + newPage.appendChild(newContainer); + mindmapContainer.appendChild(newPage); + + // Speichere die Cytoscape-Instanz für eventuelle Referenzen + if (!window.subthemeCyInstances) { + window.subthemeCyInstances = {}; + } + + const newCy = cytoscape({ + container: newContainer, + elements: [ + ...mindmapData.nodes.map(node => ({ + data: { + id: node.id, + label: node.name, + category: node.category, + description: node.description, + hasChildren: node.has_children, + expanded: false, + color: node.color_code, + fontColor: '#ffffff', + fontSize: 16 + } + })), + ...mindmapData.edges.map(edge => ({ + data: { + source: edge.source, + target: edge.target, + strength: edge.strength || 0.5 + } + })) + ], + style: cy.style(), + layout: mindmapStyles.layout.base + }); + + // Speichere die Cytoscape-Instanz + window.subthemeCyInstances[node.id()] = newCy; + + // Event-Listener für die neue Mindmap + newCy.on('tap', 'node', async function(evt) { + const clickedNode = evt.target; + if (clickedNode.data('hasChildren') && !clickedNode.data('expanded')) { + await loadSubthemes(clickedNode); + } + }); + + // Alte Seite ausblenden und neue anzeigen + cy.container().style.display = 'none'; + newPage.style.display = 'block'; + + // Wende neuronales Design auf die neue Mindmap an + applyNeuralNetworkStyle(newCy); + + showUINotification('Subthemen erfolgreich geladen', 'success'); + + } catch (error) { + console.error('Fehler beim Laden der Subthemen:', error); + showUINotification('Fehler beim Laden der Subthemen', 'error'); + } +} + +// Funktion zum Zurücknavigieren +function goBack() { + const currentPage = document.querySelector('.mindmap-page:not([style*="display: none"])'); + if (currentPage) { + currentPage.style.display = 'none'; + cy.container().style.display = 'block'; + } +} + +// CSS-Styles für die Unterkategorien-Seite +(function() { + const style = document.createElement('style'); + style.textContent = ` + .mindmap-page { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: var(--bg-color, #1a1a1a); + z-index: 1000; + } + + .mindmap-header { + display: flex; + align-items: center; + padding: 1rem; + background: rgba(0, 0, 0, 0.2); + border-bottom: 1px solid rgba(255, 255, 255, 0.1); + } + + .back-button { + background: none; + border: none; + color: #fff; + cursor: pointer; + padding: 0.5rem; + margin-right: 1rem; + border-radius: 50%; + transition: background-color 0.3s; + } + + .back-button:hover { + background: rgba(255, 255, 255, 0.1); + } + + .mindmap-title { + color: #fff; + font-size: 1.5rem; + font-weight: 600; + margin: 0; + } + + .mindmap-view { + width: 100%; + height: calc(100% - 4rem); + } + `; + document.head.appendChild(style); +})(); \ No newline at end of file