mirror of
https://github.com/zadam/trilium.git
synced 2025-01-15 19:51:57 +08:00
fix backlink count
This commit is contained in:
parent
9d38e9342d
commit
a232035d47
3 changed files with 36 additions and 13 deletions
|
@ -103,17 +103,19 @@ export default class BacklinksWidget extends NoteContextAwareWidget {
|
||||||
async refreshWithNote(note) {
|
async refreshWithNote(note) {
|
||||||
this.clearItems();
|
this.clearItems();
|
||||||
|
|
||||||
const targetRelationCount = note.getTargetRelations().length;
|
// can't use froca since that would count only relations from loaded notes
|
||||||
if (targetRelationCount === 0) {
|
const resp = await server.get(`notes/${this.noteId}/backlink-count`);
|
||||||
|
|
||||||
|
if (!resp || !resp.count) {
|
||||||
this.$ticker.hide();
|
this.$ticker.hide();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
this.$ticker.show();
|
this.$ticker.show();
|
||||||
this.$count.text(
|
this.$count.text(
|
||||||
`${targetRelationCount} backlink`
|
`${resp.count} backlink`
|
||||||
+ (targetRelationCount === 1 ? '' : 's')
|
+ (resp.count === 1 ? '' : 's')
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clearItems() {
|
clearItems() {
|
||||||
|
@ -136,18 +138,22 @@ export default class BacklinksWidget extends NoteContextAwareWidget {
|
||||||
await froca.getNotes(backlinks.map(bl => bl.noteId)); // prefetch all
|
await froca.getNotes(backlinks.map(bl => bl.noteId)); // prefetch all
|
||||||
|
|
||||||
for (const backlink of backlinks) {
|
for (const backlink of backlinks) {
|
||||||
this.$items.append(await linkService.createNoteLink(backlink.noteId, {
|
const $item = $("<div>");
|
||||||
|
|
||||||
|
$item.append(await linkService.createNoteLink(backlink.noteId, {
|
||||||
showNoteIcon: true,
|
showNoteIcon: true,
|
||||||
showNotePath: true,
|
showNotePath: true,
|
||||||
showTooltip: false
|
showTooltip: false
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (backlink.relationName) {
|
if (backlink.relationName) {
|
||||||
this.$items.append($("<p>").text("relation: " + backlink.relationName));
|
$item.append($("<p>").text("relation: " + backlink.relationName));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.$items.append(...backlink.excerpts);
|
$item.append(...backlink.excerpts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.$items.append($item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -302,6 +302,21 @@ 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().length
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getNote,
|
getNote,
|
||||||
updateNote,
|
updateNote,
|
||||||
|
@ -316,5 +331,6 @@ module.exports = {
|
||||||
duplicateSubtree,
|
duplicateSubtree,
|
||||||
eraseDeletedNotesNow,
|
eraseDeletedNotesNow,
|
||||||
getDeleteNotesPreview,
|
getDeleteNotesPreview,
|
||||||
uploadModifiedFile
|
uploadModifiedFile,
|
||||||
|
getBacklinkCount
|
||||||
};
|
};
|
||||||
|
|
|
@ -220,6 +220,7 @@ 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/change-title', notesApiRoute.changeTitle);
|
apiRoute(PUT, '/api/notes/:noteId/change-title', notesApiRoute.changeTitle);
|
||||||
|
|
Loading…
Reference in a new issue