2018-04-02 00:10:06 -05:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
|
2018-04-03 18:31:20 -05:00
|
|
|
<div v-if="ingredient === null">
|
2018-04-02 00:10:06 -05:00
|
|
|
Loading...
|
|
|
|
</div>
|
|
|
|
<div v-else>
|
2018-06-09 12:36:46 -05:00
|
|
|
<ingredient-edit :ingredient="ingredient" :validation-errors="validationErrors"></ingredient-edit>
|
2018-04-02 00:10:06 -05:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<button type="button" class="button is-primary" @click="save">Save</button>
|
|
|
|
<router-link class="button is-secondary" to="/ingredients">Cancel</router-link>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
import IngredientEdit from "./IngredientEdit";
|
|
|
|
import { mapState } from "vuex";
|
|
|
|
import api from "../lib/Api";
|
|
|
|
import * as Errors from '../lib/Errors';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
data: function () {
|
|
|
|
return {
|
|
|
|
ingredient: null,
|
2018-06-09 12:36:46 -05:00
|
|
|
validationErrors: {}
|
2018-04-02 00:10:06 -05:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
|
|
|
ingredientId: state => state.route.params.id,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
save() {
|
2018-06-09 12:36:46 -05:00
|
|
|
this.validationErrors = {};
|
2018-04-02 00:10:06 -05:00
|
|
|
this.loadResource(
|
|
|
|
api.patchIngredient(this.ingredient)
|
|
|
|
.then(() => this.$router.push({name: 'ingredient', params: {id: this.ingredientId }}))
|
|
|
|
.catch(Errors.onlyFor(Errors.ApiValidationError, err => this.validationErrors = err.validationErrors()))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
this.loadResource(
|
|
|
|
api.getIngredient(this.ingredientId)
|
|
|
|
.then(data => { this.ingredient = data; return data; })
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
components: {
|
|
|
|
IngredientEdit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
</style>
|