From 15d593db79a9c4cf1426303f07b30c3f72355a22 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Mon, 12 Apr 2021 16:04:04 +0200 Subject: [PATCH] Properties quick-inserted from the sheet now go into folders in the tree --- .../methods/insertProperty.js | 16 ++++++++++++-- .../creature/character/CharacterSheetFab.vue | 21 ++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/app/imports/api/creature/creatureProperties/methods/insertProperty.js b/app/imports/api/creature/creatureProperties/methods/insertProperty.js index 7f82cfe0..1dec5491 100644 --- a/app/imports/api/creature/creatureProperties/methods/insertProperty.js +++ b/app/imports/api/creature/creatureProperties/methods/insertProperty.js @@ -11,6 +11,7 @@ import recomputeInventory from '/imports/api/creature/denormalise/recomputeInven import { getAncestry } from '/imports/api/parenting/parenting.js'; import getParentRefByTag from '/imports/api/creature/creatureProperties/methods/getParentRefByTag.js'; import { RefSchema } from '/imports/api/parenting/ChildSchema.js'; +import { getHighestOrder } from '/imports/api/parenting/order.js'; const insertProperty = new ValidatedMethod({ name: 'creatureProperties.insert', @@ -66,13 +67,18 @@ const insertPropertyAsChildOfTag = new ValidatedMethod({ type: String, max: 20, }, + tagDefaultName: { + type: String, + max: 20, + optional: true, + }, }).validator(), mixins: [RateLimiterMixin], rateLimit: { numRequests: 5, timeInterval: 5000, }, - run({creatureProperty, creatureId, tag}) { + run({creatureProperty, creatureId, tag, tagDefaultName}) { let parentRef = getParentRefByTag(creatureId, tag); if (!parentRef){ @@ -97,17 +103,23 @@ const insertPropertyAsChildOfTag = new ValidatedMethod({ // Add the folder first if we need to if (insertFolderFirst){ + let order = getHighestOrder({ + collection: CreatureProperties, + ancestorId: parentRef.id, + }) + 1; let id = CreatureProperties.insert({ type: 'folder', - name: tag.charAt(0).toUpperCase() + tag.slice(1), + name: tagDefaultName || (tag.charAt(0).toUpperCase() + tag.slice(1)), tags: [tag], parent: parentRef, ancestors: [parentRef], + order, }); // Make the folder our new parent let newParentRef = {id, collection: 'creatureProperties'}; ancestors = [parentRef, newParentRef]; parentRef = newParentRef; + creatureProperty.order = order + 1; } creatureProperty.parent = parentRef; diff --git a/app/imports/ui/creature/character/CharacterSheetFab.vue b/app/imports/ui/creature/character/CharacterSheetFab.vue index 1caa8fc8..abcd83c4 100644 --- a/app/imports/ui/creature/character/CharacterSheetFab.vue +++ b/app/imports/ui/creature/character/CharacterSheetFab.vue @@ -62,7 +62,7 @@