Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
implemented "targetRelationCount" and exposed more of them in order by widget, fixes #1658
zadam4160da70be0a
diff --git a/src/public/app/widgets/search_options/order_by.js b/src/public/app/widgets/search_options/order_by.jsindex 484d272fcf..9d24a6e425 100644--- a/src/public/app/widgets/search_options/order_by.js+++ b/src/public/app/widgets/search_options/order_by.js@@ -16,6 +16,11 @@ const TPL = `<option value="contentSize">Note content size</option><option value="noteSize">Note content size including revisions</option><option value="revisionCount">Number of revisions</option>+ <option value="childrenCount">Number of children notes</option>+ <option value="parentCount">Number of clones</option>+ <option value="ownedLabelCount">Number of labels</option>+ <option value="ownedRelationCount">Number of relations</option>+ <option value="targetRelationCount">Number of relations targeting the note</option></select><select name="orderDirection" class="form-control w-auto d-inline">diff --git a/src/services/note_cache/entities/attribute.js b/src/services/note_cache/entities/attribute.jsindex 44024d35c8..cfcdc0a23f 100644--- a/src/services/note_cache/entities/attribute.js+++ b/src/services/note_cache/entities/attribute.js@@ -46,6 +46,10 @@ class Attribute {|| (this.type === 'relation' && this.name === 'template');}+ isAutoLink() {+ return this.type === 'relation' && ['internalLink', 'imageLink', 'relationMapLink', 'includeNoteLink'].includes(this.name);+ }+get note() {return this.noteCache.notes[this.noteId];}diff --git a/src/services/note_cache/entities/note.js b/src/services/note_cache/entities/note.jsindex 2ff63f7151..0d0da886be 100644--- a/src/services/note_cache/entities/note.js+++ b/src/services/note_cache/entities/note.js@@ -319,14 +319,42 @@ class Note {return this.attributes.filter(attr => attr.type === 'label').length;}+ get ownedLabelCount() {+ return this.ownedAttributes.filter(attr => attr.type === 'label').length;+ }+get relationCount() {+ return this.attributes.filter(attr => attr.type === 'relation' && !attr.isAutoLink()).length;+ }++ get relationCountIncludingLinks() {return this.attributes.filter(attr => attr.type === 'relation').length;}+ get ownedRelationCount() {+ return this.ownedAttributes.filter(attr => attr.type === 'relation' && !attr.isAutoLink()).length;+ }++ get ownedRelationCountIncludingLinks() {+ return this.ownedAttributes.filter(attr => attr.type === 'relation').length;+ }++ get targetRelationCount() {+ return this.targetRelations.filter(attr => !attr.isAutoLink()).length;+ }++ get targetRelationCountIncludingLinks() {+ return this.targetRelations.length;+ }+get attributeCount() {return this.attributes.length;}+ get ownedAttributeCount() {+ return this.attributes.length;+ }+get ancestors() {if (!this.ancestorCache) {const noteIds = new Set();diff --git a/src/services/search/expressions/property_comparison.js b/src/services/search/expressions/property_comparison.jsindex b12140f5ac..c9e2440bfb 100644--- a/src/services/search/expressions/property_comparison.js+++ b/src/services/search/expressions/property_comparison.js@@ -23,7 +23,13 @@ const PROP_MAPPING = {"childrencount": "childrenCount","attributecount": "attributeCount","labelcount": "labelCount",+ "ownedlabelcount": "ownedLabelCount","relationcount": "relationCount",+ "ownedrelationcount": "ownedRelationCount",+ "relationcountincludinglinks": "relationCountIncludingLinks",+ "ownedrelationcountincludinglinks": "ownedRelationCountIncludingLinks",+ "targetrelationcount": "targetRelationCount",+ "targetrelationcountincludinglinks": "targetRelationCountIncludingLinks","contentsize": "contentSize","notesize": "noteSize","revisioncount": "revisionCount"diff --git a/src/services/search/value_extractor.js b/src/services/search/value_extractor.jsindex 62c77e294c..350be2ece8 100644--- a/src/services/search/value_extractor.js+++ b/src/services/search/value_extractor.js@@ -19,7 +19,13 @@ const PROP_MAPPING = {"childrencount": "childrenCount","attributecount": "attributeCount","labelcount": "labelCount",+ "ownedlabelcount": "ownedLabelCount","relationcount": "relationCount",+ "ownedrelationcount": "ownedRelationCount",+ "relationcountincludinglinks": "relationCountIncludingLinks",+ "ownedrelationcountincludinglinks": "ownedRelationCountIncludingLinks",+ "targetrelationcount": "targetRelationCount",+ "targetrelationcountincludinglinks": "targetRelationCountIncludingLinks","contentsize": "contentSize","notesize": "noteSize","revisioncount": "revisionCount"