mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	chore(client/ts): port zpetne_odkazy
This commit is contained in:
		
							parent
							
								
									32fc5def77
								
							
						
					
					
						commit
						20584f622d
					
				@ -7,6 +7,7 @@ import NoteContextAwareWidget from "../note_context_aware_widget.js";
 | 
				
			|||||||
import linkService from "../../services/link.js";
 | 
					import linkService from "../../services/link.js";
 | 
				
			||||||
import server from "../../services/server.js";
 | 
					import server from "../../services/server.js";
 | 
				
			||||||
import froca from "../../services/froca.js";
 | 
					import froca from "../../services/froca.js";
 | 
				
			||||||
 | 
					import type FNote from "../../entities/fnote.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const TPL = `
 | 
					const TPL = `
 | 
				
			||||||
<div class="backlinks-widget">
 | 
					<div class="backlinks-widget">
 | 
				
			||||||
@ -64,7 +65,19 @@ const TPL = `
 | 
				
			|||||||
</div>
 | 
					</div>
 | 
				
			||||||
`;
 | 
					`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TODO: Deduplicate with server
 | 
				
			||||||
 | 
					interface Backlink {
 | 
				
			||||||
 | 
					    noteId: string;
 | 
				
			||||||
 | 
					    relationName?: string;
 | 
				
			||||||
 | 
					    excerpts?: string[];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default class BacklinksWidget extends NoteContextAwareWidget {
 | 
					export default class BacklinksWidget extends NoteContextAwareWidget {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private $count!: JQuery<HTMLElement>;
 | 
				
			||||||
 | 
					    private $items!: JQuery<HTMLElement>;
 | 
				
			||||||
 | 
					    private $ticker!: JQuery<HTMLElement>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    doRender() {
 | 
					    doRender() {
 | 
				
			||||||
        this.$widget = $(TPL);
 | 
					        this.$widget = $(TPL);
 | 
				
			||||||
        this.$count = this.$widget.find(".backlinks-count");
 | 
					        this.$count = this.$widget.find(".backlinks-count");
 | 
				
			||||||
@ -73,7 +86,7 @@ export default class BacklinksWidget extends NoteContextAwareWidget {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        this.$count.on("click", () => {
 | 
					        this.$count.on("click", () => {
 | 
				
			||||||
            this.$items.toggle();
 | 
					            this.$items.toggle();
 | 
				
			||||||
            this.$items.css("max-height", $(window).height() - this.$items.offset().top - 10);
 | 
					            this.$items.css("max-height", ($(window).height() ?? 0) - (this.$items.offset()?.top ?? 0) - 10);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (this.$items.is(":visible")) {
 | 
					            if (this.$items.is(":visible")) {
 | 
				
			||||||
                this.renderBacklinks();
 | 
					                this.renderBacklinks();
 | 
				
			||||||
@ -83,7 +96,7 @@ export default class BacklinksWidget extends NoteContextAwareWidget {
 | 
				
			|||||||
        this.contentSized();
 | 
					        this.contentSized();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async refreshWithNote(note) {
 | 
					    async refreshWithNote(note: FNote) {
 | 
				
			||||||
        this.clearItems();
 | 
					        this.clearItems();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (this.noteContext?.viewScope?.viewMode !== "default") {
 | 
					        if (this.noteContext?.viewScope?.viewMode !== "default") {
 | 
				
			||||||
@ -92,7 +105,8 @@ export default class BacklinksWidget extends NoteContextAwareWidget {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // 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(`note-map/${this.noteId}/backlink-count`);
 | 
					        // TODO: Deduplicate response type
 | 
				
			||||||
 | 
					        const resp = await server.get<{ count: number }>(`note-map/${this.noteId}/backlink-count`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!resp || !resp.count) {
 | 
					        if (!resp || !resp.count) {
 | 
				
			||||||
            this.toggle(false);
 | 
					            this.toggle(false);
 | 
				
			||||||
@ -106,7 +120,7 @@ export default class BacklinksWidget extends NoteContextAwareWidget {
 | 
				
			|||||||
        );
 | 
					        );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    toggle(show) {
 | 
					    toggle(show: boolean) {
 | 
				
			||||||
        this.$widget.toggleClass("hidden-no-content", !show);
 | 
					        this.$widget.toggleClass("hidden-no-content", !show);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -121,7 +135,7 @@ export default class BacklinksWidget extends NoteContextAwareWidget {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        this.$items.empty();
 | 
					        this.$items.empty();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const backlinks = await server.get(`note-map/${this.noteId}/backlinks`);
 | 
					        const backlinks = await server.get<Backlink[]>(`note-map/${this.noteId}/backlinks`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!backlinks.length) {
 | 
					        if (!backlinks.length) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
@ -143,7 +157,7 @@ export default class BacklinksWidget extends NoteContextAwareWidget {
 | 
				
			|||||||
            if (backlink.relationName) {
 | 
					            if (backlink.relationName) {
 | 
				
			||||||
                $item.append($("<p>").text(`${t("zpetne_odkazy.relation")}: ${backlink.relationName}`));
 | 
					                $item.append($("<p>").text(`${t("zpetne_odkazy.relation")}: ${backlink.relationName}`));
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                $item.append(...backlink.excerpts);
 | 
					                $item.append(...backlink.excerpts ?? []);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            this.$items.append($item);
 | 
					            this.$items.append($item);
 | 
				
			||||||
@ -6,6 +6,12 @@ import type BNote from "../../becca/entities/bnote.js";
 | 
				
			|||||||
import type BAttribute from "../../becca/entities/battribute.js";
 | 
					import type BAttribute from "../../becca/entities/battribute.js";
 | 
				
			||||||
import type { Request } from "express";
 | 
					import type { Request } from "express";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					interface Backlink {
 | 
				
			||||||
 | 
					    noteId: string;
 | 
				
			||||||
 | 
					    relationName?: string;
 | 
				
			||||||
 | 
					    excerpts?: string[];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function buildDescendantCountMap(noteIdsToCount: string[]) {
 | 
					function buildDescendantCountMap(noteIdsToCount: string[]) {
 | 
				
			||||||
    if (!Array.isArray(noteIdsToCount)) {
 | 
					    if (!Array.isArray(noteIdsToCount)) {
 | 
				
			||||||
        throw new Error("noteIdsToCount: type error");
 | 
					        throw new Error("noteIdsToCount: type error");
 | 
				
			||||||
@ -325,7 +331,7 @@ function findExcerpts(sourceNote: BNote, referencedNoteId: string) {
 | 
				
			|||||||
    return excerpts;
 | 
					    return excerpts;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getFilteredBacklinks(note: BNote) {
 | 
					function getFilteredBacklinks(note: BNote): BAttribute[] {
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
        note
 | 
					        note
 | 
				
			||||||
            .getTargetRelations()
 | 
					            .getTargetRelations()
 | 
				
			||||||
@ -344,7 +350,7 @@ function getBacklinkCount(req: Request) {
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getBacklinks(req: Request) {
 | 
					function getBacklinks(req: Request): Backlink[] {
 | 
				
			||||||
    const { noteId } = req.params;
 | 
					    const { noteId } = req.params;
 | 
				
			||||||
    const note = becca.getNoteOrThrow(noteId);
 | 
					    const note = becca.getNoteOrThrow(noteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user