meal plan in search

This commit is contained in:
vabene1111 2021-04-18 17:19:11 +02:00
parent 4ad5d6ef2f
commit 058d705170
6 changed files with 67 additions and 16 deletions

View File

@ -269,6 +269,12 @@ class NutritionInformationSerializer(serializers.ModelSerializer):
class RecipeOverviewSerializer(WritableNestedModelSerializer): class RecipeOverviewSerializer(WritableNestedModelSerializer):
keywords = KeywordLabelSerializer(many=True) keywords = KeywordLabelSerializer(many=True)
def create(self, validated_data):
pass
def update(self, instance, validated_data):
return instance
class Meta: class Meta:
model = Recipe model = Recipe
fields = ( fields = (
@ -342,7 +348,8 @@ class RecipeBookEntrySerializer(serializers.ModelSerializer):
fields = ('id', 'book', 'recipe',) fields = ('id', 'book', 'recipe',)
class MealPlanSerializer(SpacedModelSerializer): class MealPlanSerializer(SpacedModelSerializer, WritableNestedModelSerializer):
recipe = RecipeOverviewSerializer()
recipe_name = serializers.ReadOnlyField(source='recipe.name') recipe_name = serializers.ReadOnlyField(source='recipe.name')
meal_type_name = serializers.ReadOnlyField(source='meal_type.name') meal_type_name = serializers.ReadOnlyField(source='meal_type.name')
note_markdown = serializers.SerializerMethodField('get_note_markdown') note_markdown = serializers.SerializerMethodField('get_note_markdown')

File diff suppressed because one or more lines are too long

View File

@ -509,7 +509,7 @@
this.getRecipes(); this.getRecipes();
}, },
getRecipes: function () { getRecipes: function () {
let url = "{% url 'api:recipe-list' %}?limit=5" let url = "{% url 'api:recipe-list' %}?page_size=5"
if (this.recipe_query !== '') { if (this.recipe_query !== '') {
url += '&query=' + this.recipe_query; url += '&query=' + this.recipe_query;
} else { } else {
@ -524,7 +524,7 @@
}) })
}, },
getMdNote: function () { getMdNote: function () {
let url = "{% url 'api:recipe-list' %}?limit=5" let url = "{% url 'api:recipe-list' %}?page_size=5"
if (this.recipe_query !== '') { if (this.recipe_query !== '') {
url += '&query=' + this.recipe_query; url += '&query=' + this.recipe_query;
} }
@ -627,13 +627,14 @@
cloneRecipe: function (recipe) { cloneRecipe: function (recipe) {
let r = { let r = {
id: Math.round(Math.random() * 1000) + 10000, id: Math.round(Math.random() * 1000) + 10000,
recipe: recipe.id, recipe: recipe,
recipe_name: recipe.name, recipe_name: recipe.name,
servings: (this.new_note_servings > 1) ? this.new_note_servings : recipe.servings, servings: (this.new_note_servings > 1) ? this.new_note_servings : recipe.servings,
title: this.new_note_title, title: this.new_note_title,
note: this.new_note_text, note: this.new_note_text,
is_new: true is_new: true
} }
console.log(recipe)
this.new_note_title = '' this.new_note_title = ''
this.new_note_text = '' this.new_note_text = ''

View File

@ -825,7 +825,7 @@
} }
}, },
getRecipes: function () { getRecipes: function () {
let url = "{% url 'api:recipe-list' %}?limit=5&internal=true" let url = "{% url 'api:recipe-list' %}?page_size=5&internal=true"
if (this.recipe_query !== '') { if (this.recipe_query !== '') {
url += '&query=' + this.recipe_query; url += '&query=' + this.recipe_query;
} else { } else {

View File

@ -137,6 +137,12 @@
<div class="row" style="margin-top: 2vh"> <div class="row" style="margin-top: 2vh">
<div class="col col-md-12"> <div class="col col-md-12">
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));grid-gap: 1rem;"> <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));grid-gap: 1rem;">
<template v-if="search_input === '' && search_keywords.length === 0 && search_foods.length === 0 && search_books.length === 0">
<recipe-card v-bind:key="`mp_${m.id}`" v-for="m in meal_plans" :recipe="m.recipe"
:meal_plan="m"></recipe-card>
</template>
<recipe-card v-for="r in recipes" v-bind:key="r.id" :recipe="r"></recipe-card> <recipe-card v-for="r in recipes" v-bind:key="r.id" :recipe="r"></recipe-card>
</div> </div>
</div> </div>
@ -171,7 +177,7 @@ import Vue from 'vue'
import {BootstrapVue} from 'bootstrap-vue' import {BootstrapVue} from 'bootstrap-vue'
import 'bootstrap-vue/dist/bootstrap-vue.css' import 'bootstrap-vue/dist/bootstrap-vue.css'
import moment from 'moment'
import {ResolveUrlMixin} from "@/utils/utils"; import {ResolveUrlMixin} from "@/utils/utils";
@ -190,6 +196,8 @@ export default {
data() { data() {
return { return {
recipes: [], recipes: [],
meal_plans: [],
search_input: '', search_input: '',
search_internal: false, search_internal: false,
search_keywords: [], search_keywords: [],
@ -209,6 +217,8 @@ export default {
}, },
mounted() { mounted() {
this.refreshData() this.refreshData()
this.loadSpecialData()
}, },
methods: { methods: {
refreshData: function () { refreshData: function () {
@ -239,6 +249,18 @@ export default {
this.pagination_count = result.data.count this.pagination_count = result.data.count
}) })
}, },
loadSpecialData: function () {
let apiClient = new ApiApiFactory()
apiClient.listMealPlans({
query: {
from_date: moment().format('YYYY-MM-DD'),
to_date: moment().format('YYYY-MM-DD')
}
}).then(result => {
this.meal_plans = result.data
})
},
genericSelectChanged: function (obj) { genericSelectChanged: function (obj) {
this[obj.var] = obj.val this[obj.var] = obj.val
this.refreshData() this.refreshData()

View File

@ -2,26 +2,36 @@
<b-card no-body> <b-card no-body>
<a :href="resolveDjangoUrl('view_recipe', recipe.id)"> <a :href="clickUrl()">
<b-card-img-lazy style="height: 15vh; object-fit: cover" :src=recipe_image v-bind:alt="$t('Recipe_Image')" <b-card-img-lazy style="height: 15vh; object-fit: cover" :src=recipe_image v-bind:alt="$t('Recipe_Image')"
top></b-card-img-lazy> top></b-card-img-lazy>
<div class="card-img-overlay h-100 d-flex flex-column justify-content-right" <div class="card-img-overlay h-100 d-flex flex-column justify-content-right"
style="float:right; text-align: right; padding-top: 10px; padding-right: 5px"> style="float:right; text-align: right; padding-top: 10px; padding-right: 5px">
<recipe-context-menu :recipe="recipe" style="float:right"></recipe-context-menu> <recipe-context-menu :recipe="recipe" style="float:right" v-if="recipe !== null"></recipe-context-menu>
</div> </div>
</a> </a>
<b-card-body> <b-card-body>
<h5><a :href="resolveDjangoUrl('view_recipe', recipe.id)">{{ recipe.name }}</a></h5> <h5><a :href="clickUrl()">
<template v-if="recipe !== null">{{ recipe.name }}</template>
<template v-else>{{ meal_plan.title }}</template>
</a></h5>
<b-card-text style="text-overflow: ellipsis"> <b-card-text style="text-overflow: ellipsis">
<template v-if="recipe !== null">
{{ recipe.description }} {{ recipe.description }}
<keywords :recipe="recipe" style="margin-top: 4px"></keywords> <keywords :recipe="recipe" style="margin-top: 4px"></keywords>
</template>
<template v-else>{{ meal_plan.note }}</template>
</b-card-text> </b-card-text>
</b-card-body> </b-card-body>
<b-card-footer v-if="meal_plan !== undefined">
<i class="far fa-calendar-alt"></i> {{ meal_plan.meal_type_name }}
</b-card-footer>
</b-card> </b-card>
</template> </template>
@ -29,7 +39,7 @@
<script> <script>
import RecipeContextMenu from "@/components/RecipeContextMenu"; import RecipeContextMenu from "@/components/RecipeContextMenu";
import Keywords from "@/components/Keywords"; import Keywords from "@/components/Keywords";
import {ResolveUrlMixin} from "@/utils/utils"; import {resolveDjangoUrl, ResolveUrlMixin} from "@/utils/utils";
export default { export default {
name: "RecipeCard", name: "RecipeCard",
@ -39,6 +49,7 @@ export default {
components: {Keywords, RecipeContextMenu}, components: {Keywords, RecipeContextMenu},
props: { props: {
recipe: Object, recipe: Object,
meal_plan: Object,
}, },
data() { data() {
return { return {
@ -46,11 +57,21 @@ export default {
} }
}, },
mounted() { mounted() {
if (this.recipe.image === null) {
if (this.recipe == null || this.recipe.image === null) {
this.recipe_image = window.IMAGE_PLACEHOLDER this.recipe_image = window.IMAGE_PLACEHOLDER
} else { } else {
this.recipe_image = this.recipe.image this.recipe_image = this.recipe.image
} }
},
methods: {
clickUrl: function () {
if (this.recipe !== null) {
return resolveDjangoUrl('view_recipe', this.recipe.id)
} else {
return resolveDjangoUrl('view_plan_entry', this.meal_plan.id)
}
}
} }
} }
</script> </script>