feat: Enhance WebDAV file management and UI
- Add functionality to create new collections via API - Implement copy and move operations between collections - Improve image rendering in markdown preview with relative path resolution - Add support for previewing binary files (images, PDFs) - Refactor modal styling to use flat buttons and improve accessibility
This commit is contained in:
@@ -26,12 +26,21 @@ class CollectionSelector {
|
||||
this.select.appendChild(option);
|
||||
});
|
||||
|
||||
// Try to restore previously selected collection from localStorage
|
||||
const savedCollection = localStorage.getItem(this.storageKey);
|
||||
// Determine which collection to select (priority: URL > localStorage > first)
|
||||
let collectionToSelect = collections[0]; // Default to first
|
||||
|
||||
if (savedCollection && collections.includes(savedCollection)) {
|
||||
collectionToSelect = savedCollection;
|
||||
// Check URL first (highest priority)
|
||||
const urlCollection = this.getCollectionFromURL();
|
||||
if (urlCollection && collections.includes(urlCollection)) {
|
||||
collectionToSelect = urlCollection;
|
||||
Logger.info(`Using collection from URL: ${urlCollection}`);
|
||||
} else {
|
||||
// Fall back to localStorage
|
||||
const savedCollection = localStorage.getItem(this.storageKey);
|
||||
if (savedCollection && collections.includes(savedCollection)) {
|
||||
collectionToSelect = savedCollection;
|
||||
Logger.info(`Using collection from localStorage: ${savedCollection}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (collections.length > 0) {
|
||||
@@ -48,14 +57,17 @@ class CollectionSelector {
|
||||
// Save to localStorage
|
||||
localStorage.setItem(this.storageKey, collection);
|
||||
this.webdavClient.setCollection(collection);
|
||||
|
||||
|
||||
Logger.info(`Collection changed to: ${collection}`);
|
||||
|
||||
|
||||
// Update URL to reflect collection change
|
||||
this.updateURLForCollection(collection);
|
||||
|
||||
if (this.onChange) {
|
||||
this.onChange(collection);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Logger.debug(`Loaded ${collections.length} collections`);
|
||||
} catch (error) {
|
||||
Logger.error('Failed to load collections:', error);
|
||||
@@ -83,9 +95,12 @@ class CollectionSelector {
|
||||
this.select.value = collection;
|
||||
localStorage.setItem(this.storageKey, collection);
|
||||
this.webdavClient.setCollection(collection);
|
||||
|
||||
|
||||
Logger.info(`Collection set to: ${collection}`);
|
||||
|
||||
|
||||
// Update URL to reflect collection change
|
||||
this.updateURLForCollection(collection);
|
||||
|
||||
if (this.onChange) {
|
||||
this.onChange(collection);
|
||||
}
|
||||
@@ -93,6 +108,43 @@ class CollectionSelector {
|
||||
Logger.warn(`Collection "${collection}" not found in available collections`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the browser URL to reflect the current collection
|
||||
* @param {string} collection - The collection name
|
||||
*/
|
||||
updateURLForCollection(collection) {
|
||||
// Get current URL parameters
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const isEditMode = urlParams.get('edit') === 'true';
|
||||
|
||||
// Build new URL with collection
|
||||
let url = `/${collection}/`;
|
||||
if (isEditMode) {
|
||||
url += '?edit=true';
|
||||
}
|
||||
|
||||
// Use pushState to update URL without reloading
|
||||
window.history.pushState({ collection, filePath: null }, '', url);
|
||||
Logger.debug(`Updated URL to: ${url}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract collection name from current URL
|
||||
* URL format: /<collection>/ or /<collection>/<file_path>
|
||||
* @returns {string|null} The collection name or null if not found
|
||||
*/
|
||||
getCollectionFromURL() {
|
||||
const pathname = window.location.pathname;
|
||||
const parts = pathname.split('/').filter(p => p); // Remove empty parts
|
||||
|
||||
if (parts.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// First part is the collection
|
||||
return parts[0];
|
||||
}
|
||||
}
|
||||
|
||||
// Make CollectionSelector globally available
|
||||
|
||||
Reference in New Issue
Block a user