From 0d8507a5c7a34eb53acd462ecbeb850ad1dddbbc Mon Sep 17 00:00:00 2001 From: bruno Date: Tue, 14 Jul 2026 22:05:53 -0400 Subject: [PATCH] feat: Gitea file tree visible in sidebar on ALL pages - base.html Alpine: added giteaWorkspace, giteaOwner, giteaRepo data - loadGiteaTree() fetches /api/gitea/.../tree and renders in sidebar - board._sidebar_data returns gitea_owner/gitea_repo - dashboard._sidebar_data returns gitea_owner/gitea_repo - alpine:initialized triggers loadGiteaTree on every page load --- app/routers/board.py | 2 ++ app/routers/dashboard.py | 4 +++- app/templates/base.html | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/app/routers/board.py b/app/routers/board.py index 73f0d15..0f97179 100644 --- a/app/routers/board.py +++ b/app/routers/board.py @@ -366,6 +366,8 @@ def _sidebar_data(request: Request, owner: str = "", repo: str = "") -> dict: "workspace_key": f"{gitea_owner}/{gitea_repo}" if gitea_workspace else ws_key, "workspace_pages": workspace_pages, "gitea_workspace": gitea_workspace, + "gitea_owner": gitea_owner, + "gitea_repo": gitea_repo, "local_ws_id": local_ws_id, "current_page": repo or "Dashboard", "last_edited": "now", "recent_pages": recent, "private_pages": private_items, diff --git a/app/routers/dashboard.py b/app/routers/dashboard.py index af9f6b4..1bed3f1 100644 --- a/app/routers/dashboard.py +++ b/app/routers/dashboard.py @@ -150,9 +150,11 @@ def _sidebar_data(request: Request, repos: list[dict]) -> dict: "workspace_name": ws, "workspace_initial": initial, "active_ws_name": active_ws_name, "workspace_key": f"{gitea_owner}/{gitea_repo}" if gitea_workspace else "", + "gitea_workspace": gitea_workspace, + "gitea_owner": gitea_owner, + "gitea_repo": gitea_repo, "local_ws_id": local_ws_id, "workspace_pages": workspace_pages, - "gitea_workspace": gitea_workspace, "current_page": "Dashboard", "last_edited": "now", "recent_pages": recent_pages, "private_pages": private_pages, diff --git a/app/templates/base.html b/app/templates/base.html index bad01c3..c39326e 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -577,6 +577,10 @@ lastEdited: '{{ last_edited }}', workspaceKey: '{{ workspace_key }}', localWsId: {{ local_ws_id|default(0) }}, + giteaWorkspace: {{ 'true' if gitea_workspace else 'false' }}, + giteaOwner: '{{ gitea_owner|default("") }}', + giteaRepo: '{{ gitea_repo|default("") }}', + giteaTree: [], // loaded client-side for sidebar currentView: 'home', contextMenu: { visible: false, x: 0, y: 0, pageId: null, pageName: '' }, contextActions: {}, @@ -872,6 +876,30 @@ .then(data => { window.location.href = `/pages/${data.id}`; }) .catch(err => { this.toast('Failed to create sub-page: ' + err.message, 'error'); }); }, + loadGiteaTree() { + if (!this.giteaWorkspace || !this.giteaOwner || !this.giteaRepo) return; + fetch('/api/gitea/projects/' + this.giteaOwner + '/' + this.giteaRepo + '/tree') + .then(r => r.json()) + .then(data => { + this.giteaTree = data.tree || []; + // Render tree items into the sidebar workspace section + var container = document.getElementById('sidebar-workspace-items'); + if (!container) return; + container.innerHTML = ''; + if (!this.giteaTree.length) { + container.innerHTML = ''; + return; + } + this.giteaTree.forEach(function(item) { + var li = document.createElement('li'); + li.className = 'sidebar-item'; + var icon = item.type === 'dir' ? '📁' : '📄'; + li.innerHTML = '' + icon + '' + item.name + ''; + container.appendChild(li); + }); + }) + .catch(function() { /* silently ignore */ }); + }, newPageInWorkspace() { const name = prompt('File name:'); if (!name || !name.trim()) return; @@ -1082,6 +1110,14 @@ setTimeout(function() { var active = document.querySelector('.sidebar-item.active'); if (active) active.scrollIntoView({ block: 'nearest', behavior: 'smooth' }); + // Load Gitea tree in sidebar if workspace is remote + var root = document.querySelector('[x-data]'); + if (root && root.__x) { + var state = root.__x.$data; + if (state && typeof state.loadGiteaTree === 'function') { + state.loadGiteaTree(); + } + } }, 300); });