diff --git a/app/templates/local_workspace.html b/app/templates/local_workspace.html index 64932d2..a21e589 100644 --- a/app/templates/local_workspace.html +++ b/app/templates/local_workspace.html @@ -311,20 +311,20 @@ -
| Name | @@ -543,7 +543,7 @@Modified | |
|---|---|---|
| @@ -556,7 +556,7 @@ |
| Name | @@ -568,7 +568,7 @@Tags | |
|---|---|---|
| @@ -591,8 +591,8 @@ |
- In {{ workspace_name }} + In {{ workspace_name }} / /
@@ -748,6 +748,7 @@ document.addEventListener('alpine:init', function() { currentFolder: {{ current_folder_id }}, searchQuery: '', filterType: '', + folderStack: [], // Inline rename renamingId: null, @@ -790,7 +791,22 @@ document.addEventListener('alpine:init', function() { // Path bar get pathValue() { - return '/workspace/' + this.breadcrumb.map(function(b){return b.name}).join('/'); + return '/workspace/' + this.folderStack.filter(function(b){return b.id > 0}).map(function(b){return b.name}).join('/'); + }, + + async navigateToRoot() { + this.folderStack = [{id: 0, name: 'Root'}]; + this.navIndex = 0; + this._saveExpandedState(); + await this._loadFolder(0); + }, + + async navigateToBreadcrumb(idx) { + this.folderStack = this.folderStack.slice(0, idx + 1); + this.navIndex = idx; + this._saveExpandedState(); + var entry = this.folderStack[idx]; + await this._loadFolder(entry ? entry.id : 0); }, // Drag indicators @@ -808,7 +824,7 @@ document.addEventListener('alpine:init', function() { navHistory: [], navIndex: -1, get canGoBack() { return this.navIndex > 0; }, - get canGoForward() { return this.navIndex < this.navHistory.length - 1; }, + get canGoForward() { return this.navIndex < this.folderStack.length - 1; }, // Preview popup previewVisible: false, @@ -841,9 +857,17 @@ document.addEventListener('alpine:init', function() { this.displayTree = roots; this.breadcrumb = d.breadcrumb || []; this.loaded = true; - // Initialize nav history - this.navHistory = [this.currentFolder || 0]; - this.navIndex = 0; + // Initialize folder stack from breadcrumb + this.folderStack = (this.breadcrumb || []).map(function(b) { return {id: b.id, name: b.name}; }); + if (this.currentFolder && this.currentFolder > 0 && this.folderStack.length === 0) { + this.folderStack = [{id: 0, name: 'Root'}]; + // Add current folder name from tree if present + if (this.tree.length > 0) { + // The current folder's children are in breadcrumb, parent is the last + } + } + this.navIndex = this.folderStack.length > 0 ? this.folderStack.length - 1 : 0; + if (this.folderStack.length === 0) this.folderStack = [{id: 0, name: 'Root'}]; // Expose globally for renderChildren onclick handlers window._wsData = this; // Listen for online/offline @@ -1159,37 +1183,69 @@ document.addEventListener('alpine:init', function() { } }, - navigateToFolder(id) { - // Push to nav history - if (this.navIndex < this.navHistory.length - 1) { - this.navHistory = this.navHistory.slice(0, this.navIndex + 1); + async navigateToFolder(id) { + // Find the folder name for the stack + var folderNode = this._findNodeById(this.tree, id); + var folderName = folderNode ? folderNode.name : 'Folder'; + // Push to folder stack for breadcrumb + if (this.navIndex < this.folderStack.length - 1) { + this.folderStack = this.folderStack.slice(0, this.navIndex + 1); } - this.navHistory.push(id); - this.navIndex = this.navHistory.length - 1; - this._saveExpandedState(); - window.location = '/local-workspace?folder=' + id; + this.folderStack.push({id: id, name: folderName}); + this.navIndex = this.folderStack.length - 1; + // Fetch children of this folder + await this._loadFolder(id); }, - goBack() { + async goToParent() { + if (this.folderStack.length <= 1) { await this._loadFolder(0); return; } + this.folderStack.pop(); + this.navIndex = this.folderStack.length - 1; + var parentId = this.folderStack.length > 0 ? this.folderStack[this.folderStack.length - 1].id : 0; + await this._loadFolder(parentId); + }, + + async _loadFolder(folderId) { + var url = '/api/local-workspace/tree'; + if (folderId && folderId > 0) url += '?folder=' + folderId; + try { + var r = await fetch(url); + var d = await r.json(); + var roots = d.tree || []; + this._markTree(roots, 0); + this.tree = roots; + this.displayTree = [...roots]; + this.breadcrumb = d.breadcrumb || []; + this.currentFolder = folderId || 0; + this._saveExpandedState(); + this.previewItem = null; + } catch(e) { console.error('Load folder error:', e); } + }, + + _findNodeById(nodes, id) { + for (var i=0; i