it's now possible to mark relation as inheritable (previously this was hardcoded for specific relation names)

This commit is contained in:
azivner 2018-07-29 20:33:42 +02:00
parent ed1381103a
commit 2eb1a9705f
9 changed files with 18 additions and 5 deletions

View File

@ -0,0 +1 @@
ALTER TABLE relations ADD isInheritable int DEFAULT 0 NULL;

View File

@ -140,6 +140,7 @@ CREATE TABLE relations
sourceNoteId TEXT not null, sourceNoteId TEXT not null,
name TEXT not null, name TEXT not null,
targetNoteId TEXT not null, targetNoteId TEXT not null,
isInheritable int DEFAULT 0 NULL,
position INT default 0 not null, position INT default 0 not null,
dateCreated TEXT not null, dateCreated TEXT not null,
dateModified TEXT not null, dateModified TEXT not null,

View File

@ -8,7 +8,7 @@ const sql = require('../services/sql');
class Relation extends Entity { class Relation extends Entity {
static get tableName() { return "relations"; } static get tableName() { return "relations"; }
static get primaryKeyName() { return "relationId"; } 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() { async getSourceNote() {
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.sourceNoteId]); 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]); 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) { if (!this.isDeleted) {
this.isDeleted = false; this.isDeleted = false;
} }

View File

@ -123,6 +123,7 @@ function RelationsModel() {
relationId: '', relationId: '',
name: '', name: '',
targetNoteId: '', targetNoteId: '',
isInheritable: 0,
isDeleted: 0, isDeleted: 0,
position: 0 position: 0
})); }));
@ -176,7 +177,7 @@ async function showDialog() {
$dialog.dialog({ $dialog.dialog({
modal: true, modal: true,
width: 800, width: 900,
height: 500 height: 500
}); });
} }

View File

@ -33,6 +33,7 @@ async function updateNoteRelations(req) {
relationEntity.name = relation.name; relationEntity.name = relation.name;
relationEntity.targetNoteId = relation.targetNoteId; relationEntity.targetNoteId = relation.targetNoteId;
relationEntity.isInheritable = relation.isInheritable;
relationEntity.position = relation.position; relationEntity.position = relation.position;
relationEntity.isDeleted = relation.isDeleted; relationEntity.isDeleted = relation.isDeleted;

View File

@ -3,7 +3,7 @@
const build = require('./build'); const build = require('./build');
const packageJson = require('../../package'); const packageJson = require('../../package');
const APP_DB_VERSION = 106; const APP_DB_VERSION = 107;
const SYNC_VERSION = 1; const SYNC_VERSION = 1;
module.exports = { module.exports = {

View File

@ -46,7 +46,8 @@ async function getEffectiveRelations(noteId) {
JOIN notes ON notes.noteId = branches.parentNoteId JOIN notes ON notes.noteId = branches.parentNoteId
WHERE notes.isDeleted = 0 AND branches.isDeleted = 0 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 = { module.exports = {

View File

@ -40,7 +40,7 @@ async function updateEntity(sync, entity, sourceId) {
await updateApiToken(entity, sourceId); await updateApiToken(entity, sourceId);
} }
else { else {
throw new Error(`Unrecognized entity type ${sync}`); throw new Error(`Unrecognized entity type ${entityName}`);
} }
} }

View File

@ -612,6 +612,7 @@
<th>ID</th> <th>ID</th>
<th>Relation name</th> <th>Relation name</th>
<th>Target note</th> <th>Target note</th>
<th>Inheritable</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
@ -639,6 +640,9 @@
<span class="input-group-addon relations-show-recent-notes" title="Show recent notes" style="background: url('/images/icons/clock-16.png') no-repeat center; cursor: pointer;"></span> <span class="input-group-addon relations-show-recent-notes" title="Show recent notes" style="background: url('/images/icons/clock-16.png') no-repeat center; cursor: pointer;"></span>
</div> </div>
</td> </td>
<td title="Inheritable relations are automatically inherited to the child notes">
<input type="checkbox" value="1" data-bind="checked: isInheritable" />
</td>
<td title="Delete" style="padding: 13px; cursor: pointer;"> <td title="Delete" style="padding: 13px; cursor: pointer;">
<span class="glyphicon glyphicon-trash" data-bind="click: $parent.deleteRelation"></span> <span class="glyphicon glyphicon-trash" data-bind="click: $parent.deleteRelation"></span>
</td> </td>