fixed "duplicate subtree"

This commit is contained in:
zadam 2021-02-14 11:43:31 +01:00
parent f528799fed
commit 08cba1e1ce
6 changed files with 39 additions and 21 deletions

View file

@ -41,7 +41,7 @@ class Entity {
}
getUtcDateChanged() {
return this.utcDateModified || this.utcDateCreated;
return this.utcDateModified;
}
get repository() {

View file

@ -47,6 +47,7 @@ async function remove(url, sourceId) {
let i = 1;
const reqResolves = {};
const reqRejects = {};
let maxKnownEntityChangeId = 0;
@ -63,6 +64,7 @@ async function call(method, url, data, headers = {}) {
resp = await new Promise((resolve, reject) => {
reqResolves[requestId] = resolve;
reqRejects[requestId] = reject;
if (REQUEST_LOGGING_ENABLED) {
console.log(utils.now(), "Request #" + requestId + " to " + method + " " + url);
@ -96,6 +98,14 @@ async function call(method, url, data, headers = {}) {
return resp.body;
}
async function reportError(method, url, status, error) {
const message = "Error when calling " + method + " " + url + ": " + status + " - " + error;
const toastService = (await import("./toast.js")).default;
toastService.showError(message);
toastService.throwError(message);
}
function ajax(url, method, data, headers) {
return new Promise((res, rej) => {
const options = {
@ -117,11 +127,8 @@ function ajax(url, method, data, headers) {
headers: respHeaders
});
},
error: async (jqXhr, textStatus, error) => {
const message = "Error when calling " + method + " " + url + ": " + textStatus + " - " + error;
const toastService = (await import("./toast.js")).default;
toastService.showError(message);
toastService.throwError(message);
error: async (jqXhr, status, error) => {
await reportError(method, url, status, error);
rej(error);
}
@ -143,17 +150,25 @@ function ajax(url, method, data, headers) {
if (utils.isElectron()) {
const ipc = utils.dynamicRequire('electron').ipcRenderer;
ipc.on('server-response', (event, arg) => {
ipc.on('server-response', async (event, arg) => {
if (REQUEST_LOGGING_ENABLED) {
console.log(utils.now(), "Response #" + arg.requestId + ": " + arg.statusCode);
}
reqResolves[arg.requestId]({
body: arg.body,
headers: arg.headers
});
if (arg.statusCode >= 200 && arg.statusCode < 300) {
reqResolves[arg.requestId]({
body: arg.body,
headers: arg.headers
});
}
else {
await reportError(arg.method, arg.url, arg.statusCode, arg.body);
reqRejects[arg.requestId]();
}
delete reqResolves[arg.requestId];
delete reqRejects[arg.requestId];
});
}

View file

@ -30,6 +30,12 @@ const mentionSetup = {
const TPL = `
<div class="note-detail-editable-text note-detail-printable">
<style>
.note-detail-editable-text {
font-family: var(--detail-text-font-family);
padding-left: 12px;
padding-top: 10px;
}
.note-detail-editable-text a:hover {
cursor: pointer;
}
@ -53,11 +59,6 @@ const TPL = `
.note-detail-editable-text h6 { font-size: 1.1em; }
.note-detail-editable-text h6::before { content: "######\\2004"; color: var(--muted-text-color); }
.note-detail-editable-text {
font-family: var(--detail-text-font-family);
padding-left: 12px;
}
.note-detail-editable-text-editor {
padding-top: 10px;
border: 0 !important;

View file

@ -26,7 +26,8 @@ const TPL = `
.note-detail-readonly-text h6::before { content: "######\\2004"; color: var(--muted-text-color); }
.note-detail-readonly-text {
padding: 10px;
padding-left: 22px;
padding-top: 10px;
font-family: var(--detail-text-font-family);
position: relative;
}

View file

@ -26,6 +26,8 @@ function init(app) {
},
send: obj => {
event.sender.send('server-response', {
url: arg.url,
method: arg.method,
requestId: arg.requestId,
statusCode: res.statusCode,
headers: respHeaders,
@ -38,4 +40,4 @@ function init(app) {
});
}
module.exports = init;
module.exports = init;

View file

@ -759,7 +759,7 @@ function duplicateSubtree(origNoteId, newParentNoteId) {
throw new Error('Duplicating root is not possible');
}
log.info(`Duplicating ${origNote} subtree into ${newParentNoteId}`);
log.info(`Duplicating ${origNoteId} subtree into ${newParentNoteId}`);
const origNote = repository.getNote(origNoteId);
// might be null if orig note is not in the target newParentNoteId
@ -793,7 +793,7 @@ function duplicateSubtreeWithoutRoot(origNoteId, newNoteId) {
function duplicateSubtreeInner(origNote, origBranch, newParentNoteId, noteIdMapping) {
if (origNote.isProtected && !protectedSessionService.isProtectedSessionAvailable()) {
throw new Error(`Cannot duplicate note=${origNote.noteId} because it is protected and protected session is not available`);
throw new Error(`Cannot duplicate note=${origNote.noteId} because it is protected and protected session is not available. Enter protected session and try again.`);
}
const newNote = new Note(origNote);
@ -821,7 +821,6 @@ function duplicateSubtreeInner(origNote, origBranch, newParentNoteId, noteIdMapp
for (const attribute of origNote.getOwnedAttributes()) {
const attr = new Attribute(attribute);
attr.attributeId = undefined; // force creation of new attribute
attr.utcDateCreated = dateUtils.utcNowDateTime();
attr.noteId = newNote.noteId;
// if relation points to within the duplicated tree then replace the target to the duplicated note