1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-02 20:15:24 +02:00

Add Database Layer for Recipe Scaling (#506)

* move badge

* fix add individual ingredient

* fix redirect issue

Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
Hayden 2021-06-12 22:23:23 -08:00 committed by GitHub
parent 0a927afaa0
commit e95ca870b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 298 additions and 62 deletions

View file

@ -31,6 +31,7 @@ const apiReq = {
post: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
const response = await axios.post(url, data).catch(function(error) {
handleError(error, getErrorText);
return error;
});
return handleResponse(response, getSuccessText);
},
@ -38,6 +39,7 @@ const apiReq = {
put: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
const response = await axios.put(url, data).catch(function(error) {
handleError(error, getErrorText);
return error;
});
return handleResponse(response, getSuccessText);
},
@ -45,6 +47,7 @@ const apiReq = {
patch: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
const response = await axios.patch(url, data).catch(function(error) {
handleError(error, getErrorText);
return error;
});
return handleResponse(response, getSuccessText);
},
@ -52,12 +55,14 @@ const apiReq = {
get: async function(url, data, getErrorText = defaultErrorText) {
return axios.get(url, data).catch(function(error) {
handleError(error, getErrorText);
return error;
});
},
delete: async function(url, data, getErrorText = defaultErrorText, getSuccessText = defaultSuccessText) {
const response = await axios.delete(url, data).catch(function(error) {
handleError(error, getErrorText);
return error;
});
return handleResponse(response, getSuccessText);
},

View file

@ -35,9 +35,11 @@ export const recipeAPI = {
},
async requestDetails(recipeSlug) {
let response = await apiReq.get(API_ROUTES.recipesRecipeSlug(recipeSlug));
if (response && response.data) return response.data;
else return null;
const response = await apiReq.get(API_ROUTES.recipesRecipeSlug(recipeSlug));
if (response.response) {
return response.response;
}
return response;
},
updateImage(recipeSlug, fileObject, overrideSuccessMsg = false) {

View file

@ -16,25 +16,13 @@
:top="menuTop"
:nudge-top="menuTop ? '5' : '0'"
allow-overflow
close-delay="125"
open-on-hover
>
<template v-slot:activator="{ on: onMenu, attrs: attrsMenu }">
<v-tooltip bottom dark :color="color">
<template v-slot:activator="{ on: onTooltip, attrs: attrsTooltip }">
<v-btn
:fab="fab"
:small="fab"
:color="color"
:icon="!fab"
dark
v-bind="{ ...attrsMenu, ...attrsTooltip }"
v-on="{ ...onMenu, ...onTooltip }"
@click.prevent
>
<v-icon>{{ menuIcon }}</v-icon>
</v-btn>
</template>
<span>{{ $t("general.more") }}</span>
</v-tooltip>
<template v-slot:activator="{ on, attrs }">
<v-btn :fab="fab" :small="fab" :color="color" :icon="!fab" dark v-bind="attrs" v-on="on" @click.prevent>
<v-icon>{{ menuIcon }}</v-icon>
</v-btn>
</template>
<v-list dense>
<v-list-item

View file

@ -1,5 +1,5 @@
<template>
<v-tooltip right :color="buttonStyle ? 'primary' : 'secondary'">
<v-tooltip bottom nudge-right="50" :color="buttonStyle ? 'primary' : 'secondary'">
<template v-slot:activator="{ on, attrs }">
<v-btn
small

View file

@ -1,5 +1,5 @@
<template>
<div>
<div v-if="value && value.length > 0">
<h2 class="mb-4">{{ $t("recipe.ingredients") }}</h2>
<div v-if="edit">
<draggable :value="value" @input="updateIndex" @start="drag = true" @end="drag = false" handle=".handle">
@ -9,7 +9,7 @@
<v-textarea
class="mr-2"
:label="$t('recipe.ingredient')"
v-model="value[index]"
v-model="value[index].note"
mdi-move-resize
auto-grow
solo
@ -45,7 +45,7 @@
<v-checkbox hide-details :value="checked[index]" class="pt-0 my-auto py-auto" color="secondary"> </v-checkbox>
<v-list-item-content>
<vue-markdown class="ma-0 pa-0 text-subtitle-1 dense-markdown" :source="ingredient"> </vue-markdown>
<vue-markdown class="ma-0 pa-0 text-subtitle-1 dense-markdown" :source="ingredient.note"> </vue-markdown>
</v-list-item-content>
</v-list-item>
</div>
@ -85,9 +85,26 @@ export default {
methods: {
addIngredient(ingredients = null) {
if (ingredients.length) {
this.value.push(...ingredients);
const newIngredients = ingredients.map(x => {
return {
title: null,
note: x,
unit: null,
food: null,
disableAmount: true,
quantity: 1,
};
});
this.value.push(...newIngredients);
} else {
this.value.push("");
this.value.push({
title: null,
note: "",
unit: null,
food: null,
disableAmount: true,
quantity: 1,
});
}
},
generateKey(item, index) {

View file

@ -192,8 +192,12 @@ export default {
return;
}
this.recipeDetails = await api.recipes.requestDetails(this.currentRecipe);
if (!this.recipeDetails) router.push(`/login`);
const response = await api.recipes.requestDetails(this.currentRecipe);
console.log("View Response", { response });
if (response.status === 401) router.push(`/login`);
if (response.status === 404) return;
this.recipeDetails = response.data;
this.skeleton = false;
},
getImage(slug) {

View file

@ -5,18 +5,19 @@
<v-icon left>
mdi-arrow-left-bold
</v-icon>
{{$t('shopping-list.all-lists')}}
{{ $t("shopping-list.all-lists") }}
</v-btn>
<v-icon v-if="!list" large left>
mdi-format-list-checks
</v-icon>
<v-toolbar-title v-if="!list" class="headline"> {{$t('shopping-list.shopping-lists')}} </v-toolbar-title>
<v-toolbar-title v-if="!list" class="headline"> {{ $t("shopping-list.shopping-lists") }} </v-toolbar-title>
<v-spacer></v-spacer>
<BaseDialog
:title="$t('shopping-list.new-list')"
title-icon="mdi-format-list-checks"
:submit-text="$t('general.create')"
@submit="createNewList">
<BaseDialog
:title="$t('shopping-list.new-list')"
title-icon="mdi-format-list-checks"
:submit-text="$t('general.create')"
@submit="createNewList"
>
<template v-slot:open="{ open }">
<TheButton create @click="open" />
</template>
@ -41,7 +42,7 @@
<v-icon left>
mdi-cart-check
</v-icon>
{{$t('general.view')}}
{{ $t("general.view") }}
</v-btn>
</v-card-actions>
</v-card>
@ -65,7 +66,7 @@
<v-card-text>
<v-row dense v-for="(item, index) in activeList.items" :key="index">
<v-col v-if="edit" cols="12" class="d-flex no-wrap align-center">
<p class="mb-0">{{$t('shopping-list.quantity', [item.quantity])}}</p>
<p class="mb-0">{{ $t("shopping-list.quantity", [item.quantity]) }}</p>
<div v-if="edit">
<v-btn x-small text class="ml-1" @click="activeList.items[index].quantity -= 1">
<v-icon>
@ -123,13 +124,13 @@
<v-icon left>
{{ $globals.icons.primary }}
</v-icon>
{{$t('shopping-list.from-recipe')}}
{{ $t("shopping-list.from-recipe") }}
</v-btn>
<v-btn v-if="edit" color="success" @click="newItem">
<v-icon left>
{{ $globals.icons.create }}
</v-icon>
{{$t('general.new')}}
{{ $t("general.new") }}
</v-btn>
</v-card-actions>
</v-card>
@ -197,7 +198,8 @@ export default {
this.$refs.searchRecipe.open();
},
async importIngredients(selected) {
const recipe = await api.recipes.requestDetails(selected.slug);
const response = await api.recipes.requestDetails(selected.slug);
const recipe = response.data;
const ingredients = recipe.recipeIngredient.map(x => ({
title: "",

View file

@ -26,7 +26,8 @@ export const recipeRoutes = [
component: ViewRecipe,
meta: {
title: async route => {
const recipe = await api.recipes.requestDetails(route.params.recipe);
const response = await api.recipes.requestDetails(route.params.recipe);
const recipe = response.data;
if (recipe && recipe.name) return recipe.name;
else return null;
},