Implemented remove button on archive files
This commit is contained in:
@@ -2,3 +2,4 @@
|
|||||||
import '/imports/api/creature/archive/methods/archiveCreatureToFile.js';
|
import '/imports/api/creature/archive/methods/archiveCreatureToFile.js';
|
||||||
import '/imports/api/creature/archive/methods/restoreCreatures.js';
|
import '/imports/api/creature/archive/methods/restoreCreatures.js';
|
||||||
import '/imports/api/creature/archive/methods/restoreCreatureFromFile.js';
|
import '/imports/api/creature/archive/methods/restoreCreatureFromFile.js';
|
||||||
|
import '/imports/api/creature/archive/methods/removeArchiveCreature.js';
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import SCHEMA_VERSION from '/imports/constants/SCHEMA_VERSION.js';
|
||||||
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
|
import CreatureLogs from '/imports/api/creature/log/CreatureLogs.js';
|
||||||
|
import Experiences from '/imports/api/creature/experience/Experiences.js';
|
||||||
|
import { removeCreatureWork } from '/imports/api/creature/creatures/methods/removeCreature.js';
|
||||||
|
import ArchiveCreatureFiles from '/imports/api/creature/archive/ArchiveCreatureFiles.js';
|
||||||
|
import assertHasCharactersSlots from '/imports/api/creature/creatures/methods/assertHasCharacterSlots.js';
|
||||||
|
import { incrementFileStorageUsed } from '/imports/api/users/methods/updateFileStorageUsed.js';
|
||||||
|
|
||||||
|
const removeArchiveCreature = new ValidatedMethod({
|
||||||
|
name: 'ArchiveCreatureFiles.methods.removeArchiveCreature',
|
||||||
|
validate: new SimpleSchema({
|
||||||
|
'fileId': {
|
||||||
|
type: String,
|
||||||
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
|
},
|
||||||
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
|
async run({ fileId }) {
|
||||||
|
// fetch the file
|
||||||
|
const file = ArchiveCreatureFiles.findOne({ _id: fileId }).get();
|
||||||
|
if (!file) {
|
||||||
|
throw new Meteor.Error('File not found',
|
||||||
|
'The requested creature archive does not exist');
|
||||||
|
}
|
||||||
|
// Assert ownership
|
||||||
|
const userId = file?.userId;
|
||||||
|
if (!userId || userId !== this.userId) {
|
||||||
|
throw new Meteor.Error('Permission denied',
|
||||||
|
'You can only restore creatures you own');
|
||||||
|
}
|
||||||
|
//Remove the archive once the restore succeeded
|
||||||
|
ArchiveCreatureFiles.remove({ _id: fileId });
|
||||||
|
// Update the user's file storage limits
|
||||||
|
incrementFileStorageUsed(userId, -file.size);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default removeArchiveCreature;
|
||||||
@@ -4,8 +4,11 @@
|
|||||||
Delete {{ typeName }}
|
Delete {{ typeName }}
|
||||||
</v-toolbar-title>
|
</v-toolbar-title>
|
||||||
<div>
|
<div>
|
||||||
|
<v-alert type="warning" outlined>
|
||||||
|
This cannot be undone
|
||||||
|
</v-alert>
|
||||||
<p v-if="name">
|
<p v-if="name">
|
||||||
Type "{{ name }}" to permanenetly delete
|
Type "{{ name }}" to permanenetly delete.
|
||||||
</p>
|
</p>
|
||||||
<v-text-field
|
<v-text-field
|
||||||
v-if="name"
|
v-if="name"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-card>
|
<v-card :data-id="`${model._id}-archive-card`">
|
||||||
<v-card-title>
|
<v-card-title>
|
||||||
{{ model.meta.creatureName }}
|
{{ model.meta.creatureName }}
|
||||||
</v-card-title>
|
</v-card-title>
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
<v-flex />
|
<v-flex />
|
||||||
<v-btn
|
<v-btn
|
||||||
icon
|
icon
|
||||||
|
@click="removeArchiveCharacter"
|
||||||
>
|
>
|
||||||
<v-icon>mdi-delete</v-icon>
|
<v-icon>mdi-delete</v-icon>
|
||||||
</v-btn>
|
</v-btn>
|
||||||
@@ -34,6 +35,7 @@
|
|||||||
import restoreCreatureFromFile from '/imports/api/creature/archive/methods/restoreCreatureFromFile.js';
|
import restoreCreatureFromFile from '/imports/api/creature/archive/methods/restoreCreatureFromFile.js';
|
||||||
import { snackbar } from '/imports/ui/components/snackbars/SnackbarQueue.js';
|
import { snackbar } from '/imports/ui/components/snackbars/SnackbarQueue.js';
|
||||||
import { characterSlotsRemaining } from '/imports/api/creature/creatures/methods/assertHasCharacterSlots.js';
|
import { characterSlotsRemaining } from '/imports/api/creature/creatures/methods/assertHasCharacterSlots.js';
|
||||||
|
import removeArchiveCreature from '/imports/api/creature/archive/methods/removeArchiveCreature.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
@@ -62,7 +64,24 @@ export default {
|
|||||||
console.error(error);
|
console.error(error);
|
||||||
snackbar({text: error.reason});
|
snackbar({text: error.reason});
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
|
removeArchiveCharacter(){
|
||||||
|
let that = this;
|
||||||
|
this.$store.commit('pushDialogStack', {
|
||||||
|
component: 'delete-confirmation-dialog',
|
||||||
|
elementId: `${that.model._id}-archive-card`,
|
||||||
|
data: {
|
||||||
|
name: this.model.meta.creatureName,
|
||||||
|
typeName: 'Character Archive'
|
||||||
|
},
|
||||||
|
callback(confirmation){
|
||||||
|
if(!confirmation) return;
|
||||||
|
removeArchiveCreature.call({fileId: that.model._id}, (error) => {
|
||||||
|
if (error) console.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
<v-row>
|
<v-row dense>
|
||||||
<template v-if="archiveFiles && archiveFiles.length">
|
<template v-if="archiveFiles && archiveFiles.length">
|
||||||
<v-col cols="12">
|
<v-col cols="12">
|
||||||
<v-subheader> Archived Characters </v-subheader>
|
<v-subheader> Archived Characters </v-subheader>
|
||||||
@@ -102,10 +102,7 @@ export default {
|
|||||||
if (!error) return;
|
if (!error) return;
|
||||||
snackbar({text: error.reason});
|
snackbar({text: error.reason});
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
|
||||||
</style>
|
|
||||||
Reference in New Issue
Block a user