feature: move docs
This commit is contained in:
42
apps/server/internal/httpserver/static/move.js
Normal file
42
apps/server/internal/httpserver/static/move.js
Normal file
@@ -0,0 +1,42 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function apiDocumentPath(path) {
|
||||
return (path || '')
|
||||
.replace(/^\/+/, '')
|
||||
.split('/')
|
||||
.map(encodeURIComponent)
|
||||
.join('/');
|
||||
}
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
var button = event.target.closest('[data-move-path]');
|
||||
if (!button) return;
|
||||
|
||||
var currentPath = button.getAttribute('data-move-path');
|
||||
var baseHash = button.getAttribute('data-move-hash');
|
||||
var destination = window.prompt('Move document to:', currentPath);
|
||||
if (destination === null || destination.trim() === '' || destination.trim() === currentPath) return;
|
||||
|
||||
button.disabled = true;
|
||||
fetch('/api/documents/' + apiDocumentPath(currentPath) + '/move', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ path: destination.trim(), baseHash: baseHash }),
|
||||
})
|
||||
.then(function (response) {
|
||||
return response.json().then(function (data) {
|
||||
if (!response.ok) throw new Error(data.error || 'Move failed');
|
||||
return data;
|
||||
});
|
||||
})
|
||||
.then(function (data) {
|
||||
window.location.assign(data.url);
|
||||
})
|
||||
.catch(function (error) {
|
||||
window.alert(error.message || 'Failed to move document');
|
||||
button.disabled = false;
|
||||
});
|
||||
});
|
||||
})();
|
||||
@@ -142,8 +142,7 @@
|
||||
|
||||
function notificationURL(notification) {
|
||||
if (notification.resourceType !== 'document' || !notification.resourceId) return '';
|
||||
const path = notification.resourceId.replace(/^doc:/, '').split('/').map(encodeURIComponent).join('/');
|
||||
return '/docs/' + path;
|
||||
return '/documents/' + encodeURIComponent(notification.resourceId);
|
||||
}
|
||||
|
||||
// Listen for WebSocket notification events
|
||||
|
||||
@@ -298,6 +298,7 @@
|
||||
|
||||
const currentPath = documentShell ? documentShell.getAttribute("data-document-path") : null;
|
||||
const currentHash = documentShell ? documentShell.getAttribute("data-document-hash") : null;
|
||||
const currentDocumentID = documentShell ? documentShell.getAttribute("data-document-id") : null;
|
||||
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
|
||||
let reconnectTimer = null;
|
||||
|
||||
@@ -332,6 +333,11 @@
|
||||
|
||||
const change = payload.data;
|
||||
|
||||
if (change.type === "move" && currentDocumentID && change.documentId === currentDocumentID) {
|
||||
window.location.assign("/documents/" + encodeURIComponent(currentDocumentID));
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEditing && currentPath && change.path === currentPath) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user