From ffc3211ff9db8b0b3b8b43f5d01380b1f855eac7 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Thu, 12 Aug 2021 18:28:53 +0200 Subject: [PATCH] Fixed some issues with slot filler searching --- .../server/publications/slotFillers.js | 14 ++--- .../ui/creature/slots/SlotFillDialog.vue | 53 ++++++------------- 2 files changed, 23 insertions(+), 44 deletions(-) diff --git a/app/imports/server/publications/slotFillers.js b/app/imports/server/publications/slotFillers.js index 94dbf7fc..812ee9be 100644 --- a/app/imports/server/publications/slotFillers.js +++ b/app/imports/server/publications/slotFillers.js @@ -4,7 +4,10 @@ import LibraryNodes from '/imports/api/library/LibraryNodes.js'; import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js'; import getSlotFillFilter from '/imports/api/creature/creatureProperties/methods/getSlotFillFilter.js' -Meteor.publish('slotFillers', function(slotId){ +Meteor.publish('slotFillers', function(slotId, searchTerm){ + if (searchTerm) check(searchTerm, String); + console.log({slotId, searchTerm}) + let self = this; this.autorun(function (){ let userId = this.userId; @@ -42,21 +45,17 @@ Meteor.publish('slotFillers', function(slotId){ var limit = self.data('limit') || 50; check(limit, Number); - // Get the search term - let searchTerm = self.data('searchTerm') || ''; - check(searchTerm, String); - let options = undefined; if (searchTerm){ filter.$text = {$search: searchTerm}; options = { // relevant documents have a higher score. fields: { - score: { $meta: 'textScore' } + _score: { $meta: 'textScore' } }, sort: { // `score` property specified in the projection fields above. - score: { $meta: 'textScore' }, + _score: { $meta: 'textScore' }, name: 1, order: 1, } @@ -74,6 +73,7 @@ Meteor.publish('slotFillers', function(slotId){ self.setData('countAll', LibraryNodes.find(filter).count()); }); self.autorun(function () { + Meteor._sleepForMs(1000); return [LibraryNodes.find(filter, options), libraries]; }); }); diff --git a/app/imports/ui/creature/slots/SlotFillDialog.vue b/app/imports/ui/creature/slots/SlotFillDialog.vue index c6fdf4fb..40b2585b 100644 --- a/app/imports/ui/creature/slots/SlotFillDialog.vue +++ b/app/imports/ui/creature/slots/SlotFillDialog.vue @@ -8,14 +8,17 @@ {{ model.name }} -
= this.countAll) return; this._subs['slotFillers'].setData('limit', this.currentLimit + 50); }, - insert(){ - if (!this.selectedNode) return; - this.$store.dispatch('popDialogStack', this.selectedNode); - }, openPropertyDetails(id){ this.$store.commit('pushDialogStack', { component: 'library-node-dialog', @@ -281,14 +274,17 @@ export default { node._disabledByQuantityFilled && !this.selectedNodeIds.includes(node._id) ) - } + }, }, meteor: { $subscribe: { 'slotFillers'(){ - return [this.slotId] + return [this.slotId, this.searchValue || undefined] }, }, + searchLoading(){ + return !!this.searchValue && !this.$subReady.slotFillers; + }, model(){ if (this.slotId){ return CreatureProperties.findOne(this.slotId); @@ -359,8 +355,6 @@ export default { sort: {name: 1, order: 1} }).fetch(); let disabledNodeCount = 0; - let activeNodeCount = 0; - let lastActiveNodeId = undefined; // Mark slotFillers whose condition isn't met or are too big to fit // the quantity to fill nodes.forEach(node => { @@ -384,23 +378,8 @@ export default { if (this.alreadyAdded.has(node._id)){ node._disabledByAlreadyAdded = true; } - if ( - !node._disabledBySlotFillerCondition && - !node._disabledByQuantityFilled && - !node._disabledByAlreadyAdded - ){ - activeNodeCount += 1; - lastActiveNodeId = node._id; - } }); this.disabledNodeCount = disabledNodeCount; - if ( - activeNodeCount === 1 && - this.$subReady.slotFillers && - this.currentLimit >= this.countAll - ) { - this.selectedNodeIds = [lastActiveNodeId] - } return nodes; }, }