2020-12-24 16:37:38 -09:00
|
|
|
<template>
|
|
|
|
<v-card id="myRecipe">
|
|
|
|
<v-img
|
|
|
|
height="400"
|
|
|
|
:src="getImage(recipeDetails.image)"
|
|
|
|
class="d-print-none"
|
|
|
|
:key="imageKey"
|
|
|
|
>
|
2021-01-17 22:22:54 -09:00
|
|
|
<RecipeTimeCard
|
|
|
|
class="force-bottom"
|
|
|
|
:prepTime="recipeDetails.prepTime"
|
|
|
|
:totalTime="recipeDetails.totalTime"
|
|
|
|
:performTime="recipeDetails.performTime"
|
|
|
|
/>
|
2020-12-24 16:37:38 -09:00
|
|
|
</v-img>
|
|
|
|
<ButtonRow
|
|
|
|
:open="showIcons"
|
|
|
|
@json="jsonEditor = true"
|
|
|
|
@editor="
|
|
|
|
jsonEditor = false;
|
|
|
|
form = true;
|
|
|
|
"
|
|
|
|
@save="saveRecipe"
|
|
|
|
@delete="deleteRecipe"
|
2021-02-08 09:47:40 -09:00
|
|
|
class="sticky"
|
2020-12-24 16:37:38 -09:00
|
|
|
/>
|
|
|
|
|
2021-01-08 17:09:03 -09:00
|
|
|
<RecipeViewer
|
2020-12-24 16:37:38 -09:00
|
|
|
v-if="!form"
|
|
|
|
:name="recipeDetails.name"
|
|
|
|
:ingredients="recipeDetails.recipeIngredient"
|
|
|
|
:description="recipeDetails.description"
|
|
|
|
:instructions="recipeDetails.recipeInstructions"
|
|
|
|
:tags="recipeDetails.tags"
|
|
|
|
:categories="recipeDetails.categories"
|
|
|
|
:notes="recipeDetails.notes"
|
|
|
|
:rating="recipeDetails.rating"
|
|
|
|
:yields="recipeDetails.recipeYield"
|
|
|
|
:orgURL="recipeDetails.orgURL"
|
|
|
|
/>
|
|
|
|
<VJsoneditor
|
2021-01-03 12:09:22 -09:00
|
|
|
@error="logError()"
|
2020-12-24 16:37:38 -09:00
|
|
|
class="mt-10"
|
|
|
|
v-else-if="showJsonEditor"
|
|
|
|
v-model="recipeDetails"
|
|
|
|
height="1500px"
|
|
|
|
:options="jsonEditorOptions"
|
|
|
|
/>
|
2021-02-08 09:47:40 -09:00
|
|
|
<RecipeEditor
|
|
|
|
v-else
|
|
|
|
v-model="recipeDetails"
|
|
|
|
ref="recipeEditor"
|
|
|
|
@upload="getImageFile"
|
|
|
|
/>
|
2020-12-24 16:37:38 -09:00
|
|
|
</v-card>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-02-10 19:39:46 -09:00
|
|
|
import api from "../api";
|
|
|
|
import utils from "../utils";
|
2020-12-24 16:37:38 -09:00
|
|
|
import VJsoneditor from "v-jsoneditor";
|
2021-01-08 17:09:03 -09:00
|
|
|
import RecipeViewer from "../components/Recipe/RecipeViewer";
|
|
|
|
import RecipeEditor from "../components/Recipe/RecipeEditor";
|
2021-01-17 22:22:54 -09:00
|
|
|
import RecipeTimeCard from "../components/Recipe/RecipeTimeCard.vue";
|
2021-01-08 17:09:03 -09:00
|
|
|
import ButtonRow from "../components/UI/ButtonRow";
|
2020-12-24 16:37:38 -09:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
VJsoneditor,
|
2021-01-08 17:09:03 -09:00
|
|
|
RecipeViewer,
|
|
|
|
RecipeEditor,
|
|
|
|
ButtonRow,
|
2021-01-17 22:22:54 -09:00
|
|
|
RecipeTimeCard,
|
2020-12-24 16:37:38 -09:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2021-01-17 22:22:54 -09:00
|
|
|
// currentRecipe: this.$route.params.recipe,
|
2020-12-24 16:37:38 -09:00
|
|
|
form: false,
|
|
|
|
jsonEditor: false,
|
|
|
|
jsonEditorOptions: {
|
|
|
|
mode: "code",
|
|
|
|
search: false,
|
2021-01-08 17:09:03 -09:00
|
|
|
mainMenuBar: false,
|
2020-12-24 16:37:38 -09:00
|
|
|
},
|
|
|
|
// Recipe Details //
|
|
|
|
recipeDetails: {
|
|
|
|
name: "",
|
|
|
|
description: "",
|
|
|
|
image: "",
|
|
|
|
recipeYield: "",
|
|
|
|
recipeIngredient: [],
|
|
|
|
recipeInstructions: [],
|
|
|
|
slug: "",
|
|
|
|
filePath: "",
|
|
|
|
url: "",
|
|
|
|
tags: [],
|
|
|
|
categories: [],
|
|
|
|
dateAdded: "",
|
|
|
|
notes: [],
|
2021-01-08 17:09:03 -09:00
|
|
|
rating: 0,
|
2020-12-24 16:37:38 -09:00
|
|
|
},
|
2021-01-08 17:09:03 -09:00
|
|
|
imageKey: 1,
|
2020-12-24 16:37:38 -09:00
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.getRecipeDetails();
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
2021-02-10 19:39:46 -09:00
|
|
|
$route: function () {
|
2020-12-24 16:37:38 -09:00
|
|
|
this.getRecipeDetails();
|
2021-01-08 17:09:03 -09:00
|
|
|
},
|
2020-12-24 16:37:38 -09:00
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2021-01-17 22:22:54 -09:00
|
|
|
currentRecipe() {
|
2020-12-24 16:37:38 -09:00
|
|
|
return this.$route.params.recipe;
|
|
|
|
},
|
|
|
|
showIcons() {
|
|
|
|
return this.form;
|
|
|
|
},
|
|
|
|
showJsonEditor() {
|
|
|
|
if ((this.form === true) & (this.jsonEditor === true)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2021-01-08 17:09:03 -09:00
|
|
|
},
|
2020-12-24 16:37:38 -09:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getImageFile(fileObject) {
|
|
|
|
this.fileObject = fileObject;
|
|
|
|
},
|
|
|
|
async getRecipeDetails() {
|
2021-01-17 22:22:54 -09:00
|
|
|
this.recipeDetails = await api.recipes.requestDetails(this.currentRecipe);
|
2020-12-24 16:37:38 -09:00
|
|
|
this.form = false;
|
|
|
|
},
|
|
|
|
getImage(image) {
|
|
|
|
if (image) {
|
|
|
|
return utils.getImageURL(image) + "?rnd=" + this.imageKey;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
deleteRecipe() {
|
|
|
|
api.recipes.delete(this.recipeDetails.slug);
|
|
|
|
},
|
2021-02-08 09:47:40 -09:00
|
|
|
validateRecipe() {
|
|
|
|
if (this.jsonEditor) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return this.$refs.recipeEditor.validateRecipe();
|
|
|
|
}
|
|
|
|
},
|
2020-12-24 16:37:38 -09:00
|
|
|
async saveRecipe() {
|
2021-02-08 09:47:40 -09:00
|
|
|
if (this.validateRecipe()) {
|
|
|
|
let slug = await api.recipes.update(this.recipeDetails);
|
2020-12-24 16:37:38 -09:00
|
|
|
|
2021-02-08 09:47:40 -09:00
|
|
|
if (this.fileObject) {
|
|
|
|
await api.recipes.updateImage(
|
|
|
|
this.recipeDetails.slug,
|
|
|
|
this.fileObject
|
|
|
|
);
|
|
|
|
}
|
2020-12-24 16:37:38 -09:00
|
|
|
|
2021-02-08 09:47:40 -09:00
|
|
|
this.form = false;
|
|
|
|
this.imageKey += 1;
|
|
|
|
if (slug != this.recipeDetails.slug) {
|
|
|
|
this.$router.push(`/recipe/${slug}`);
|
|
|
|
}
|
|
|
|
}
|
2020-12-24 16:37:38 -09:00
|
|
|
},
|
|
|
|
showForm() {
|
|
|
|
this.form = true;
|
|
|
|
this.jsonEditor = false;
|
2021-01-08 17:09:03 -09:00
|
|
|
},
|
|
|
|
},
|
2020-12-24 16:37:38 -09:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.card-btn {
|
|
|
|
margin-top: -10px;
|
|
|
|
}
|
|
|
|
.disabled-card {
|
2021-01-03 17:41:18 -05:00
|
|
|
opacity: 0.5;
|
2020-12-24 16:37:38 -09:00
|
|
|
}
|
2021-01-17 22:22:54 -09:00
|
|
|
|
|
|
|
.force-bottom {
|
|
|
|
position: absolute;
|
|
|
|
width: 100%;
|
|
|
|
bottom: 0;
|
|
|
|
}
|
2021-02-08 09:47:40 -09:00
|
|
|
.sticky {
|
|
|
|
position: sticky !important;
|
|
|
|
top: 0;
|
|
|
|
z-index: 2;
|
|
|
|
}
|
2020-12-24 16:37:38 -09:00
|
|
|
</style>
|