Implemented remove button on archive files

This commit is contained in:
Stefan Zermatten
2022-04-23 09:35:29 +02:00
parent f440e030cf
commit 7609e916c6
5 changed files with 75 additions and 8 deletions

View File

@@ -2,3 +2,4 @@
import '/imports/api/creature/archive/methods/archiveCreatureToFile.js';
import '/imports/api/creature/archive/methods/restoreCreatures.js';
import '/imports/api/creature/archive/methods/restoreCreatureFromFile.js';
import '/imports/api/creature/archive/methods/removeArchiveCreature.js';

View File

@@ -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;

View File

@@ -4,8 +4,11 @@
Delete {{ typeName }}
</v-toolbar-title>
<div>
<v-alert type="warning" outlined>
This cannot be undone
</v-alert>
<p v-if="name">
Type "{{ name }}" to permanenetly delete
Type "{{ name }}" to permanenetly delete.
</p>
<v-text-field
v-if="name"

View File

@@ -1,5 +1,5 @@
<template>
<v-card>
<v-card :data-id="`${model._id}-archive-card`">
<v-card-title>
{{ model.meta.creatureName }}
</v-card-title>
@@ -17,6 +17,7 @@
<v-flex />
<v-btn
icon
@click="removeArchiveCharacter"
>
<v-icon>mdi-delete</v-icon>
</v-btn>
@@ -34,6 +35,7 @@
import restoreCreatureFromFile from '/imports/api/creature/archive/methods/restoreCreatureFromFile.js';
import { snackbar } from '/imports/ui/components/snackbars/SnackbarQueue.js';
import { characterSlotsRemaining } from '/imports/api/creature/creatures/methods/assertHasCharacterSlots.js';
import removeArchiveCreature from '/imports/api/creature/archive/methods/removeArchiveCreature.js';
export default {
props: {
@@ -62,7 +64,24 @@ export default {
console.error(error);
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>

View File

@@ -28,7 +28,7 @@
</div>
</v-col>
</v-row>
<v-row>
<v-row dense>
<template v-if="archiveFiles && archiveFiles.length">
<v-col cols="12">
<v-subheader> Archived Characters </v-subheader>
@@ -102,10 +102,7 @@ export default {
if (!error) return;
snackbar({text: error.reason});
});
}
},
},
}
</script>
<style>
</style>