Slot fill now shows selected slots while searching
This commit is contained in:
@@ -58,7 +58,7 @@
|
|||||||
multiple
|
multiple
|
||||||
hover
|
hover
|
||||||
>
|
>
|
||||||
<template v-for="libraryNode in libraryNodes">
|
<template v-for="libraryNode in [...selectedExcludedNodes, ...libraryNodes]">
|
||||||
<v-expansion-panel
|
<v-expansion-panel
|
||||||
v-if="showDisabled || !libraryNode._disabledBySlotFillerCondition"
|
v-if="showDisabled || !libraryNode._disabledBySlotFillerCondition"
|
||||||
:key="libraryNode._id"
|
: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 LibraryNodeExpansionContent from '/imports/client/ui/library/LibraryNodeExpansionContent.vue';
|
||||||
import PropertyTags from '/imports/client/ui/properties/viewers/shared/PropertyTags.vue';
|
import PropertyTags from '/imports/client/ui/properties/viewers/shared/PropertyTags.vue';
|
||||||
import { getPropertyName } from '/imports/constants/PROPERTIES.js';
|
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 getDefaultSlotFiller from '/imports/api/library/methods/getDefaultSlotFiller.js';
|
||||||
import insertPropertyFromLibraryNode from '/imports/api/creature/creatureProperties/methods/insertPropertyFromLibraryNode.js';
|
import insertPropertyFromLibraryNode from '/imports/api/creature/creatureProperties/methods/insertPropertyFromLibraryNode.js';
|
||||||
import insertProperty from '/imports/api/creature/creatureProperties/methods/insertProperty.js';
|
import insertProperty from '/imports/api/creature/creatureProperties/methods/insertProperty.js';
|
||||||
@@ -400,6 +400,9 @@ export default {
|
|||||||
'slotFillers'() {
|
'slotFillers'() {
|
||||||
return [this.slotId || this.dummySlot?._id, this.searchValue || undefined, !!this.dummySlot]
|
return [this.slotId || this.dummySlot?._id, this.searchValue || undefined, !!this.dummySlot]
|
||||||
},
|
},
|
||||||
|
'selectedFillers'() {
|
||||||
|
return [this.slotId || this.dummySlot?._id, this.selectedNodeIds, !!this.dummySlot]
|
||||||
|
},
|
||||||
},
|
},
|
||||||
searchLoading() {
|
searchLoading() {
|
||||||
return !!this.searchValue && !this.$subReady.slotFillers;
|
return !!this.searchValue && !this.$subReady.slotFillers;
|
||||||
@@ -541,6 +544,11 @@ export default {
|
|||||||
this.disabledNodeCount = disabledNodeCount;
|
this.disabledNodeCount = disabledNodeCount;
|
||||||
return nodes;
|
return nodes;
|
||||||
},
|
},
|
||||||
|
selectedExcludedNodes() {
|
||||||
|
const displayedIds = this.libraryNodes.map(node => node._id);
|
||||||
|
const excludedNodeIds = difference(this.selectedNodeIds, displayedIds);
|
||||||
|
return LibraryNodes.find({ _id: { $in: excludedNodeIds } });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -7,6 +7,58 @@ import getCreatureLibraryIds from '/imports/api/library/getCreatureLibraryIds.js
|
|||||||
import { LIBRARY_NODE_TREE_FIELDS } from '/imports/server/publications/library.js';
|
import { LIBRARY_NODE_TREE_FIELDS } from '/imports/server/publications/library.js';
|
||||||
import escapeRegex from '/imports/api/utility/escapeRegex.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) {
|
Meteor.publish('slotFillers', function (slotId, searchTerm, isDummySlot) {
|
||||||
if (searchTerm) check(searchTerm, String);
|
if (searchTerm) check(searchTerm, String);
|
||||||
|
|
||||||
@@ -50,6 +102,7 @@ Meteor.publish('slotFillers', function (slotId, searchTerm, isDummySlot) {
|
|||||||
|
|
||||||
let options = undefined;
|
let options = undefined;
|
||||||
if (searchTerm) {
|
if (searchTerm) {
|
||||||
|
if (!filter.$and) filter.$and = [];
|
||||||
filter.$and.push({
|
filter.$and.push({
|
||||||
$or: [
|
$or: [
|
||||||
{ name: { $regex: escapeRegex(searchTerm), '$options': 'i' } },
|
{ name: { $regex: escapeRegex(searchTerm), '$options': 'i' } },
|
||||||
|
|||||||
Reference in New Issue
Block a user