diff --git a/app/imports/api/library/LibraryNodes.js b/app/imports/api/library/LibraryNodes.js
index eecfa76d..3ad52403 100644
--- a/app/imports/api/library/LibraryNodes.js
+++ b/app/imports/api/library/LibraryNodes.js
@@ -94,16 +94,25 @@ const updateNode = new ValidatedMethod({
function libraryNodesToTree(ancestorId){
// Store a dict of all the nodes
let nodeIndex = {};
- LibraryNodes.find({'ancestors.id': ancestorId}).forEach( node => {
- node.children = [];
- nodeIndex[node._id] = node;
+ let nodeList = [];
+ LibraryNodes.find({
+ 'ancestors.id': ancestorId
+ }, {
+ sort: {order: 1}
+ }).forEach( node => {
+ let treeNode = {
+ node: node,
+ children: [],
+ };
+ nodeIndex[node._id] = treeNode;
+ nodeList.push(treeNode);
});
// Create a forest of trees
let forest = [];
// Either the node is a child of another node, or in the forest as a root
nodeList.forEach(node => {
- if (nodeIndex[node.parent.id]){
- nodeIndex[node.parent.id].children.push(node);
+ if (nodeIndex[node.node.parent.id]){
+ nodeIndex[node.node.parent.id].children.push(node);
} else {
forest.push(node);
}
@@ -112,4 +121,4 @@ function libraryNodesToTree(ancestorId){
}
export default LibraryNodes;
-export { LibraryNodeSchema, insertNode, updateNode };
+export { LibraryNodeSchema, insertNode, updateNode, libraryNodesToTree };
diff --git a/app/imports/ui/components/tree/TreeNode.vue b/app/imports/ui/components/tree/TreeNode.vue
index ebb866ad..8551484d 100644
--- a/app/imports/ui/components/tree/TreeNode.vue
+++ b/app/imports/ui/components/tree/TreeNode.vue
@@ -5,18 +5,24 @@
small icon
:class="showExpanded ? 'rotate-90' : null"
@click="expanded = !expanded"
- :disabled="!hasChildren && !showEmpty"
+ :disabled="!hasChildren && !organize"
>
- chevron_right
+ chevron_right
-
{{name}}
+ reorder
+
+ {{node && node.order}}
+ {{node && node.name}}
+
$emit('moved', e)"
/>
@@ -30,12 +36,8 @@
* the tree view shows off the full character structure, and where each part of
* character comes from.
**/
- import draggable from 'vuedraggable';
export default {
name: 'tree-node',
- components: {
- draggable,
- },
beforeCreate() {
this.$options.components.TreeNodeList = require('./TreeNodeList.vue').default
},
@@ -43,9 +45,9 @@
expanded: false,
}},
props: {
- name: String,
+ node: Object,
group: String,
- showEmpty: Boolean,
+ organize: Boolean,
children: Array,
getChildren: Function,
},
@@ -54,7 +56,7 @@
return this.children && this.children.length || this.lazy && !this.expanded;
},
showExpanded(){
- return this.expanded && (this.showEmpty || this.hasChildren)
+ return this.expanded && (this.organize || this.hasChildren)
},
computedChildren(){
let children = [];
@@ -79,6 +81,9 @@
box-shadow: -2px 0px 0px 0px #808080;
margin-left: 23px;
}
+ .handle {
+ cursor: move;
+ }
.empty .drag-area {
box-shadow: -2px 0px 0px 0px rgb(128, 128, 128, 0.4);
}
diff --git a/app/imports/ui/components/tree/TreeNodeList.vue b/app/imports/ui/components/tree/TreeNodeList.vue
index 4c725ba3..2031cbae 100644
--- a/app/imports/ui/components/tree/TreeNodeList.vue
+++ b/app/imports/ui/components/tree/TreeNodeList.vue
@@ -1,21 +1,25 @@
e.dataTransfer.setData('cow', child.name)"
+ @moved="e => $emit('moved', e)"
+ @dragstart.native="e => e.dataTransfer.setData('cow', child.node && child.node.name)"
/>
@@ -32,8 +36,9 @@
expanded: false,
}},
props: {
+ node: Object,
group: String,
- showEmpty: Boolean,
+ organize: Boolean,
lazy: Boolean,
children: {
type: Array,
@@ -45,7 +50,14 @@
return this.children && this.children.length;
},
showExpanded(){
- return this.expanded && (this.showEmpty || this.hasChildren)
+ return this.expanded && (this.organize || this.hasChildren)
+ },
+ },
+ methods: {
+ change({added, removed, moved}){
+ if (removed) return;
+ let newIndex = (added || moved).newIndex;
+ this.$emit('moved', {parent: this.node, newIndex});
},
},
};
diff --git a/app/imports/ui/library/LibraryContentsContainer.vue b/app/imports/ui/library/LibraryContentsContainer.vue
index de84a6ae..32b68745 100644
--- a/app/imports/ui/library/LibraryContentsContainer.vue
+++ b/app/imports/ui/library/LibraryContentsContainer.vue
@@ -1,13 +1,19 @@
-
+
This library is empty