From 7562e29fac3e08e85fda808dc36e31f8c2b0003a Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Mon, 26 Jun 2023 14:45:19 +0200 Subject: [PATCH] Increased power of tree searching --- app/imports/api/parenting/nodesToTree.js | 12 +- app/imports/api/utility/escapeRegex.js | 2 +- .../ui/components/tree/TreeSearchInput.vue | 185 ++++++++++++++---- .../character/characterSheetTabs/TreeTab.vue | 13 +- .../client/ui/library/LibraryAndNode.vue | 17 +- .../ui/library/LibraryContentsContainer.vue | 6 +- app/imports/client/ui/utility/escapeRegex.js | 3 - app/imports/server/publications/library.js | 30 ++- 8 files changed, 205 insertions(+), 63 deletions(-) delete mode 100644 app/imports/client/ui/utility/escapeRegex.js diff --git a/app/imports/api/parenting/nodesToTree.js b/app/imports/api/parenting/nodesToTree.js index fae36df1..86fbe1c1 100644 --- a/app/imports/api/parenting/nodesToTree.js +++ b/app/imports/api/parenting/nodesToTree.js @@ -1,4 +1,4 @@ -import { union, difference, sortBy, findLast } from 'lodash'; +import { union, difference, sortBy, findLast, intersection } from 'lodash'; export function nodeArrayToTree(nodes) { // Store a dict and list of all the nodes @@ -83,9 +83,15 @@ export default function nodesToTree({ docs.forEach(doc => { ancestorIds = union(ancestorIds, doc.ancestors.map(ref => ref.id)); }); - // Remove the IDs of docs we have already found + // Get all the docs that are also ancestors and mark them + docs.forEach(doc => { + if (ancestorIds.includes(doc._id)) { + doc._ancestorOfMatchedDocument = true; + } + }); + // Remove the ancestor IDs of docs we have already found ancestorIds = difference(ancestorIds, docIds); - // Get the docs from the collection, don't worry about `removed` docs, + // Get the ancestor docs from the collection, don't worry about `removed` docs, // if their descendant was not removed, neither are they ancestors = collection.find({ _id: { $in: ancestorIds } }).map(doc => { // Mark that the nodes are ancestors of the found nodes diff --git a/app/imports/api/utility/escapeRegex.js b/app/imports/api/utility/escapeRegex.js index 8ec4073c..4f0be7de 100644 --- a/app/imports/api/utility/escapeRegex.js +++ b/app/imports/api/utility/escapeRegex.js @@ -1,3 +1,3 @@ export default function escapeRegex(string) { - return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, ''); + return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); } \ No newline at end of file diff --git a/app/imports/client/ui/components/tree/TreeSearchInput.vue b/app/imports/client/ui/components/tree/TreeSearchInput.vue index 5abac7e5..ab0f1e40 100644 --- a/app/imports/client/ui/components/tree/TreeSearchInput.vue +++ b/app/imports/client/ui/components/tree/TreeSearchInput.vue @@ -1,19 +1,111 @@ diff --git a/app/imports/client/ui/creature/character/characterSheetTabs/TreeTab.vue b/app/imports/client/ui/creature/character/characterSheetTabs/TreeTab.vue index a133f0b9..23ee01f8 100644 --- a/app/imports/client/ui/creature/character/characterSheetTabs/TreeTab.vue +++ b/app/imports/client/ui/creature/character/characterSheetTabs/TreeTab.vue @@ -11,9 +11,14 @@