From 37c457ca3f114b539d4ed2faf97a42afb7f35b3f Mon Sep 17 00:00:00 2001 From: marwin Date: Thu, 22 May 2025 12:15:50 +0100 Subject: [PATCH] Kategorien- Button Funktion --- static/js/update_mindmap.js | 200 +++++++++++++++++++++++++++++++++++- 1 file changed, 199 insertions(+), 1 deletion(-) diff --git a/static/js/update_mindmap.js b/static/js/update_mindmap.js index 083e407..18edc01 100644 --- a/static/js/update_mindmap.js +++ b/static/js/update_mindmap.js @@ -499,6 +499,11 @@ document.addEventListener('DOMContentLoaded', function() { details: error.message }, 'error'); }); + + // Initialisiere das Kategorien-Panel + document.addEventListener('mindmap-loaded', function() { + initializeCategoriesPanel(); + }); }); // Funktion zum Initialisieren des neuronalen Designs @@ -2523,4 +2528,197 @@ function hideNodeInfo() { if (infoPanel) { infoPanel.classList.remove('visible'); } -} \ No newline at end of file +} + +// Funktion zum Erstellen und Verwalten des Kategorien-Panels +function initializeCategoriesPanel() { + const toggleCategoriesBtn = document.getElementById('toggleCategories'); + if (toggleCategoriesBtn) { + toggleCategoriesBtn.addEventListener('click', function() { + // Hier können Sie die gewünschte Funktionalität für den Kategorien-Button implementieren + console.log('Kategorien-Button wurde geklickt'); + }); + } +} + +// Neue, vereinfachte Version der initializeCategoriesPanel Funktion +function initializeCategoriesPanel() { + const toggleCategoriesBtn = document.getElementById('toggleCategories'); + if (toggleCategoriesBtn) { + toggleCategoriesBtn.addEventListener('click', function() { + // Hier können Sie die gewünschte Funktionalität für den Kategorien-Button implementieren + console.log('Kategorien-Button wurde geklickt'); + }); + } +} + +// Neue Funktionen für das Kategorien-Popup +function showCategoriesPopup(event) { + // Entferne existierendes Popup falls vorhanden + const existingPopup = document.querySelector('.categories-popup'); + if (existingPopup) { + existingPopup.remove(); + } + + // Erstelle neues Popup + const popup = document.createElement('div'); + popup.className = 'categories-popup'; + + // Sammle Kategorien und deren Knoten + const categories = new Map(); + cy.nodes().forEach(node => { + const category = node.data('category'); + if (category) { + if (!categories.has(category)) { + categories.set(category, { + color: node.data('color'), + icon: mindmapConfig.categories[category]?.icon || 'fa-solid fa-circle', + nodes: [] + }); + } + categories.get(category).nodes.push({ + id: node.id(), + name: node.data('label') || node.data('name'), + description: node.data('description') + }); + } + }); + + // Generiere HTML für das Popup + let html = ''; + categories.forEach((data, category) => { + html += ` +
+
+ + ${category} + (${data.nodes.length}) +
+
+ ${data.nodes.map(node => ` +
+ ${node.name} + ${node.description ? `${node.description}` : ''} +
+ `).join('')} +
+
+ `; + }); + + popup.innerHTML = html; + + // Positioniere das Popup + const buttonRect = event.target.getBoundingClientRect(); + popup.style.position = 'fixed'; + popup.style.top = `${buttonRect.bottom + 10}px`; + popup.style.left = `${buttonRect.left}px`; + + // Füge Event-Listener für Knoten-Klicks hinzu + popup.querySelectorAll('.category-node').forEach(nodeElement => { + nodeElement.addEventListener('click', () => { + const nodeId = nodeElement.getAttribute('data-node-id'); + const node = cy.getElementById(nodeId); + if (node.length > 0) { + cy.center(node); + cy.fit(node); + node.select(); + popup.remove(); + } + }); + }); + + // Füge Event-Listener für Klicks außerhalb des Popups hinzu + document.addEventListener('click', function closePopup(e) { + if (!popup.contains(e.target) && e.target !== event.target) { + popup.remove(); + document.removeEventListener('click', closePopup); + } + }); + + // Füge das Popup zum DOM hinzu + document.body.appendChild(popup); +} + +// Aktualisiere die initializeCategoriesPanel Funktion +function initializeCategoriesPanel() { + const toggleCategoriesBtn = document.getElementById('toggleCategories'); + if (toggleCategoriesBtn) { + toggleCategoriesBtn.addEventListener('click', showCategoriesPopup); + } +} + +// Füge CSS-Styles für das Popup hinzu +const categoriesPopupStyles = document.createElement('style'); +categoriesPopupStyles.textContent = ` + .categories-popup { + position: fixed; + background: rgba(15, 23, 42, 0.95); + border-radius: 0.5rem; + box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3); + z-index: 1000; + backdrop-filter: blur(10px); + border: 1px solid rgba(255, 255, 255, 0.1); + max-width: 400px; + max-height: 80vh; + overflow-y: auto; + padding: 1rem; + } + + .category-group { + margin-bottom: 1rem; + } + + .category-header { + display: flex; + align-items: center; + gap: 0.5rem; + padding: 0.5rem; + font-weight: 600; + border-radius: 0.25rem; + background: rgba(255, 255, 255, 0.05); + } + + .category-header i { + font-size: 1rem; + } + + .node-count { + margin-left: auto; + font-size: 0.9rem; + opacity: 0.7; + } + + .category-nodes { + margin-top: 0.5rem; + margin-left: 1rem; + } + + .category-node { + padding: 0.5rem; + margin: 0.25rem 0; + border-radius: 0.25rem; + cursor: pointer; + transition: all 0.2s ease; + } + + .category-node:hover { + background: rgba(255, 255, 255, 0.1); + } + + .node-name { + display: block; + color: white; + font-weight: 500; + } + + .node-description { + display: block; + font-size: 0.9rem; + color: rgba(255, 255, 255, 0.7); + margin-top: 0.25rem; + } +`; +document.head.appendChild(categoriesPopupStyles); + +// ... existing code ... \ No newline at end of file