✨ feat: erweitere die Mindmap-API zur dynamischen Erstellung und Anzeige wissenschaftlicher Knoten sowie zur Verbesserung der Fehlerbehandlung. Füge neues Skript zur Aktualisierung der Mindmap hinzu.
This commit is contained in:
93
static/js/update_mindmap.js
Normal file
93
static/js/update_mindmap.js
Normal file
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* Update Mindmap
|
||||
* Dieses Skript fügt die neuen wissenschaftlichen Knoten zur Mindmap hinzu
|
||||
* und stellt sicher, dass sie korrekt angezeigt werden.
|
||||
*/
|
||||
|
||||
// Warte bis DOM geladen ist
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Prüfe, ob wir auf der Mindmap-Seite sind
|
||||
const cyContainer = document.getElementById('cy');
|
||||
|
||||
if (!cyContainer) {
|
||||
console.log('Kein Mindmap-Container gefunden, überspringe Initialisierung.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Auf das Laden der Mindmap warten
|
||||
document.addEventListener('mindmap-loaded', function() {
|
||||
console.log('Mindmap geladen, füge wissenschaftliche Knoten hinzu...');
|
||||
enhanceMindmap();
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Erweitert die Mindmap mit den neu hinzugefügten wissenschaftlichen Knoten
|
||||
*/
|
||||
function enhanceMindmap() {
|
||||
// Auf die bestehende Cytoscape-Instanz zugreifen
|
||||
const cy = window.cy;
|
||||
|
||||
if (!cy) {
|
||||
console.error('Keine Cytoscape-Instanz gefunden.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Aktualisiere das Layout mit zusätzlichem Platz für die neuen Knoten
|
||||
cy.layout({
|
||||
name: 'cose',
|
||||
animate: true,
|
||||
animationDuration: 800,
|
||||
nodeDimensionsIncludeLabels: true,
|
||||
padding: 100,
|
||||
spacingFactor: 1.8,
|
||||
randomize: false,
|
||||
fit: true
|
||||
}).run();
|
||||
|
||||
console.log('Mindmap wurde erfolgreich aktualisiert!');
|
||||
|
||||
// Wenn ein Wissen-Knoten existiert, sicherstellen, dass er im Zentrum ist
|
||||
const rootNode = cy.getElementById('1');
|
||||
if (rootNode.length > 0) {
|
||||
cy.center(rootNode);
|
||||
}
|
||||
}
|
||||
|
||||
// Hilfe-Funktion zum Hinzufügen eines Flash-Hinweises
|
||||
function showFlash(message, type = 'info') {
|
||||
const flashContainer = document.getElementById('flash-messages') || createFlashContainer();
|
||||
|
||||
const flashMsg = document.createElement('div');
|
||||
flashMsg.className = `flash-message flash-${type} mb-2 p-3 rounded`;
|
||||
flashMsg.innerHTML = `
|
||||
<div class="flex items-center justify-between">
|
||||
<div>${message}</div>
|
||||
<button class="close-flash ml-2">×</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
flashContainer.appendChild(flashMsg);
|
||||
|
||||
// Nach 5 Sekunden automatisch ausblenden
|
||||
setTimeout(() => {
|
||||
flashMsg.style.opacity = '0';
|
||||
setTimeout(() => flashMsg.remove(), 300);
|
||||
}, 5000);
|
||||
|
||||
// Close-Button
|
||||
const closeBtn = flashMsg.querySelector('.close-flash');
|
||||
closeBtn.addEventListener('click', () => {
|
||||
flashMsg.style.opacity = '0';
|
||||
setTimeout(() => flashMsg.remove(), 300);
|
||||
});
|
||||
}
|
||||
|
||||
// Hilfsfunktion zum Erstellen eines Flash-Containers, falls keiner existiert
|
||||
function createFlashContainer() {
|
||||
const container = document.createElement('div');
|
||||
container.id = 'flash-messages';
|
||||
container.className = 'fixed top-4 right-4 z-50 w-64';
|
||||
document.body.appendChild(container);
|
||||
return container;
|
||||
}
|
||||
Reference in New Issue
Block a user