Compare commits
2 Commits
2.0-beta.2
...
2.0-beta.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfb860605f | ||
|
|
d87524418a |
@@ -65,7 +65,6 @@ let CreaturePropertySchema = new SimpleSchema({
|
|||||||
},
|
},
|
||||||
'dependencies.$': {
|
'dependencies.$': {
|
||||||
type: String,
|
type: String,
|
||||||
regEx: SimpleSchema.RegEx.Id,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,24 @@ import SimpleSchema from 'simpl-schema';
|
|||||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
|
||||||
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
||||||
import { insertPropertyWork } from '/imports/api/creature/creatureProperties/methods/insertProperty.js';
|
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
||||||
|
import {
|
||||||
|
setLineageOfDocs,
|
||||||
|
renewDocIds
|
||||||
|
} from '/imports/api/parenting/parenting.js';
|
||||||
|
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
|
||||||
|
import { reorderDocs } from '/imports/api/parenting/order.js';
|
||||||
|
import recomputeInventory from '/imports/api/creature/denormalise/recomputeInventory.js';
|
||||||
|
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
||||||
|
var snackbar;
|
||||||
|
if (Meteor.isClient){
|
||||||
|
snackbar = require(
|
||||||
|
'/imports/ui/components/snackbars/SnackbarQueue.js'
|
||||||
|
).snackbar
|
||||||
|
}
|
||||||
|
|
||||||
|
const DUPLICATE_CHILDREN_LIMIT = 50;
|
||||||
|
|
||||||
const duplicateProperty = new ValidatedMethod({
|
const duplicateProperty = new ValidatedMethod({
|
||||||
name: 'creatureProperties.duplicate',
|
name: 'creatureProperties.duplicate',
|
||||||
@@ -20,13 +35,70 @@ const duplicateProperty = new ValidatedMethod({
|
|||||||
timeInterval: 5000,
|
timeInterval: 5000,
|
||||||
},
|
},
|
||||||
run({_id}) {
|
run({_id}) {
|
||||||
let creatureProperty = CreatureProperties.findOne(_id);
|
let property = CreatureProperties.findOne(_id);
|
||||||
let rootCreature = getRootCreatureAncestor(creatureProperty);
|
let creature = getRootCreatureAncestor(property);
|
||||||
assertEditPermission(rootCreature, this.userId);
|
|
||||||
insertPropertyWork({
|
assertEditPermission(creature, this.userId);
|
||||||
property: creatureProperty,
|
|
||||||
creature: rootCreature,
|
// Renew the doc ID
|
||||||
|
let randomSrc = DDP.randomStream('duplicateProperty');
|
||||||
|
let propertyId = randomSrc.id();
|
||||||
|
property._id = propertyId;
|
||||||
|
|
||||||
|
// Get all the descendants
|
||||||
|
let nodes = CreatureProperties.find({
|
||||||
|
'ancestors.id': _id,
|
||||||
|
removed: {$ne: true},
|
||||||
|
}, {
|
||||||
|
limit: DUPLICATE_CHILDREN_LIMIT + 1,
|
||||||
|
sort: {order: 1},
|
||||||
|
}).fetch();
|
||||||
|
|
||||||
|
// Alert the user if the limit was hit
|
||||||
|
if (nodes.length > DUPLICATE_CHILDREN_LIMIT){
|
||||||
|
nodes.pop();
|
||||||
|
if (Meteor.isClient){
|
||||||
|
snackbar({
|
||||||
|
text: `Only the first ${DUPLICATE_CHILDREN_LIMIT} children were duplicated`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// re-map all the ancestors
|
||||||
|
setLineageOfDocs({
|
||||||
|
docArray: nodes,
|
||||||
|
newAncestry : [
|
||||||
|
...property.ancestors,
|
||||||
|
{id: propertyId, collection: 'creatureProperties'}
|
||||||
|
],
|
||||||
|
oldParent : {id: _id, collection: 'creatureProperties'},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Give the docs new IDs without breaking internal references
|
||||||
|
renewDocIds({docArray: nodes});
|
||||||
|
|
||||||
|
// Order the root node
|
||||||
|
property.order += 0.5;
|
||||||
|
|
||||||
|
// Insert the properties
|
||||||
|
CreatureProperties.batchInsert([property, ...nodes]);
|
||||||
|
|
||||||
|
// Tree structure changed by inserts, reorder the tree
|
||||||
|
reorderDocs({
|
||||||
|
collection: CreatureProperties,
|
||||||
|
ancestorId: property.ancestors[0].id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Inserting the active status of the property needs to be denormalised
|
||||||
|
recomputeInactiveProperties(creature._id);
|
||||||
|
|
||||||
|
// Recompute the inventory
|
||||||
|
recomputeInventory(creature._id);
|
||||||
|
|
||||||
|
// Inserting a creature property invalidates dependencies: full recompute
|
||||||
|
recomputeCreatureByDoc(creature);
|
||||||
|
|
||||||
|
return propertyId;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ const duplicateLibraryNode = new ValidatedMethod({
|
|||||||
run({_id}) {
|
run({_id}) {
|
||||||
let libraryNode = LibraryNodes.findOne(_id);
|
let libraryNode = LibraryNodes.findOne(_id);
|
||||||
assertDocEditPermission(libraryNode, this.userId);
|
assertDocEditPermission(libraryNode, this.userId);
|
||||||
let libraryNodeId = Random.id();
|
|
||||||
|
let randomSrc = DDP.randomStream('duplicateLibraryNode');
|
||||||
|
let libraryNodeId = randomSrc.id();
|
||||||
libraryNode._id = libraryNodeId;
|
libraryNode._id = libraryNodeId;
|
||||||
|
|
||||||
let nodes = LibraryNodes.find({
|
let nodes = LibraryNodes.find({
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const AdjustmentSchema = new SimpleSchema({
|
|||||||
|
|
||||||
const ComputedOnlyAdjustmentSchema = new SimpleSchema({
|
const ComputedOnlyAdjustmentSchema = new SimpleSchema({
|
||||||
amountResult: {
|
amountResult: {
|
||||||
type: SimpleSchema.Integer,
|
type: SimpleSchema.oneOf(String, Number),
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
amountErrors: {
|
amountErrors: {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ const DamageSchema = new SimpleSchema({
|
|||||||
|
|
||||||
const ComputedOnlyDamageSchema = new SimpleSchema({
|
const ComputedOnlyDamageSchema = new SimpleSchema({
|
||||||
amountResult: {
|
amountResult: {
|
||||||
type: SimpleSchema.oneOf(String, SimpleSchema.Integer),
|
type: SimpleSchema.oneOf(String, Number),
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
amountErrors: {
|
amountErrors: {
|
||||||
|
|||||||
@@ -10,7 +10,11 @@ const InlineComputationSchema = new SimpleSchema({
|
|||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
errors: ErrorSchema,
|
errors: {
|
||||||
|
type: Array,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
'errors.$': ErrorSchema,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default InlineComputationSchema;
|
export default InlineComputationSchema;
|
||||||
|
|||||||
@@ -213,7 +213,7 @@
|
|||||||
component: 'creature-property-from-library-dialog',
|
component: 'creature-property-from-library-dialog',
|
||||||
elementId: 'insert-creature-property-from-library-btn',
|
elementId: 'insert-creature-property-from-library-btn',
|
||||||
callback(libraryNode){
|
callback(libraryNode){
|
||||||
if (!libraryNode) return;
|
if (!libraryNode) return 'insert-creature-property-fab';
|
||||||
revealFab(fab);
|
revealFab(fab);
|
||||||
|
|
||||||
let nodeId = libraryNode._id;
|
let nodeId = libraryNode._id;
|
||||||
|
|||||||
@@ -53,6 +53,7 @@
|
|||||||
embedded
|
embedded
|
||||||
:_id="selected"
|
:_id="selected"
|
||||||
@removed="selected = undefined"
|
@removed="selected = undefined"
|
||||||
|
@duplicated="id => selected = id"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</tree-detail-layout>
|
</tree-detail-layout>
|
||||||
|
|||||||
@@ -158,12 +158,12 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
getPropertyName,
|
getPropertyName,
|
||||||
duplicate(){
|
duplicate(){
|
||||||
duplicateProperty.call({_id: this.currentId}, (error) => {
|
duplicateProperty.call({_id: this.currentId}, (error, id) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
if (this.embedded){
|
if (this.embedded){
|
||||||
this.$emit('duplicated');
|
this.$emit('duplicated', id);
|
||||||
} else {
|
} else {
|
||||||
this.$store.dispatch('popDialogStack');
|
this.$store.dispatch('popDialogStack');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user