mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-30 04:01:31 +08:00 
			
		
		
		
	added "what links here" widget
This commit is contained in:
		
							parent
							
								
									c9d0b8cc40
								
							
						
					
					
						commit
						02c9dabcff
					
				| @ -1,33 +0,0 @@ | ||||
| class Link { | ||||
|     constructor(treeCache, row) { | ||||
|         this.treeCache = treeCache; | ||||
|         /** @param {string} linkId */ | ||||
|         this.linkId = row.linkId; | ||||
|         /** @param {string} noteId */ | ||||
|         this.noteId = row.noteId; | ||||
|         /** @param {string} type */ | ||||
|         this.type = row.type; | ||||
|         /** @param {string} targetNoteId */ | ||||
|         this.targetNoteId = row.targetNoteId; | ||||
|         /** @param {string} utcDateCreated */ | ||||
|         this.utcDateCreated = row.utcDateCreated; | ||||
|         /** @param {string} utcDateModified */ | ||||
|         this.utcDateModified = row.utcDateModified; | ||||
|     } | ||||
| 
 | ||||
|     /** @returns {NoteShort} */ | ||||
|     async getNote() { | ||||
|         return await this.treeCache.getNote(this.noteId); | ||||
|     } | ||||
| 
 | ||||
|     /** @returns {NoteShort} */ | ||||
|     async getTargetNote() { | ||||
|         return await this.treeCache.getNote(this.targetNoteId); | ||||
|     } | ||||
| 
 | ||||
|     get toString() { | ||||
|         return `Link(linkId=${this.linkId}, type=${this.type}, note=${this.noteId}, targetNoteId=${this.targetNoteId})`; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| export default Link; | ||||
| @ -1,6 +1,5 @@ | ||||
| import server from '../services/server.js'; | ||||
| import Attribute from './attribute.js'; | ||||
| import Link from './link.js'; | ||||
| 
 | ||||
| const LABEL = 'label'; | ||||
| const LABEL_DEFINITION = 'label-definition'; | ||||
| @ -231,11 +230,13 @@ class NoteShort { | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @return {Promise<Link[]>} | ||||
|      * Get relations which target this note | ||||
|      * | ||||
|      * @returns {Promise<Attribute[]>} | ||||
|      */ | ||||
|     async getLinks() { | ||||
|         return (await server.get('notes/' + this.noteId + '/links')) | ||||
|             .map(linkRow => new Link(this.treeCache, linkRow)); | ||||
|     async getTargetRelations() { | ||||
|         return (await server.get('notes/' + this.noteId + '/target-relations')) | ||||
|             .map(attrRow => new Attribute(this.treeCache, attrRow)); | ||||
|     } | ||||
| 
 | ||||
|     get toString() { | ||||
|  | ||||
| @ -2,6 +2,7 @@ import NoteInfoWidget from "../widgets/note_info.js"; | ||||
| import LinkMapWidget from "../widgets/link_map.js"; | ||||
| import NoteRevisionsWidget from "../widgets/note_revisions.js"; | ||||
| import AttributesWidget from "../widgets/attributes.js"; | ||||
| import WhatLinksHereWidget from "../widgets/what_links_here.js"; | ||||
| import bundleService from "./bundle.js"; | ||||
| import messagingService from "./messaging.js"; | ||||
| 
 | ||||
| @ -52,7 +53,7 @@ class Sidebar { | ||||
|         this.widgets = []; | ||||
|         this.$widgetContainer.empty(); | ||||
| 
 | ||||
|         const widgetClasses = [AttributesWidget, LinkMapWidget, NoteRevisionsWidget, NoteInfoWidget]; | ||||
|         const widgetClasses = [AttributesWidget, LinkMapWidget, WhatLinksHereWidget, NoteRevisionsWidget, NoteInfoWidget]; | ||||
| 
 | ||||
|         const widgetRelations = await this.ctx.note.getRelations('widget'); | ||||
| 
 | ||||
|  | ||||
| @ -37,6 +37,13 @@ class StandardWidget { | ||||
| 
 | ||||
|         this.$body = this.$bodyWrapper.find('.card-body'); | ||||
| 
 | ||||
|         const maxHeight = this.getMaxHeight(); | ||||
| 
 | ||||
|         if (maxHeight) { | ||||
|             this.$body.css("max-height", maxHeight); | ||||
|             this.$body.css("overflow", "auto"); | ||||
|         } | ||||
| 
 | ||||
|         this.$widget.on('shown.bs.collapse', () => this.renderBody()); | ||||
|         this.$widget.on('shown.bs.collapse', () => this.ctx.stateChanged()); | ||||
|         this.$widget.on('hidden.bs.collapse', () => this.ctx.stateChanged()); | ||||
| @ -50,6 +57,8 @@ class StandardWidget { | ||||
| 
 | ||||
|     getHeaderActions() { return []; } | ||||
| 
 | ||||
|     getMaxHeight() { return null; } | ||||
| 
 | ||||
|     async renderBody() { | ||||
|         if (!this.isVisible() || this.rendered) { | ||||
|             return; | ||||
|  | ||||
| @ -1,30 +1,30 @@ | ||||
| import StandardWidget from "./standard_widget.js"; | ||||
| import linkService from "../services/link.js"; | ||||
| 
 | ||||
| class WhatLinksHereWidget extends StandardWidget { | ||||
|     getWidgetTitle() { return "What links here"; } | ||||
| 
 | ||||
|     getMaxHeight() { return "200px"; } | ||||
| 
 | ||||
|     async doRenderBody() { | ||||
|         const targetRelations = await this.ctx.note.getTargetRelations(); | ||||
| 
 | ||||
| 
 | ||||
|         const $noteId = this.$body.find(".note-info-note-id"); | ||||
|         const $dateCreated = this.$body.find(".note-info-date-created"); | ||||
|         const $dateModified = this.$body.find(".note-info-date-modified"); | ||||
|         const $type = this.$body.find(".note-info-type"); | ||||
|         const $mime = this.$body.find(".note-info-mime"); | ||||
| 
 | ||||
|         const note = this.ctx.note; | ||||
| 
 | ||||
|         $noteId.text(note.noteId); | ||||
|         $dateCreated.text(note.dateCreated); | ||||
|         $dateModified.text(note.dateModified); | ||||
|         $type.text(note.type); | ||||
|         $mime.text(note.mime); | ||||
|     } | ||||
| 
 | ||||
|     syncDataReceived(syncData) { | ||||
|         if (syncData.find(sd => sd.entityName === 'notes' && sd.entityId === this.ctx.note.noteId)) { | ||||
|             this.doRenderBody(); | ||||
|         if (targetRelations.length === 0) { | ||||
|             this.$body.text("Nothing links here yet ..."); | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         const $list = $("<ul>"); | ||||
| 
 | ||||
|         for (const rel of targetRelations) { | ||||
|             const $item = $("<li>") | ||||
|                 .append(await linkService.createNoteLink(rel.noteId)) | ||||
|                 .append($("<span>").text(" (" + rel.name + ")")); | ||||
| 
 | ||||
|             $list.append($item); | ||||
|         } | ||||
| 
 | ||||
|         this.$body.empty().append($list); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -157,6 +157,12 @@ async function deleteRelation(req) { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| async function getTargetRelations(req) { | ||||
|     const note = await repository.getNote(req.params.noteId); | ||||
| 
 | ||||
|     return await note.getTargetRelations(); | ||||
| } | ||||
| 
 | ||||
| module.exports = { | ||||
|     updateNoteAttributes, | ||||
|     updateNoteAttribute, | ||||
| @ -165,5 +171,6 @@ module.exports = { | ||||
|     getValuesForAttribute, | ||||
|     getEffectiveNoteAttributes, | ||||
|     createRelation, | ||||
|     deleteRelation | ||||
|     deleteRelation, | ||||
|     getTargetRelations | ||||
| }; | ||||
| @ -157,6 +157,7 @@ function register(app) { | ||||
|     apiRoute(DELETE, '/api/notes/:noteId/attributes/:attributeId', attributesRoute.deleteNoteAttribute); | ||||
|     apiRoute(GET, '/api/attributes/names', attributesRoute.getAttributeNames); | ||||
|     apiRoute(GET, '/api/attributes/values/:attributeName', attributesRoute.getValuesForAttribute); | ||||
|     apiRoute(GET, '/api/notes/:noteId/target-relations', attributesRoute.getTargetRelations); | ||||
| 
 | ||||
|     apiRoute(POST, '/api/notes/:noteId/link-map', linkMapRoute.getLinkMap); | ||||
|     apiRoute(GET, '/api/notes/:noteId/links', linksRoute.getLinks); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam