Commit 8afdedea authored by Jan Koester's avatar Jan Koester
Browse files

editor: Dokumente auch ueber die Projektgruppe zuordnen, Projekt beim Oeffnen waehlen

Die Dokumentliste filterte nur nach Projektname; per MCP (new_document +
save_connection, z. B. SchimmelBlog) angelegte Dokumente tragen aber die
Gruppe des Projekts und fehlten deshalb im Projekt. Beides zaehlt jetzt.
Beim Oeffnen eines Dokuments (Liste oder ?document=) wird das zugehoerige
Projekt gewaehlt und verbunden.

Co-Authored-By: default avatarClaude Opus 5.5 <noreply@anthropic.com>
parent d4a861b7
Loading
Loading
Loading
Loading
+42 −2
Changes for editor/html/js/editor.js: 42 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -302,6 +302,7 @@
            currentDocGroup = (resp && resp.group) || '';
            dropDocumentParam();
            refreshDocument();
            selectProjectForDocGroup(currentDocGroup);
        }).catch(function(err) {
            try { sessionStorage.removeItem(OPEN_DOCUMENT_STORAGE_KEY); } catch(e) {}
            console.error('Failed to open document ' + docId + ':', err);
@@ -1799,6 +1800,7 @@
            var id = this.getAttribute('data-id');
            EditorApi.loadDocument(id).then(function(resp) {
                currentDocGroup = resp.group || '';
                selectProjectForDocGroup(currentDocGroup);
                document.getElementById('open-dialog').close();
                Canvas.clearSelection(); DocumentTree.clearSelection();
                PropertiesPanel.clear();
@@ -2694,13 +2696,51 @@
        if (!listEl) return;
        EditorApi.listDocuments().then(function(resp) {
            var docs = resp.documents || [];
            if (currentProjectName) {
                docs = docs.filter(function(d) { return (d.group || '') === currentProjectName; });
            if (currentProjectId) {
                var proj = findProject(currentProjectId);
                docs = docs.filter(function(d) { return docBelongsToProject(d.group || '', proj); });
            }
            renderDocList(docs);
        });
    }

    function findProject(id) {
        for (var i = 0; i < projectsCache.length; i++) {
            if (projectsCache[i].id === id) return projectsCache[i];
        }
        return null;
    }

    // A document belongs to a project when its group is the project's name (documents
    // saved from the UI, see openSaveDialog) or the project's group (documents created
    // via MCP new_document + save_connection, e.g. by the SchimmelBlog plugin).
    function docBelongsToProject(docGroup, proj) {
        if (!proj || !docGroup) return false;
        return docGroup === (proj.name || '') || docGroup === (proj.group || '');
    }

    // Selects (and connects) the project an opened document belongs to, so a deep
    // link lands in the right project. Keeps the current one if it already matches.
    function selectProjectForDocGroup(docGroup) {
        if (!docGroup) return;
        var pick = function() {
            if (docBelongsToProject(docGroup, findProject(currentProjectId))) {
                if (!connectedConnections[currentProjectId]) connectCurrentProject();
                return;
            }
            var byName = null, byGroup = null;
            for (var i = 0; i < projectsCache.length; i++) {
                var p = projectsCache[i];
                if (!byName && p.name === docGroup) byName = p;
                if (!byGroup && p.group === docGroup) byGroup = p;
            }
            var proj = byName || byGroup;
            if (proj) onProjectSelected(proj.id);
        };
        if (projectsCache.length) pick();
        else loadProjectSelectOptions(pick);
    }

    // --- Project manager (merged into the "\u00d6ffnen"/#open-dialog modal) ---
    // The sidebar (#conn-list) picks the active project \u2014 selecting one reuses
    // onProjectSelected() (auto-connect, toolbar sync) and refreshes the template list