mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	fix backlinks in day note subtree, fixes #3158
This commit is contained in:
		| @@ -86,7 +86,7 @@ export default class BacklinksWidget extends NoteContextAwareWidget { | |||||||
|         this.clearItems(); |         this.clearItems(); | ||||||
|  |  | ||||||
|         // can't use froca since that would count only relations from loaded notes |         // can't use froca since that would count only relations from loaded notes | ||||||
|         const resp = await server.get(`notes/${this.noteId}/backlink-count`); |         const resp = await server.get(`note-map/${this.noteId}/backlink-count`); | ||||||
|  |  | ||||||
|         if (!resp || !resp.count) { |         if (!resp || !resp.count) { | ||||||
|             this.toggle(false); |             this.toggle(false); | ||||||
|   | |||||||
| @@ -287,6 +287,27 @@ function findExcerpts(sourceNote, referencedNoteId) { | |||||||
|     return excerpts; |     return excerpts; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | function getFilteredBacklinks(note) { | ||||||
|  |     return note.getTargetRelations() | ||||||
|  |         // search notes have "ancestor" relations which are not interesting | ||||||
|  |         .filter(note => note.getNote().type !== 'search'); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function getBacklinkCount(req) { | ||||||
|  |     const {noteId} = req.params; | ||||||
|  |  | ||||||
|  |     const note = becca.getNote(noteId); | ||||||
|  |  | ||||||
|  |     if (!note) { | ||||||
|  |         return [404, "Not found"]; | ||||||
|  |     } | ||||||
|  |     else { | ||||||
|  |         return { | ||||||
|  |             count: getFilteredBacklinks(note).length | ||||||
|  |         }; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| function getBacklinks(req) { | function getBacklinks(req) { | ||||||
|     const {noteId} = req.params; |     const {noteId} = req.params; | ||||||
|     const note = becca.getNote(noteId); |     const note = becca.getNote(noteId); | ||||||
| @@ -295,11 +316,9 @@ function getBacklinks(req) { | |||||||
|         return [404, `Note ${noteId} was not found`]; |         return [404, `Note ${noteId} was not found`]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     let backlinks = note.getTargetRelations(); |  | ||||||
|  |  | ||||||
|     let backlinksWithExcerptCount = 0; |     let backlinksWithExcerptCount = 0; | ||||||
|  |  | ||||||
|     return backlinks.filter(note => !note.getNote().hasLabel('excludeFromNoteMap')).map(backlink => { |     return getFilteredBacklinks(note).map(backlink => { | ||||||
|         const sourceNote = backlink.note; |         const sourceNote = backlink.note; | ||||||
|  |  | ||||||
|         if (sourceNote.type !== 'text' || backlinksWithExcerptCount > 50) { |         if (sourceNote.type !== 'text' || backlinksWithExcerptCount > 50) { | ||||||
| @@ -323,5 +342,6 @@ function getBacklinks(req) { | |||||||
| module.exports = { | module.exports = { | ||||||
|     getLinkMap, |     getLinkMap, | ||||||
|     getTreeMap, |     getTreeMap, | ||||||
|  |     getBacklinkCount, | ||||||
|     getBacklinks |     getBacklinks | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -305,21 +305,6 @@ function uploadModifiedFile(req) { | |||||||
|     note.setContent(fileContent); |     note.setContent(fileContent); | ||||||
| } | } | ||||||
|  |  | ||||||
| function getBacklinkCount(req) { |  | ||||||
|     const {noteId} = req.params; |  | ||||||
|  |  | ||||||
|     const note = becca.getNote(noteId); |  | ||||||
|  |  | ||||||
|     if (!note) { |  | ||||||
|         return [404, "Not found"]; |  | ||||||
|     } |  | ||||||
|     else { |  | ||||||
|         return { |  | ||||||
|             count: note.getTargetRelations().filter(note => !note.getNote().hasLabel('excludeFromNoteMap')).length |  | ||||||
|         }; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| module.exports = { | module.exports = { | ||||||
|     getNote, |     getNote, | ||||||
|     updateNoteContent, |     updateNoteContent, | ||||||
| @@ -334,6 +319,5 @@ module.exports = { | |||||||
|     duplicateSubtree, |     duplicateSubtree, | ||||||
|     eraseDeletedNotesNow, |     eraseDeletedNotesNow, | ||||||
|     getDeleteNotesPreview, |     getDeleteNotesPreview, | ||||||
|     uploadModifiedFile, |     uploadModifiedFile | ||||||
|     getBacklinkCount |  | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -264,7 +264,6 @@ function register(app) { | |||||||
|     apiRoute(DELETE, '/api/notes/:noteId/revisions/:noteRevisionId', noteRevisionsApiRoute.eraseNoteRevision); |     apiRoute(DELETE, '/api/notes/:noteId/revisions/:noteRevisionId', noteRevisionsApiRoute.eraseNoteRevision); | ||||||
|     route(GET, '/api/notes/:noteId/revisions/:noteRevisionId/download', [auth.checkApiAuthOrElectron], noteRevisionsApiRoute.downloadNoteRevision); |     route(GET, '/api/notes/:noteId/revisions/:noteRevisionId/download', [auth.checkApiAuthOrElectron], noteRevisionsApiRoute.downloadNoteRevision); | ||||||
|     apiRoute(PUT, '/api/notes/:noteId/restore-revision/:noteRevisionId', noteRevisionsApiRoute.restoreNoteRevision); |     apiRoute(PUT, '/api/notes/:noteId/restore-revision/:noteRevisionId', noteRevisionsApiRoute.restoreNoteRevision); | ||||||
|     apiRoute(GET, '/api/notes/:noteId/backlink-count', notesApiRoute.getBacklinkCount); |  | ||||||
|     apiRoute(POST, '/api/notes/relation-map', notesApiRoute.getRelationMap); |     apiRoute(POST, '/api/notes/relation-map', notesApiRoute.getRelationMap); | ||||||
|     apiRoute(POST, '/api/notes/erase-deleted-notes-now', notesApiRoute.eraseDeletedNotesNow); |     apiRoute(POST, '/api/notes/erase-deleted-notes-now', notesApiRoute.eraseDeletedNotesNow); | ||||||
|     apiRoute(PUT, '/api/notes/:noteId/title', notesApiRoute.changeTitle); |     apiRoute(PUT, '/api/notes/:noteId/title', notesApiRoute.changeTitle); | ||||||
| @@ -306,6 +305,7 @@ function register(app) { | |||||||
|  |  | ||||||
|     apiRoute(POST, '/api/note-map/:noteId/tree', noteMapRoute.getTreeMap); |     apiRoute(POST, '/api/note-map/:noteId/tree', noteMapRoute.getTreeMap); | ||||||
|     apiRoute(POST, '/api/note-map/:noteId/link', noteMapRoute.getLinkMap); |     apiRoute(POST, '/api/note-map/:noteId/link', noteMapRoute.getLinkMap); | ||||||
|  |     apiRoute(GET, '/api/note-map/:noteId/backlink-count', noteMapRoute.getBacklinkCount); | ||||||
|     apiRoute(GET, '/api/note-map/:noteId/backlinks', noteMapRoute.getBacklinks); |     apiRoute(GET, '/api/note-map/:noteId/backlinks', noteMapRoute.getBacklinks); | ||||||
|  |  | ||||||
|     apiRoute(GET, '/api/special-notes/inbox/:date', specialNotesRoute.getInboxNote); |     apiRoute(GET, '/api/special-notes/inbox/:date', specialNotesRoute.getInboxNote); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user