Slot fill now shows selected slots while searching

This commit is contained in:
Stefan Zermatten
2023-08-24 13:00:26 +02:00
parent d973463126
commit 7fa993de47
2 changed files with 63 additions and 2 deletions

View File

@@ -58,7 +58,7 @@
multiple
hover
>
<template v-for="libraryNode in libraryNodes">
<template v-for="libraryNode in [...selectedExcludedNodes, ...libraryNodes]">
<v-expansion-panel
v-if="showDisabled || !libraryNode._disabledBySlotFillerCondition"
:key="libraryNode._id"
@@ -245,7 +245,7 @@ import Libraries from '/imports/api/library/Libraries.js';
import LibraryNodeExpansionContent from '/imports/client/ui/library/LibraryNodeExpansionContent.vue';
import PropertyTags from '/imports/client/ui/properties/viewers/shared/PropertyTags.vue';
import { getPropertyName } from '/imports/constants/PROPERTIES.js';
import { clone } from 'lodash';
import { clone, difference } from 'lodash';
import getDefaultSlotFiller from '/imports/api/library/methods/getDefaultSlotFiller.js';
import insertPropertyFromLibraryNode from '/imports/api/creature/creatureProperties/methods/insertPropertyFromLibraryNode.js';
import insertProperty from '/imports/api/creature/creatureProperties/methods/insertProperty.js';
@@ -400,6 +400,9 @@ export default {
'slotFillers'() {
return [this.slotId || this.dummySlot?._id, this.searchValue || undefined, !!this.dummySlot]
},
'selectedFillers'() {
return [this.slotId || this.dummySlot?._id, this.selectedNodeIds, !!this.dummySlot]
},
},
searchLoading() {
return !!this.searchValue && !this.$subReady.slotFillers;
@@ -541,6 +544,11 @@ export default {
this.disabledNodeCount = disabledNodeCount;
return nodes;
},
selectedExcludedNodes() {
const displayedIds = this.libraryNodes.map(node => node._id);
const excludedNodeIds = difference(this.selectedNodeIds, displayedIds);
return LibraryNodes.find({ _id: { $in: excludedNodeIds } });
}
}
}
</script>

View File

@@ -7,6 +7,58 @@ import getCreatureLibraryIds from '/imports/api/library/getCreatureLibraryIds.js
import { LIBRARY_NODE_TREE_FIELDS } from '/imports/server/publications/library.js';
import escapeRegex from '/imports/api/utility/escapeRegex.js';
// Publish docs the user has already selected so they don't disappear when searching
Meteor.publish('selectedFillers', function (slotId, nodeIds, isDummySlot) {
let autorun = this.autorun;
autorun(function () {
let userId = this.userId;
if (!userId) {
return [];
}
// Get the slot from the right collection
let slot;
if (isDummySlot) {
slot = LibraryNodes.findOne(slotId);
} else {
slot = CreatureProperties.findOne(slotId);
}
if (!slot) return [];
// Get all the ids of libraries the user can access
const creatureId = slot.ancestors[0].id;
const libraryIds = getCreatureLibraryIds(creatureId, userId);
const libraries = Libraries.find({
$or: [
{ owner: userId },
{ writers: userId },
{ readers: userId },
{ _id: { $in: libraryIds }, public: true },
]
}, {
sort: { name: 1 }
});
let filter = { _id: { $in: nodeIds } };
// Get the limit of the documents the user can fetch
let options = {
sort: {
name: 1,
order: 1,
},
limit: 100,
fields: LIBRARY_NODE_TREE_FIELDS,
};
autorun(function () {
return [
LibraryNodes.find(filter, options),
libraries
];
});
});
});
Meteor.publish('slotFillers', function (slotId, searchTerm, isDummySlot) {
if (searchTerm) check(searchTerm, String);
@@ -50,6 +102,7 @@ Meteor.publish('slotFillers', function (slotId, searchTerm, isDummySlot) {
let options = undefined;
if (searchTerm) {
if (!filter.$and) filter.$and = [];
filter.$and.push({
$or: [
{ name: { $regex: escapeRegex(searchTerm), '$options': 'i' } },