Fixed showstopping bugs with tree organize functions
This commit is contained in:
@@ -55,14 +55,15 @@
|
||||
<tree-node-list
|
||||
v-if="showExpanded"
|
||||
:node="node"
|
||||
:root="node.root"
|
||||
:children="computedChildren"
|
||||
:group="group"
|
||||
:organize="organize"
|
||||
:selected-node="selectedNode"
|
||||
:start-expanded="startExpanded"
|
||||
:show-external-details="showExternalDetails"
|
||||
@reordered="e => $emit('reordered', e)"
|
||||
@reorganized="e => $emit('reorganized', e)"
|
||||
@move-within-root="e => $emit('move-within-root', e)"
|
||||
@move-between-roots="e => $emit('move-between-roots', e)"
|
||||
@selected="e => $emit('selected', e)"
|
||||
/>
|
||||
<div v-else>
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
:start-expanded="startExpanded"
|
||||
:show-external-details="showExternalDetails"
|
||||
@selected="e => $emit('selected', e)"
|
||||
@reordered="e => $emit('reordered', e)"
|
||||
@reorganized="e => $emit('reorganized', e)"
|
||||
@move-within-root="e => $emit('move-within-root', e)"
|
||||
@move-between-roots="e => $emit('move-between-roots', e)"
|
||||
/>
|
||||
</draggable>
|
||||
</template>
|
||||
@@ -45,6 +45,10 @@ export default {
|
||||
type: Object,
|
||||
default: undefined,
|
||||
},
|
||||
root: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
group: {
|
||||
type: String,
|
||||
default: undefined,
|
||||
@@ -93,32 +97,31 @@ export default {
|
||||
let event = moved || added;
|
||||
if (event) {
|
||||
let doc = event.element.doc;
|
||||
let newIndex;
|
||||
if (event.newIndex === 0) {
|
||||
newIndex = 0.5;
|
||||
} else {
|
||||
if (event.newIndex < this.children.length) {
|
||||
let childAtNewIndex = this.children[event.newIndex];
|
||||
if (event.newIndex > event.oldIndex) {
|
||||
newIndex = childAtNewIndex.doc.right + 0.5;
|
||||
} else {
|
||||
newIndex = childAtNewIndex.doc.left - 0.5;
|
||||
}
|
||||
let newPosition;
|
||||
if (!this.children.length) {
|
||||
if (this.node) {
|
||||
newPosition = this.node.left + 0.5;
|
||||
} else {
|
||||
let childBeforeNewIndex = this.children[event.newIndex - 1];
|
||||
newIndex = childBeforeNewIndex.doc.right + 0.5;
|
||||
newPosition = 0.5;
|
||||
}
|
||||
} else if (event.newIndex < this.children.length) {
|
||||
let childAtNewIndex = this.children[event.newIndex];
|
||||
if (event.newIndex > event.oldIndex) {
|
||||
newPosition = childAtNewIndex.doc.right + 0.5;
|
||||
} else {
|
||||
newPosition = childAtNewIndex.doc.left - 0.5;
|
||||
}
|
||||
} else {
|
||||
let childBeforeNewIndex = this.children[event.newIndex - 1];
|
||||
newPosition = childBeforeNewIndex.doc.right + 0.5;
|
||||
}
|
||||
if (moved) {
|
||||
this.$emit('reordered', { doc, newIndex });
|
||||
} else if (added) {
|
||||
this.$emit('reorganized', { doc, parent: this.node, newIndex });
|
||||
if (doc.root.id === this.root.id) {
|
||||
this.$emit('move-within-root', { doc, newPosition });
|
||||
} else {
|
||||
this.$emit('move-between-roots', { doc, newPosition, newRootRef: this.root });
|
||||
}
|
||||
}
|
||||
},
|
||||
move() {
|
||||
return true;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -6,16 +6,17 @@
|
||||
:organize="organize"
|
||||
:selected-node="selectedNode"
|
||||
:start-expanded="expanded"
|
||||
:root="root"
|
||||
@selected="e => $emit('selected', e)"
|
||||
@reordered="reordered"
|
||||
@reorganized="reorganized"
|
||||
@move-within-root="moveWithinRoot"
|
||||
@move-between-roots="moveBetweenRoots"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script lang="js">
|
||||
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 { moveBetweenRoots, moveWithinRoot } from '/imports/api/parenting/organizeMethods';
|
||||
import { getCollectionByName } from '/imports/api/parenting/parentingFunctions';
|
||||
|
||||
export default {
|
||||
@@ -57,38 +58,28 @@ export default {
|
||||
includeFilteredDocDescendants: true,
|
||||
}
|
||||
) || [];
|
||||
console.log(children)
|
||||
this.$emit('length', children.length);
|
||||
return children;
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
reordered({ doc, newIndex }) {
|
||||
reorderDoc.callAsync({
|
||||
moveWithinRoot({ doc, newPosition }) {
|
||||
moveWithinRoot.callAsync({
|
||||
docRef: {
|
||||
id: doc._id,
|
||||
collection: this.collection,
|
||||
},
|
||||
order: newIndex,
|
||||
newPosition,
|
||||
});
|
||||
},
|
||||
reorganized({ doc, parent, newIndex }) {
|
||||
let parentRef;
|
||||
if (parent) {
|
||||
parentRef = {
|
||||
id: parent._id,
|
||||
collection: this.collection,
|
||||
};
|
||||
} else {
|
||||
parentRef = this.root;
|
||||
}
|
||||
organizeDoc.callAsync({
|
||||
moveBetweenRoots({ doc, newPosition, newRootRef }) {
|
||||
moveBetweenRoots.callAsync({
|
||||
docRef: {
|
||||
id: doc._id,
|
||||
collection: this.collection,
|
||||
},
|
||||
parentRef,
|
||||
order: newIndex,
|
||||
newPosition,
|
||||
newRootRef,
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
@@ -6,9 +6,10 @@
|
||||
:children="libraryChildren"
|
||||
:organize="organizeMode"
|
||||
:selected-node="selectedNode"
|
||||
:root="{collection: 'libraries', id: libraryId}"
|
||||
@selected="e => $emit('selected', e)"
|
||||
@reordered="reordered"
|
||||
@reorganized="reorganized"
|
||||
@move-within-root="moveWithinRoot"
|
||||
@move-between-roots="moveBetweenRoots"
|
||||
/>
|
||||
<v-layout
|
||||
v-else
|
||||
@@ -29,7 +30,7 @@ import Libraries from '/imports/api/library/Libraries';
|
||||
import LibraryNodes from '/imports/api/library/LibraryNodes';
|
||||
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 { moveBetweenRoots, moveWithinRoot } from '/imports/api/parenting/organizeMethods';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@@ -92,7 +93,7 @@ export default {
|
||||
if (!this.library) return;
|
||||
return filterToForest(
|
||||
LibraryNodes,
|
||||
this.library._id,
|
||||
this.libraryId,
|
||||
this.filter,
|
||||
{
|
||||
includeFilteredDocAncestors: true,
|
||||
@@ -102,35 +103,23 @@ export default {
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
reordered({ doc, newIndex }) {
|
||||
reorderDoc.callAsync({
|
||||
moveWithinRoot({ doc, newPosition }) {
|
||||
moveWithinRoot.callAsync({
|
||||
docRef: {
|
||||
id: doc._id,
|
||||
collection: 'libraryNodes',
|
||||
},
|
||||
order: newIndex,
|
||||
newPosition,
|
||||
});
|
||||
},
|
||||
reorganized({ doc, parent, newIndex }) {
|
||||
let parentRef;
|
||||
if (parent) {
|
||||
parentRef = {
|
||||
id: parent._id,
|
||||
collection: 'libraryNodes',
|
||||
};
|
||||
} else {
|
||||
parentRef = {
|
||||
id: this.libraryId,
|
||||
collection: 'libraries',
|
||||
};
|
||||
}
|
||||
organizeDoc.callAsync({
|
||||
moveBetweenRoots({ doc, newPosition, newRootRef }) {
|
||||
moveBetweenRoots.callAsync({
|
||||
docRef: {
|
||||
id: doc._id,
|
||||
collection: 'libraryNodes',
|
||||
},
|
||||
parentRef,
|
||||
order: newIndex,
|
||||
newPosition,
|
||||
newRootRef,
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user