1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-30 02:29:41 +02:00
mealie/frontend/src/components/Recipe.vue

157 lines
3.3 KiB
Vue
Raw Normal View History

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"
>
</v-img>
<ButtonRow
:open="showIcons"
@json="jsonEditor = true"
@editor="
jsonEditor = false;
form = true;
"
@save="saveRecipe"
@delete="deleteRecipe"
/>
<ViewRecipe
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"
/>
<EditRecipe v-else v-model="recipeDetails" @upload="getImageFile" />
</v-card>
</template>
<script>
import api from "../api";
import utils from "../utils";
import VJsoneditor from "v-jsoneditor";
import ViewRecipe from "./RecipeEditor/ViewRecipe";
import EditRecipe from "./RecipeEditor/EditRecipe";
import ButtonRow from "./UI/ButtonRow";
export default {
components: {
VJsoneditor,
ViewRecipe,
EditRecipe,
2021-01-07 23:16:55 -06:00
ButtonRow
2020-12-24 16:37:38 -09:00
},
data() {
return {
// CurrentRecipe: this.$route.params.recipe,
form: false,
jsonEditor: false,
jsonEditorOptions: {
mode: "code",
search: false,
2021-01-07 23:16:55 -06: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-07 23:16:55 -06:00
rating: 0
2020-12-24 16:37:38 -09:00
},
2021-01-07 23:16:55 -06:00
imageKey: 1
2020-12-24 16:37:38 -09:00
};
},
mounted() {
this.getRecipeDetails();
},
watch: {
2021-01-07 23:16:55 -06:00
$route: function() {
2020-12-24 16:37:38 -09:00
this.getRecipeDetails();
2021-01-07 23:16:55 -06:00
}
2020-12-24 16:37:38 -09:00
},
computed: {
CurrentRecipe() {
return this.$route.params.recipe;
},
showIcons() {
return this.form;
},
showJsonEditor() {
if ((this.form === true) & (this.jsonEditor === true)) {
return true;
} else {
return false;
}
2021-01-07 23:16:55 -06:00
}
2020-12-24 16:37:38 -09:00
},
methods: {
getImageFile(fileObject) {
this.fileObject = fileObject;
},
async getRecipeDetails() {
this.recipeDetails = await api.recipes.requestDetails(this.CurrentRecipe);
this.form = false;
},
getImage(image) {
if (image) {
return utils.getImageURL(image) + "?rnd=" + this.imageKey;
}
},
deleteRecipe() {
api.recipes.delete(this.recipeDetails.slug);
},
async saveRecipe() {
await api.recipes.update(this.recipeDetails);
if (this.fileObject) {
await api.recipes.updateImage(this.recipeDetails.slug, this.fileObject);
}
this.form = false;
this.imageKey += 1;
},
showForm() {
this.form = true;
this.jsonEditor = false;
2021-01-07 23:16:55 -06:00
}
}
2020-12-24 16:37:38 -09:00
};
</script>
<style>
.card-btn {
margin-top: -10px;
}
.disabled-card {
opacity: 0.5;
2020-12-24 16:37:38 -09:00
}
</style>