Merge pull request #2938 from patmagauran/meal-plan-serving-size-link
Add ability to open recipes with specified number of servings from meal plan
This commit is contained in:
commit
b99443cb30
@ -79,6 +79,7 @@
|
||||
|
||||
window.CUSTOM_LOCALE = '{{ request.LANGUAGE_CODE }}'
|
||||
window.RECIPE_ID = {{recipe.pk}};
|
||||
window.RECIPE_SERVINGS = '{{ servings }}'
|
||||
window.SHARE_UID = '{{ share }}';
|
||||
window.USER_PREF = {
|
||||
'use_fractions': {% if request.user.userpreference.use_fractions %} true {% else %} false {% endif %},
|
||||
|
@ -171,9 +171,10 @@ def recipe_view(request, pk, share=None):
|
||||
created_at__gt=(timezone.now() - timezone.timedelta(minutes=5)),
|
||||
space=request.space).exists():
|
||||
ViewLog.objects.create(recipe=recipe, created_by=request.user, space=request.space)
|
||||
|
||||
if request.method == "GET":
|
||||
servings = request.GET.get("servings")
|
||||
return render(request, 'recipe_view.html',
|
||||
{'recipe': recipe, 'comments': comments, 'comment_form': comment_form, 'share': share, })
|
||||
{'recipe': recipe, 'comments': comments, 'comment_form': comment_form, 'share': share, 'servings': servings })
|
||||
|
||||
|
||||
@group_required('user')
|
||||
|
@ -126,7 +126,7 @@
|
||||
<div class="flex-grow-1 ml-2"
|
||||
style="text-overflow: ellipsis; overflow-wrap: anywhere;">
|
||||
<span class="two-row-text">
|
||||
<a :href="resolveDjangoUrl('view_recipe', plan.entry.recipe.id)" v-if="plan.entry.recipe">{{ plan.entry.recipe.name }}</a>
|
||||
<a :href="getRecipeURL(plan.entry.recipe, plan.entry.servings)" v-if="plan.entry.recipe">{{ plan.entry.recipe.name }}</a>
|
||||
<span v-else>{{ plan.entry.title }}</span> <br/>
|
||||
</span>
|
||||
<span v-if="plan.entry.note" class="two-row-text">
|
||||
@ -169,7 +169,7 @@
|
||||
v-if="contextData && contextData.originalItem && contextData.originalItem.entry.recipe != null"
|
||||
@click="
|
||||
$refs.menu.close()
|
||||
openRecipe(contextData.originalItem.entry.recipe)
|
||||
openRecipe(contextData.originalItem.entry.recipe, contextData.originalItem.entry.servings)
|
||||
"
|
||||
>
|
||||
<a class="dropdown-item p-2" href="javascript:void(0)"><i class="fas fa-pizza-slice"></i>
|
||||
@ -392,8 +392,13 @@ export default {
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
openRecipe: function (recipe) {
|
||||
window.open(this.resolveDjangoUrl("view_recipe", recipe.id))
|
||||
|
||||
getRecipeURL: function (recipe, servings) {
|
||||
return this.resolveDjangoUrl("view_recipe",`${recipe.id}?servings=${servings}`)
|
||||
},
|
||||
|
||||
openRecipe: function (recipe, servings) {
|
||||
window.open(this.getRecipeURL(recipe, servings))
|
||||
},
|
||||
setStartingDay(days) {
|
||||
if (this.settings.startingDayOfWeek + days < 0) {
|
||||
|
@ -237,6 +237,7 @@ export default {
|
||||
},
|
||||
props: {
|
||||
recipe_id: Number,
|
||||
def_servings: Number,
|
||||
recipe_obj: {type: Object, default: null},
|
||||
show_context_menu: {type: Boolean, default: true},
|
||||
enable_keyword_links: {type: Boolean, default: true},
|
||||
@ -320,8 +321,13 @@ export default {
|
||||
|
||||
|
||||
if (this.recipe.image === null) this.printReady()
|
||||
|
||||
window.RECIPE_SERVINGS = Number(window.RECIPE_SERVINGS)
|
||||
if (window.RECIPE_SERVINGS && ! isNaN(window.RECIPE_SERVINGS)) {
|
||||
//I am not sure this is the best way. This overwrites our servings cache, which may not be intended?
|
||||
this.servings = window.RECIPE_SERVINGS
|
||||
} else {
|
||||
this.servings = this.servings_cache[this.rootrecipe.id] = this.recipe.servings
|
||||
}
|
||||
this.loading = false
|
||||
|
||||
setTimeout(() => {
|
||||
|
Loading…
Reference in New Issue
Block a user