diff --git a/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml b/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml index f9cd3efb1..526cb2feb 100644 --- a/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml +++ b/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml @@ -309,359 +309,365 @@ parentNoteId INT|0s 1 - + 5 INT|0s 1 0 - + 6 - TEXT|0s + INT|0s 1 + 0 - + 7 TEXT|0s 1 - + 8 TEXT|0s 1 - + 9 TEXT|0s 1 - + 10 TEXT|0s 1 - + 11 TEXT|0s 1 - '' - + 12 TEXT|0s 1 '' - + 13 TEXT|0s 1 '' - + + 14 + TEXT|0s + 1 + '' + + 1 noteRevisionId 1 - + noteId - + utcDateLastEdited - + utcDateCreated - + dateLastEdited - + dateCreated - + noteRevisionId 1 sqlite_autoindex_note_revisions_1 - + 1 TEXT|0s 1 - + 2 TEXT|0s 1 "note" - + 3 INT|0s 1 - + 4 INT|0s 1 0 - + 5 TEXT|0s 1 'text' - + 6 TEXT|0s 1 'text/html' - + 7 TEXT|0s 1 "" - + 8 INT|0s 1 0 - + 9 INT|0s 1 0 - + 10 TEXT|0s 1 - + 11 TEXT|0s 1 - + 12 TEXT|0s 1 - + 13 TEXT|0s 1 - + 1 noteId 1 - + title - + type - + isDeleted - + dateCreated - + dateModified - + utcDateCreated - + utcDateModified - + noteId 1 sqlite_autoindex_notes_1 - + 1 TEXT|0s 1 - + 2 TEXT|0s - + 3 INTEGER|0s 1 0 - + 4 TEXT|0s 1 "" - + 5 TEXT|0s 1 - + 6 TEXT|0s 1 - + 1 name 1 - + name 1 sqlite_autoindex_options_1 - + 1 TEXT|0s 1 - + 2 TEXT|0s 1 - + 3 TEXT|0s 1 "" - + 4 TEXT|0s 1 - + 5 INT|0s - + 1 noteId 1 - + noteId 1 sqlite_autoindex_recent_notes_1 - + 1 TEXT|0s 1 - + 2 TEXT|0s 1 - + 1 sourceId 1 - + sourceId 1 sqlite_autoindex_source_ids_1 - + 1 text|0s - + 2 text|0s - + 3 text|0s - + 4 int|0s - + 5 text|0s - + 1 - + 2 - + 1 INTEGER|0s 1 1 - + 2 TEXT|0s 1 - + 3 TEXT|0s 1 - + 4 TEXT|0s 1 - + 5 TEXT|0s 1 - + entityName entityId 1 - + utcSyncDate - + id 1 diff --git a/db/migrations/0153__add_isErased_to_note_revision.sql b/db/migrations/0153__add_isErased_to_note_revision.sql new file mode 100644 index 000000000..0327d251c --- /dev/null +++ b/db/migrations/0153__add_isErased_to_note_revision.sql @@ -0,0 +1,26 @@ +CREATE TABLE IF NOT EXISTS "note_revisions_mig" (`noteRevisionId` TEXT NOT NULL PRIMARY KEY, + `noteId` TEXT NOT NULL, + `title` TEXT, + `contentLength` INT NOT NULL, + `isErased` INT NOT NULL DEFAULT 0, + `isProtected` INT NOT NULL DEFAULT 0, + `utcDateLastEdited` TEXT NOT NULL, + `utcDateCreated` TEXT NOT NULL, + `utcDateModified` TEXT NOT NULL, + `dateLastEdited` TEXT NOT NULL, + `dateCreated` TEXT NOT NULL, + type TEXT DEFAULT '' NOT NULL, + mime TEXT DEFAULT '' NOT NULL, + hash TEXT DEFAULT '' NOT NULL); + +INSERT INTO note_revisions_mig (noteRevisionId, noteId, title, contentLength, isErased, isProtected, utcDateLastEdited, utcDateCreated, utcDateModified, dateLastEdited, dateCreated, type, mime, hash) +SELECT noteRevisionId, noteId, title, contentLength, 0, isProtected, utcDateLastEdited, utcDateCreated, utcDateModified, dateLastEdited, dateCreated, type, mime, hash FROM note_revisions; + +DROP TABLE note_revisions; +ALTER TABLE note_revisions_mig RENAME TO note_revisions; + +CREATE INDEX `IDX_note_revisions_noteId` ON `note_revisions` (`noteId`); +CREATE INDEX `IDX_note_revisions_utcDateCreated` ON `note_revisions` (`utcDateCreated`); +CREATE INDEX `IDX_note_revisions_utcDateLastEdited` ON `note_revisions` (`utcDateLastEdited`); +CREATE INDEX `IDX_note_revisions_dateCreated` ON `note_revisions` (`dateCreated`); +CREATE INDEX `IDX_note_revisions_dateLastEdited` ON `note_revisions` (`dateLastEdited`); \ No newline at end of file diff --git a/src/entities/note_revision.js b/src/entities/note_revision.js index 8de57a76b..f52afa1e7 100644 --- a/src/entities/note_revision.js +++ b/src/entities/note_revision.js @@ -16,8 +16,9 @@ const syncTableService = require('../services/sync_table'); * @property {string} type * @property {string} mime * @property {string} title - * @property {int} contentLength - length of content - * @property {string} isProtected + * @property {int} contentLength + * @property {boolean} isErased + * @property {boolean} isProtected * @property {string} dateLastEdited * @property {string} dateCreated * @property {string} utcDateLastEdited @@ -29,7 +30,7 @@ const syncTableService = require('../services/sync_table'); class NoteRevision extends Entity { static get entityName() { return "note_revisions"; } static get primaryKeyName() { return "noteRevisionId"; } - static get hashedProperties() { return ["noteRevisionId", "noteId", "title", "contentLength", "isProtected", "dateLastEdited", "dateCreated", "utcDateLastEdited", "utcDateCreated", "utcDateModified"]; } + static get hashedProperties() { return ["noteRevisionId", "noteId", "title", "contentLength", "isErased", "isProtected", "dateLastEdited", "dateCreated", "utcDateLastEdited", "utcDateCreated", "utcDateModified"]; } constructor(row) { super(row); @@ -103,7 +104,7 @@ class NoteRevision extends Entity { async setContent(content) { // force updating note itself so that utcDateModified is represented correctly even for the content this.forcedChange = true; - this.contentLength = content.length; + this.contentLength = content === null ? 0 : content.length; await this.save(); this.content = content; diff --git a/src/public/javascripts/dialogs/note_revisions.js b/src/public/javascripts/dialogs/note_revisions.js index a62f2b617..9c315cb7e 100644 --- a/src/public/javascripts/dialogs/note_revisions.js +++ b/src/public/javascripts/dialogs/note_revisions.js @@ -1,12 +1,14 @@ import noteDetailService from '../services/note_detail.js'; import utils from '../services/utils.js'; import server from '../services/server.js'; +import toastService from "../services/toast.js"; const $dialog = $("#note-revisions-dialog"); const $list = $("#note-revision-list"); const $content = $("#note-revision-content"); const $title = $("#note-revision-title"); const $titleButtons = $("#note-revision-title-buttons"); +const $eraseAllRevisionsButton = $("#note-revisions-erase-all-revisions-button"); let revisionItems = []; let note; @@ -22,6 +24,10 @@ export async function showNoteRevisionsDialog(noteId, noteRevisionId) { $dialog.modal(); + await loadNoteRevisions(noteId, noteRevisionId); +} + +async function loadNoteRevisions(noteId, noteRevisionId) { $list.empty(); $content.empty(); @@ -31,7 +37,7 @@ export async function showNoteRevisionsDialog(noteId, noteRevisionId) { for (const item of revisionItems) { $list.append($('