diff --git a/db/migrations/0217__note_attachments.sql b/db/migrations/0217__note_attachments.sql index e98ae1045..374ace9b6 100644 --- a/db/migrations/0217__note_attachments.sql +++ b/db/migrations/0217__note_attachments.sql @@ -1,6 +1,6 @@ -CREATE TABLE IF NOT EXISTS "note_ancillaries" +CREATE TABLE IF NOT EXISTS "note_attachments" ( - noteAncillaryId TEXT not null primary key, + noteAttachmentId TEXT not null primary key, noteId TEXT not null, name TEXT not null, mime TEXT not null, @@ -10,7 +10,7 @@ CREATE TABLE IF NOT EXISTS "note_ancillaries" isDeleted INT not null, `deleteId` TEXT DEFAULT NULL); -CREATE INDEX IDX_note_ancillaries_name - on note_ancillaries (name); -CREATE UNIQUE INDEX IDX_note_ancillaries_noteId_name - on note_ancillaries (noteId, name); +CREATE INDEX IDX_note_attachments_name + on note_attachments (name); +CREATE UNIQUE INDEX IDX_note_attachments_noteId_name + on note_attachments (noteId, name); diff --git a/db/schema.sql b/db/schema.sql index bf8225c2e..10008f2b2 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -112,9 +112,9 @@ CREATE TABLE IF NOT EXISTS "recent_notes" notePath TEXT not null, utcDateCreated TEXT not null ); -CREATE TABLE IF NOT EXISTS "note_ancillaries" +CREATE TABLE IF NOT EXISTS "note_attachments" ( - noteAncillaryId TEXT not null primary key, + noteAttachmentId TEXT not null primary key, noteId TEXT not null, name TEXT not null, mime TEXT not null, @@ -123,7 +123,7 @@ CREATE TABLE IF NOT EXISTS "note_ancillaries" isDeleted INT not null, `deleteId` TEXT DEFAULT NULL); -CREATE INDEX IDX_note_ancillaries_name - on note_ancillaries (name); -CREATE UNIQUE INDEX IDX_note_ancillaries_noteId_name - on note_ancillaries (noteId, name); +CREATE INDEX IDX_note_attachments_name + on note_attachments (name); +CREATE UNIQUE INDEX IDX_note_attachments_noteId_name + on note_attachments (noteId, name); diff --git a/src/becca/becca.js b/src/becca/becca.js index f40a40dec..91fdcbb61 100644 --- a/src/becca/becca.js +++ b/src/becca/becca.js @@ -121,12 +121,12 @@ class Becca { return row ? new BNoteRevision(row) : null; } - /** @returns {BNoteAncillary|null} */ - getNoteAncillary(noteAncillaryId) { - const row = sql.getRow("SELECT * FROM note_ancillaries WHERE noteAncillaryId = ?", [noteAncillaryId]); + /** @returns {BNoteAttachment|null} */ + getNoteAttachment(noteAttachmentId) { + const row = sql.getRow("SELECT * FROM note_attachments WHERE noteAttachmentId = ?", [noteAttachmentId]); - const BNoteAncillary = require("./entities/bnote_attachment.js"); // avoiding circular dependency problems - return row ? new BNoteAncillary(row) : null; + const BNoteAttachment = require("./entities/bnote_attachment.js"); // avoiding circular dependency problems + return row ? new BNoteAttachment(row) : null; } /** @returns {BOption|null} */ @@ -151,8 +151,8 @@ class Becca { if (entityName === 'note_revisions') { return this.getNoteRevision(entityId); - } else if (entityName === 'note_ancillaries') { - return this.getNoteAncillary(entityId); + } else if (entityName === 'note_attachments') { + return this.getNoteAttachment(entityId); } const camelCaseEntityName = entityName.toLowerCase().replace(/(_[a-z])/g, diff --git a/src/becca/entities/bbranch.js b/src/becca/entities/bbranch.js index 06912b9fb..f1ad72dc3 100644 --- a/src/becca/entities/bbranch.js +++ b/src/becca/entities/bbranch.js @@ -198,8 +198,8 @@ class BBranch extends AbstractBeccaEntity { relation.markAsDeleted(deleteId); } - for (const noteAncillary of note.getNoteAncillaries()) { - noteAncillary.markAsDeleted(deleteId); + for (const noteAttachment of note.getNoteAttachments()) { + noteAttachment.markAsDeleted(deleteId); } note.markAsDeleted(deleteId); diff --git a/src/becca/entities/bnote.js b/src/becca/entities/bnote.js index 4561368b3..c867ca0d7 100644 --- a/src/becca/entities/bnote.js +++ b/src/becca/entities/bnote.js @@ -8,7 +8,7 @@ const dateUtils = require('../../services/date_utils'); const entityChangesService = require('../../services/entity_changes'); const AbstractBeccaEntity = require("./abstract_becca_entity"); const BNoteRevision = require("./bnote_revision"); -const BNoteAncillary = require("./bnote_attachment.js"); +const BNoteAttachment = require("./bnote_attachment.js"); const TaskContext = require("../../services/task_context"); const dayjs = require("dayjs"); const utc = require('dayjs/plugin/utc'); @@ -1161,16 +1161,16 @@ class BNote extends AbstractBeccaEntity { .map(row => new BNoteRevision(row)); } - /** @returns {BNoteAncillary[]} */ - getNoteAncillaries() { - return sql.getRows("SELECT * FROM note_ancillaries WHERE noteId = ? AND isDeleted = 0", [this.noteId]) - .map(row => new BNoteAncillary(row)); + /** @returns {BNoteAttachment[]} */ + getNoteAttachments() { + return sql.getRows("SELECT * FROM note_attachments WHERE noteId = ? AND isDeleted = 0", [this.noteId]) + .map(row => new BNoteAttachment(row)); } - /** @returns {BNoteAncillary|undefined} */ - getNoteAncillaryByName(name) { - return sql.getRows("SELECT * FROM note_ancillaries WHERE noteId = ? AND name = ? AND isDeleted = 0", [this.noteId, name]) - .map(row => new BNoteAncillary(row)) + /** @returns {BNoteAttachment|undefined} */ + getNoteAttachmentByName(name) { + return sql.getRows("SELECT * FROM note_attachments WHERE noteId = ? AND name = ? AND isDeleted = 0", [this.noteId, name]) + .map(row => new BNoteAttachment(row)) [0]; } @@ -1502,21 +1502,21 @@ class BNote extends AbstractBeccaEntity { } /** - * @returns {BNoteAncillary} + * @returns {BNoteAttachment} */ - saveNoteAncillary(name, mime, content) { - let noteAncillary = this.getNoteAncillaryByName(name); + saveNoteAttachment(name, mime, content) { + let noteAttachment = this.getNoteAttachmentByName(name); - noteAncillary = new BNoteAncillary({ + noteAttachment = new BNoteAttachment({ noteId: this.noteId, name, mime, isProtected: this.isProtected }); - noteAncillary.setContent(content); + noteAttachment.setContent(content); - return noteAncillary; + return noteAttachment; } beforeSaving() { diff --git a/src/becca/entities/bnote_attachment.js b/src/becca/entities/bnote_attachment.js index daf1e063f..5931814db 100644 --- a/src/becca/entities/bnote_attachment.js +++ b/src/becca/entities/bnote_attachment.js @@ -9,29 +9,29 @@ const entityChangesService = require('../../services/entity_changes'); const AbstractBeccaEntity = require("./abstract_becca_entity"); /** - * NoteAncillary represent data related/attached to the note. Conceptually similar to attributes, but intended for + * NoteAttachment represent data related/attached to the note. Conceptually similar to attributes, but intended for * larger amounts of data and generally not accessible to the user. * * @extends AbstractBeccaEntity */ -class BNoteAncillary extends AbstractBeccaEntity { - static get entityName() { return "note_ancillaries"; } - static get primaryKeyName() { return "noteAncillaryId"; } - static get hashedProperties() { return ["noteAncillaryId", "noteId", "name", "content", "utcDateModified"]; } +class BNoteAttachment extends AbstractBeccaEntity { + static get entityName() { return "note_attachments"; } + static get primaryKeyName() { return "noteAttachmentId"; } + static get hashedProperties() { return ["noteAttachmentId", "noteId", "name", "content", "utcDateModified"]; } constructor(row) { super(); if (!row.noteId) { - throw new Error("'noteId' must be given to initialize a NoteAncillary entity"); + throw new Error("'noteId' must be given to initialize a NoteAttachment entity"); } if (!row.name) { - throw new Error("'name' must be given to initialize a NoteAncillary entity"); + throw new Error("'name' must be given to initialize a NoteAttachment entity"); } /** @type {string} needs to be set at the initialization time since it's used in the .setContent() */ - this.noteAncillaryId = row.noteAncillaryId || `${this.noteId}_${this.name}`; + this.noteAttachmentId = row.noteAttachmentId || `${this.noteId}_${this.name}`; /** @type {string} */ this.noteId = row.noteId; /** @type {string} */ @@ -55,14 +55,14 @@ class BNoteAncillary extends AbstractBeccaEntity { /** @returns {*} */ getContent(silentNotFoundError = false) { - const res = sql.getRow(`SELECT content FROM note_ancillary_contents WHERE noteAncillaryId = ?`, [this.noteAncillaryId]); + const res = sql.getRow(`SELECT content FROM note_attachment_contents WHERE noteAttachmentId = ?`, [this.noteAttachmentId]); if (!res) { if (silentNotFoundError) { return undefined; } else { - throw new Error(`Cannot find note ancillary content for noteAncillaryId=${this.noteAncillaryId}`); + throw new Error(`Cannot find note attachment content for noteAttachmentId=${this.noteAttachmentId}`); } } @@ -89,10 +89,10 @@ class BNoteAncillary extends AbstractBeccaEntity { setContent(content) { sql.transactional(() => { - this.save(); // also explicitly save note_ancillary to update contentCheckSum + this.save(); // also explicitly save note_attachment to update contentCheckSum const pojo = { - noteAncillaryId: this.noteAncillaryId, + noteAttachmentId: this.noteAttachmentId, content: content, utcDateModified: dateUtils.utcNowDateTime() }; @@ -101,15 +101,15 @@ class BNoteAncillary extends AbstractBeccaEntity { if (protectedSessionService.isProtectedSessionAvailable()) { pojo.content = protectedSessionService.encrypt(pojo.content); } else { - throw new Error(`Cannot update content of noteAncillaryId=${this.noteAncillaryId} since we're out of protected session.`); + throw new Error(`Cannot update content of noteAttachmentId=${this.noteAttachmentId} since we're out of protected session.`); } } - sql.upsert("note_ancillary_contents", "noteAncillaryId", pojo); + sql.upsert("note_attachment_contents", "noteAttachmentId", pojo); entityChangesService.addEntityChange({ - entityName: 'note_ancillary_contents', - entityId: this.noteAncillaryId, + entityName: 'note_attachment_contents', + entityId: this.noteAttachmentId, hash: this.contentCheckSum, // FIXME isErased: false, utcDateChanged: pojo.utcDateModified, @@ -119,7 +119,7 @@ class BNoteAncillary extends AbstractBeccaEntity { } calculateCheckSum(content) { - return utils.hash(`${this.noteAncillaryId}|${content.toString()}`); + return utils.hash(`${this.noteAttachmentId}|${content.toString()}`); } beforeSaving() { @@ -127,7 +127,7 @@ class BNoteAncillary extends AbstractBeccaEntity { throw new Error(`Name must be alphanumerical, "${this.name}" given.`); } - this.noteAncillaryId = `${this.noteId}_${this.name}`; + this.noteAttachmentId = `${this.noteId}_${this.name}`; super.beforeSaving(); @@ -136,7 +136,7 @@ class BNoteAncillary extends AbstractBeccaEntity { getPojo() { return { - noteAncillaryId: this.noteAncillaryId, + noteAttachmentId: this.noteAttachmentId, noteId: this.noteId, name: this.name, mime: this.mime, @@ -155,4 +155,4 @@ class BNoteAncillary extends AbstractBeccaEntity { } } -module.exports = BNoteAncillary; +module.exports = BNoteAttachment; diff --git a/src/becca/entity_constructor.js b/src/becca/entity_constructor.js index e4549ef40..39d3af197 100644 --- a/src/becca/entity_constructor.js +++ b/src/becca/entity_constructor.js @@ -1,6 +1,6 @@ const BNote = require('./entities/bnote'); const BNoteRevision = require('./entities/bnote_revision'); -const BNoteAncillary = require("./entities/bnote_attachment.js"); +const BNoteAttachment = require("./entities/bnote_attachment.js"); const BBranch = require('./entities/bbranch'); const BAttribute = require('./entities/battribute'); const BRecentNote = require('./entities/brecent_note'); @@ -12,7 +12,7 @@ const ENTITY_NAME_TO_ENTITY = { "branches": BBranch, "notes": BNote, "note_revisions": BNoteRevision, - "note_ancillaries": BNoteAncillary, + "note_attachments": BNoteAttachment, "recent_notes": BRecentNote, "etapi_tokens": BEtapiToken, "options": BOption diff --git a/src/public/app/services/froca_updater.js b/src/public/app/services/froca_updater.js index ab59ee7c2..56c654723 100644 --- a/src/public/app/services/froca_updater.js +++ b/src/public/app/services/froca_updater.js @@ -34,7 +34,7 @@ async function processEntityChanges(entityChanges) { loadResults.addOption(ec.entity.name); } - else if (['etapi_tokens', 'note_ancillaries'].includes(ec.entityName)) { + else if (['etapi_tokens', 'note_attachments'].includes(ec.entityName)) { // NOOP } else { diff --git a/src/public/app/widgets/buttons/note_actions.js b/src/public/app/widgets/buttons/note_actions.js index b75c118a5..66fd16e15 100644 --- a/src/public/app/widgets/buttons/note_actions.js +++ b/src/public/app/widgets/buttons/note_actions.js @@ -28,7 +28,7 @@ const TPL = ` Re-render note Search in note Note source - Note ancillaries + Note attachments Open note externally Import files Export note diff --git a/src/public/app/widgets/note_detail.js b/src/public/app/widgets/note_detail.js index b146c3f32..890e819b0 100644 --- a/src/public/app/widgets/note_detail.js +++ b/src/public/app/widgets/note_detail.js @@ -27,7 +27,7 @@ import NoteMapTypeWidget from "./type_widgets/note_map.js"; import WebViewTypeWidget from "./type_widgets/web_view.js"; import DocTypeWidget from "./type_widgets/doc.js"; import ContentWidgetTypeWidget from "./type_widgets/content_widget.js"; -import AncillariesTypeWidget from "./type_widgets/attachments.js"; +import AttachmentsTypeWidget from "./type_widgets/attachments.js"; const TPL = `