Migrated some UI to nested sets, app starts now
This commit is contained in:
@@ -87,13 +87,15 @@ type FilteredDoc = {
|
||||
_ancestorOfMatchedDocument?: boolean,
|
||||
} & TreeDoc;
|
||||
|
||||
export default async function filterToForest(
|
||||
export async function filterToForest(
|
||||
collection: Mongo.Collection<TreeDoc>,
|
||||
rootId: string,
|
||||
filter: Mongo.Selector<TreeDoc>,
|
||||
options: Mongo.Options<object> = {},
|
||||
includeFilteredDocAncestors = false,
|
||||
includeFilteredDocDescendants = false
|
||||
{
|
||||
options = <Mongo.Options<object>>{},
|
||||
includeFilteredDocAncestors = false,
|
||||
includeFilteredDocDescendants = false
|
||||
} = {}
|
||||
): Promise<TreeNode<FilteredDoc>[]> {
|
||||
// Setup the filter
|
||||
let collectionFilter = {
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
|
||||
<script lang="js">
|
||||
import LabeledFab from '/imports/client/ui/components/LabeledFab.vue';
|
||||
import { getHighestOrder } from '/imports/api/parenting/order';
|
||||
import insertProperty from '/imports/api/creature/creatureProperties/methods/insertProperty';
|
||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties';
|
||||
import Creatures from '/imports/api/creature/creatures/Creatures';
|
||||
@@ -48,11 +47,11 @@
|
||||
import insertPropertyFromLibraryNode from '/imports/api/creature/creatureProperties/methods/insertPropertyFromLibraryNode';
|
||||
import { fetchDocByRef } from '/imports/api/parenting/parentingFunctions';
|
||||
|
||||
function getParentAndOrderFromSelectedTreeNode(creatureId, $store){
|
||||
function getParentFromSelectedTreeNode(creatureId, $store){
|
||||
// find the parent based on the currently selected property
|
||||
let el = document.querySelector('.tree-tab .tree-node-title.primary--text');
|
||||
let selectedComponent = el && el.parentElement.__vue__.$parent;
|
||||
let parentRef, order;
|
||||
let parentRef;
|
||||
const onTreeTab = $store.getters.tabNameById(creatureId) === 'tree';
|
||||
if (onTreeTab && selectedComponent){
|
||||
if (selectedComponent.showExpanded){
|
||||
@@ -60,22 +59,13 @@
|
||||
id: selectedComponent.node._id,
|
||||
collection: 'creatureProperties',
|
||||
};
|
||||
order = getHighestOrder({
|
||||
collection: CreatureProperties,
|
||||
ancestorId: parentRef.id,
|
||||
}) + 0.5;
|
||||
} else {
|
||||
parentRef = selectedComponent.node.parent;
|
||||
order = selectedComponent.node.order + 0.5;
|
||||
}
|
||||
} else {
|
||||
parentRef = {collection: 'creatures', id: creatureId};
|
||||
order = getHighestOrder({
|
||||
collection: CreatureProperties,
|
||||
ancestorId: parentRef.id,
|
||||
}) + 0.5;
|
||||
}
|
||||
return {parentRef, order}
|
||||
return parentRef;
|
||||
}
|
||||
|
||||
function hideFab(){
|
||||
@@ -144,7 +134,7 @@
|
||||
let creatureId = this.creatureId;
|
||||
let fab = hideFab();
|
||||
|
||||
let {parentRef, order } = getParentAndOrderFromSelectedTreeNode(creatureId, this.$store);
|
||||
let parentRef = getParentFromSelectedTreeNode(creatureId, this.$store);
|
||||
let parent;
|
||||
try {
|
||||
parent = fetchDocByRef(parentRef);
|
||||
@@ -168,13 +158,11 @@
|
||||
if (Array.isArray(result)){
|
||||
revealFab(fab);
|
||||
let nodeIds = result;
|
||||
let id = insertPropertyFromLibraryNode.call({nodeIds, parentRef, order});
|
||||
let id = insertPropertyFromLibraryNode.call({nodeIds, parentRef});
|
||||
return forcedType ? id : `tree-node-${id}`;
|
||||
} else {
|
||||
revealFab(fab);
|
||||
let creatureProperty = result;
|
||||
// Get order and parent
|
||||
creatureProperty.order = order;
|
||||
// Insert the property
|
||||
let id = insertProperty.call({creatureProperty, parentRef});
|
||||
return forcedType ? id : `tree-node-${id}`;
|
||||
|
||||
@@ -72,7 +72,6 @@ import propertyFormIndex from '/imports/client/ui/properties/forms/shared/proper
|
||||
import propertyViewerIndex from '/imports/client/ui/properties/viewers/shared/propertyViewerIndex';
|
||||
import CreaturePropertiesTree from '/imports/client/ui/creature/creatureProperties/CreaturePropertiesTree.vue';
|
||||
import { assertEditPermission } from '/imports/api/creature/creatures/creaturePermissions';
|
||||
import { getHighestOrder } from '/imports/api/parenting/order';
|
||||
import insertProperty from '/imports/api/creature/creatureProperties/methods/insertProperty';
|
||||
import insertPropertyFromLibraryNode from '/imports/api/creature/creatureProperties/methods/insertPropertyFromLibraryNode';
|
||||
|
||||
@@ -163,18 +162,12 @@ export default {
|
||||
id: parentPropertyId,
|
||||
collection: 'creatures',
|
||||
};
|
||||
let order = getHighestOrder({
|
||||
collection: CreatureProperties,
|
||||
ancestorId: parentRef.id,
|
||||
}) + 0.5;
|
||||
if (Array.isArray(result)){
|
||||
let nodeIds = result;
|
||||
let id = insertPropertyFromLibraryNode.call({nodeIds, parentRef, order});
|
||||
let id = insertPropertyFromLibraryNode.call({ nodeIds, parentRef });
|
||||
return `tree-node-${id}`;
|
||||
} else {
|
||||
let creatureProperty = result;
|
||||
// Get order and parent
|
||||
creatureProperty.order = order;
|
||||
// Insert the property
|
||||
let id = insertProperty.call({creatureProperty, parentRef});
|
||||
return `tree-node-${id}`;
|
||||
|
||||
@@ -410,7 +410,7 @@ import EventButton from '/imports/client/ui/properties/components/actions/EventB
|
||||
import { snackbar } from '/imports/client/ui/components/snackbars/SnackbarQueue';
|
||||
import FolderGroupCard from '/imports/client/ui/properties/components/folders/FolderGroupCard.vue';
|
||||
import { get, set, uniqBy } from 'lodash';
|
||||
import { nodeArrayToTree } from '/imports/api/parenting/nodesToTree'
|
||||
import { docsToForest } from '/imports/api/parenting/parentingFunctions';
|
||||
|
||||
function walkDown(forest, callback){
|
||||
let stack = [...forest];
|
||||
@@ -555,8 +555,8 @@ export default {
|
||||
if (creature.settings.hideUnusedStats) {
|
||||
filter.hide = { $ne: true };
|
||||
}
|
||||
const allProps = CreatureProperties.find(filter, { sort: { order: -1 } });
|
||||
const forest = nodeArrayToTree(allProps);
|
||||
const allProps = CreatureProperties.find(filter, { sort: { order: -1 } }).fetch();
|
||||
const forest = docsToForest(allProps);
|
||||
const properties = { folder: {}, attribute: {}, skill: {} };
|
||||
walkDown(forest, node => {
|
||||
const prop = node.doc
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="js">
|
||||
import nodesToTree from '/imports/api/parenting/nodesToTree'
|
||||
import { filterToForest } from '/imports/api/parenting/parentingFunctions';
|
||||
import TreeNodeList from '/imports/client/ui/components/tree/TreeNodeList.vue';
|
||||
import { organizeDoc, reorderDoc } from '/imports/api/parenting/organizeMethods';
|
||||
import { getCollectionByName } from '/imports/api/parenting/parentingFunctions';
|
||||
@@ -47,14 +47,16 @@ export default {
|
||||
expanded: Boolean,
|
||||
},
|
||||
meteor: {
|
||||
children() {
|
||||
const children = nodesToTree({
|
||||
collection: getCollectionByName(this.collection),
|
||||
ancestorId: this.root.id,
|
||||
filter: this.filter,
|
||||
includeFilteredDocAncestors: true,
|
||||
includeFilteredDocDescendants: true,
|
||||
});
|
||||
async children() {
|
||||
const children = await filterToForest(
|
||||
getCollectionByName(this.collection),
|
||||
this.root.id,
|
||||
this.filter,
|
||||
{
|
||||
includeFilteredDocAncestors: true,
|
||||
includeFilteredDocDescendants: true,
|
||||
}
|
||||
);
|
||||
this.$emit('length', children.length);
|
||||
return children;
|
||||
},
|
||||
|
||||
@@ -88,7 +88,6 @@ import { assertEditPermission } from '/imports/api/creature/creatures/creaturePe
|
||||
import { get, findLast } from 'lodash';
|
||||
import equipItem from '/imports/api/creature/creatureProperties/methods/equipItem';
|
||||
import { snackbar } from '/imports/client/ui/components/snackbars/SnackbarQueue';
|
||||
import { getHighestOrder } from '/imports/api/parenting/order';
|
||||
import insertProperty from '/imports/api/creature/creatureProperties/methods/insertProperty';
|
||||
import Breadcrumbs from '/imports/client/ui/creature/creatureProperties/Breadcrumbs.vue';
|
||||
import insertPropertyFromLibraryNode from '/imports/api/creature/creatureProperties/methods/insertPropertyFromLibraryNode';
|
||||
@@ -270,18 +269,12 @@ export default {
|
||||
id: parentPropertyId,
|
||||
collection: 'creatureProperties',
|
||||
};
|
||||
let order = getHighestOrder({
|
||||
collection: CreatureProperties,
|
||||
ancestorId: parentRef.id,
|
||||
}) + 0.5;
|
||||
if (Array.isArray(result)){
|
||||
let nodeIds = result;
|
||||
let id = insertPropertyFromLibraryNode.call({nodeIds, parentRef, order});
|
||||
let id = insertPropertyFromLibraryNode.call({ nodeIds, parentRef });
|
||||
return `tree-node-${id}`;
|
||||
} else {
|
||||
let creatureProperty = result;
|
||||
// Get order and parent
|
||||
creatureProperty.order = order;
|
||||
// Insert the property
|
||||
let id = insertProperty.call({creatureProperty, parentRef});
|
||||
return `tree-node-${id}`;
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<script lang="js">
|
||||
import Libraries from '/imports/api/library/Libraries';
|
||||
import LibraryNodes from '/imports/api/library/LibraryNodes';
|
||||
import nodesToTree from '/imports/api/parenting/nodesToTree';
|
||||
import { filterToForest } from '/imports/api/parenting/parentingFunctions';
|
||||
import TreeNodeList from '/imports/client/ui/components/tree/TreeNodeList.vue';
|
||||
import { organizeDoc, reorderDoc } from '/imports/api/parenting/organizeMethods';
|
||||
|
||||
@@ -90,13 +90,15 @@ export default {
|
||||
},
|
||||
libraryChildren() {
|
||||
if (!this.library) return;
|
||||
return nodesToTree({
|
||||
collection: LibraryNodes,
|
||||
ancestorId: this.library._id,
|
||||
filter: this.filter,
|
||||
includeFilteredDocAncestors: true,
|
||||
includeFilteredDocDescendants: true,
|
||||
});
|
||||
return filterToForest(
|
||||
LibraryNodes,
|
||||
this.library._id,
|
||||
this.filter,
|
||||
{
|
||||
includeFilteredDocAncestors: true,
|
||||
includeFilteredDocDescendants: true,
|
||||
}
|
||||
);
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
|
||||
@@ -120,7 +120,6 @@ import { organizeDoc } from '/imports/api/parenting/organizeMethods';
|
||||
import { snackbar } from '/imports/client/ui/components/snackbars/SnackbarQueue';
|
||||
import getPropertyTitle from '/imports/client/ui/properties/shared/getPropertyTitle';
|
||||
import copyLibraryNodeTo from '/imports/api/library/methods/copyLibraryNodeTo';
|
||||
import { getHighestOrder } from '/imports/api/parenting/order';
|
||||
import { getUserTier } from '/imports/api/users/patreon/tiers';
|
||||
import PropertyForm from '/imports/client/ui/properties/PropertyForm.vue';
|
||||
import PropertyViewer from '/imports/client/ui/properties/shared/PropertyViewer.vue';
|
||||
@@ -215,7 +214,6 @@ export default {
|
||||
collection: 'libraryNodes',
|
||||
id: this.model._id,
|
||||
},
|
||||
order: (this.model.order || 0) + 0.5,
|
||||
},
|
||||
parentRef: this.model.parent,
|
||||
}, (error, docId) => {
|
||||
@@ -257,7 +255,6 @@ export default {
|
||||
collection: 'libraryNodes',
|
||||
id: parentId
|
||||
},
|
||||
order: -0.5
|
||||
}, (error) => {
|
||||
if (error) console.error(error);
|
||||
});
|
||||
@@ -353,13 +350,7 @@ export default {
|
||||
id: parentPropertyId,
|
||||
collection: 'libraryNodes',
|
||||
};
|
||||
let order = getHighestOrder({
|
||||
collection: LibraryNodes,
|
||||
ancestorId: parentRef.id,
|
||||
}) + 0.5;
|
||||
let libraryNode = result;
|
||||
// Get order and parent
|
||||
libraryNode.order = order;
|
||||
// Insert the property
|
||||
let id = insertNode.call({libraryNode, parentRef});
|
||||
return `tree-node-${id}`;
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="js">
|
||||
import nodesToTree from '/imports/api/parenting/nodesToTree'
|
||||
import { filterToForest } from '/imports/api/parenting/parentingFunctions';
|
||||
import LibraryNodes from '/imports/api/library/LibraryNodes';
|
||||
import propertyViewerIndex from '/imports/client/ui/properties/viewers/shared/propertyViewerIndex';
|
||||
import TreeNodeList from '/imports/client/ui/components/tree/TreeNodeList.vue';
|
||||
@@ -70,11 +70,8 @@ export default {
|
||||
model() {
|
||||
return LibraryNodes.findOne(this.id);
|
||||
},
|
||||
propertyChildren(){
|
||||
return nodesToTree({
|
||||
collection: LibraryNodes,
|
||||
ancestorId: this.id
|
||||
});
|
||||
propertyChildren() {
|
||||
return filterToForest(LibraryNodes, this.id, {});
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties';
|
||||
|
||||
export default function cleanArchiveAtCurrent(archive) {
|
||||
archive.properties = archive.properties.map(prop => {
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
import './dbv1/dbv1';
|
||||
import './dbv2/dbv2';
|
||||
import './dbv3/dbv3';
|
||||
|
||||
Reference in New Issue
Block a user