mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
renamed "mirror" relation to "inverse" relation
This commit is contained in:
parent
eb9bae9010
commit
30249a353e
BIN
db/demo.tar
BIN
db/demo.tar
Binary file not shown.
1
db/migrations/0119__rename_mirror_to_inverse.sql
Normal file
1
db/migrations/0119__rename_mirror_to_inverse.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
UPDATE attributes SET value = replace(value, 'mirrorRelation', 'inverseRelation') WHERE type = 'relation-definition';
|
@ -72,7 +72,7 @@ function AttributesModel() {
|
|||||||
|
|
||||||
attr.relationDefinition = (attr.type === 'relation-definition' && attr.value) ? attr.value : {
|
attr.relationDefinition = (attr.type === 'relation-definition' && attr.value) ? attr.value : {
|
||||||
multiplicityType: "singlevalue",
|
multiplicityType: "singlevalue",
|
||||||
mirrorRelation: "",
|
inverseRelation: "",
|
||||||
isPromoted: true
|
isPromoted: true
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ function AttributesModel() {
|
|||||||
},
|
},
|
||||||
relationDefinition: {
|
relationDefinition: {
|
||||||
multiplicityType: "singlevalue",
|
multiplicityType: "singlevalue",
|
||||||
mirrorRelation: "",
|
inverseRelation: "",
|
||||||
isPromoted: true
|
isPromoted: true
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -50,7 +50,7 @@ const biDirectionalOverlays = [
|
|||||||
} ]
|
} ]
|
||||||
];
|
];
|
||||||
|
|
||||||
const mirrorOverlays = [
|
const inverseRelationsOverlays = [
|
||||||
[ "Arrow", {
|
[ "Arrow", {
|
||||||
location: 1,
|
location: 1,
|
||||||
id: "arrow",
|
id: "arrow",
|
||||||
@ -134,12 +134,12 @@ async function loadNotesAndRelations() {
|
|||||||
|
|
||||||
for (const relation of data.relations) {
|
for (const relation of data.relations) {
|
||||||
const match = relations.find(rel =>
|
const match = relations.find(rel =>
|
||||||
rel.name === data.mirrorRelations[relation.name]
|
rel.name === data.inverseRelations[relation.name]
|
||||||
&& ((rel.sourceNoteId === relation.sourceNoteId && rel.targetNoteId === relation.targetNoteId)
|
&& ((rel.sourceNoteId === relation.sourceNoteId && rel.targetNoteId === relation.targetNoteId)
|
||||||
|| (rel.sourceNoteId === relation.targetNoteId && rel.targetNoteId === relation.sourceNoteId)));
|
|| (rel.sourceNoteId === relation.targetNoteId && rel.targetNoteId === relation.sourceNoteId)));
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
match.type = relation.type = relation.name === data.mirrorRelations[relation.name] ? 'biDirectional' : 'mirror';
|
match.type = relation.type = relation.name === data.inverseRelations[relation.name] ? 'biDirectional' : 'inverse';
|
||||||
relation.render = false; // don't render second relation
|
relation.render = false; // don't render second relation
|
||||||
} else {
|
} else {
|
||||||
relation.type = 'uniDirectional';
|
relation.type = 'uniDirectional';
|
||||||
@ -173,9 +173,9 @@ async function loadNotesAndRelations() {
|
|||||||
|
|
||||||
connection.id = relation.attributeId;
|
connection.id = relation.attributeId;
|
||||||
|
|
||||||
if (relation.type === 'mirror') {
|
if (relation.type === 'inverse') {
|
||||||
connection.getOverlay("label-source").setLabel(relation.name);
|
connection.getOverlay("label-source").setLabel(relation.name);
|
||||||
connection.getOverlay("label-target").setLabel(data.mirrorRelations[relation.name]);
|
connection.getOverlay("label-target").setLabel(data.inverseRelations[relation.name]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
connection.getOverlay("label").setLabel(relation.name);
|
connection.getOverlay("label").setLabel(relation.name);
|
||||||
@ -290,7 +290,7 @@ function initJsPlumbInstance () {
|
|||||||
|
|
||||||
jsPlumbInstance.registerConnectionType("biDirectional", { anchor:"Continuous", connector:"StateMachine", overlays: biDirectionalOverlays });
|
jsPlumbInstance.registerConnectionType("biDirectional", { anchor:"Continuous", connector:"StateMachine", overlays: biDirectionalOverlays });
|
||||||
|
|
||||||
jsPlumbInstance.registerConnectionType("mirror", { anchor:"Continuous", connector:"StateMachine", overlays: mirrorOverlays });
|
jsPlumbInstance.registerConnectionType("inverse", { anchor:"Continuous", connector:"StateMachine", overlays: inverseRelationsOverlays });
|
||||||
|
|
||||||
jsPlumbInstance.registerConnectionType("link", { anchor:"Continuous", connector:"StateMachine", overlays: linkOverlays });
|
jsPlumbInstance.registerConnectionType("link", { anchor:"Continuous", connector:"StateMachine", overlays: linkOverlays });
|
||||||
|
|
||||||
|
@ -117,8 +117,8 @@ async function getRelationMap(req) {
|
|||||||
// noteId => title
|
// noteId => title
|
||||||
noteTitles: {},
|
noteTitles: {},
|
||||||
relations: [],
|
relations: [],
|
||||||
// relation name => mirror relation name
|
// relation name => inverse relation name
|
||||||
mirrorRelations: {},
|
inverseRelations: {},
|
||||||
links: []
|
links: []
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -143,8 +143,8 @@ async function getRelationMap(req) {
|
|||||||
}; }));
|
}; }));
|
||||||
|
|
||||||
for (const relationDefinition of await note.getRelationDefinitions()) {
|
for (const relationDefinition of await note.getRelationDefinitions()) {
|
||||||
if (relationDefinition.value.mirrorRelation) {
|
if (relationDefinition.value.inverseRelation) {
|
||||||
resp.mirrorRelations[relationDefinition.name] = relationDefinition.value.mirrorRelation;
|
resp.inverseRelations[relationDefinition.name] = relationDefinition.value.inverseRelation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
const build = require('./build');
|
const build = require('./build');
|
||||||
const packageJson = require('../../package');
|
const packageJson = require('../../package');
|
||||||
|
|
||||||
const APP_DB_VERSION = 118;
|
const APP_DB_VERSION = 119;
|
||||||
const SYNC_VERSION = 2;
|
const SYNC_VERSION = 2;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -59,7 +59,7 @@ eventService.subscribe(eventService.CHILD_NOTE_CREATED, async ({ parentNote, chi
|
|||||||
await runAttachedRelations(parentNote, 'runOnChildNoteCreation', childNote);
|
await runAttachedRelations(parentNote, 'runOnChildNoteCreation', childNote);
|
||||||
});
|
});
|
||||||
|
|
||||||
async function processMirrorRelations(entityName, entity, handler) {
|
async function processInverseRelations(entityName, entity, handler) {
|
||||||
if (entityName === 'attributes' && entity.type === 'relation') {
|
if (entityName === 'attributes' && entity.type === 'relation') {
|
||||||
const note = await entity.getNote();
|
const note = await entity.getNote();
|
||||||
const attributes = (await note.getAttributes(entity.name)).filter(relation => relation.type === 'relation-definition');
|
const attributes = (await note.getAttributes(entity.name)).filter(relation => relation.type === 'relation-definition');
|
||||||
@ -67,7 +67,7 @@ async function processMirrorRelations(entityName, entity, handler) {
|
|||||||
for (const attribute of attributes) {
|
for (const attribute of attributes) {
|
||||||
const definition = attribute.value;
|
const definition = attribute.value;
|
||||||
|
|
||||||
if (definition.mirrorRelation && definition.mirrorRelation.trim()) {
|
if (definition.inverseRelation && definition.inverseRelation.trim()) {
|
||||||
const targetNote = await entity.getTargetNote();
|
const targetNote = await entity.getTargetNote();
|
||||||
|
|
||||||
await handler(definition, note, targetNote);
|
await handler(definition, note, targetNote);
|
||||||
@ -77,17 +77,17 @@ async function processMirrorRelations(entityName, entity, handler) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
eventService.subscribe(eventService.ENTITY_CHANGED, async ({ entityName, entity }) => {
|
eventService.subscribe(eventService.ENTITY_CHANGED, async ({ entityName, entity }) => {
|
||||||
await processMirrorRelations(entityName, entity, async (definition, note, targetNote) => {
|
await processInverseRelations(entityName, entity, async (definition, note, targetNote) => {
|
||||||
// we need to make sure that also target's mirror attribute exists and if note, then create it
|
// we need to make sure that also target's inverse attribute exists and if note, then create it
|
||||||
// mirror attribute has to target our note as well
|
// inverse attribute has to target our note as well
|
||||||
const hasMirrorAttribute = (await targetNote.getRelations(definition.mirrorRelation))
|
const hasInverseAttribute = (await targetNote.getRelations(definition.inverseRelation))
|
||||||
.some(attr => attr.value === note.noteId);
|
.some(attr => attr.value === note.noteId);
|
||||||
|
|
||||||
if (!hasMirrorAttribute) {
|
if (!hasInverseAttribute) {
|
||||||
await new Attribute({
|
await new Attribute({
|
||||||
noteId: targetNote.noteId,
|
noteId: targetNote.noteId,
|
||||||
type: 'relation',
|
type: 'relation',
|
||||||
name: definition.mirrorRelation,
|
name: definition.inverseRelation,
|
||||||
value: note.noteId,
|
value: note.noteId,
|
||||||
isInheritable: entity.isInheritable
|
isInheritable: entity.isInheritable
|
||||||
}).save();
|
}).save();
|
||||||
@ -98,9 +98,9 @@ eventService.subscribe(eventService.ENTITY_CHANGED, async ({ entityName, entity
|
|||||||
});
|
});
|
||||||
|
|
||||||
eventService.subscribe(eventService.ENTITY_DELETED, async ({ entityName, entity }) => {
|
eventService.subscribe(eventService.ENTITY_DELETED, async ({ entityName, entity }) => {
|
||||||
await processMirrorRelations(entityName, entity, async (definition, note, targetNote) => {
|
await processInverseRelations(entityName, entity, async (definition, note, targetNote) => {
|
||||||
// if one mirror attribute is deleted then the other should be deleted as well
|
// if one inverse attribute is deleted then the other should be deleted as well
|
||||||
const relations = await targetNote.getRelations(definition.mirrorRelation);
|
const relations = await targetNote.getRelations(definition.inverseRelation);
|
||||||
let deletedSomething = false;
|
let deletedSomething = false;
|
||||||
|
|
||||||
for (const relation of relations) {
|
for (const relation of relations) {
|
||||||
|
@ -72,9 +72,9 @@
|
|||||||
</label>
|
</label>
|
||||||
<br/>
|
<br/>
|
||||||
<label>
|
<label>
|
||||||
Mirror relation:
|
Inverse relation:
|
||||||
|
|
||||||
<input type="text" value="true" class="attribute-name" data-bind="value: relationDefinition.mirrorRelation"/>
|
<input type="text" value="true" class="attribute-name" data-bind="value: relationDefinition.inverseRelation"/>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user