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
This commit is contained in:
@@ -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_key": f"{gitea_owner}/{gitea_repo}" if gitea_workspace else ws_key,
|
||||||
"workspace_pages": workspace_pages,
|
"workspace_pages": workspace_pages,
|
||||||
"gitea_workspace": gitea_workspace,
|
"gitea_workspace": gitea_workspace,
|
||||||
|
"gitea_owner": gitea_owner,
|
||||||
|
"gitea_repo": gitea_repo,
|
||||||
"local_ws_id": local_ws_id,
|
"local_ws_id": local_ws_id,
|
||||||
"current_page": repo or "Dashboard", "last_edited": "now",
|
"current_page": repo or "Dashboard", "last_edited": "now",
|
||||||
"recent_pages": recent, "private_pages": private_items,
|
"recent_pages": recent, "private_pages": private_items,
|
||||||
|
|||||||
@@ -150,9 +150,11 @@ def _sidebar_data(request: Request, repos: list[dict]) -> dict:
|
|||||||
"workspace_name": ws, "workspace_initial": initial,
|
"workspace_name": ws, "workspace_initial": initial,
|
||||||
"active_ws_name": active_ws_name,
|
"active_ws_name": active_ws_name,
|
||||||
"workspace_key": f"{gitea_owner}/{gitea_repo}" if gitea_workspace else "",
|
"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,
|
"local_ws_id": local_ws_id,
|
||||||
"workspace_pages": workspace_pages,
|
"workspace_pages": workspace_pages,
|
||||||
"gitea_workspace": gitea_workspace,
|
|
||||||
"current_page": "Dashboard", "last_edited": "now",
|
"current_page": "Dashboard", "last_edited": "now",
|
||||||
"recent_pages": recent_pages,
|
"recent_pages": recent_pages,
|
||||||
"private_pages": private_pages,
|
"private_pages": private_pages,
|
||||||
|
|||||||
@@ -577,6 +577,10 @@
|
|||||||
lastEdited: '{{ last_edited }}',
|
lastEdited: '{{ last_edited }}',
|
||||||
workspaceKey: '{{ workspace_key }}',
|
workspaceKey: '{{ workspace_key }}',
|
||||||
localWsId: {{ local_ws_id|default(0) }},
|
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',
|
currentView: 'home',
|
||||||
contextMenu: { visible: false, x: 0, y: 0, pageId: null, pageName: '' },
|
contextMenu: { visible: false, x: 0, y: 0, pageId: null, pageName: '' },
|
||||||
contextActions: {},
|
contextActions: {},
|
||||||
@@ -872,6 +876,30 @@
|
|||||||
.then(data => { window.location.href = `/pages/${data.id}`; })
|
.then(data => { window.location.href = `/pages/${data.id}`; })
|
||||||
.catch(err => { this.toast('Failed to create sub-page: ' + err.message, 'error'); });
|
.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 = '<li class="sidebar-item empty-hint"><span class="page-icon">📄</span><span class="page-name text-dim">No files yet</span></li>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.giteaTree.forEach(function(item) {
|
||||||
|
var li = document.createElement('li');
|
||||||
|
li.className = 'sidebar-item';
|
||||||
|
var icon = item.type === 'dir' ? '📁' : '📄';
|
||||||
|
li.innerHTML = '<span class="page-icon">' + icon + '</span><span class="page-name">' + item.name + '</span>';
|
||||||
|
container.appendChild(li);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(function() { /* silently ignore */ });
|
||||||
|
},
|
||||||
newPageInWorkspace() {
|
newPageInWorkspace() {
|
||||||
const name = prompt('File name:');
|
const name = prompt('File name:');
|
||||||
if (!name || !name.trim()) return;
|
if (!name || !name.trim()) return;
|
||||||
@@ -1082,6 +1110,14 @@
|
|||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
var active = document.querySelector('.sidebar-item.active');
|
var active = document.querySelector('.sidebar-item.active');
|
||||||
if (active) active.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
|
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);
|
}, 300);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user