Skip to content

Commit

Permalink
Merge pull request #2404 from ignas2526/feature/2402-make-now-count
Browse files Browse the repository at this point in the history
Add ability to set maximum missing ingredient count
  • Loading branch information
vabene1111 authored Oct 5, 2023
2 parents 339ab57 + 429886e commit c56a76f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cookbook/helper/recipe_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def _makenow_filter(self, missing=None):
),
has_child_sub=Case(When(steps__ingredients__food__in=self.__children_substitute_filter(shopping_users), then=Value(1)), default=Value(0)),
has_sibling_sub=Case(When(steps__ingredients__food__in=self.__sibling_substitute_filter(shopping_users), then=Value(1)), default=Value(0))
).annotate(missingfood=F('count_food') - F('count_onhand') - F('count_ignore_shopping')).filter(missingfood=missing)
).annotate(missingfood=F('count_food') - F('count_onhand') - F('count_ignore_shopping')).filter(missingfood__lte=missing)
self._queryset = self._queryset.distinct().filter(id__in=makenow_recipes.values('id'))

@staticmethod
Expand Down
26 changes: 17 additions & 9 deletions vue/src/apps/RecipeSearchView/RecipeSearchView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -558,14 +558,16 @@
<b-input-group-append v-if="ui.show_makenow">
<b-input-group-text>
{{ $t("make_now") }}
<b-form-checkbox
v-model="search.makenow"
name="check-button"
@change="refreshData(false)"
class="shadow-none"
switch
style="width: 4em"
/>
<b-form-checkbox v-model="search.makenow" name="check-button"
@change="refreshData(false)"
class="shadow-none" switch style="width: 4em"/>
</b-input-group-text>
<b-input-group-text>
<span>{{ $t("make_now_count") }}</span>
<b-form-input type="number" min="0" max="20" v-model="search.makenow_count"
@change="refreshData(false)"
size="sm" class="mt-1"></b-form-input>

</b-input-group-text>
</b-input-group-append>
</b-input-group>
Expand Down Expand Up @@ -921,6 +923,7 @@ export default {
timescooked: undefined,
timescooked_gte: true,
makenow: false,
makenow_count: 0,
cookedon: undefined,
cookedon_gte: true,
createdon: undefined,
Expand Down Expand Up @@ -1233,6 +1236,7 @@ export default {
this.search.pagination_page = 1
this.search.timescooked = undefined
this.search.makenow = false
this.search.make_now_count = 0
this.search.cookedon = undefined
this.search.viewedon = undefined
this.search.createdon = undefined
Expand Down Expand Up @@ -1317,6 +1321,10 @@ export default {
} else if (!this.search.timescooked_gte) {
timescooked = timescooked * -1
}
let makenow = this.search.makenow || undefined
if (makenow !== undefined) {
makenow = parseInt(this.search.makenow_count)
}
// when a filter is selected - added search params will be added to the filter
params = {
...params,
Expand All @@ -1329,7 +1337,7 @@ export default {
internal: this.search.search_internal,
random: this.random_search,
timescooked: timescooked,
makenow: this.search.makenow || undefined,
makenow: makenow,
cookedon: cookedon,
createdon: createdon,
updatedon: updatedon,
Expand Down
1 change: 1 addition & 0 deletions vue/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@
"show_sortby": "Show Sort By",
"search_rank": "Search Rank",
"make_now": "Make Now",
"make_now_count": "At most missing ingredients",
"recipe_filter": "Recipe Filter",
"book_filter_help": "Include recipes from recipe filter in addition to manually assigned ones.",
"review_shopping": "Review shopping entries before saving",
Expand Down

0 comments on commit c56a76f

Please sign in to comment.