Inserting library nodes into libraries now works as expected
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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){
|
||||
|
||||
@@ -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}
|
||||
@@ -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`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<v-expand-transition>
|
||||
<div v-if="showExpanded">
|
||||
<tree-node-list
|
||||
:children="children"
|
||||
:children="computedChildren"
|
||||
:group="group"
|
||||
:show-empty="showEmpty"
|
||||
/>
|
||||
@@ -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;
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template lang="html">
|
||||
<toolbar-layout>
|
||||
<span slot="toolbar">Library</span>
|
||||
<span slot="toolbar">{{library && library.name || 'Library'}}</span>
|
||||
<v-card class="ma-4">
|
||||
<library-contents-container
|
||||
:library-id="$route.params.id"
|
||||
@@ -19,7 +19,9 @@
|
||||
<script>
|
||||
import ToolbarLayout from '/imports/ui/layouts/ToolbarLayout.vue';
|
||||
import LibraryContentsContainer from '/imports/ui/library/LibraryContentsContainer.vue';
|
||||
import {insertNode} from '/imports/api/library/LibraryNodes.js';
|
||||
import LibraryNodes, { insertNode } from '/imports/api/library/LibraryNodes.js';
|
||||
import Libraries from '/imports/api/library/Libraries.js';
|
||||
import { setDocToLastOrder } from '/imports/api/order/order.js';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@@ -28,18 +30,31 @@
|
||||
},
|
||||
methods: {
|
||||
insertLibraryNode(){
|
||||
let that = this;
|
||||
this.$store.commit('pushDialogStack', {
|
||||
component: 'library-node-creation-dialog',
|
||||
elementId: 'insert-library-node-fab',
|
||||
callback(libraryNode){
|
||||
if (!libraryNode) return;
|
||||
console.log({libraryNode});
|
||||
throw "TODO: give this library node ancestry before inserting it"
|
||||
libraryNode.parent = {collection: "library", id: that.library._id};
|
||||
libraryNode.ancestors = [ {collection: "library", id: that.library._id}];
|
||||
setDocToLastOrder({collection: LibraryNodes, doc: libraryNode});
|
||||
console.log(libraryNode);
|
||||
let libraryNodeId = insertNode.call(libraryNode);
|
||||
return libraryNodeId;
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
meteor: {
|
||||
$subscribe: {
|
||||
library(){
|
||||
return [this.$route.params.id];
|
||||
},
|
||||
},
|
||||
library(){
|
||||
return Libraries.findOne(this.$route.params.id);
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user