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