parsley/app/javascript/components/RecipeEdit.vue

135 lines
3.0 KiB
Vue
Raw Normal View History

2018-03-30 14:31:09 -05:00
<template>
2018-09-12 14:17:18 -05:00
<div class="recipe-edit">
2018-04-13 10:25:18 -05:00
<template v-if="!forLogging">
2018-03-30 14:31:09 -05:00
2018-04-13 10:25:18 -05:00
<div class="columns">
<div class="column">
<app-text-field label="Name" v-model="recipe.name"></app-text-field>
2018-04-01 21:43:23 -05:00
</div>
2018-04-13 10:25:18 -05:00
<div class="column">
<app-text-field label="Source" v-model="recipe.source"></app-text-field>
2018-04-01 21:43:23 -05:00
</div>
</div>
2018-04-13 10:25:18 -05:00
<app-text-field label="Description" type="textarea" v-model="recipe.description"></app-text-field>
<div class="field">
<label class="label is-small-mobile">Tags</label>
<app-tag-editor v-model="recipe.tags"></app-tag-editor>
2018-04-01 21:43:23 -05:00
</div>
2018-04-13 10:25:18 -05:00
</template>
2018-04-01 21:43:23 -05:00
<div class="columns">
<div class="column">
2018-04-13 10:25:18 -05:00
<app-text-field label="Yields" v-model="recipe.yields"></app-text-field>
2018-04-01 21:43:23 -05:00
</div>
<div class="column">
2018-04-13 10:25:18 -05:00
<app-text-field label="Total Time" type="number" v-model="recipe.total_time"></app-text-field>
2018-04-01 21:43:23 -05:00
</div>
<div class="column">
2018-04-13 10:25:18 -05:00
<app-text-field label="Active Time" v-model="recipe.active_time"></app-text-field>
2018-04-01 21:43:23 -05:00
</div>
</div>
<recipe-edit-ingredient-editor :ingredients="recipe.ingredients"></recipe-edit-ingredient-editor>
<div class="field">
<label class="label title is-4">Directions</label>
<div class="control columns">
<div class="column">
2018-04-04 19:46:02 -05:00
<textarea ref="step_text_area" class="textarea directions-input" v-model="recipe.step_text"></textarea>
2018-04-01 21:43:23 -05:00
</div>
<div class="column">
<div class="box content" v-html="stepPreview">
</div>
</div>
</div>
</div>
2018-09-12 14:17:18 -05:00
<div class="field">
<label class="checkbox">
<input type="checkbox" v-model="recipe.is_ingredient" />
Is Ingredient
</label>
</div>
2018-04-01 21:43:23 -05:00
</div>
2018-03-30 14:31:09 -05:00
</template>
<script>
2018-04-01 21:43:23 -05:00
import autosize from "autosize";
import debounce from "lodash/debounce";
import api from "../lib/Api";
import RecipeEditIngredientEditor from "./RecipeEditIngredientEditor";
2018-03-30 14:31:09 -05:00
export default {
2018-04-01 21:43:23 -05:00
props: {
recipe: {
required: true,
type: Object
},
2018-04-13 10:25:18 -05:00
forLogging: {
2018-04-01 21:43:23 -05:00
required: false,
2018-04-13 10:25:18 -05:00
type: Boolean,
default: false
2018-04-01 21:43:23 -05:00
}
},
data() {
return {
stepPreviewCache: null
};
},
computed: {
stepPreview() {
if (this.stepPreviewCache === null) {
return this.recipe.rendered_steps;
} else {
return this.stepPreviewCache;
}
}
},
2018-03-30 14:31:09 -05:00
2018-04-01 21:43:23 -05:00
methods: {
updatePreview: debounce(function() {
api.postPreviewSteps(this.recipe.step_text)
.then(data => this.stepPreviewCache = data.rendered_steps)
.catch(err => this.stepPreviewCache = "?? Error ??");
}, 750)
},
watch: {
'recipe.step_text': function() {
this.updatePreview();
}
},
mounted() {
2018-04-04 19:46:02 -05:00
//autosize(this.$refs.step_text_area);
2018-04-01 21:43:23 -05:00
},
components: {
RecipeEditIngredientEditor
}
2018-03-30 14:31:09 -05:00
}
</script>
<style lang="scss" scoped>
2018-04-04 19:46:02 -05:00
2018-09-12 14:17:18 -05:00
.recipe-edit {
margin-bottom: 1rem;
}
2018-04-04 19:46:02 -05:00
.directions-input {
height: 100%;
}
2018-03-30 14:31:09 -05:00
</style>