fixes for relation map rendering

This commit is contained in:
azivner 2018-11-12 21:18:22 +01:00
parent 2523f81f3b
commit e7cea59ba7
3 changed files with 20 additions and 23 deletions

View File

@ -11,9 +11,7 @@ function info(message) {
$dialog.modal(); $dialog.modal();
return new Promise((res, rej) => { return new Promise((res, rej) => { resolve = res; });
resolve = res;
});
} }
$dialog.on('shown.bs.modal', () => $okButton.trigger("focus")); $dialog.on('shown.bs.modal', () => $okButton.trigger("focus"));

View File

@ -13,9 +13,7 @@ function ask(message, defaultValue = '') {
$dialog.modal(); $dialog.modal();
return new Promise((res, rej) => { return new Promise((res, rej) => { resolve = res; });
resolve = res;
});
} }
$dialog.on('shown.bs.modal', () => $answer.focus().select()); $dialog.on('shown.bs.modal', () => $answer.focus().select());

View File

@ -6,6 +6,7 @@ import treeService from "./tree.js";
import contextMenuWidget from "./context_menu.js"; import contextMenuWidget from "./context_menu.js";
import infoService from "./info.js"; import infoService from "./info.js";
import promptDialog from "../dialogs/prompt.js"; import promptDialog from "../dialogs/prompt.js";
import infoDialog from "../dialogs/info.js";
const $component = $("#note-detail-relation-map"); const $component = $("#note-detail-relation-map");
const $relationMapContainer = $("#relation-map-container"); const $relationMapContainer = $("#relation-map-container");
@ -62,10 +63,6 @@ function loadMapData() {
} }
async function show() { async function show() {
const result = await promptDialog.ask("Enter name of new note:", "new note");
alert(result);
$component.show(); $component.show();
await libraryLoader.requireLibrary(libraryLoader.RELATION_MAP); await libraryLoader.requireLibrary(libraryLoader.RELATION_MAP);
@ -95,15 +92,22 @@ async function loadNotesAndRelations() {
|| (rel.sourceNoteId === relation.targetNoteId && rel.targetNoteId === relation.sourceNoteId))); || (rel.sourceNoteId === relation.targetNoteId && rel.targetNoteId === relation.sourceNoteId)));
if (match) { if (match) {
match.type = 'biDirectional'; match.type = relation.type = 'biDirectional';
relation.render = false; // don't render second relation
} else { } else {
relation.type = 'uniDirectional'; relation.type = 'uniDirectional';
relations.push(relation); relation.render = true;
} }
relations.push(relation);
} }
mapData.notes = mapData.notes.filter(note => note.id in data.noteTitles); mapData.notes = mapData.notes.filter(note => note.id in data.noteTitles);
// delete all endpoints and connections
// this is done at this point (after async operations) to reduce flicker to the minimum
jsPlumbInstance.deleteEveryEndpoint();
jsPlumbInstance.batch(async function () { jsPlumbInstance.batch(async function () {
for (const note of mapData.notes) { for (const note of mapData.notes) {
const title = data.noteTitles[note.id]; const title = data.noteTitles[note.id];
@ -112,7 +116,7 @@ async function loadNotesAndRelations() {
} }
for (const relation of relations) { for (const relation of relations) {
if (relation.name === 'isChildOf') { if (!relation.render) {
continue; continue;
} }
@ -256,7 +260,7 @@ async function connectionCreatedHandler(info, originalEvent) {
return; return;
} }
const name = prompt("Specify new relation name:"); const name = await promptDialog.ask("Specify new relation name:");
if (!name || !name.trim()) { if (!name || !name.trim()) {
jsPlumbInstance.deleteConnection(connection); jsPlumbInstance.deleteConnection(connection);
@ -273,7 +277,7 @@ async function connectionCreatedHandler(info, originalEvent) {
&& rel.name === name); && rel.name === name);
if (relationExists) { if (relationExists) {
alert("Connection '" + name + "' between these notes already exists."); await infoDialog.info("Connection '" + name + "' between these notes already exists.");
jsPlumbInstance.deleteConnection(connection); jsPlumbInstance.deleteConnection(connection);
@ -284,8 +288,7 @@ async function connectionCreatedHandler(info, originalEvent) {
relations.push({ attributeId: attribute.attributeId , targetNoteId, sourceNoteId, name }); relations.push({ attributeId: attribute.attributeId , targetNoteId, sourceNoteId, name });
connection.id = attribute.attributeId; await refresh();
connection.getOverlay("label").setLabel(name);
} }
$relationMapContainer.on("contextmenu", ".note-box", e => { $relationMapContainer.on("contextmenu", ".note-box", e => {
@ -318,7 +321,7 @@ async function noteContextMenuHandler(event, cmd) {
} }
else if (cmd === "edit-title") { else if (cmd === "edit-title") {
const $title = $noteBox.find(".title a"); const $title = $noteBox.find(".title a");
const title = prompt("Enter new note title:", $title.text()); const title = await promptDialog.ask("Enter new note title:", $title.text());
if (!title) { if (!title) {
return; return;
@ -382,16 +385,13 @@ async function createNoteBox(id, title, x, y) {
} }
async function refresh() { async function refresh() {
// delete all endpoints and connections
jsPlumbInstance.deleteEveryEndpoint();
await loadNotesAndRelations(); await loadNotesAndRelations();
} }
let clipboard = null; let clipboard = null;
$createChildNote.click(async () => { $createChildNote.click(async () => {
const title = prompt("Enter title of new note", "new note"); const title = await promptDialog.ask("Enter title of new note", "new note");
if (!title.trim()) { if (!title.trim()) {
return; return;
@ -443,7 +443,8 @@ async function dropNoteOntoRelationMapHandler(ev) {
const exists = mapData.notes.some(n => n.noteId === note.noteId); const exists = mapData.notes.some(n => n.noteId === note.noteId);
if (exists) { if (exists) {
alert(`Note "${note.title}" is already placed into the diagram`); await infoDialog.info(`Note "${note.title}" is already placed into the diagram`);
continue; continue;
} }