101 lines
2.3 KiB
Vue
101 lines
2.3 KiB
Vue
<template lang="html">
|
|
<log-component
|
|
:logs="logs"
|
|
:edit-permission="editPermission"
|
|
@submit="submit"
|
|
/>
|
|
</template>
|
|
|
|
<script lang="js">
|
|
import CreatureLogs, { logRoll } from '/imports/api/creature/log/CreatureLogs.js';
|
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
|
import CreatureVariables from '/imports/api/creature/creatures/CreatureVariables';
|
|
import { assertEditPermission } from '/imports/api/creature/creatures/creaturePermissions.js';
|
|
import LogComponent from '/imports/ui/log/LogComponent.vue';
|
|
|
|
export default {
|
|
components: {
|
|
LogComponent,
|
|
},
|
|
props: {
|
|
creatureId: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
},
|
|
data(){return {
|
|
inputHint: undefined,
|
|
inputError: undefined,
|
|
input: undefined,
|
|
}},
|
|
watch: {
|
|
input(value){
|
|
this.input = value;
|
|
this.inputHint = this.inputError = undefined;
|
|
if (!this.input) return;
|
|
let result;
|
|
try {
|
|
result = parse(value);
|
|
} catch (e){
|
|
if (e.constructor.name === 'EndOfInputError'){
|
|
this.inputError = '...';
|
|
} else {
|
|
let error = prettifyParseError(e);
|
|
this.inputError = error;
|
|
}
|
|
return;
|
|
}
|
|
try {
|
|
let {result: compiled} = resolve('compile', result, this.variables);
|
|
this.inputHint = toString(compiled);
|
|
return;
|
|
} catch (e){
|
|
console.warn(e);
|
|
this.inputError = 'Compilation error';
|
|
return;
|
|
}
|
|
},
|
|
},
|
|
methods: {
|
|
submit(input){
|
|
logRoll.call({
|
|
roll: input,
|
|
creatureId: this.creatureId,
|
|
}, (error) => {
|
|
if (error) console.error(error);
|
|
});
|
|
},
|
|
},
|
|
meteor: {
|
|
logs(){
|
|
return CreatureLogs.find({
|
|
creatureId: this.creatureId,
|
|
}, {
|
|
sort: {date: -1},
|
|
limit: 20
|
|
});
|
|
},
|
|
creature(){
|
|
return Creatures.findOne(this.creatureId) || {};
|
|
},
|
|
variables(){
|
|
return CreatureVariables.findOne({_creatureId: this.creatureId}) || {};
|
|
},
|
|
editPermission(){
|
|
try {
|
|
assertEditPermission(this.creature, Meteor.userId());
|
|
return true;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
},
|
|
},
|
|
}
|
|
</script>
|
|
|
|
<style lang="css">
|
|
.log-tab p:last-child {
|
|
margin-bottom: 0;
|
|
}
|
|
</style>
|