Merge pull request #1421 from TandoorRecipes/minor_fixes

Minor fixes
This commit is contained in:
vabene1111
2022-01-27 08:02:06 +01:00
committed by GitHub
20 changed files with 351 additions and 309 deletions

View File

@@ -79,7 +79,7 @@ def list_from_recipe(list_recipe=None, recipe=None, mealplan=None, servings=None
elif ingredients: elif ingredients:
ingredients = Ingredient.objects.filter(pk__in=ingredients, space=space) ingredients = Ingredient.objects.filter(pk__in=ingredients, space=space)
else: else:
ingredients = Ingredient.objects.filter(step__recipe=r, space=space) ingredients = Ingredient.objects.filter(step__recipe=r, food__ignore_shopping=False, space=space)
if exclude_onhand := created_by.userpreference.mealplan_autoexclude_onhand: if exclude_onhand := created_by.userpreference.mealplan_autoexclude_onhand:
ingredients = ingredients.exclude(food__onhand_users__id__in=[x.id for x in shared_users]) ingredients = ingredients.exclude(food__onhand_users__id__in=[x.id for x in shared_users])
@@ -101,9 +101,9 @@ def list_from_recipe(list_recipe=None, recipe=None, mealplan=None, servings=None
if ingredients.filter(food__recipe=x).exists(): if ingredients.filter(food__recipe=x).exists():
for ing in ingredients.filter(food__recipe=x): for ing in ingredients.filter(food__recipe=x):
if exclude_onhand: if exclude_onhand:
x_ing = Ingredient.objects.filter(step__recipe=x, space=space).exclude(food__onhand_users__id__in=[x.id for x in shared_users]) x_ing = Ingredient.objects.filter(step__recipe=x, food__ignore_shopping=False, space=space).exclude(food__onhand_users__id__in=[x.id for x in shared_users])
else: else:
x_ing = Ingredient.objects.filter(step__recipe=x, space=space) x_ing = Ingredient.objects.filter(step__recipe=x, food__ignore_shopping=False, space=space).exclude(food__ignore_shopping=True)
for i in [x for x in x_ing]: for i in [x for x in x_ing]:
ShoppingListEntry.objects.create( ShoppingListEntry.objects.create(
list_recipe=list_recipe, list_recipe=list_recipe,

View File

@@ -33,7 +33,7 @@ class ExtendedRecipeMixin(serializers.ModelSerializer):
images = None images = None
image = serializers.SerializerMethodField('get_image') image = serializers.SerializerMethodField('get_image')
numrecipe = serializers.ReadOnlyField(source='count_recipes_test') numrecipe = serializers.ReadOnlyField(source='recipe_count')
def get_fields(self, *args, **kwargs): def get_fields(self, *args, **kwargs):
fields = super().get_fields(*args, **kwargs) fields = super().get_fields(*args, **kwargs)
@@ -58,9 +58,6 @@ class ExtendedRecipeMixin(serializers.ModelSerializer):
if obj.recipe_image: if obj.recipe_image:
return MEDIA_URL + obj.recipe_image return MEDIA_URL + obj.recipe_image
def count_recipes(self, obj):
return Recipe.objects.filter(**{self.recipe_filter: obj}, space=obj.space).count()
class CustomDecimalField(serializers.Field): class CustomDecimalField(serializers.Field):
""" """
@@ -169,6 +166,11 @@ class UserPreferenceSerializer(WritableNestedModelSerializer):
food_inherit_default = FoodInheritFieldSerializer(source='space.food_inherit', many=True, allow_null=True, required=False, read_only=True) food_inherit_default = FoodInheritFieldSerializer(source='space.food_inherit', many=True, allow_null=True, required=False, read_only=True)
plan_share = UserNameSerializer(many=True, allow_null=True, required=False, read_only=True) plan_share = UserNameSerializer(many=True, allow_null=True, required=False, read_only=True)
shopping_share = UserNameSerializer(many=True, allow_null=True, required=False) shopping_share = UserNameSerializer(many=True, allow_null=True, required=False)
food_children_exist = serializers.SerializerMethodField('get_food_children_exist')
def get_food_children_exist(self, obj):
space = getattr(self.context.get('request', None), 'space', None)
return Food.objects.filter(depth__gt=0, space=space).exists()
def create(self, validated_data): def create(self, validated_data):
if not validated_data.get('user', None): if not validated_data.get('user', None):
@@ -183,7 +185,7 @@ class UserPreferenceSerializer(WritableNestedModelSerializer):
'user', 'theme', 'nav_color', 'default_unit', 'default_page', 'use_fractions', 'use_kj', 'search_style', 'show_recent', 'plan_share', 'user', 'theme', 'nav_color', 'default_unit', 'default_page', 'use_fractions', 'use_kj', 'search_style', 'show_recent', 'plan_share',
'ingredient_decimals', 'comments', 'shopping_auto_sync', 'mealplan_autoadd_shopping', 'food_inherit_default', 'default_delay', 'ingredient_decimals', 'comments', 'shopping_auto_sync', 'mealplan_autoadd_shopping', 'food_inherit_default', 'default_delay',
'mealplan_autoinclude_related', 'mealplan_autoexclude_onhand', 'shopping_share', 'shopping_recent_days', 'csv_delim', 'csv_prefix', 'mealplan_autoinclude_related', 'mealplan_autoexclude_onhand', 'shopping_share', 'shopping_recent_days', 'csv_delim', 'csv_prefix',
'filter_to_supermarket', 'shopping_add_onhand', 'left_handed' 'filter_to_supermarket', 'shopping_add_onhand', 'left_handed', 'food_children_exist'
) )
@@ -429,7 +431,7 @@ class FoodSerializer(UniqueFieldsMixin, WritableNestedModelSerializer, ExtendedR
model = Food model = Food
fields = ( fields = (
'id', 'name', 'description', 'shopping', 'recipe', 'food_onhand', 'supermarket_category', 'id', 'name', 'description', 'shopping', 'recipe', 'food_onhand', 'supermarket_category',
'image', 'parent', 'numchild', 'numrecipe', 'inherit_fields', 'full_name' 'image', 'parent', 'numchild', 'numrecipe', 'inherit_fields', 'full_name', 'ignore_shopping'
) )
read_only_fields = ('id', 'numchild', 'parent', 'image', 'numrecipe') read_only_fields = ('id', 'numchild', 'parent', 'image', 'numrecipe')
@@ -683,14 +685,15 @@ class ShoppingListRecipeSerializer(serializers.ModelSerializer):
value = Decimal(value) value = Decimal(value)
value = value.quantize(Decimal(1)) if value == value.to_integral() else value.normalize() # strips trailing zero value = value.quantize(Decimal(1)) if value == value.to_integral() else value.normalize() # strips trailing zero
return ( return (
obj.name obj.name
or getattr(obj.mealplan, 'title', None) or getattr(obj.mealplan, 'title', None)
or (d := getattr(obj.mealplan, 'date', None)) and ': '.join([obj.mealplan.recipe.name, str(d)]) or (d := getattr(obj.mealplan, 'date', None)) and ': '.join([obj.mealplan.recipe.name, str(d)])
or obj.recipe.name or obj.recipe.name
) + f' ({value:.2g})' ) + f' ({value:.2g})'
def update(self, instance, validated_data): def update(self, instance, validated_data):
if 'servings' in validated_data: # TODO remove once old shopping list
if 'servings' in validated_data and self.context.get('view', None).__class__.__name__ != 'ShoppingListViewSet':
list_from_recipe( list_from_recipe(
list_recipe=instance, list_recipe=instance,
servings=validated_data['servings'], servings=validated_data['servings'],

View File

@@ -121,11 +121,3 @@ def auto_add_shopping(sender, instance=None, created=False, weak=False, **kwargs
'servings': instance.servings 'servings': instance.servings
} }
list_recipe = list_from_recipe(**kwargs) list_recipe = list_from_recipe(**kwargs)
# user = self.context['request'].user
# if user.userpreference.shopping_add_onhand:
# if checked := validated_data.get('checked', None):
# instance.food.onhand_users.add(*user.userpreference.shopping_share.all(), user)
# elif checked == False:
# instance.food.onhand_users.remove(*user.userpreference.shopping_share.all(), user)

View File

@@ -834,7 +834,7 @@
this.$http.get('{% url 'api:recipe-detail' 123456 %}'.replace('123456', recipe.id)).then((response) => { this.$http.get('{% url 'api:recipe-detail' 123456 %}'.replace('123456', recipe.id)).then((response) => {
for (let s of response.data.steps) { for (let s of response.data.steps) {
for (let i of s.ingredients) { for (let i of s.ingredients) {
if (!i.is_header && i.food !== null && i.food.food_onhand === false) { if (!i.is_header && i.food !== null && !i.food.ignore_food) {
this.shopping_list.entries.push({ this.shopping_list.entries.push({
'list_recipe': slr.id, 'list_recipe': slr.id,
'food': i.food, 'food': i.food,

View File

@@ -118,7 +118,7 @@ class ExtendedRecipeMixin():
# add a recipe count annotation to the query # add a recipe count annotation to the query
# explanation on construction https://stackoverflow.com/a/43771738/15762829 # explanation on construction https://stackoverflow.com/a/43771738/15762829
recipe_count = Recipe.objects.filter(**{recipe_filter: OuterRef('id')}, space=space).values(recipe_filter).annotate(count=Count('pk')).values('count') recipe_count = Recipe.objects.filter(**{recipe_filter: OuterRef('id')}, space=space).values(recipe_filter).annotate(count=Count('pk')).values('count')
queryset = queryset.annotate(recipe_count_test=Coalesce(Subquery(recipe_count), 0)) queryset = queryset.annotate(recipe_count=Coalesce(Subquery(recipe_count), 0))
# add a recipe image annotation to the query # add a recipe image annotation to the query
image_subquery = Recipe.objects.filter(**{recipe_filter: OuterRef('id')}, space=space).exclude(image__isnull=True).exclude(image__exact='').order_by("?").values('image')[:1] image_subquery = Recipe.objects.filter(**{recipe_filter: OuterRef('id')}, space=space).exclude(image__isnull=True).exclude(image__exact='').order_by("?").values('image')[:1]
@@ -400,7 +400,7 @@ class SupermarketCategoryViewSet(viewsets.ModelViewSet, StandardFilterMixin):
permission_classes = [CustomIsUser] permission_classes = [CustomIsUser]
def get_queryset(self): def get_queryset(self):
self.queryset = self.queryset.filter(space=self.request.space) self.queryset = self.queryset.filter(space=self.request.space).order_by('name')
return super().get_queryset() return super().get_queryset()

View File

@@ -18,7 +18,7 @@
<h3> <h3>
<!-- <span><b-button variant="link" size="sm" class="text-dark shadow-none"><i class="fas fa-chevron-down"></i></b-button></span> --> <!-- <span><b-button variant="link" size="sm" class="text-dark shadow-none"><i class="fas fa-chevron-down"></i></b-button></span> -->
<model-menu /> <model-menu />
<span>{{ this.this_model.name }}</span> <span>{{ $t(this.this_model.name) }}</span>
<span v-if="apiName !== 'Step'"> <span v-if="apiName !== 'Step'">
<b-button variant="link" @click="startAction({ action: 'new' })"> <b-button variant="link" @click="startAction({ action: 'new' })">
<i class="fas fa-plus-circle fa-2x"></i> <i class="fas fa-plus-circle fa-2x"></i>

View File

@@ -1,6 +1,6 @@
<template> <template>
<div id="app" style="margin-bottom: 4vh"> <div id="app" style="margin-bottom: 4vh">
<RecipeSwitcher ref="ref_recipe_switcher"/> <RecipeSwitcher ref="ref_recipe_switcher" />
<div class="row"> <div class="row">
<div class="col-12 col-xl-8 col-lg-10 offset-xl-2 offset-lg-1"> <div class="col-12 col-xl-8 col-lg-10 offset-xl-2 offset-lg-1">
<div class="row"> <div class="row">
@@ -8,21 +8,15 @@
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-12 col-lg-10 col-xl-8 mt-3 mb-3"> <div class="col-12 col-lg-10 col-xl-8 mt-3 mb-3">
<b-input-group> <b-input-group>
<b-input <b-input class="form-control form-control-lg form-control-borderless form-control-search" v-model="search.search_input" v-bind:placeholder="$t('Search')"></b-input>
class="form-control form-control-lg form-control-borderless form-control-search"
v-model="search.search_input" v-bind:placeholder="$t('Search')"></b-input>
<b-input-group-append> <b-input-group-append>
<b-button v-b-tooltip.hover :title="$t('show_sql')" @click="showSQL()" <b-button v-b-tooltip.hover :title="$t('show_sql')" @click="showSQL()" v-if="debug && ui.sql_debug">
v-if="debug && ui.sql_debug">
<i class="fas fa-bug" style="font-size: 1.5em"></i> <i class="fas fa-bug" style="font-size: 1.5em"></i>
</b-button> </b-button>
<b-button variant="light" v-b-tooltip.hover :title="$t('Random Recipes')" <b-button variant="light" v-b-tooltip.hover :title="$t('Random Recipes')" @click="openRandom()">
@click="openRandom()">
<i class="fas fa-dice-five" style="font-size: 1.5em"></i> <i class="fas fa-dice-five" style="font-size: 1.5em"></i>
</b-button> </b-button>
<b-button v-b-toggle.collapse_advanced_search v-b-tooltip.hover <b-button v-b-toggle.collapse_advanced_search v-b-tooltip.hover :title="$t('Advanced Settings')" v-bind:variant="!searchFiltered(true) ? 'primary' : 'danger'">
:title="$t('Advanced Settings')"
v-bind:variant="!searchFiltered(true) ? 'primary' : 'danger'">
<!-- TODO consider changing this icon to a filter --> <!-- TODO consider changing this icon to a filter -->
<i class="fas fa-caret-down" v-if="!search.advanced_search_visible"></i> <i class="fas fa-caret-down" v-if="!search.advanced_search_visible"></i>
<i class="fas fa-caret-up" v-if="search.advanced_search_visible"></i> <i class="fas fa-caret-up" v-if="search.advanced_search_visible"></i>
@@ -32,18 +26,15 @@
</div> </div>
</div> </div>
<b-collapse id="collapse_advanced_search" class="mt-2 shadow-sm" <b-collapse id="collapse_advanced_search" class="mt-2 shadow-sm" v-model="search.advanced_search_visible">
v-model="search.advanced_search_visible">
<div class="card"> <div class="card">
<div class="card-body p-4"> <div class="card-body p-4">
<div class="row"> <div class="row">
<div class="col-md-3"> <div class="col-md-3">
<a class="btn btn-primary btn-block text-uppercase" <a class="btn btn-primary btn-block text-uppercase" :href="resolveDjangoUrl('new_recipe')">{{ $t("New_Recipe") }}</a>
:href="resolveDjangoUrl('new_recipe')">{{ $t("New_Recipe") }}</a>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<a class="btn btn-primary btn-block text-uppercase" <a class="btn btn-primary btn-block text-uppercase" :href="resolveDjangoUrl('data_import_url')">{{ $t("Import") }}</a>
:href="resolveDjangoUrl('data_import_url')">{{ $t("Import") }}</a>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<button <button
@@ -62,92 +53,57 @@
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<button id="id_settings_button" <button id="id_settings_button" class="btn btn-primary btn-block text-uppercase"><i class="fas fa-cog fa-lg m-1"></i></button>
class="btn btn-primary btn-block text-uppercase"><i
class="fas fa-cog fa-lg m-1"></i></button>
</div> </div>
</div> </div>
<b-popover target="id_settings_button" triggers="click" placement="bottom"> <b-popover target="id_settings_button" triggers="click" placement="bottom">
<b-tabs content-class="mt-1" small> <b-tabs content-class="mt-1" small>
<b-tab :title="$t('Settings')" active> <b-tab :title="$t('Settings')" active>
<b-form-group v-bind:label="$t('Recently_Viewed')" <b-form-group v-bind:label="$t('Recently_Viewed')" label-for="popover-input-1" label-cols="6" class="mb-3">
label-for="popover-input-1" label-cols="6" class="mb-3"> <b-form-input type="number" v-model="ui.recently_viewed" id="popover-input-1" size="sm"></b-form-input>
<b-form-input type="number" v-model="ui.recently_viewed"
id="popover-input-1" size="sm"></b-form-input>
</b-form-group> </b-form-group>
<b-form-group v-bind:label="$t('Recipes_per_page')" <b-form-group v-bind:label="$t('Recipes_per_page')" label-for="popover-input-page-count" label-cols="6" class="mb-3">
label-for="popover-input-page-count" label-cols="6" <b-form-input type="number" v-model="ui.page_size" id="popover-input-page-count" size="sm"></b-form-input>
class="mb-3">
<b-form-input type="number" v-model="ui.page_size"
id="popover-input-page-count"
size="sm"></b-form-input>
</b-form-group> </b-form-group>
<b-form-group v-bind:label="$t('Meal_Plan')" label-for="popover-input-2" <b-form-group v-bind:label="$t('Meal_Plan')" label-for="popover-input-2" label-cols="6" class="mb-3">
label-cols="6" class="mb-3"> <b-form-checkbox switch v-model="ui.show_meal_plan" id="popover-input-2" size="sm"></b-form-checkbox>
<b-form-checkbox switch v-model="ui.show_meal_plan"
id="popover-input-2" size="sm"></b-form-checkbox>
</b-form-group> </b-form-group>
<b-form-group v-if="ui.show_meal_plan" <b-form-group v-if="ui.show_meal_plan" v-bind:label="$t('Meal_Plan_Days')" label-for="popover-input-5" label-cols="6" class="mb-3">
v-bind:label="$t('Meal_Plan_Days')" <b-form-input type="number" v-model="ui.meal_plan_days" id="popover-input-5" size="sm"></b-form-input>
label-for="popover-input-5" label-cols="6" class="mb-3">
<b-form-input type="number" v-model="ui.meal_plan_days"
id="popover-input-5" size="sm"></b-form-input>
</b-form-group> </b-form-group>
<b-form-group v-bind:label="$t('Sort_by_new')" <b-form-group v-bind:label="$t('Sort_by_new')" label-for="popover-input-3" label-cols="6" class="mb-3">
label-for="popover-input-3" label-cols="6" class="mb-3"> <b-form-checkbox switch v-model="ui.sort_by_new" id="popover-input-3" size="sm"></b-form-checkbox>
<b-form-checkbox switch v-model="ui.sort_by_new"
id="popover-input-3" size="sm"></b-form-checkbox>
</b-form-group> </b-form-group>
<div class="row" style="margin-top: 1vh"> <div class="row" style="margin-top: 1vh">
<div class="col-12"> <div class="col-12">
<a :href="resolveDjangoUrl('view_settings') + '#search'">{{ <a :href="resolveDjangoUrl('view_settings') + '#search'">{{ $t("Search Settings") }}</a>
$t("Search Settings")
}}</a>
</div> </div>
</div> </div>
</b-tab> </b-tab>
<b-tab title="Expert Settings"> <b-tab title="Expert Settings">
<b-form-group v-bind:label="$t('remember_search')" <b-form-group v-bind:label="$t('remember_search')" label-for="popover-rem-search" label-cols="6" class="mb-3">
label-for="popover-rem-search" label-cols="6" <b-form-checkbox switch v-model="ui.remember_search" id="popover-rem-search" size="sm"></b-form-checkbox>
class="mb-3">
<b-form-checkbox switch v-model="ui.remember_search"
id="popover-rem-search"
size="sm"></b-form-checkbox>
</b-form-group> </b-form-group>
<b-form-group v-if="ui.remember_search" <b-form-group v-if="ui.remember_search" v-bind:label="$t('remember_hours')" label-for="popover-input-rem-hours" label-cols="6" class="mb-3">
v-bind:label="$t('remember_hours')" <b-form-input type="number" v-model="ui.remember_hours" id="popover-rem-hours" size="sm"></b-form-input>
label-for="popover-input-rem-hours" label-cols="6"
class="mb-3">
<b-form-input type="number" v-model="ui.remember_hours"
id="popover-rem-hours" size="sm"></b-form-input>
</b-form-group> </b-form-group>
<b-form-group v-bind:label="$t('tree_select')" <b-form-group v-bind:label="$t('tree_select')" label-for="popover-input-treeselect" label-cols="6" class="mb-3">
label-for="popover-input-treeselect" label-cols="6" <b-form-checkbox switch v-model="ui.tree_select" id="popover-input-treeselect" size="sm"></b-form-checkbox>
class="mb-3">
<b-form-checkbox switch v-model="ui.tree_select"
id="popover-input-treeselect"
size="sm"></b-form-checkbox>
</b-form-group> </b-form-group>
<b-form-group v-if="debug" v-bind:label="$t('sql_debug')" <b-form-group v-if="debug" v-bind:label="$t('sql_debug')" label-for="popover-input-sqldebug" label-cols="6" class="mb-3">
label-for="popover-input-sqldebug" label-cols="6" <b-form-checkbox switch v-model="ui.sql_debug" id="popover-input-sqldebug" size="sm"></b-form-checkbox>
class="mb-3">
<b-form-checkbox switch v-model="ui.sql_debug"
id="popover-input-sqldebug"
size="sm"></b-form-checkbox>
</b-form-group> </b-form-group>
</b-tab> </b-tab>
</b-tabs> </b-tabs>
<div class="row" style="margin-top: 1vh"> <div class="row" style="margin-top: 1vh">
<div class="col-12" style="text-align: right"> <div class="col-12" style="text-align: right">
<b-button size="sm" variant="secondary" style="margin-right: 8px" <b-button size="sm" variant="secondary" style="margin-right: 8px" @click="$root.$emit('bv::hide::popover')">{{ $t("Close") }} </b-button>
@click="$root.$emit('bv::hide::popover')">{{ $t("Close") }}
</b-button>
</div> </div>
</div> </div>
</b-popover> </b-popover>
@@ -182,12 +138,8 @@
></generic-multiselect> ></generic-multiselect>
<b-input-group-append> <b-input-group-append>
<b-input-group-text> <b-input-group-text>
<b-form-checkbox v-model="search.search_keywords_or" <b-form-checkbox v-model="search.search_keywords_or" name="check-button" @change="refreshData(false)" class="shadow-none" switch>
name="check-button" <span class="text-uppercase" v-if="search.search_keywords_or">{{ $t("or") }}</span>
@change="refreshData(false)"
class="shadow-none" switch>
<span class="text-uppercase"
v-if="search.search_keywords_or">{{ $t("or") }}</span>
<span class="text-uppercase" v-else>{{ $t("and") }}</span> <span class="text-uppercase" v-else>{{ $t("and") }}</span>
</b-form-checkbox> </b-form-checkbox>
</b-input-group-text> </b-input-group-text>
@@ -226,13 +178,8 @@
></generic-multiselect> ></generic-multiselect>
<b-input-group-append> <b-input-group-append>
<b-input-group-text> <b-input-group-text>
<b-form-checkbox v-model="search.search_foods_or" <b-form-checkbox v-model="search.search_foods_or" name="check-button" @change="refreshData(false)" class="shadow-none" switch>
name="check-button" <span class="text-uppercase" v-if="search.search_foods_or">{{ $t("or") }}</span>
@change="refreshData(false)"
class="shadow-none" switch>
<span class="text-uppercase" v-if="search.search_foods_or">{{
$t("or")
}}</span>
<span class="text-uppercase" v-else>{{ $t("and") }}</span> <span class="text-uppercase" v-else>{{ $t("and") }}</span>
</b-form-checkbox> </b-form-checkbox>
</b-input-group-text> </b-input-group-text>
@@ -256,13 +203,8 @@
></generic-multiselect> ></generic-multiselect>
<b-input-group-append> <b-input-group-append>
<b-input-group-text> <b-input-group-text>
<b-form-checkbox v-model="search.search_books_or" <b-form-checkbox v-model="search.search_books_or" name="check-button" @change="refreshData(false)" class="shadow-none" tyle="width: 100%" switch>
name="check-button" <span class="text-uppercase" v-if="search.search_books_or">{{ $t("or") }}</span>
@change="refreshData(false)"
class="shadow-none" tyle="width: 100%" switch>
<span class="text-uppercase" v-if="search.search_books_or">{{
$t("or")
}}</span>
<span class="text-uppercase" v-else>{{ $t("and") }}</span> <span class="text-uppercase" v-else>{{ $t("and") }}</span>
</b-form-checkbox> </b-form-checkbox>
</b-input-group-text> </b-input-group-text>
@@ -299,9 +241,7 @@
<div class="row"> <div class="row">
<div class="col col-md-12 text-right" style="margin-top: 2vh"> <div class="col col-md-12 text-right" style="margin-top: 2vh">
<span class="text-muted"> <span class="text-muted">
{{ $t("Page") }} {{ search.pagination_page }}/{{ {{ $t("Page") }} {{ search.pagination_page }}/{{ Math.ceil(pagination_count / ui.page_size) }}
Math.ceil(pagination_count / ui.page_size)
}}
<a href="#" @click="resetSearch"><i class="fas fa-times-circle"></i> {{ $t("Reset") }}</a> <a href="#" @click="resetSearch"><i class="fas fa-times-circle"></i> {{ $t("Reset") }}</a>
</span> </span>
</div> </div>
@@ -309,24 +249,18 @@
<div class="row"> <div class="row">
<div class="col col-md-12"> <div class="col col-md-12">
<div <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); grid-gap: 0.8rem">
style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); grid-gap: 0.8rem">
<template v-if="!searchFiltered()"> <template v-if="!searchFiltered()">
<recipe-card v-bind:key="`mp_${m.id}`" v-for="m in meal_plans" :recipe="m.recipe" <recipe-card v-bind:key="`mp_${m.id}`" v-for="m in meal_plans" :recipe="m.recipe" :meal_plan="m" :footer_text="m.meal_type_name" footer_icon="far fa-calendar-alt"></recipe-card>
:meal_plan="m" :footer_text="m.meal_type_name"
footer_icon="far fa-calendar-alt"></recipe-card>
</template> </template>
<recipe-card v-for="r in recipes" v-bind:key="r.id" :recipe="r" <recipe-card v-for="r in recipes" v-bind:key="r.id" :recipe="r" :footer_text="isRecentOrNew(r)[0]" :footer_icon="isRecentOrNew(r)[1]"></recipe-card>
:footer_text="isRecentOrNew(r)[0]"
:footer_icon="isRecentOrNew(r)[1]"></recipe-card>
</div> </div>
</div> </div>
</div> </div>
<div class="row" style="margin-top: 2vh" v-if="!random_search"> <div class="row" style="margin-top: 2vh" v-if="!random_search">
<div class="col col-md-12"> <div class="col col-md-12">
<b-pagination pills v-model="search.pagination_page" :total-rows="pagination_count" <b-pagination pills v-model="search.pagination_page" :total-rows="pagination_count" :per-page="ui.page_size" @change="pageChange" align="center"></b-pagination>
:per-page="ui.page_size" @change="pageChange" align="center"></b-pagination>
</div> </div>
</div> </div>
</div> </div>
@@ -337,26 +271,22 @@
<script> <script>
import Vue from "vue" import Vue from "vue"
import {BootstrapVue} from "bootstrap-vue" import { BootstrapVue } from "bootstrap-vue"
import VueCookies from "vue-cookies"
import "bootstrap-vue/dist/bootstrap-vue.css" import "bootstrap-vue/dist/bootstrap-vue.css"
import moment from "moment" import moment from "moment"
import _debounce from "lodash/debounce" import _debounce from "lodash/debounce"
import VueCookies from "vue-cookies" import { ApiMixin, ResolveUrlMixin } from "@/utils/utils"
Vue.use(VueCookies)
import {ApiMixin, ResolveUrlMixin} from "@/utils/utils"
import LoadingSpinner from "@/components/LoadingSpinner" // TODO: is this deprecated? import LoadingSpinner from "@/components/LoadingSpinner" // TODO: is this deprecated?
import RecipeCard from "@/components/RecipeCard" import RecipeCard from "@/components/RecipeCard"
import GenericMultiselect from "@/components/GenericMultiselect" import GenericMultiselect from "@/components/GenericMultiselect"
import {Treeselect, LOAD_CHILDREN_OPTIONS} from "@riophae/vue-treeselect" //TODO: delete import { Treeselect, LOAD_CHILDREN_OPTIONS } from "@riophae/vue-treeselect" //TODO: delete
import "@riophae/vue-treeselect/dist/vue-treeselect.css" //TODO: delete import "@riophae/vue-treeselect/dist/vue-treeselect.css" //TODO: delete
import RecipeSwitcher from "@/components/Buttons/RecipeSwitcher" import RecipeSwitcher from "@/components/Buttons/RecipeSwitcher"
Vue.use(VueCookies)
Vue.use(BootstrapVue) Vue.use(BootstrapVue)
let SEARCH_COOKIE_NAME = "search_settings" let SEARCH_COOKIE_NAME = "search_settings"
@@ -365,7 +295,7 @@ let UI_COOKIE_NAME = "_uisearch_settings"
export default { export default {
name: "RecipeSearchView", name: "RecipeSearchView",
mixins: [ResolveUrlMixin, ApiMixin], mixins: [ResolveUrlMixin, ApiMixin],
components: {GenericMultiselect, RecipeCard, Treeselect, RecipeSwitcher}, components: { GenericMultiselect, RecipeCard, Treeselect, RecipeSwitcher },
data() { data() {
return { return {
// this.Models and this.Actions inherited from ApiMixin // this.Models and this.Actions inherited from ApiMixin
@@ -416,12 +346,12 @@ export default {
} }
} }
return [ return [
{id: 5, label: "⭐⭐⭐⭐⭐" + ratingCount(this.facets.Ratings?.["5.0"] ?? 0)}, { id: 5, label: "⭐⭐⭐⭐⭐" + ratingCount(this.facets.Ratings?.["5.0"] ?? 0) },
{id: 4, label: "⭐⭐⭐⭐ " + this.$t("and_up") + ratingCount(this.facets.Ratings?.["4.0"] ?? 0)}, { id: 4, label: "⭐⭐⭐⭐ " + this.$t("and_up") + ratingCount(this.facets.Ratings?.["4.0"] ?? 0) },
{id: 3, label: "⭐⭐⭐ " + this.$t("and_up") + ratingCount(this.facets.Ratings?.["3.0"] ?? 0)}, { id: 3, label: "⭐⭐⭐ " + this.$t("and_up") + ratingCount(this.facets.Ratings?.["3.0"] ?? 0) },
{id: 2, label: "⭐⭐ " + this.$t("and_up") + ratingCount(this.facets.Ratings?.["2.0"] ?? 0)}, { id: 2, label: "⭐⭐ " + this.$t("and_up") + ratingCount(this.facets.Ratings?.["2.0"] ?? 0) },
{id: 1, label: "⭐ " + this.$t("and_up") + ratingCount(this.facets.Ratings?.["1.0"] ?? 0)}, { id: 1, label: "⭐ " + this.$t("and_up") + ratingCount(this.facets.Ratings?.["1.0"] ?? 0) },
{id: 0, label: this.$t("Unrated") + ratingCount(this.facets.Ratings?.["0.0"] ?? 0)}, { id: 0, label: this.$t("Unrated") + ratingCount(this.facets.Ratings?.["0.0"] ?? 0) },
] ]
}, },
}, },
@@ -435,42 +365,43 @@ export default {
} }
let urlParams = new URLSearchParams(window.location.search) let urlParams = new URLSearchParams(window.location.search)
if (urlParams.has("keyword")) { if (urlParams.has("keyword")) {
this.search.search_keywords = [] this.search.search_keywords = []
this.facets.Keywords = [] this.facets.Keywords = []
for (let x of urlParams.getAll("keyword")) { for (let x of urlParams.getAll("keyword")) {
let initial_keyword = {id: Number.parseInt(x), name: "loading..."} let initial_keyword = { id: Number.parseInt(x), name: "loading..." }
this.search.search_keywords.push(initial_keyword) this.search.search_keywords.push(initial_keyword)
this.genericAPI(this.Models.KEYWORD, this.Actions.FETCH, {id: initial_keyword.id}).then((response) => { this.genericAPI(this.Models.KEYWORD, this.Actions.FETCH, { id: initial_keyword.id })
let kw_index = this.search.search_keywords.findIndex((k => k.id === initial_keyword.id)) .then((response) => {
this.$set(this.search.search_keywords, kw_index, response.data) let kw_index = this.search.search_keywords.findIndex((k) => k.id === initial_keyword.id)
this.$set(this.facets.Keywords, kw_index, response.data) this.$set(this.search.search_keywords, kw_index, response.data)
}).catch((err) => { this.$set(this.facets.Keywords, kw_index, response.data)
if (err.response.status === 404) { })
let kw_index = this.search.search_keywords.findIndex((k => k.id === initial_keyword.id)) .catch((err) => {
this.search.search_keywords.splice(kw_index, 1) if (err.response.status === 404) {
this.facets.Keywords.splice(kw_index, 1) let kw_index = this.search.search_keywords.findIndex((k) => k.id === initial_keyword.id)
this.refreshData(false) this.search.search_keywords.splice(kw_index, 1)
} this.facets.Keywords.splice(kw_index, 1)
}) this.refreshData(false)
}
})
} }
} }
this.facets.Foods = [] this.facets.Foods = []
for (let x of this.search.search_foods) { for (let x of this.search.search_foods) {
this.facets.Foods.push({id: x, name: "loading..."}) this.facets.Foods.push({ id: x, name: "loading..." })
} }
this.facets.Keywords = [] this.facets.Keywords = []
for (let x of this.search.search_keywords) { for (let x of this.search.search_keywords) {
this.facets.Keywords.push({id: x, name: "loading..."}) this.facets.Keywords.push({ id: x, name: "loading..." })
} }
this.facets.Books = [] this.facets.Books = []
for (let x of this.search.search_books) { for (let x of this.search.search_books) {
this.facets.Books.push({id: x, name: "loading..."}) this.facets.Books.push({ id: x, name: "loading..." })
} }
this.loadMealPlan() this.loadMealPlan()
@@ -606,28 +537,27 @@ export default {
if (!this.ui.tree_select) { if (!this.ui.tree_select) {
return return
} }
let params = {hash: hash} let params = { hash: hash }
if (facet) { if (facet) {
params[facet] = id params[facet] = id
} }
return this.genericGetAPI("api_get_facets", params).then((response) => { return this.genericGetAPI("api_get_facets", params).then((response) => {
this.facets = {...this.facets, ...response.data.facets} this.facets = { ...this.facets, ...response.data.facets }
}) })
}, },
showSQL: function () { showSQL: function () {
let params = this.buildParams() let params = this.buildParams()
this.genericAPI(this.Models.RECIPE, this.Actions.LIST, params).then((result) => { this.genericAPI(this.Models.RECIPE, this.Actions.LIST, params).then((result) => {})
})
}, },
// TODO refactor to combine with load KeywordChildren // TODO refactor to combine with load KeywordChildren
loadFoodChildren({action, parentNode, callback}) { loadFoodChildren({ action, parentNode, callback }) {
if (action === LOAD_CHILDREN_OPTIONS) { if (action === LOAD_CHILDREN_OPTIONS) {
if (this.facets?.cache_key) { if (this.facets?.cache_key) {
this.getFacets(this.facets.cache_key, "food", parentNode.id).then(callback()) this.getFacets(this.facets.cache_key, "food", parentNode.id).then(callback())
} }
} }
}, },
loadKeywordChildren({action, parentNode, callback}) { loadKeywordChildren({ action, parentNode, callback }) {
if (action === LOAD_CHILDREN_OPTIONS) { if (action === LOAD_CHILDREN_OPTIONS) {
if (this.facets?.cache_key) { if (this.facets?.cache_key) {
this.getFacets(this.facets.cache_key, "keyword", parentNode.id).then(callback()) this.getFacets(this.facets.cache_key, "keyword", parentNode.id).then(callback())
@@ -657,7 +587,7 @@ export default {
pageSize: this.ui.page_size, pageSize: this.ui.page_size,
} }
if (!this.searchFiltered()) { if (!this.searchFiltered()) {
params.options = {query: {last_viewed: this.ui.recently_viewed}} params.options = { query: { last_viewed: this.ui.recently_viewed } }
} }
return params return params
}, },

View File

@@ -401,14 +401,14 @@
</div> </div>
<div v-if="settings.mealplan_autoadd_shopping"> <div v-if="settings.mealplan_autoadd_shopping">
<div class="row"> <div class="row">
<div class="col col-md-6">{{ $t("mealplan_autoadd_shopping") }}</div> <div class="col col-md-6">{{ $t("mealplan_autoexclude_onhand") }}</div>
<div class="col col-md-6 text-right"> <div class="col col-md-6 text-right">
<input type="checkbox" class="form-control settings-checkbox" v-model="settings.mealplan_autoexclude_onhand" @change="saveSettings" /> <input type="checkbox" class="form-control settings-checkbox" v-model="settings.mealplan_autoexclude_onhand" @change="saveSettings" />
</div> </div>
</div> </div>
<div class="row sm mb-3"> <div class="row sm mb-3">
<div class="col"> <div class="col">
<em class="small text-muted">{{ $t("mealplan_autoadd_shopping_desc") }}</em> <em class="small text-muted">{{ $t("mealplan_autoexclude_onhand_desc") }}</em>
</div> </div>
</div> </div>
</div> </div>
@@ -432,7 +432,7 @@
<div class="col col-md-6 text-right"> <div class="col col-md-6 text-right">
<generic-multiselect <generic-multiselect
size="sm" size="sm"
@change="settings.shopping_share = $event.valsaveSettings()" @change="settings.shopping_share = $event.val;saveSettings()"
:model="Models.USER" :model="Models.USER"
:initial_selection="settings.shopping_share" :initial_selection="settings.shopping_share"
label="username" label="username"
@@ -1096,6 +1096,7 @@ export default {
if (!autosync) { if (!autosync) {
if (results.data?.length) { if (results.data?.length) {
this.items = results.data this.items = results.data
console.log(this.items)
} else { } else {
console.log("no data returned") console.log("no data returned")
} }

View File

@@ -0,0 +1,58 @@
<template>
<span><i class="mx-1 far fa-question-circle text-muted" @click="this_help.show = !this_help.show" /></span>
</template>
<script>
import Vue from "vue"
import VueCookies from "vue-cookies"
Vue.use(VueCookies)
let HELP_COOKIE_NAME = "help_settings"
export default {
name: "HelpBadge",
props: {
component: { type: String, required: true },
},
data() {
return {
help: {},
default: {
show: true,
},
this_help: undefined,
}
},
mounted() {
this.$nextTick(function () {
if (this.$cookies.isKey(HELP_COOKIE_NAME)) {
this.help = Object.assign({}, this.help, this.$cookies.get(HELP_COOKIE_NAME))
}
this.this_help = Object.assign({}, this.default, this.help?.[this.component])
})
},
watch: {
help: {
handler() {
this.$cookies.set(HELP_COOKIE_NAME, this.help)
},
deep: true,
},
this_help: {
handler() {
this.help[this.component] = Object.assign({}, this.this_help)
this.$cookies.set(HELP_COOKIE_NAME, this.help)
},
deep: true,
},
"this_help.show": function () {
if (this.this_help.show) {
this.$emit("show")
} else {
this.$emit("hide")
}
},
},
methods: {},
}
</script>

View File

@@ -1,5 +1,5 @@
<template> <template>
<span> <span v-if="!item.ignore_shopping">
<b-button class="btn text-decoration-none px-1 border-0" variant="link" :id="`shopping${item.id}`" @click="addShopping()"> <b-button class="btn text-decoration-none px-1 border-0" variant="link" :id="`shopping${item.id}`" @click="addShopping()">
<i <i
class="fas" class="fas"

View File

@@ -5,21 +5,21 @@
<template #button-content> <template #button-content>
<i class="fas fa-chevron-down"></i> <i class="fas fa-chevron-down"></i>
</template> </template>
<b-dropdown-item :href="resolveDjangoUrl('list_food')"> <i class="fas fa-leaf fa-fw"></i> {{ Models["FOOD"].name }} </b-dropdown-item> <b-dropdown-item :href="resolveDjangoUrl('list_food')"> <i class="fas fa-leaf fa-fw"></i> {{ $t(Models["FOOD"].name) }} </b-dropdown-item>
<b-dropdown-item :href="resolveDjangoUrl('list_keyword')"> <i class="fas fa-tags fa-fw"></i> {{ Models["KEYWORD"].name }} </b-dropdown-item> <b-dropdown-item :href="resolveDjangoUrl('list_keyword')"> <i class="fas fa-tags fa-fw"></i> {{ $t(Models["KEYWORD"].name) }} </b-dropdown-item>
<b-dropdown-item :href="resolveDjangoUrl('list_unit')"> <i class="fas fa-balance-scale fa-fw"></i> {{ Models["UNIT"].name }} </b-dropdown-item> <b-dropdown-item :href="resolveDjangoUrl('list_unit')"> <i class="fas fa-balance-scale fa-fw"></i> {{ $t(Models["UNIT"].name) }} </b-dropdown-item>
<b-dropdown-item :href="resolveDjangoUrl('list_supermarket')"> <i class="fas fa-store-alt fa-fw"></i> {{ Models["SUPERMARKET"].name }} </b-dropdown-item> <b-dropdown-item :href="resolveDjangoUrl('list_supermarket')"> <i class="fas fa-store-alt fa-fw"></i> {{ $t(Models["SUPERMARKET"].name) }} </b-dropdown-item>
<b-dropdown-item :href="resolveDjangoUrl('list_supermarket_category')"> <i class="fas fa-cubes fa-fw"></i> {{ Models["SHOPPING_CATEGORY"].name }} </b-dropdown-item> <b-dropdown-item :href="resolveDjangoUrl('list_supermarket_category')"> <i class="fas fa-cubes fa-fw"></i> {{ $t(Models["SHOPPING_CATEGORY"].name) }} </b-dropdown-item>
<b-dropdown-item :href="resolveDjangoUrl('list_automation')"> <i class="fas fa-robot fa-fw"></i> {{ Models["AUTOMATION"].name }} </b-dropdown-item> <b-dropdown-item :href="resolveDjangoUrl('list_automation')"> <i class="fas fa-robot fa-fw"></i> {{ $t(Models["AUTOMATION"].name) }} </b-dropdown-item>
<b-dropdown-item :href="resolveDjangoUrl('list_user_file')"> <i class="fas fa-file fa-fw"></i> {{ Models["USERFILE"].name }} </b-dropdown-item> <b-dropdown-item :href="resolveDjangoUrl('list_user_file')"> <i class="fas fa-file fa-fw"></i> {{ $t(Models["USERFILE"].name) }} </b-dropdown-item>
<b-dropdown-item :href="resolveDjangoUrl('list_step')"> <i class="fas fa-puzzle-piece fa-fw"></i>{{ Models["STEP"].name }} </b-dropdown-item> <b-dropdown-item :href="resolveDjangoUrl('list_step')"> <i class="fas fa-puzzle-piece fa-fw"></i>{{ $t(Models["STEP"].name) }} </b-dropdown-item>
</b-dropdown> </b-dropdown>
</span> </span>
</template> </template>

View File

@@ -34,6 +34,7 @@
</td> </td>
<td v-else-if="show_shopping" class="text-right text-nowrap"> <td v-else-if="show_shopping" class="text-right text-nowrap">
<b-button <b-button
v-if="!ingredient.food.ignore_shopping"
class="btn text-decoration-none fas fa-shopping-cart px-2 user-select-none" class="btn text-decoration-none fas fa-shopping-cart px-2 user-select-none"
variant="link" variant="link"
v-b-popover.hover.click.blur.html.top="{ title: ShoppingPopover, variant: 'outline-dark' }" v-b-popover.hover.click.blur.html.top="{ title: ShoppingPopover, variant: 'outline-dark' }"
@@ -43,10 +44,10 @@
'text-warning': shopping_status === null, 'text-warning': shopping_status === null,
}" }"
/> />
<span class="px-2"> <span v-if="!ingredient.food.ignore_shopping" class="px-2">
<input type="checkbox" class="align-middle" v-model="shop" @change="changeShopping" /> <input type="checkbox" class="align-middle" v-model="shop" @change="changeShopping" />
</span> </span>
<on-hand-badge :item="ingredient.food" /> <on-hand-badge v-if="!ingredient.food.ignore_shopping" :item="ingredient.food" />
</td> </td>
</template> </template>
</tr> </tr>
@@ -100,10 +101,10 @@ export default {
filtered_list = filtered_list.filter((x) => x.list_recipe == this.recipe_list) filtered_list = filtered_list.filter((x) => x.list_recipe == this.recipe_list)
} }
// how many ShoppingListRecipes are there for this recipe? // how many ShoppingListRecipes are there for this recipe?
let count_shopping_recipes = [...new Set(filtered_list.map((x) => x.list_recipe))].length let count_shopping_recipes = [...new Set(filtered_list.filter((x) => x.list_recipe))].length
let count_shopping_ingredient = filtered_list.filter((x) => x.ingredient == this.ingredient.id).length let count_shopping_ingredient = filtered_list.filter((x) => x.ingredient == this.ingredient.id).length
if (count_shopping_recipes >= 1) { if (count_shopping_recipes >= 1 && this.recipe_list) {
// This recipe is in the shopping list // This recipe is in the shopping list
this.shop = false // don't check any boxes until user selects a shopping list to edit this.shop = false // don't check any boxes until user selects a shopping list to edit
if (count_shopping_ingredient >= 1) { if (count_shopping_ingredient >= 1) {
@@ -117,7 +118,7 @@ export default {
} else { } else {
// there are not recipes in the shopping list // there are not recipes in the shopping list
// set default value // set default value
this.shop = !this.ingredient?.food?.food_onhand && !this.ingredient?.food?.recipe this.shop = !this.ingredient?.food?.food_onhand && !this.ingredient?.food?.recipe && !this.ingredient?.food?.ignore_shopping
this.$emit("add-to-shopping", { item: this.ingredient, add: this.shop }) this.$emit("add-to-shopping", { item: this.ingredient, add: this.shop })
// mark checked if the food is in the shopping list for this ingredient/recipe // mark checked if the food is in the shopping list for this ingredient/recipe
if (count_shopping_ingredient >= 1) { if (count_shopping_ingredient >= 1) {
@@ -135,7 +136,7 @@ export default {
if (this.add_shopping_mode) { if (this.add_shopping_mode) {
// if we are in add shopping mode (e.g. recipe_shopping_modal) start with all checks marked // if we are in add shopping mode (e.g. recipe_shopping_modal) start with all checks marked
// except if on_hand (could be if recipe too?) // except if on_hand (could be if recipe too?)
this.shop = !this.ingredient?.food?.food_onhand && !this.ingredient?.food?.recipe this.shop = !this.ingredient?.food?.food_onhand && !this.ingredient?.food?.recipe && !this.ingredient?.food?.ignore_shopping
} }
}, },
}, },

View File

@@ -1,34 +1,34 @@
<template> <template>
<div> <div>
<b-form-checkbox v-model="new_value">{{label}}</b-form-checkbox> <b-form-checkbox v-model="new_value">{{ label }}</b-form-checkbox>
<em v-if="help" class="small text-muted">{{ help }}</em>
</div> </div>
</template> </template>
<script> <script>
export default { export default {
name: 'CheckboxInput', name: "CheckboxInput",
props: { props: {
field: {type: String, default: 'You Forgot To Set Field Name'}, field: { type: String, default: "You Forgot To Set Field Name" },
label: {type: String, default: 'Checkbox Field'}, label: { type: String, default: "Checkbox Field" },
value: {type: Boolean, default: false}, value: { type: Boolean, default: false },
show_move: {type: Boolean, default: false}, show_move: { type: Boolean, default: false },
show_merge: {type: Boolean, default: false}, show_merge: { type: Boolean, default: false },
}, help: { type: String, default: undefined },
data() {
return {
new_value: undefined,
}
},
mounted() {
this.new_value = this.value
},
watch: {
'new_value': function () {
this.$root.$emit('change', this.field, this.new_value)
}, },
}, data() {
methods: { return {
} new_value: undefined,
}
},
mounted() {
this.new_value = this.value
},
watch: {
new_value: function () {
this.$root.$emit("change", this.field, this.new_value)
},
},
methods: {},
} }
</script> </script>

View File

@@ -2,22 +2,26 @@
<div> <div>
<b-modal :id="'modal_' + id" @hidden="cancelAction"> <b-modal :id="'modal_' + id" @hidden="cancelAction">
<template v-slot:modal-title> <template v-slot:modal-title>
<h4>{{ form.title }}</h4> <h4 class="d-inline">{{ form.title }}</h4>
<help-badge v-if="form.show_help" @show="show_help = true" @hide="show_help = false" :component="`GenericModal${form.title}`" />
</template> </template>
<div v-for="(f, i) in form.fields" v-bind:key="i"> <div v-for="(f, i) in form.fields" v-bind:key="i">
<p v-if="visibleCondition(f, 'instruction')">{{ f.label }}</p> <p v-if="visibleCondition(f, 'instruction')">{{ f.label }}</p>
<lookup-input v-if="visibleCondition(f, 'lookup')" :form="f" :model="listModel(f.list)" @change="storeValue" /> <lookup-input v-if="visibleCondition(f, 'lookup')" :form="f" :model="listModel(f.list)" @change="storeValue" :help="showHelp && f.help" />
<checkbox-input class="mb-3" v-if="visibleCondition(f, 'checkbox')" :label="f.label" :value="f.value" :field="f.field" /> <checkbox-input class="mb-3" v-if="visibleCondition(f, 'checkbox')" :label="f.label" :value="f.value" :field="f.field" :help="showHelp && f.help" />
<text-input v-if="visibleCondition(f, 'text')" :label="f.label" :value="f.value" :field="f.field" :placeholder="f.placeholder" /> <text-input v-if="visibleCondition(f, 'text')" :label="f.label" :value="f.value" :field="f.field" :placeholder="f.placeholder" :help="showHelp && f.help" :subtitle="f.subtitle" />
<choice-input v-if="visibleCondition(f, 'choice')" :label="f.label" :value="f.value" :field="f.field" :options="f.options" :placeholder="f.placeholder" /> <choice-input v-if="visibleCondition(f, 'choice')" :label="f.label" :value="f.value" :field="f.field" :options="f.options" :placeholder="f.placeholder" />
<emoji-input v-if="visibleCondition(f, 'emoji')" :label="f.label" :value="f.value" :field="f.field" @change="storeValue" /> <emoji-input v-if="visibleCondition(f, 'emoji')" :label="f.label" :value="f.value" :field="f.field" @change="storeValue" />
<file-input v-if="visibleCondition(f, 'file')" :label="f.label" :value="f.value" :field="f.field" @change="storeValue" /> <file-input v-if="visibleCondition(f, 'file')" :label="f.label" :value="f.value" :field="f.field" @change="storeValue" />
<small-text v-if="visibleCondition(f, 'smalltext')" :value="f.value" /> <small-text v-if="visibleCondition(f, 'smalltext')" :value="f.value" />
</div> </div>
<template v-slot:modal-footer> <template v-slot:modal-footer>
<b-button class="float-right mx-1" variant="secondary" v-on:click="cancelAction">{{ $t("Cancel") }}</b-button> <div class="row w-100 justify-content-end">
<b-button class="float-right mx-1" variant="primary" v-on:click="doAction">{{ form.ok_label }}</b-button> <div class="col-auto">
<b-button class="mx-1" variant="secondary" v-on:click="cancelAction">{{ $t("Cancel") }}</b-button>
<b-button class="mx-1" variant="primary" v-on:click="doAction">{{ form.ok_label }}</b-button>
</div>
</div>
</template> </template>
</b-modal> </b-modal>
</div> </div>
@@ -31,7 +35,7 @@ import { getForm, formFunctions } from "@/utils/utils"
Vue.use(BootstrapVue) Vue.use(BootstrapVue)
import { ApiApiFactory } from "@/utils/openapi/api" import { ApiApiFactory } from "@/utils/openapi/api"
import { ApiMixin, StandardToasts, ToastMixin } from "@/utils/utils" import { ApiMixin, StandardToasts, ToastMixin, getUserPreference } from "@/utils/utils"
import CheckboxInput from "@/components/Modals/CheckboxInput" import CheckboxInput from "@/components/Modals/CheckboxInput"
import LookupInput from "@/components/Modals/LookupInput" import LookupInput from "@/components/Modals/LookupInput"
import TextInput from "@/components/Modals/TextInput" import TextInput from "@/components/Modals/TextInput"
@@ -39,10 +43,11 @@ import EmojiInput from "@/components/Modals/EmojiInput"
import ChoiceInput from "@/components/Modals/ChoiceInput" import ChoiceInput from "@/components/Modals/ChoiceInput"
import FileInput from "@/components/Modals/FileInput" import FileInput from "@/components/Modals/FileInput"
import SmallText from "@/components/Modals/SmallText" import SmallText from "@/components/Modals/SmallText"
import HelpBadge from "@/components/Badges/Help"
export default { export default {
name: "GenericModalForm", name: "GenericModalForm",
components: { FileInput, CheckboxInput, LookupInput, TextInput, EmojiInput, ChoiceInput, SmallText }, components: { FileInput, CheckboxInput, LookupInput, TextInput, EmojiInput, ChoiceInput, SmallText, HelpBadge },
mixins: [ApiMixin, ToastMixin], mixins: [ApiMixin, ToastMixin],
props: { props: {
model: { required: true, type: Object }, model: { required: true, type: Object },
@@ -73,6 +78,7 @@ export default {
form: {}, form: {},
dirty: false, dirty: false,
special_handling: false, special_handling: false,
show_help: true,
} }
}, },
mounted() { mounted() {
@@ -83,11 +89,19 @@ export default {
buttonLabel() { buttonLabel() {
return this.buttons[this.action].label return this.buttons[this.action].label
}, },
showHelp() {
if (this.show_help) {
return true
} else {
return undefined
}
},
}, },
watch: { watch: {
show: function () { show: function () {
if (this.show) { if (this.show) {
this.form = getForm(this.model, this.action, this.item1, this.item2) this.form = getForm(this.model, this.action, this.item1, this.item2)
if (this.form?.form_function) { if (this.form?.form_function) {
this.form = formFunctions[this.form.form_function](this.form) this.form = formFunctions[this.form.form_function](this.form)
} }
@@ -256,15 +270,33 @@ export default {
let type_match = field?.type == field_type let type_match = field?.type == field_type
let checks = true let checks = true
if (type_match && field?.condition) { if (type_match && field?.condition) {
if (field.condition?.condition === "exists") { const value = this.item1[field?.condition?.field]
if ((this.item1[field.condition.field] != undefined) === field.condition.value) { const preference = getUserPreference(field?.condition?.field)
checks = true console.log("condition", field?.condition?.condition)
} else { switch (field?.condition?.condition) {
checks = false case "field_exists":
} if ((value != undefined) === field.condition.value) {
checks = true
} else {
checks = false
}
break
case "preference__array_exists":
if (preference?.length > 0 === field.condition.value) {
checks = true
} else {
checks = false
}
break
case "preference_equals":
if (preference === field.condition.value) {
checks = true
} else {
checks = false
}
break
} }
} }
return type_match && checks return type_match && checks
}, },
}, },

View File

@@ -19,6 +19,7 @@
@new="addNew" @new="addNew"
> >
</generic-multiselect> </generic-multiselect>
<em v-if="help" class="small text-muted">{{ help }}</em>
</b-form-group> </b-form-group>
</div> </div>
</template> </template>
@@ -47,6 +48,7 @@ export default {
class_list: { type: String, default: "mb-3" }, class_list: { type: String, default: "mb-3" },
show_label: { type: Boolean, default: true }, show_label: { type: Boolean, default: true },
clear: { type: Number }, clear: { type: Number },
help: { type: String, default: undefined },
}, },
data() { data() {
return { return {

View File

@@ -2,6 +2,8 @@
<div> <div>
<b-form-group v-bind:label="label" class="mb-3"> <b-form-group v-bind:label="label" class="mb-3">
<b-form-input v-model="new_value" type="text" :placeholder="placeholder"></b-form-input> <b-form-input v-model="new_value" type="text" :placeholder="placeholder"></b-form-input>
<em v-if="help" class="small text-muted">{{ help }}</em>
<small v-if="subtitle" class="text-muted">{{ subtitle }}</small>
</b-form-group> </b-form-group>
</div> </div>
</template> </template>
@@ -14,7 +16,8 @@ export default {
label: { type: String, default: "Text Field" }, label: { type: String, default: "Text Field" },
value: { type: String, default: "" }, value: { type: String, default: "" },
placeholder: { type: String, default: "You Should Add Placeholder Text" }, placeholder: { type: String, default: "You Should Add Placeholder Text" },
show_merge: { type: Boolean, default: false }, help: { type: String, default: undefined },
subtitle: { type: String, default: undefined },
}, },
data() { data() {
return { return {

View File

@@ -289,5 +289,10 @@
"remember_hours": "Hours to Remember", "remember_hours": "Hours to Remember",
"tree_select": "Use Tree Selection", "tree_select": "Use Tree Selection",
"left_handed": "Left-handed mode", "left_handed": "Left-handed mode",
"left_handed_help": "Will optimize the UI for use with your left hand." "left_handed_help": "Will optimize the UI for use with your left hand.",
"OnHand_help": "Food is in inventory and will not be automatically added to a shopping list.",
"ignore_shopping_help": "Never add food to the shopping list (e.g. water)",
"shopping_category_help": "Supermarkets can be ordered and filtered by Shopping Category according to the layout of the aisles.",
"food_recipe_help": "Linking a recipe here will include the linked recipe in any other recipe that use this food",
"Foods":"Foods"
} }

View File

@@ -59,7 +59,7 @@ export class Models {
// MODELS - inherits and takes precedence over MODEL_TYPES and ACTIONS // MODELS - inherits and takes precedence over MODEL_TYPES and ACTIONS
static FOOD = { static FOOD = {
name: i18n.t("Food"), // *OPTIONAL* : parameters will be built model -> model_type -> default name: "Food", // *OPTIONAL* : parameters will be built model -> model_type -> default
apiName: "Food", // *REQUIRED* : the name that is used in api.ts for this model apiName: "Food", // *REQUIRED* : the name that is used in api.ts for this model
model_type: this.TREE, // *OPTIONAL* : model specific params for api, if not present will attempt modeltype_create then default_create model_type: this.TREE, // *OPTIONAL* : model specific params for api, if not present will attempt modeltype_create then default_create
paginated: true, paginated: true,
@@ -76,15 +76,17 @@ export class Models {
// REQUIRED: unordered array of fields that can be set during create // REQUIRED: unordered array of fields that can be set during create
create: { create: {
// if not defined partialUpdate will use the same parameters, prepending 'id' // if not defined partialUpdate will use the same parameters, prepending 'id'
params: [["name", "description", "recipe", "food_onhand", "supermarket_category", "inherit", "inherit_fields"]], params: [["name", "description", "recipe", "food_onhand", "supermarket_category", "inherit", "inherit_fields", "ignore_shopping"]],
form: { form: {
show_help: true,
name: { name: {
form_field: true, form_field: true,
type: "text", type: "text",
field: "name", field: "name",
label: i18n.t("Name"), label: i18n.t("Name"),
placeholder: "", placeholder: "",
subtitle_field: "full_name",
}, },
description: { description: {
form_field: true, form_field: true,
@@ -99,12 +101,21 @@ export class Models {
field: "recipe", field: "recipe",
list: "RECIPE", list: "RECIPE",
label: i18n.t("Recipe"), label: i18n.t("Recipe"),
help_text: i18n.t("food_recipe_help"),
}, },
shopping: { onhand: {
form_field: true, form_field: true,
type: "checkbox", type: "checkbox",
field: "food_onhand", field: "food_onhand",
label: i18n.t("OnHand"), label: i18n.t("OnHand"),
help_text: i18n.t("OnHand_help"),
},
ignore_shopping: {
form_field: true,
type: "checkbox",
field: "ignore_shopping",
label: i18n.t("Ignore_Shopping"),
help_text: i18n.t("ignore_shopping_help"),
}, },
shopping_category: { shopping_category: {
form_field: true, form_field: true,
@@ -113,6 +124,7 @@ export class Models {
list: "SHOPPING_CATEGORY", list: "SHOPPING_CATEGORY",
label: i18n.t("Shopping_Category"), label: i18n.t("Shopping_Category"),
allow_create: true, allow_create: true,
help_text: i18n.t("shopping_category_help"),
}, },
inherit_fields: { inherit_fields: {
form_field: true, form_field: true,
@@ -121,12 +133,7 @@ export class Models {
field: "inherit_fields", field: "inherit_fields",
list: "FOOD_INHERIT_FIELDS", list: "FOOD_INHERIT_FIELDS",
label: i18n.t("InheritFields"), label: i18n.t("InheritFields"),
condition: { field: "parent", value: true, condition: "exists" }, condition: { field: "food_children_exist", value: true, condition: "preference_equals" },
},
full_name: {
form_field: true,
type: "smalltext",
field: "full_name",
}, },
form_function: "FoodCreateDefault", form_function: "FoodCreateDefault",
}, },
@@ -136,12 +143,12 @@ export class Models {
}, },
} }
static FOOD_INHERIT_FIELDS = { static FOOD_INHERIT_FIELDS = {
name: i18n.t("FoodInherit"), name: "FoodInherit",
apiName: "FoodInheritField", apiName: "FoodInheritField",
} }
static KEYWORD = { static KEYWORD = {
name: i18n.t("Keyword"), // *OPTIONAL: parameters will be built model -> model_type -> default name: "Keyword", // *OPTIONAL: parameters will be built model -> model_type -> default
apiName: "Keyword", apiName: "Keyword",
model_type: this.TREE, model_type: this.TREE,
paginated: true, paginated: true,
@@ -184,7 +191,7 @@ export class Models {
} }
static UNIT = { static UNIT = {
name: i18n.t("Unit"), name: "Unit",
apiName: "Unit", apiName: "Unit",
paginated: true, paginated: true,
create: { create: {
@@ -210,7 +217,7 @@ export class Models {
} }
static SHOPPING_LIST = { static SHOPPING_LIST = {
name: i18n.t("Shopping_list"), name: "Shopping_list",
apiName: "ShoppingListEntry", apiName: "ShoppingListEntry",
list: { list: {
params: ["id", "checked", "supermarket", "options"], params: ["id", "checked", "supermarket", "options"],
@@ -239,7 +246,7 @@ export class Models {
} }
static RECIPE_BOOK = { static RECIPE_BOOK = {
name: i18n.t("Recipe_Book"), name: "Recipe_Book",
apiName: "RecipeBook", apiName: "RecipeBook",
create: { create: {
params: [["name", "description", "icon"]], params: [["name", "description", "icon"]],
@@ -269,7 +276,7 @@ export class Models {
} }
static SHOPPING_CATEGORY = { static SHOPPING_CATEGORY = {
name: i18n.t("Shopping_Category"), name: "Shopping_Category",
apiName: "SupermarketCategory", apiName: "SupermarketCategory",
create: { create: {
params: [["name", "description"]], params: [["name", "description"]],
@@ -293,7 +300,7 @@ export class Models {
} }
static SHOPPING_CATEGORY_RELATION = { static SHOPPING_CATEGORY_RELATION = {
name: i18n.t("Shopping_Category_Relation"), name: "Shopping_Category_Relation",
apiName: "SupermarketCategoryRelation", apiName: "SupermarketCategoryRelation",
create: { create: {
params: [["category", "supermarket", "order"]], params: [["category", "supermarket", "order"]],
@@ -317,7 +324,7 @@ export class Models {
} }
static SUPERMARKET = { static SUPERMARKET = {
name: i18n.t("Supermarket"), name: "Supermarket",
apiName: "Supermarket", apiName: "Supermarket",
ordered_tags: [{ field: "category_to_supermarket", label: "category::name", color: "info" }], ordered_tags: [{ field: "category_to_supermarket", label: "category::name", color: "info" }],
create: { create: {
@@ -360,7 +367,7 @@ export class Models {
} }
static AUTOMATION = { static AUTOMATION = {
name: i18n.t("Automation"), name: "Automation",
apiName: "Automation", apiName: "Automation",
paginated: true, paginated: true,
list: { list: {
@@ -423,7 +430,7 @@ export class Models {
} }
static RECIPE = { static RECIPE = {
name: i18n.t("Recipe"), name: "Recipe",
apiName: "Recipe", apiName: "Recipe",
list: { list: {
params: ["query", "keywords", "foods", "units", "rating", "books", "keywordsOr", "foodsOr", "booksOr", "internal", "random", "_new", "page", "pageSize", "options"], params: ["query", "keywords", "foods", "units", "rating", "books", "keywordsOr", "foodsOr", "booksOr", "internal", "random", "_new", "page", "pageSize", "options"],
@@ -439,7 +446,7 @@ export class Models {
} }
static USER_NAME = { static USER_NAME = {
name: i18n.t("User"), name: "User",
apiName: "User", apiName: "User",
list: { list: {
params: ["filter_list"], params: ["filter_list"],
@@ -447,7 +454,7 @@ export class Models {
} }
static MEAL_TYPE = { static MEAL_TYPE = {
name: i18n.t("Meal_Type"), name: "Meal_Type",
apiName: "MealType", apiName: "MealType",
list: { list: {
params: ["filter_list"], params: ["filter_list"],
@@ -455,7 +462,7 @@ export class Models {
} }
static MEAL_PLAN = { static MEAL_PLAN = {
name: i18n.t("Meal_Plan"), name: "Meal_Plan",
apiName: "MealPlan", apiName: "MealPlan",
list: { list: {
params: ["options"], params: ["options"],
@@ -463,7 +470,7 @@ export class Models {
} }
static USERFILE = { static USERFILE = {
name: i18n.t("File"), name: "File",
apiName: "UserFile", apiName: "UserFile",
paginated: false, paginated: false,
list: { list: {
@@ -492,13 +499,13 @@ export class Models {
}, },
} }
static USER = { static USER = {
name: i18n.t("User"), name: "User",
apiName: "User", apiName: "User",
paginated: false, paginated: false,
} }
static STEP = { static STEP = {
name: i18n.t("Step"), name: "Step",
apiName: "Step", apiName: "Step",
list: { list: {
params: ["recipe", "query", "page", "pageSize", "options"], params: ["recipe", "query", "page", "pageSize", "options"],

View File

@@ -211,10 +211,10 @@ export interface Food {
recipe?: FoodRecipe | null; recipe?: FoodRecipe | null;
/** /**
* *
* @type {boolean} * @type {string}
* @memberof Food * @memberof Food
*/ */
food_onhand?: boolean; food_onhand?: string | null;
/** /**
* *
* @type {FoodSupermarketCategory} * @type {FoodSupermarketCategory}
@@ -245,6 +245,12 @@ export interface Food {
* @memberof Food * @memberof Food
*/ */
full_name?: string; full_name?: string;
/**
*
* @type {boolean}
* @memberof Food
*/
ignore_shopping?: boolean;
} }
/** /**
* *
@@ -607,10 +613,10 @@ export interface IngredientFood {
recipe?: FoodRecipe | null; recipe?: FoodRecipe | null;
/** /**
* *
* @type {boolean} * @type {string}
* @memberof IngredientFood * @memberof IngredientFood
*/ */
food_onhand?: boolean; food_onhand?: string | null;
/** /**
* *
* @type {FoodSupermarketCategory} * @type {FoodSupermarketCategory}
@@ -641,6 +647,12 @@ export interface IngredientFood {
* @memberof IngredientFood * @memberof IngredientFood
*/ */
full_name?: string; full_name?: string;
/**
*
* @type {boolean}
* @memberof IngredientFood
*/
ignore_shopping?: boolean;
} }
/** /**
* *
@@ -1182,7 +1194,7 @@ export interface MealPlanRecipe {
* @type {any} * @type {any}
* @memberof MealPlanRecipe * @memberof MealPlanRecipe
*/ */
image?: any; image?: any | null;
/** /**
* *
* @type {Array<MealPlanRecipeKeywords>} * @type {Array<MealPlanRecipeKeywords>}
@@ -1255,6 +1267,12 @@ export interface MealPlanRecipe {
* @memberof MealPlanRecipe * @memberof MealPlanRecipe
*/ */
_new?: string; _new?: string;
/**
*
* @type {string}
* @memberof MealPlanRecipe
*/
recent?: string;
} }
/** /**
* *
@@ -1372,7 +1390,7 @@ export interface Recipe {
* @type {any} * @type {any}
* @memberof Recipe * @memberof Recipe
*/ */
image?: any; image?: any | null;
/** /**
* *
* @type {Array<RecipeKeywords>} * @type {Array<RecipeKeywords>}
@@ -1715,25 +1733,25 @@ export interface RecipeNutrition {
* @type {string} * @type {string}
* @memberof RecipeNutrition * @memberof RecipeNutrition
*/ */
carbohydrates?: string; carbohydrates: string;
/** /**
* *
* @type {string} * @type {string}
* @memberof RecipeNutrition * @memberof RecipeNutrition
*/ */
fats?: string; fats: string;
/** /**
* *
* @type {string} * @type {string}
* @memberof RecipeNutrition * @memberof RecipeNutrition
*/ */
proteins?: string; proteins: string;
/** /**
* *
* @type {string} * @type {string}
* @memberof RecipeNutrition * @memberof RecipeNutrition
*/ */
calories?: string; calories: string;
/** /**
* *
* @type {string} * @type {string}
@@ -1770,7 +1788,7 @@ export interface RecipeOverview {
* @type {any} * @type {any}
* @memberof RecipeOverview * @memberof RecipeOverview
*/ */
image?: any; image?: any | null;
/** /**
* *
* @type {Array<MealPlanRecipeKeywords>} * @type {Array<MealPlanRecipeKeywords>}
@@ -1843,6 +1861,12 @@ export interface RecipeOverview {
* @memberof RecipeOverview * @memberof RecipeOverview
*/ */
_new?: string; _new?: string;
/**
*
* @type {string}
* @memberof RecipeOverview
*/
recent?: string;
} }
/** /**
* *
@@ -1918,12 +1942,6 @@ export interface RecipeSteps {
* @memberof RecipeSteps * @memberof RecipeSteps
*/ */
name?: string; name?: string;
/**
*
* @type {string}
* @memberof RecipeSteps
*/
type?: RecipeStepsTypeEnum;
/** /**
* *
* @type {string} * @type {string}
@@ -1991,18 +2009,6 @@ export interface RecipeSteps {
*/ */
numrecipe?: string; numrecipe?: string;
} }
/**
* @export
* @enum {string}
*/
export enum RecipeStepsTypeEnum {
Text = 'TEXT',
Time = 'TIME',
File = 'FILE',
Recipe = 'RECIPE'
}
/** /**
* *
* @export * @export
@@ -2523,12 +2529,6 @@ export interface Step {
* @memberof Step * @memberof Step
*/ */
name?: string; name?: string;
/**
*
* @type {string}
* @memberof Step
*/
type?: StepTypeEnum;
/** /**
* *
* @type {string} * @type {string}
@@ -2596,18 +2596,6 @@ export interface Step {
*/ */
numrecipe?: string; numrecipe?: string;
} }
/**
* @export
* @enum {string}
*/
export enum StepTypeEnum {
Text = 'TEXT',
Time = 'TIME',
File = 'FILE',
Recipe = 'RECIPE'
}
/** /**
* *
* @export * @export
@@ -2952,6 +2940,12 @@ export interface UserPreference {
* @memberof UserPreference * @memberof UserPreference
*/ */
default_page?: UserPreferenceDefaultPageEnum; default_page?: UserPreferenceDefaultPageEnum;
/**
*
* @type {boolean}
* @memberof UserPreference
*/
use_fractions?: boolean;
/** /**
* *
* @type {boolean} * @type {boolean}
@@ -3026,10 +3020,10 @@ export interface UserPreference {
mealplan_autoexclude_onhand?: boolean; mealplan_autoexclude_onhand?: boolean;
/** /**
* *
* @type {Array<number>} * @type {Array<MealPlanShared>}
* @memberof UserPreference * @memberof UserPreference
*/ */
shopping_share?: Array<number>; shopping_share?: Array<MealPlanShared> | null;
/** /**
* *
* @type {number} * @type {number}
@@ -3054,6 +3048,18 @@ export interface UserPreference {
* @memberof UserPreference * @memberof UserPreference
*/ */
filter_to_supermarket?: boolean; filter_to_supermarket?: boolean;
/**
*
* @type {boolean}
* @memberof UserPreference
*/
shopping_add_onhand?: boolean;
/**
*
* @type {boolean}
* @memberof UserPreference
*/
left_handed?: boolean;
} }
/** /**

View File

@@ -156,7 +156,7 @@ export function getUserPreference(pref = undefined) {
return undefined return undefined
} }
if (pref) { if (pref) {
return user_preference[pref] return user_preference?.[pref]
} }
return user_preference return user_preference
} }
@@ -389,6 +389,8 @@ export function getForm(model, action, item1, item2) {
} }
if (value?.form_field) { if (value?.form_field) {
value["value"] = item1?.[value?.field] ?? undefined value["value"] = item1?.[value?.field] ?? undefined
value["help"] = item1?.[value?.help_text_field] ?? value?.help_text ?? undefined
value["subtitle"] = item1?.[value?.subtitle_field] ?? value?.subtitle ?? undefined
form.fields.push({ form.fields.push({
...value, ...value,
...{ ...{