Archive UI
This commit is contained in:
@@ -12,9 +12,9 @@ import ArchivedCreatures from '/imports/api/creature/archive/ArchivedCreatures.j
|
||||
function archiveCreature(creatureId){
|
||||
// Build the archive document
|
||||
const creature = Creatures.findOne(creatureId);
|
||||
const properties = CreatureProperties.find({'ancestors.id': creatureId});
|
||||
const experiences = Experiences.find({creatureId});
|
||||
const logs = CreatureLogs.find({creatureId});
|
||||
const properties = CreatureProperties.find({'ancestors.id': creatureId}).fetch();
|
||||
const experiences = Experiences.find({creatureId}).fetch();
|
||||
const logs = CreatureLogs.find({creatureId}).fetch();
|
||||
let archiveCreature = {
|
||||
owner: creature.owner,
|
||||
archiveDate: new Date(),
|
||||
@@ -51,11 +51,11 @@ const archiveCreatures = new ValidatedMethod({
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({creatureIds}) {
|
||||
for (let id in creatureIds){
|
||||
for (let id of creatureIds){
|
||||
assertOwnership(id, this.userId)
|
||||
}
|
||||
let archivedIds = [];
|
||||
for (let id in creatureIds){
|
||||
for (let id of creatureIds){
|
||||
let archivedId = archiveCreature(id);
|
||||
archivedIds.push(archivedId);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import CreatureProperties from '/imports/api/creature/creatureProperties/Creatur
|
||||
import CreatureLogs from '/imports/api/creature/log/CreatureLogs.js';
|
||||
import Experiences from '/imports/api/creature/experience/Experiences.js';
|
||||
import ArchivedCreatures from '/imports/api/creature/archive/ArchivedCreatures.js';
|
||||
import { removeCreatureWork } from '/imports/api/creature/creatures/methods/removeCreature.js';
|
||||
|
||||
function restoreCreature(archiveId){
|
||||
// Get the archive
|
||||
@@ -15,15 +16,28 @@ function restoreCreature(archiveId){
|
||||
// Insert the creature sub documents
|
||||
// They still have their original _id's
|
||||
Creatures.insert(archivedCreature.creature);
|
||||
CreatureProperties.batchInsert(archivedCreature.properties);
|
||||
Experiences.batchInsert(archivedCreature.experiences);
|
||||
CreatureLogs.batchInsert(archivedCreature.logs);
|
||||
try {
|
||||
// Add all the properties
|
||||
if (archivedCreature.properties && archivedCreature.properties.length){
|
||||
CreatureProperties.batchInsert(archivedCreature.properties);
|
||||
}
|
||||
if (archivedCreature.experiences && archivedCreature.experiences.length){
|
||||
Experiences.batchInsert(archivedCreature.experiences);
|
||||
}
|
||||
if (archivedCreature.logs && archivedCreature.logs.length){
|
||||
CreatureLogs.batchInsert(archivedCreature.logs);
|
||||
}
|
||||
// Remove the archived creature
|
||||
ArchivedCreatures.remove(archiveId);
|
||||
} catch (e) {
|
||||
// If the above fails, delete the inserted creature
|
||||
removeCreatureWork(archivedCreature.creature._id);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Do not recompute. The creature was in a computed and ordered state when
|
||||
// we archived it, just restore everything as-is
|
||||
|
||||
// Remove the archived creature
|
||||
ArchivedCreatures.remove(archiveId);
|
||||
|
||||
return archivedCreature.creature._id;
|
||||
}
|
||||
|
||||
@@ -45,14 +59,14 @@ const restoreCreatures = new ValidatedMethod({
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({archiveIds}) {
|
||||
for (let id in archiveIds){
|
||||
for (let id of archiveIds){
|
||||
let archivedCreature = ArchivedCreatures.findOne(id, {
|
||||
fields: {owner: 1}
|
||||
});
|
||||
assertOwnership(archivedCreature, this.userId)
|
||||
}
|
||||
let creatureIds = [];
|
||||
for (let id in archiveIds){
|
||||
for (let id of archiveIds){
|
||||
let creatureId = restoreCreature(id);
|
||||
creatureIds.push(creatureId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user