diff --git a/db/migrations/0107__add_inheritable_attribute_to_relations.sql b/db/migrations/0107__add_inheritable_attribute_to_relations.sql new file mode 100644 index 000000000..282c13f12 --- /dev/null +++ b/db/migrations/0107__add_inheritable_attribute_to_relations.sql @@ -0,0 +1 @@ +ALTER TABLE relations ADD isInheritable int DEFAULT 0 NULL; \ No newline at end of file diff --git a/db/schema.sql b/db/schema.sql index b6a3a17f4..5335c7616 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -140,6 +140,7 @@ CREATE TABLE relations sourceNoteId TEXT not null, name TEXT not null, targetNoteId TEXT not null, + isInheritable int DEFAULT 0 NULL, position INT default 0 not null, dateCreated TEXT not null, dateModified TEXT not null, diff --git a/src/entities/relation.js b/src/entities/relation.js index 25c2760e8..1c98fcd60 100644 --- a/src/entities/relation.js +++ b/src/entities/relation.js @@ -8,7 +8,7 @@ const sql = require('../services/sql'); class Relation extends Entity { static get tableName() { return "relations"; } static get primaryKeyName() { return "relationId"; } - static get hashedProperties() { return ["relationId", "sourceNoteId", "name", "targetNoteId", "dateModified", "dateCreated"]; } + static get hashedProperties() { return ["relationId", "sourceNoteId", "name", "targetNoteId", "isInheritable", "dateModified", "dateCreated"]; } async getSourceNote() { return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.sourceNoteId]); @@ -25,6 +25,10 @@ class Relation extends Entity { this.position = 1 + await sql.getValue(`SELECT COALESCE(MAX(position), 0) FROM relations WHERE sourceNoteId = ?`, [this.sourceNoteId]); } + if (!this.isInheritable) { + this.isInheritable = false; + } + if (!this.isDeleted) { this.isDeleted = false; } diff --git a/src/public/javascripts/dialogs/relations.js b/src/public/javascripts/dialogs/relations.js index 7b2aeeddb..62dc212c0 100644 --- a/src/public/javascripts/dialogs/relations.js +++ b/src/public/javascripts/dialogs/relations.js @@ -123,6 +123,7 @@ function RelationsModel() { relationId: '', name: '', targetNoteId: '', + isInheritable: 0, isDeleted: 0, position: 0 })); @@ -176,7 +177,7 @@ async function showDialog() { $dialog.dialog({ modal: true, - width: 800, + width: 900, height: 500 }); } diff --git a/src/routes/api/relations.js b/src/routes/api/relations.js index d6c3e1185..d88362fec 100644 --- a/src/routes/api/relations.js +++ b/src/routes/api/relations.js @@ -33,6 +33,7 @@ async function updateNoteRelations(req) { relationEntity.name = relation.name; relationEntity.targetNoteId = relation.targetNoteId; + relationEntity.isInheritable = relation.isInheritable; relationEntity.position = relation.position; relationEntity.isDeleted = relation.isDeleted; diff --git a/src/services/app_info.js b/src/services/app_info.js index 10b6c9bf9..40b2f7a8e 100644 --- a/src/services/app_info.js +++ b/src/services/app_info.js @@ -3,7 +3,7 @@ const build = require('./build'); const packageJson = require('../../package'); -const APP_DB_VERSION = 106; +const APP_DB_VERSION = 107; const SYNC_VERSION = 1; module.exports = { diff --git a/src/services/relations.js b/src/services/relations.js index 6f259e805..5c273871f 100644 --- a/src/services/relations.js +++ b/src/services/relations.js @@ -46,7 +46,8 @@ async function getEffectiveRelations(noteId) { JOIN notes ON notes.noteId = branches.parentNoteId WHERE notes.isDeleted = 0 AND branches.isDeleted = 0 ) - SELECT relations.* FROM relations JOIN tree ON relations.sourceNoteId = tree.noteId WHERE relations.isDeleted = 0 AND relations.name IN ('runOnNoteView')`, [noteId]); + SELECT relations.* FROM relations JOIN tree ON relations.sourceNoteId = tree.noteId + WHERE relations.isDeleted = 0 AND (relations.isInheritable = 1 OR relations.sourceNoteId = ?)`, [noteId, noteId]); } module.exports = { diff --git a/src/services/sync_update.js b/src/services/sync_update.js index d342849f0..6fad891ab 100644 --- a/src/services/sync_update.js +++ b/src/services/sync_update.js @@ -40,7 +40,7 @@ async function updateEntity(sync, entity, sourceId) { await updateApiToken(entity, sourceId); } else { - throw new Error(`Unrecognized entity type ${sync}`); + throw new Error(`Unrecognized entity type ${entityName}`); } } diff --git a/src/views/index.ejs b/src/views/index.ejs index 740790de3..d7a6f6898 100644 --- a/src/views/index.ejs +++ b/src/views/index.ejs @@ -612,6 +612,7 @@