From a3355dd98875180afdf01d52cc920703ee33a51f Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Tue, 22 Nov 2022 00:56:10 +0200 Subject: [PATCH] stat grouping is now everywhere This lead to a complete refactor of the stats page Some things might break --- app/imports/api/parenting/nodesToTree.js | 30 +- app/imports/api/properties/Folders.js | 18 + .../character/characterSheetTabs/BuildTab.vue | 44 ++- .../characterSheetTabs/FeaturesTab.vue | 23 ++ .../characterSheetTabs/InventoryTab.vue | 30 +- .../characterSheetTabs/JournalTab.vue | 23 ++ .../characterSheetTabs/SpellsTab.vue | 28 +- .../character/characterSheetTabs/StatsTab.vue | 317 ++++++++++-------- .../components/folders/tabFoldersMixin.js | 53 +++ .../client/ui/properties/forms/FolderForm.vue | 71 +++- 10 files changed, 461 insertions(+), 176 deletions(-) create mode 100644 app/imports/client/ui/properties/components/folders/tabFoldersMixin.js diff --git a/app/imports/api/parenting/nodesToTree.js b/app/imports/api/parenting/nodesToTree.js index b8589967..3e4b5733 100644 --- a/app/imports/api/parenting/nodesToTree.js +++ b/app/imports/api/parenting/nodesToTree.js @@ -1,10 +1,10 @@ import { union, difference, sortBy, findLast } from 'lodash'; -export function nodeArrayToTree(nodes){ +export function nodeArrayToTree(nodes) { // Store a dict and list of all the nodes let nodeIndex = {}; let nodeList = []; - nodes.forEach( node => { + nodes.forEach(node => { let treeNode = { node: node, children: [], @@ -20,7 +20,7 @@ export function nodeArrayToTree(nodes){ treeNode.node.ancestors, ancestor => !!nodeIndex[ancestor.id] ); - if (ancestorInForest){ + if (ancestorInForest) { nodeIndex[ancestorInForest.id].children.push(treeNode); } else { forest.push(treeNode); @@ -33,13 +33,13 @@ export function nodeArrayToTree(nodes){ export default function nodesToTree({ collection, ancestorId, filter, options = {}, includeFilteredDocAncestors = false, includeFilteredDocDescendants = false -}){ +}) { // Setup the filter let collectionFilter = { 'ancestors.id': ancestorId, - 'removed': {$ne: true}, + 'removed': { $ne: true }, }; - if (filter){ + if (filter) { collectionFilter = { ...collectionFilter, ...filter, @@ -49,7 +49,7 @@ export default function nodesToTree({ let collectionSort = { order: 1 }; - if (options && options.sort){ + if (options && options.sort) { collectionSort = { ...collectionSort, ...options.sort, @@ -58,7 +58,7 @@ export default function nodesToTree({ let collectionOptions = { sort: collectionSort, } - if (options){ + if (options) { collectionOptions = { ...collectionOptions, ...options, @@ -74,10 +74,10 @@ export default function nodesToTree({ let ancestors = []; let ancestorIds = []; let docIds = []; - if (filter && (includeFilteredDocAncestors || includeFilteredDocDescendants)){ + if (filter && (includeFilteredDocAncestors || includeFilteredDocDescendants)) { docIds = docs.map(doc => doc._id) } - if (filter && includeFilteredDocAncestors){ + if (filter && includeFilteredDocAncestors) { // Add all ancestor ids to an array docs.forEach(doc => { ancestorIds = union(ancestorIds, doc.ancestors.map(ref => ref.id)); @@ -86,19 +86,19 @@ export default function nodesToTree({ ancestorIds = difference(ancestorIds, docIds); // Get the docs from the collection, don't worry about `removed` docs, // if their descendant was not removed, neither are they - ancestors = collection.find({_id: {$in: ancestorIds}}).map(doc => { + ancestors = collection.find({ _id: { $in: ancestorIds } }).map(doc => { // Mark that the nodes are ancestors of the found nodes doc._ancestorOfMatchedDocument = true; return doc; }); } let descendants = []; - if (filter && includeFilteredDocDescendants){ + if (filter && includeFilteredDocDescendants) { let exludeIds = union(ancestorIds, docIds); descendants = collection.find({ - '_id': {$nin: exludeIds}, - 'ancestors.id': {$in: docIds}, - 'removed': {$ne: true}, + '_id': { $nin: exludeIds }, + 'ancestors.id': { $in: docIds }, + 'removed': { $ne: true }, }).map(doc => { // Mark that the nodes are descendants of the found nodes doc._descendantOfMatchedDocument = true; diff --git a/app/imports/api/properties/Folders.js b/app/imports/api/properties/Folders.js index aa68e56f..605975b3 100644 --- a/app/imports/api/properties/Folders.js +++ b/app/imports/api/properties/Folders.js @@ -13,6 +13,24 @@ let FolderSchema = new createPropertySchema({ type: Boolean, optional: true, }, + hideStatsGroup: { + type: Boolean, + optional: true, + }, + tab: { + type: String, + optional: true, + allowedValues: [ + 'stats', 'features', 'inventory', 'spells', 'journal', 'build' + ], + }, + location: { + type: String, + optional: true, + allowedValues: [ + 'start', 'events', 'stats', 'skills', 'actions', 'proficiencies', 'end' + ], + }, }); const ComputedOnlyFolderSchema = new createPropertySchema({}); diff --git a/app/imports/client/ui/creature/character/characterSheetTabs/BuildTab.vue b/app/imports/client/ui/creature/character/characterSheetTabs/BuildTab.vue index 8e6881e5..1f4cd4bb 100644 --- a/app/imports/client/ui/creature/character/characterSheetTabs/BuildTab.vue +++ b/app/imports/client/ui/creature/character/characterSheetTabs/BuildTab.vue @@ -13,9 +13,19 @@ + + + @@ -81,9 +91,7 @@ + + + @@ -190,6 +210,7 @@ import CharacterErrors from '/imports/client/ui/creature/character/errors/Charac import { snackbar } from '/imports/client/ui/components/snackbars/SnackbarQueue.js'; import updateCreatureProperty from '/imports/api/creature/creatureProperties/methods/updateCreatureProperty.js'; import getPropertyTitle from '/imports/client/ui/properties/shared/getPropertyTitle.js'; +import tabFoldersMixin from '/imports/client/ui/properties/components/folders/tabFoldersMixin.js'; function traverse(tree, callback, parents = []){ tree.forEach(node => { @@ -204,12 +225,23 @@ export default { BuildTreeNodeList, SlotCardsToFill, }, + mixins: [tabFoldersMixin], props: { creatureId: { type: String, required: true, }, }, + data() { + return { + tabName: 'build', + cols: { + cols: '12', + md: '6', + xl: '4', + } + }; + }, computed: { highestLevels(){ let highestLevels = {}; diff --git a/app/imports/client/ui/creature/character/characterSheetTabs/FeaturesTab.vue b/app/imports/client/ui/creature/character/characterSheetTabs/FeaturesTab.vue index 8630a938..11144684 100644 --- a/app/imports/client/ui/creature/character/characterSheetTabs/FeaturesTab.vue +++ b/app/imports/client/ui/creature/character/characterSheetTabs/FeaturesTab.vue @@ -1,6 +1,14 @@ @@ -19,18 +35,25 @@ import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js'; import ColumnLayout from '/imports/client/ui/components/ColumnLayout.vue'; import FeatureCard from '/imports/client/ui/properties/components/features/FeatureCard.vue'; +import tabFoldersMixin from '/imports/client/ui/properties/components/folders/tabFoldersMixin.js'; export default { components: { ColumnLayout, FeatureCard, }, + mixins: [tabFoldersMixin], props: { creatureId: { type: String, required: true, }, }, + data() { + return { + tabName: 'features', + }; + }, meteor: { features() { return CreatureProperties.find({ diff --git a/app/imports/client/ui/creature/character/characterSheetTabs/InventoryTab.vue b/app/imports/client/ui/creature/character/characterSheetTabs/InventoryTab.vue index b78e0d73..89c4d59b 100644 --- a/app/imports/client/ui/creature/character/characterSheetTabs/InventoryTab.vue +++ b/app/imports/client/ui/creature/character/characterSheetTabs/InventoryTab.vue @@ -1,6 +1,14 @@ @@ -101,6 +117,7 @@ import BUILT_IN_TAGS from '/imports/constants/BUILT_IN_TAGS.js'; import CoinValue from '/imports/client/ui/components/CoinValue.vue'; import stripFloatingPointOddities from '/imports/api/engine/computation/utility/stripFloatingPointOddities.js'; import CreatureVariables from '/imports/api/creature/creatures/CreatureVariables.js'; +import tabFoldersMixin from '/imports/client/ui/properties/components/folders/tabFoldersMixin.js'; export default { components: { @@ -110,6 +127,7 @@ export default { ItemList, CoinValue, }, + mixins: [tabFoldersMixin], props: { creatureId: { type: String, @@ -119,7 +137,8 @@ export default { data() { return { organize: false, - } + tabName: 'inventory', + }; }, meteor: { containers() { @@ -216,15 +235,6 @@ export default { ); }, }, - methods: { - clickProperty(_id) { - this.$store.commit('pushDialogStack', { - component: 'creature-property-dialog', - elementId: `tree-node-${_id}`, - data: { _id }, - }); - }, - }, } diff --git a/app/imports/client/ui/creature/character/characterSheetTabs/JournalTab.vue b/app/imports/client/ui/creature/character/characterSheetTabs/JournalTab.vue index 4bc52058..2679265a 100644 --- a/app/imports/client/ui/creature/character/characterSheetTabs/JournalTab.vue +++ b/app/imports/client/ui/creature/character/characterSheetTabs/JournalTab.vue @@ -1,6 +1,14 @@ @@ -22,6 +38,7 @@ import Creatures from '/imports/api/creature/creatures/Creatures.js'; import NoteCard from '/imports/client/ui/properties/components/persona/NoteCard.vue'; import CreatureSummary from '/imports/client/ui/creature/character/CreatureSummary.vue'; import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js'; +import tabFoldersMixin from '/imports/client/ui/properties/components/folders/tabFoldersMixin.js'; export default { components: { @@ -29,12 +46,18 @@ export default { CreatureSummary, NoteCard, }, + mixins: [tabFoldersMixin], props: { creatureId: { type: String, required: true, }, }, + data() { + return { + tabName: 'journal', + }; + }, meteor: { notes(){ return CreatureProperties.find({ diff --git a/app/imports/client/ui/creature/character/characterSheetTabs/SpellsTab.vue b/app/imports/client/ui/creature/character/characterSheetTabs/SpellsTab.vue index 14a5ff5c..12c65775 100644 --- a/app/imports/client/ui/creature/character/characterSheetTabs/SpellsTab.vue +++ b/app/imports/client/ui/creature/character/characterSheetTabs/SpellsTab.vue @@ -1,6 +1,14 @@ @@ -27,6 +43,7 @@ import ColumnLayout from '/imports/client/ui/components/ColumnLayout.vue'; import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js'; import SpellListCard from '/imports/client/ui/properties/components/spells/SpellListCard.vue'; import SpellList from '/imports/client/ui/properties/components/spells/SpellList.vue'; +import tabFoldersMixin from '/imports/client/ui/properties/components/folders/tabFoldersMixin.js'; export default { components: { @@ -34,6 +51,7 @@ export default { SpellList, SpellListCard, }, + mixins: [tabFoldersMixin], props: { creatureId: { type: String, @@ -43,6 +61,7 @@ export default { data() { return { organize: false, + tabName: 'spells', } }, meteor: { @@ -92,15 +111,6 @@ export default { return this.spellLists.map(spellList => spellList._id); }, }, - methods: { - clickProperty(_id) { - this.$store.commit('pushDialogStack', { - component: 'creature-property-dialog', - elementId: `spell-list-tile-${_id}`, - data: { _id }, - }); - }, - }, } diff --git a/app/imports/client/ui/creature/character/characterSheetTabs/StatsTab.vue b/app/imports/client/ui/creature/character/characterSheetTabs/StatsTab.vue index 50b880ee..2da6dfb5 100644 --- a/app/imports/client/ui/creature/character/characterSheetTabs/StatsTab.vue +++ b/app/imports/client/ui/creature/character/characterSheetTabs/StatsTab.vue @@ -1,12 +1,15 @@