note revision sync fix

This commit is contained in:
zadam 2019-11-09 16:51:51 +01:00
parent da92809299
commit 179d530ea9
5 changed files with 21 additions and 14 deletions

View File

@ -130,6 +130,14 @@ class NoteRevision extends Entity {
await syncTableService.addNoteRevisionContentSync(this.noteRevisionId); await syncTableService.addNoteRevisionContentSync(this.noteRevisionId);
} }
beforeSaving() {
super.beforeSaving();
if (this.isChanged) {
this.utcDateModified = dateUtils.utcNowDateTime();
}
}
// cannot be static! // cannot be static!
updatePojo(pojo) { updatePojo(pojo) {
if (pojo.isProtected) { if (pojo.isProtected) {

View File

@ -37,7 +37,7 @@ async function loadNoteRevisions(noteId, noteRevisionId) {
for (const item of revisionItems) { for (const item of revisionItems) {
$list.append($('<option>', { $list.append($('<option>', {
value: item.noteRevisionId, value: item.noteRevisionId,
text: item.dateLastEdited.substr(0, 16) + (item.isErased ? ' (erased)' : '') text: item.dateLastEdited.substr(0, 16)
})); }));
} }
@ -60,25 +60,20 @@ $list.on('change', async () => {
$titleButtons.empty(); $titleButtons.empty();
$content.empty(); $content.empty();
if (revisionItem.isErased) {
$title.text('This revision has been erased');
return;
}
$title.html(revisionItem.title); $title.html(revisionItem.title);
const $eraseRevisionButton = $('<button class="btn btn-sm" type="button">Erase this revision</button>'); const $eraseRevisionButton = $('<button class="btn btn-sm" type="button">Delete this revision</button>');
$eraseRevisionButton.on('click', async () => { $eraseRevisionButton.on('click', async () => {
const confirmDialog = await import('../dialogs/confirm.js'); const confirmDialog = await import('../dialogs/confirm.js');
const text = 'Do you want to erase this revision? This action will erase revision title and content, but still preserve revision metadata.'; const text = 'Do you want to delete this revision? This action will delete revision title and content, but still preserve revision metadata.';
if (await confirmDialog.confirm(text)) { if (await confirmDialog.confirm(text)) {
await server.remove(`notes/${revisionItem.noteId}/revisions/${revisionItem.noteRevisionId}`); await server.remove(`notes/${revisionItem.noteId}/revisions/${revisionItem.noteRevisionId}`);
loadNoteRevisions(revisionItem.noteId); loadNoteRevisions(revisionItem.noteId);
toastService.showMessage('Note revision has been erased.'); toastService.showMessage('Note revision has been deleted.');
} }
}); });
@ -139,13 +134,13 @@ $list.on('change', async () => {
$eraseAllRevisionsButton.on('click', async () => { $eraseAllRevisionsButton.on('click', async () => {
const confirmDialog = await import('../dialogs/confirm.js'); const confirmDialog = await import('../dialogs/confirm.js');
const text = 'Do you want to erase all revision of this note? This action will erase revision title and content, but still preserve revision metadata.'; const text = 'Do you want to delete all revisions of this note? This action will erase revision title and content, but still preserve revision metadata.';
if (await confirmDialog.confirm(text)) { if (await confirmDialog.confirm(text)) {
await server.remove(`notes/${note.noteId}/revisions`); await server.remove(`notes/${note.noteId}/revisions`);
$dialog.modal('hide'); $dialog.modal('hide');
toastService.showMessage('Note revisions has been erased.'); toastService.showMessage('Note revisions has been deleted.');
} }
}); });

View File

@ -83,6 +83,9 @@ async function downloadNoteRevision(req, res) {
res.send(await noteRevision.getContent()); res.send(await noteRevision.getContent());
} }
/**
* @param {NoteRevision} noteRevision
*/
async function eraseOneNoteRevision(noteRevision) { async function eraseOneNoteRevision(noteRevision) {
noteRevision.isErased = true; noteRevision.isErased = true;
noteRevision.title = null; noteRevision.title = null;

View File

@ -255,6 +255,7 @@ const primaryKeys = {
"note_contents": "noteId", "note_contents": "noteId",
"branches": "branchId", "branches": "branchId",
"note_revisions": "noteRevisionId", "note_revisions": "noteRevisionId",
"note_revision_contents": "noteRevisionId",
"recent_notes": "noteId", "recent_notes": "noteId",
"api_tokens": "apiTokenId", "api_tokens": "apiTokenId",
"options": "name", "options": "name",
@ -278,7 +279,7 @@ async function getEntityRow(entityName, entityId) {
throw new Error(`Entity ${entityName} ${entityId} not found.`); throw new Error(`Entity ${entityName} ${entityId} not found.`);
} }
if (['note_contents', 'note_revisions'].includes(entityName) && entity.content !== null) { if (['note_contents', 'note_revision_contents'].includes(entityName) && entity.content !== null) {
if (typeof entity.content === 'string') { if (typeof entity.content === 'string') {
entity.content = Buffer.from(entity.content, 'UTF-8'); entity.content = Buffer.from(entity.content, 'UTF-8');
} }

View File

@ -6,8 +6,8 @@
<button class="btn btn-xs" <button class="btn btn-xs"
id="note-revisions-erase-all-revisions-button" id="note-revisions-erase-all-revisions-button"
title="Erase all revisions of this note" title="Delete all revisions of this note"
style="padding: 0 10px 0 10px;" type="button">Erase all revisions</button> style="padding: 0 10px 0 10px;" type="button">Delete all revisions</button>
<button class="help-button" type="button" data-help-page="Note-revisions" title="Help on Note revisions">?</button> <button class="help-button" type="button" data-help-page="Note-revisions" title="Help on Note revisions">?</button>