93 lines
2.8 KiB
JavaScript
93 lines
2.8 KiB
JavaScript
/**
|
|
* 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;
|
|
}
|