From 7cb65954b5fde33bf563e3476b13ac05dc88ef8a Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Thu, 5 Nov 2020 14:05:17 +0200 Subject: [PATCH] Added the ability to hide slots when full --- .../denormalise/recomputeSlotFullness.js | 12 ++++++++-- app/imports/api/properties/Slots.js | 10 +++++++- .../ui/creature/slots/SlotFillDialog.vue | 8 ++----- app/imports/ui/creature/slots/Slots.vue | 16 +++++++++---- app/imports/ui/properties/forms/SlotForm.vue | 24 ++++++++++++------- 5 files changed, 48 insertions(+), 22 deletions(-) diff --git a/app/imports/api/creature/denormalise/recomputeSlotFullness.js b/app/imports/api/creature/denormalise/recomputeSlotFullness.js index 775e4c97..3da2320b 100644 --- a/app/imports/api/creature/denormalise/recomputeSlotFullness.js +++ b/app/imports/api/creature/denormalise/recomputeSlotFullness.js @@ -8,6 +8,8 @@ export default function recomputeSlotFullness(ancestorId){ let children = CreatureProperties.find({ 'parent.id': slot._id, removed: {$ne: true}, + }, { + fields: {slotQuantityFilled: 1} }).fetch(); let totalFilled = 0; children.forEach(child => { @@ -17,9 +19,15 @@ export default function recomputeSlotFullness(ancestorId){ totalFilled++; } }); - if (slot.totalFilled !== totalFilled){ + let spaceLeft; + if (slot.quantityExpected === 0){ + spaceLeft = null; + } else { + spaceLeft = slot.quantityExpected - totalFilled; + } + if (slot.totalFilled !== totalFilled || slot.spaceLeft !== spaceLeft){ CreatureProperties.update(slot._id, { - $set: {totalFilled}, + $set: {totalFilled, spaceLeft}, }, { selector: {type: 'propertySlot'} }); diff --git a/app/imports/api/properties/Slots.js b/app/imports/api/properties/Slots.js index 288ee12c..e1f9bbf4 100644 --- a/app/imports/api/properties/Slots.js +++ b/app/imports/api/properties/Slots.js @@ -34,6 +34,10 @@ let SlotSchema = new SimpleSchema({ type: String, optional: true, }, + hideWhenFull: { + type: Boolean, + optional: true, + } }); const ComputedOnlySlotSchema = new SimpleSchema({ @@ -53,7 +57,11 @@ const ComputedOnlySlotSchema = new SimpleSchema({ totalFilled: { type: SimpleSchema.Integer, defaultValue: 0, - } + }, + spaceLeft: { + type: SimpleSchema.Integer, + optional: true, + }, }); const ComputedSlotSchema = new SimpleSchema() diff --git a/app/imports/ui/creature/slots/SlotFillDialog.vue b/app/imports/ui/creature/slots/SlotFillDialog.vue index dfb71e7b..52c319ab 100644 --- a/app/imports/ui/creature/slots/SlotFillDialog.vue +++ b/app/imports/ui/creature/slots/SlotFillDialog.vue @@ -129,10 +129,6 @@ export default { type: String, required: true, }, - numToFill: { - type: Number, - required: true, - }, }, data(){return { selectedNode: undefined, @@ -194,8 +190,8 @@ export default { } if ( node.type === 'slotFiller' && - this.numToFill > 0 && - node.slotQuantityFilled > this.numToFill + this.model.spaceLeft > 0 && + node.slotQuantityFilled > this.model.spaceLeft ){ return false; } diff --git a/app/imports/ui/creature/slots/Slots.vue b/app/imports/ui/creature/slots/Slots.vue index 3f3c2833..e89d59a0 100644 --- a/app/imports/ui/creature/slots/Slots.vue +++ b/app/imports/ui/creature/slots/Slots.vue @@ -38,7 +38,7 @@ !( // Hide full and ignored slots + !this.showHiddenSlots && + slot.hideWhenFull && + slot.quantityExpected > 0 && + slot.totalFilled >= slot.quantityExpected || + slot.ignored + )); }, }, } diff --git a/app/imports/ui/properties/forms/SlotForm.vue b/app/imports/ui/properties/forms/SlotForm.vue index fdf4eddc..8f7ca4c7 100644 --- a/app/imports/ui/properties/forms/SlotForm.vue +++ b/app/imports/ui/properties/forms/SlotForm.vue @@ -54,15 +54,15 @@ name="Advanced" standalone > -
+
+