links are now shown in the relation map as well

This commit is contained in:
azivner 2018-11-14 10:11:15 +01:00
parent 247275d391
commit fc9495bcdf
4 changed files with 43 additions and 5 deletions

View File

@ -67,6 +67,14 @@ const mirrorOverlays = [
} ]
];
const linkOverlays = [
[ "Arrow", {
location: 1,
id: "arrow",
length: 14,
foldback: 0.8
} ]
];
function loadMapData() {
const currentNote = noteDetailService.getCurrentNote();
@ -159,6 +167,14 @@ async function loadNotesAndRelations() {
connection.canvas.setAttribute("data-connection-id", connection.id);
}
for (const link of data.links) {
jsPlumbInstance.connect({
source: link.sourceNoteId,
target: link.targetNoteId,
type: 'link'
});
}
});
}
@ -253,6 +269,8 @@ function initJsPlumbInstance () {
jsPlumbInstance.registerConnectionType("mirror", { anchor:"Continuous", connector:"StateMachine", overlays: mirrorOverlays });
jsPlumbInstance.registerConnectionType("link", { anchor:"Continuous", connector:"StateMachine", overlays: linkOverlays });
jsPlumbInstance.bind("connection", connectionCreatedHandler);
// so that canvas is not panned when clicking/dragging note box
@ -285,7 +303,18 @@ function connectionContextMenuHandler(connection, event) {
async function connectionCreatedHandler(info, originalEvent) {
const connection = info.connection;
connection.bind("contextmenu", (obj, event) => connectionContextMenuHandler(connection, event));
const isRelation = relations.some(rel => rel.attributeId === connection.id);
connection.bind("contextmenu", (obj, event) => {
if (connection.getType().includes("link")) {
// don't create context menu if it's a link since there's nothing to do with link from relation map
// (don't open browser menu either)
event.preventDefault();
}
else {
connectionContextMenuHandler(connection, event);
}
});
// if there's no event, then this has been triggered programatically
if (!originalEvent) {

View File

@ -108,8 +108,6 @@ async function renderTooltip(note, attributes) {
.prop("src", `/api/images/${note.noteId}/${note.title}`)
.prop("style", "max-width: 300px; max-height: 300px;")
.prop('outerHTML');
console.log(content);
}
// other types of notes don't have tooltip preview

View File

@ -99,7 +99,8 @@ async function getRelationMap(req) {
noteTitles: {},
relations: [],
// relation name => mirror relation name
mirrorRelations: {}
mirrorRelations: {},
links: []
};
if (noteIds.length === 0) {
@ -129,6 +130,16 @@ async function getRelationMap(req) {
}
}
resp.links = (await repository.getEntities(`SELECT * FROM links WHERE isDeleted = 0 AND noteId IN (${questionMarks})`, noteIds))
.filter(link => noteIds.includes(link.targetNoteId))
.map(link => {
return {
linkId: link.linkId,
sourceNoteId: link.noteId,
targetNoteId: link.targetNoteId
}
});
return resp;
}

View File

@ -183,7 +183,7 @@ function findImageLinks(content, foundLinks) {
}
function findHyperLinks(content, foundLinks) {
const re = /href="#root[a-zA-Z0-9\/]*\/([a-zA-Z0-9]+)\//g;
const re = /href="#root[a-zA-Z0-9\/]*\/([a-zA-Z0-9]+)\/?"/g;
let match;
while (match = re.exec(content)) {