From 9b3f3fde05c2d824019d32b1c24d0b14065ddec6 Mon Sep 17 00:00:00 2001 From: azivner Date: Sat, 28 Jul 2018 17:59:55 +0200 Subject: [PATCH] #126, relation list in note detail and fixes in saving --- src/public/javascripts/dialogs/add_link.js | 6 ++-- src/public/javascripts/dialogs/relations.js | 25 +++++++++++----- src/public/javascripts/services/link.js | 4 +-- .../javascripts/services/note_detail.js | 29 +++++++++++++++++++ src/public/javascripts/services/tooltip.js | 8 +++-- src/public/stylesheets/style.css | 8 ++--- src/routes/api/relations.js | 2 +- src/views/index.ejs | 18 ++++++++---- 8 files changed, 75 insertions(+), 25 deletions(-) diff --git a/src/public/javascripts/dialogs/add_link.js b/src/public/javascripts/dialogs/add_link.js index cbe619f5d..8872810a2 100644 --- a/src/public/javascripts/dialogs/add_link.js +++ b/src/public/javascripts/dialogs/add_link.js @@ -79,7 +79,7 @@ async function showDialog() { return; } - const notePath = linkService.getNodePathFromLabel(ui.item.value); + const notePath = linkService.getNotePathFromLabel(ui.item.value); if (!notePath) { return; @@ -99,7 +99,7 @@ async function showDialog() { // this is called when user goes through autocomplete list with keyboard // at this point the item isn't selected yet so we use supplied ui.item to see WHERE the cursor is focus: async (event, ui) => { - const notePath = linkService.getNodePathFromLabel(ui.item.value); + const notePath = linkService.getNotePathFromLabel(ui.item.value); const noteId = treeUtils.getNoteIdFromNotePath(notePath); await setDefaultLinkTitle(noteId); @@ -114,7 +114,7 @@ async function showDialog() { $form.submit(() => { const value = $autoComplete.val(); - const notePath = linkService.getNodePathFromLabel(value); + const notePath = linkService.getNotePathFromLabel(value); const noteId = treeUtils.getNoteIdFromNotePath(notePath); if (notePath) { diff --git a/src/public/javascripts/dialogs/relations.js b/src/public/javascripts/dialogs/relations.js index 0d0d74830..f661680d6 100644 --- a/src/public/javascripts/dialogs/relations.js +++ b/src/public/javascripts/dialogs/relations.js @@ -1,6 +1,8 @@ import noteDetailService from '../services/note_detail.js'; import server from '../services/server.js'; import infoService from "../services/info.js"; +import linkService from "../services/link.js"; +import treeUtils from "../services/tree_utils.js"; const $dialog = $("#relations-dialog"); const $saveRelationsButton = $("#save-relations-button"); @@ -26,12 +28,20 @@ function RelationsModel() { }); }; + async function showRelations(relations) { + for (const relation of relations) { + relation.targetNoteId = await treeUtils.getNoteTitle(relation.targetNoteId) + " (" + relation.targetNoteId + ")"; + } + + self.relations(relations.map(ko.observable)); + } + this.loadRelations = async function() { const noteId = noteDetailService.getCurrentNoteId(); const relations = await server.get('notes/' + noteId + '/relations'); - self.relations(relations.map(ko.observable)); + await showRelations(relations); addLastEmptyRow(); @@ -89,19 +99,18 @@ function RelationsModel() { .map(relation => relation()) .filter(relation => relation.relationId !== "" || relation.name !== ""); + relationsToSave.forEach(relation => relation.targetNoteId = treeUtils.getNoteIdFromNotePath(linkService.getNotePathFromLabel(relation.targetNoteId))); + + console.log(relationsToSave); + const relations = await server.put('notes/' + noteId + '/relations', relationsToSave); - self.relations(relations.map(ko.observable)); + await showRelations(relations); addLastEmptyRow(); infoService.showMessage("Relations have been saved."); - // FIXME FIXME FIXME FIXME FIXME - // FIXME FIXME FIXME FIXME FIXME - // FIXME FIXME FIXME FIXME FIXME - // FIXME FIXME FIXME FIXME FIXME - // FIXME FIXME FIXME FIXME FIXME noteDetailService.loadRelationList(); }; @@ -218,7 +227,7 @@ async function initAutocomplete($el) { if (ui.item.value === 'No results') { return false; } - }, + } }); } } diff --git a/src/public/javascripts/services/link.js b/src/public/javascripts/services/link.js index 9a648f34d..3afb5b24b 100644 --- a/src/public/javascripts/services/link.js +++ b/src/public/javascripts/services/link.js @@ -13,7 +13,7 @@ function getNotePathFromLink(url) { } } -function getNodePathFromLabel(label) { +function getNotePathFromLabel(label) { const notePathMatch = / \(([A-Za-z0-9/]+)\)/.exec(label); if (notePathMatch !== null) { @@ -97,7 +97,7 @@ $(document).on('click', 'div.popover-content a, div.ui-tooltip-content a', goToL $(document).on('dblclick', '#note-detail-text a', goToLink); export default { - getNodePathFromLabel, + getNotePathFromLabel, getNotePathFromLink, createNoteLink, addLinkToEditor, diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index 3d2dcc21d..b6710032a 100644 --- a/src/public/javascripts/services/note_detail.js +++ b/src/public/javascripts/services/note_detail.js @@ -7,6 +7,7 @@ import utils from './utils.js'; import server from './server.js'; import messagingService from "./messaging.js"; import infoService from "./info.js"; +import linkService from "./link.js"; import treeCache from "./tree_cache.js"; import NoteFull from "../entities/note_full.js"; import noteDetailCode from './note_detail_code.js'; @@ -26,6 +27,8 @@ const $noteDetailComponentWrapper = $("#note-detail-component-wrapper"); const $noteIdDisplay = $("#note-id-display"); const $labelList = $("#label-list"); const $labelListInner = $("#label-list-inner"); +const $relationList = $("#relation-list"); +const $relationListInner = $("#relation-list-inner"); const $childrenOverview = $("#children-overview"); let currentNote = null; @@ -180,6 +183,8 @@ async function loadNoteDetail(noteId) { const labels = await loadLabelList(); + loadRelationList(); // no need to wait + const hideChildrenOverview = labels.some(label => label.name === 'hideChildrenOverview'); await showChildrenOverview(hideChildrenOverview); } @@ -230,6 +235,29 @@ async function loadLabelList() { return labels; } +async function loadRelationList() { + const noteId = getCurrentNoteId(); + + const relations = await server.get('notes/' + noteId + '/relations'); + + $relationListInner.html(''); + + if (relations.length > 0) { + for (const relation of relations) { + $relationListInner.append(relation.name + " = "); + $relationListInner.append(await linkService.createNoteLink(relation.targetNoteId)); + $relationListInner.append(" "); + } + + $relationList.show(); + } + else { + $relationList.hide(); + } + + return relations; +} + async function loadNote(noteId) { const row = await server.get('notes/' + noteId); @@ -279,6 +307,7 @@ export default { newNoteCreated, focus, loadLabelList, + loadRelationList, saveNote, saveNoteIfChanged, noteChanged diff --git a/src/public/javascripts/services/tooltip.js b/src/public/javascripts/services/tooltip.js index 7162a50fb..f2ac105e8 100644 --- a/src/public/javascripts/services/tooltip.js +++ b/src/public/javascripts/services/tooltip.js @@ -4,9 +4,13 @@ import linkService from "./link.js"; function setupTooltip() { $(document).tooltip({ - items: "#note-detail-text a", + items: "#note-detail-wrapper a", content: function (callback) { - const notePath = linkService.getNotePathFromLink($(this).attr("href")); + let notePath = linkService.getNotePathFromLink($(this).attr("href")); + + if (!notePath) { + notePath = $(this).attr("note-path"); + } if (notePath !== null) { const noteId = treeUtils.getNoteIdFromNotePath(notePath); diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css index cfc0fd8c9..5d1c653bf 100644 --- a/src/public/stylesheets/style.css +++ b/src/public/stylesheets/style.css @@ -308,13 +308,13 @@ div.ui-tooltip { .cm-matchhighlight {background-color: #eeeeee} -#label-list { +#label-list, #relation-list { color: #777777; - border-top: 1px solid #eee; - padding: 5px; display: none; + padding: 5px; + display: none; } -#label-list button { +#label-list button, #relation-list button { padding: 2px; margin-right: 5px; } diff --git a/src/routes/api/relations.js b/src/routes/api/relations.js index 64ef88d2c..d6c3e1185 100644 --- a/src/routes/api/relations.js +++ b/src/routes/api/relations.js @@ -18,7 +18,7 @@ async function updateNoteRelations(req) { for (const relation of relations) { let relationEntity; - if (relation.labelId) { + if (relation.relationId) { relationEntity = await repository.getRelation(relation.relationId); } else { diff --git a/src/views/index.ejs b/src/views/index.ejs index 8fcfbb422..b0e1d8928 100644 --- a/src/views/index.ejs +++ b/src/views/index.ejs @@ -254,10 +254,18 @@
-
- +
+ + - + + + + + + + +
@@ -578,7 +586,7 @@ - + @@ -629,7 +637,7 @@ - +