2018-04-13 10:25:18 -05:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
|
2018-04-13 23:32:34 -05:00
|
|
|
<log-edit v-if="log.recipe !== null" :log="log">
|
|
|
|
<div class="buttons">
|
|
|
|
<button type="button" class="button is-primary" @click="save">Save Log</button>
|
|
|
|
<router-link class="button is-secondary" to="/">Cancel</router-link>
|
|
|
|
</div>
|
|
|
|
</log-edit>
|
2018-04-13 10:25:18 -05:00
|
|
|
|
2018-04-13 23:32:34 -05:00
|
|
|
<div class="buttons">
|
|
|
|
<button type="button" class="button is-primary" @click="save">Save Log</button>
|
|
|
|
<router-link class="button is-secondary" to="/">Cancel</router-link>
|
|
|
|
</div>
|
2018-04-13 10:25:18 -05:00
|
|
|
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
import LogEdit from "./LogEdit";
|
|
|
|
import { mapState } from "vuex";
|
|
|
|
import api from "../lib/Api";
|
|
|
|
import * as Errors from '../lib/Errors';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
validationErrors: [],
|
|
|
|
log: {
|
|
|
|
date: null,
|
|
|
|
rating: null,
|
|
|
|
notes: null,
|
|
|
|
recipe: null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
|
|
|
recipeId: state => state.route.params.recipeId,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
save() {
|
2018-04-13 23:32:34 -05:00
|
|
|
this.log.original_recipe_id = this.recipeId;
|
|
|
|
|
2018-04-13 10:25:18 -05:00
|
|
|
this.loadResource(
|
|
|
|
api.postLog(this.log)
|
|
|
|
.then(() => this.$router.push('/'))
|
|
|
|
.catch(Errors.onlyFor(Errors.ApiValidationError, err => this.validationErrors = err.validationErrors()))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
this.loadResource(
|
2018-04-18 17:04:25 -05:00
|
|
|
api.getRecipe(this.recipeId, data => this.log.recipe = data)
|
2018-04-13 10:25:18 -05:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
components: {
|
|
|
|
LogEdit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
</style>
|