mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	#126, relation list in note detail and fixes in saving
This commit is contained in:
		| @@ -79,7 +79,7 @@ async function showDialog() { | |||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             const notePath = linkService.getNodePathFromLabel(ui.item.value); |             const notePath = linkService.getNotePathFromLabel(ui.item.value); | ||||||
|  |  | ||||||
|             if (!notePath) { |             if (!notePath) { | ||||||
|                 return; |                 return; | ||||||
| @@ -99,7 +99,7 @@ async function showDialog() { | |||||||
|         // this is called when user goes through autocomplete list with keyboard |         // 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 |         // 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) => { |         focus: async (event, ui) => { | ||||||
|             const notePath = linkService.getNodePathFromLabel(ui.item.value); |             const notePath = linkService.getNotePathFromLabel(ui.item.value); | ||||||
|             const noteId = treeUtils.getNoteIdFromNotePath(notePath); |             const noteId = treeUtils.getNoteIdFromNotePath(notePath); | ||||||
|  |  | ||||||
|             await setDefaultLinkTitle(noteId); |             await setDefaultLinkTitle(noteId); | ||||||
| @@ -114,7 +114,7 @@ async function showDialog() { | |||||||
| $form.submit(() => { | $form.submit(() => { | ||||||
|     const value = $autoComplete.val(); |     const value = $autoComplete.val(); | ||||||
|  |  | ||||||
|     const notePath = linkService.getNodePathFromLabel(value); |     const notePath = linkService.getNotePathFromLabel(value); | ||||||
|     const noteId = treeUtils.getNoteIdFromNotePath(notePath); |     const noteId = treeUtils.getNoteIdFromNotePath(notePath); | ||||||
|  |  | ||||||
|     if (notePath) { |     if (notePath) { | ||||||
|   | |||||||
| @@ -1,6 +1,8 @@ | |||||||
| import noteDetailService from '../services/note_detail.js'; | import noteDetailService from '../services/note_detail.js'; | ||||||
| import server from '../services/server.js'; | import server from '../services/server.js'; | ||||||
| import infoService from "../services/info.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 $dialog = $("#relations-dialog"); | ||||||
| const $saveRelationsButton = $("#save-relations-button"); | 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() { |     this.loadRelations = async function() { | ||||||
|         const noteId = noteDetailService.getCurrentNoteId(); |         const noteId = noteDetailService.getCurrentNoteId(); | ||||||
|  |  | ||||||
|         const relations = await server.get('notes/' + noteId + '/relations'); |         const relations = await server.get('notes/' + noteId + '/relations'); | ||||||
|  |  | ||||||
|         self.relations(relations.map(ko.observable)); |         await showRelations(relations); | ||||||
|  |  | ||||||
|         addLastEmptyRow(); |         addLastEmptyRow(); | ||||||
|  |  | ||||||
| @@ -89,19 +99,18 @@ function RelationsModel() { | |||||||
|             .map(relation => relation()) |             .map(relation => relation()) | ||||||
|             .filter(relation => relation.relationId !== "" || relation.name !== ""); |             .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); |         const relations = await server.put('notes/' + noteId + '/relations', relationsToSave); | ||||||
|  |  | ||||||
|         self.relations(relations.map(ko.observable)); |         await showRelations(relations); | ||||||
|  |  | ||||||
|         addLastEmptyRow(); |         addLastEmptyRow(); | ||||||
|  |  | ||||||
|         infoService.showMessage("Relations have been saved."); |         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(); |         noteDetailService.loadRelationList(); | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
| @@ -218,7 +227,7 @@ async function initAutocomplete($el) { | |||||||
|                 if (ui.item.value === 'No results') { |                 if (ui.item.value === 'No results') { | ||||||
|                     return false; |                     return false; | ||||||
|                 } |                 } | ||||||
|             }, |             } | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ function getNotePathFromLink(url) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| function getNodePathFromLabel(label) { | function getNotePathFromLabel(label) { | ||||||
|     const notePathMatch = / \(([A-Za-z0-9/]+)\)/.exec(label); |     const notePathMatch = / \(([A-Za-z0-9/]+)\)/.exec(label); | ||||||
|  |  | ||||||
|     if (notePathMatch !== null) { |     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); | $(document).on('dblclick', '#note-detail-text a', goToLink); | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
|     getNodePathFromLabel, |     getNotePathFromLabel, | ||||||
|     getNotePathFromLink, |     getNotePathFromLink, | ||||||
|     createNoteLink, |     createNoteLink, | ||||||
|     addLinkToEditor, |     addLinkToEditor, | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import utils from './utils.js'; | |||||||
| import server from './server.js'; | import server from './server.js'; | ||||||
| import messagingService from "./messaging.js"; | import messagingService from "./messaging.js"; | ||||||
| import infoService from "./info.js"; | import infoService from "./info.js"; | ||||||
|  | import linkService from "./link.js"; | ||||||
| import treeCache from "./tree_cache.js"; | import treeCache from "./tree_cache.js"; | ||||||
| import NoteFull from "../entities/note_full.js"; | import NoteFull from "../entities/note_full.js"; | ||||||
| import noteDetailCode from './note_detail_code.js'; | import noteDetailCode from './note_detail_code.js'; | ||||||
| @@ -26,6 +27,8 @@ const $noteDetailComponentWrapper = $("#note-detail-component-wrapper"); | |||||||
| const $noteIdDisplay = $("#note-id-display"); | const $noteIdDisplay = $("#note-id-display"); | ||||||
| const $labelList = $("#label-list"); | const $labelList = $("#label-list"); | ||||||
| const $labelListInner = $("#label-list-inner"); | const $labelListInner = $("#label-list-inner"); | ||||||
|  | const $relationList = $("#relation-list"); | ||||||
|  | const $relationListInner = $("#relation-list-inner"); | ||||||
| const $childrenOverview = $("#children-overview"); | const $childrenOverview = $("#children-overview"); | ||||||
|  |  | ||||||
| let currentNote = null; | let currentNote = null; | ||||||
| @@ -180,6 +183,8 @@ async function loadNoteDetail(noteId) { | |||||||
|  |  | ||||||
|     const labels = await loadLabelList(); |     const labels = await loadLabelList(); | ||||||
|  |  | ||||||
|  |     loadRelationList(); // no need to wait | ||||||
|  |  | ||||||
|     const hideChildrenOverview = labels.some(label => label.name === 'hideChildrenOverview'); |     const hideChildrenOverview = labels.some(label => label.name === 'hideChildrenOverview'); | ||||||
|     await showChildrenOverview(hideChildrenOverview); |     await showChildrenOverview(hideChildrenOverview); | ||||||
| } | } | ||||||
| @@ -230,6 +235,29 @@ async function loadLabelList() { | |||||||
|     return labels; |     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) { | async function loadNote(noteId) { | ||||||
|     const row = await server.get('notes/' + noteId); |     const row = await server.get('notes/' + noteId); | ||||||
|  |  | ||||||
| @@ -279,6 +307,7 @@ export default { | |||||||
|     newNoteCreated, |     newNoteCreated, | ||||||
|     focus, |     focus, | ||||||
|     loadLabelList, |     loadLabelList, | ||||||
|  |     loadRelationList, | ||||||
|     saveNote, |     saveNote, | ||||||
|     saveNoteIfChanged, |     saveNoteIfChanged, | ||||||
|     noteChanged |     noteChanged | ||||||
|   | |||||||
| @@ -4,9 +4,13 @@ import linkService from "./link.js"; | |||||||
|  |  | ||||||
| function setupTooltip() { | function setupTooltip() { | ||||||
|     $(document).tooltip({ |     $(document).tooltip({ | ||||||
|         items: "#note-detail-text a", |         items: "#note-detail-wrapper a", | ||||||
|         content: function (callback) { |         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) { |             if (notePath !== null) { | ||||||
|                 const noteId = treeUtils.getNoteIdFromNotePath(notePath); |                 const noteId = treeUtils.getNoteIdFromNotePath(notePath); | ||||||
|   | |||||||
| @@ -308,13 +308,13 @@ div.ui-tooltip { | |||||||
|  |  | ||||||
| .cm-matchhighlight {background-color: #eeeeee} | .cm-matchhighlight {background-color: #eeeeee} | ||||||
|  |  | ||||||
| #label-list { | #label-list, #relation-list { | ||||||
|     color: #777777; |     color: #777777; | ||||||
|     border-top: 1px solid #eee; |     padding: 5px; | ||||||
|     padding: 5px; display: none; |     display: none; | ||||||
| } | } | ||||||
|  |  | ||||||
| #label-list button { | #label-list button, #relation-list button { | ||||||
|     padding: 2px; |     padding: 2px; | ||||||
|     margin-right: 5px; |     margin-right: 5px; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ async function updateNoteRelations(req) { | |||||||
|     for (const relation of relations) { |     for (const relation of relations) { | ||||||
|         let relationEntity; |         let relationEntity; | ||||||
|  |  | ||||||
|         if (relation.labelId) { |         if (relation.relationId) { | ||||||
|             relationEntity = await repository.getRelation(relation.relationId); |             relationEntity = await repository.getRelation(relation.relationId); | ||||||
|         } |         } | ||||||
|         else { |         else { | ||||||
|   | |||||||
| @@ -254,10 +254,18 @@ | |||||||
|  |  | ||||||
|         <div id="children-overview"></div> |         <div id="children-overview"></div> | ||||||
|  |  | ||||||
|         <div id="label-list"> |         <div id="labels-and-relations"> | ||||||
|           <button class="btn btn-sm show-labels-button">Labels:</button> |           <span id="label-list"> | ||||||
|  |             <button class="btn btn-sm show-labels-button">Labels:</button> | ||||||
|  |  | ||||||
|           <span id="label-list-inner"></span> |             <span id="label-list-inner"></span> | ||||||
|  |           </span> | ||||||
|  |  | ||||||
|  |           <span id="relation-list"> | ||||||
|  |             <button class="btn btn-sm show-relations-button">Relations:</button> | ||||||
|  |  | ||||||
|  |             <span id="relation-list-inner"></span> | ||||||
|  |           </span> | ||||||
|         </div> |         </div> | ||||||
|       </div> |       </div> | ||||||
|     </div> |     </div> | ||||||
| @@ -578,7 +586,7 @@ | |||||||
|               <td> |               <td> | ||||||
|                 <input type="text" class="label-value form-control" data-bind="value: value, valueUpdate: 'blur', event: { blur: $parent.labelChanged }" style="width: 300px"/> |                 <input type="text" class="label-value form-control" data-bind="value: value, valueUpdate: 'blur', event: { blur: $parent.labelChanged }" style="width: 300px"/> | ||||||
|               </td> |               </td> | ||||||
|               <td title="Delete" style="padding: 13px;"> |               <td title="Delete" style="padding: 13px; cursor: pointer;"> | ||||||
|                 <span class="glyphicon glyphicon-trash" data-bind="click: $parent.deleteLabel"></span> |                 <span class="glyphicon glyphicon-trash" data-bind="click: $parent.deleteLabel"></span> | ||||||
|               </td> |               </td> | ||||||
|             </tr> |             </tr> | ||||||
| @@ -629,7 +637,7 @@ | |||||||
|                   <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="Delete" style="padding: 13px;"> |               <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> | ||||||
|             </tr> |             </tr> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user