diff --git a/app/imports/api/creature/mixins/setDocToLastMixin.js b/app/imports/api/creature/mixins/setDocToLastMixin.js index 944cfa69..db056d9b 100644 --- a/app/imports/api/creature/mixins/setDocToLastMixin.js +++ b/app/imports/api/creature/mixins/setDocToLastMixin.js @@ -1,5 +1,5 @@ import SimpleSchema from 'simpl-schema'; -import { setDocToLastOrder } from '/imports/api/creature/order/order.js'; +import { setDocToLastOrder } from '/imports/api/order/order.js'; export function setDocToLastMixin(methodOptions){ // Make sure the doc has a charId diff --git a/app/imports/api/library/LibraryNodes.js b/app/imports/api/library/LibraryNodes.js index 4d0602e8..277d8b31 100644 --- a/app/imports/api/library/LibraryNodes.js +++ b/app/imports/api/library/LibraryNodes.js @@ -55,7 +55,9 @@ for (let key in librarySchemas){ function getLibrary(node){ if (!node) throw new Meteor.Error('No node provided'); - return Libraries.findOne(node.ancestors[0].id); + let library = Libraries.findOne(node.ancestors[0].id); + if (!library) throw new Meteor.Error('Library does not exist'); + return library; } function assertNodeEditPermission(node, userId){ diff --git a/app/imports/api/creature/order/order.js b/app/imports/api/order/order.js similarity index 86% rename from app/imports/api/creature/order/order.js rename to app/imports/api/order/order.js index 834f69af..f128aeea 100644 --- a/app/imports/api/creature/order/order.js +++ b/app/imports/api/order/order.js @@ -1,8 +1,8 @@ import SimpleSchema from 'simpl-schema'; -export function getHighestOrder({collection, charId}){ +export function getHighestOrder({collection, rootAncestor}){ const highestOrderedDoc = collection.findOne({ - charId + 'ancestors.0': rootAncestor, }, { fields: {order: 1}, sort: {order: -1}, @@ -13,7 +13,7 @@ export function getHighestOrder({collection, charId}){ export function setDocToLastOrder({collection, doc}){ doc.order = getHighestOrder({ collection, - charId: doc.charId, + rootAncestor: doc.ancestors[0], }) + 1; } @@ -42,7 +42,7 @@ export function setDocOrder({collection, doc, order}){ } collection.update({ order: {$and: inBetweenSelector}, - charId: doc.charId, + rootAncestor: doc.ancestors[0], }, { $inc: {order: increment}, }, { @@ -51,10 +51,10 @@ export function setDocOrder({collection, doc, order}){ } } -export function reorderDocs({collection, charId}){ +export function reorderDocs({collection, rootAncestor}){ let bulkWrite = []; collection.find({ - charId + 'ancestors.0': rootAncestor, }, { fields: {order: 1}, sort: {order: 1} diff --git a/app/imports/api/sharing/sharingPermissions.js b/app/imports/api/sharing/sharingPermissions.js index e04d1133..645bfb23 100644 --- a/app/imports/api/sharing/sharingPermissions.js +++ b/app/imports/api/sharing/sharingPermissions.js @@ -10,7 +10,7 @@ function assertIdValid(userId){ function assertdocExists(doc){ if (!doc){ throw new Meteor.Error("Edit permission denied", - `No doc exists with the given id: ${charId}`); + `No such document exists`); } } @@ -32,7 +32,7 @@ export function assertEditPermission(doc, userId) { return true; } else { throw new Meteor.Error("Edit permission denied", - `You do not have permission to edit this character`); + `You do not have permission to edit this document`); } } diff --git a/app/imports/ui/components/tree/TreeNode.vue b/app/imports/ui/components/tree/TreeNode.vue index fe5e683a..ebb866ad 100644 --- a/app/imports/ui/components/tree/TreeNode.vue +++ b/app/imports/ui/components/tree/TreeNode.vue @@ -14,7 +14,7 @@
@@ -46,18 +46,26 @@ name: String, group: String, showEmpty: Boolean, - children: { - type: Array, - required: true, - }, + children: Array, + getChildren: Function, }, computed: { hasChildren(){ - return this.children && this.children.length; + return this.children && this.children.length || this.lazy && !this.expanded; }, showExpanded(){ return this.expanded && (this.showEmpty || this.hasChildren) }, + computedChildren(){ + let children = []; + if (this.children){ + children.push(...this.children) + } + if (this.getChildren){ + children.push(...this.getChildren()) + } + return children; + } }, }; diff --git a/app/imports/ui/components/tree/TreeNodeList.vue b/app/imports/ui/components/tree/TreeNodeList.vue index 30efb8ec..4c725ba3 100644 --- a/app/imports/ui/components/tree/TreeNodeList.vue +++ b/app/imports/ui/components/tree/TreeNodeList.vue @@ -11,8 +11,9 @@ v-for="child in children" v-bind="child" :group="group" - :key="child.name" + :key="child._id || child.name" :showEmpty="showEmpty" + :lazy="lazy" class="item" @dragstart.native="e => e.dataTransfer.setData('cow', child.name)" /> @@ -33,6 +34,7 @@ props: { group: String, showEmpty: Boolean, + lazy: Boolean, children: { type: Array, required: true, diff --git a/app/imports/ui/pages/Library.vue b/app/imports/ui/pages/Library.vue index b4ab3bfc..3315b069 100644 --- a/app/imports/ui/pages/Library.vue +++ b/app/imports/ui/pages/Library.vue @@ -1,6 +1,6 @@