Merge pull request #1143 from smilerz/fix_get_facet_api

fix bug in get_facet_api
This commit is contained in:
vabene1111 2021-12-16 18:10:48 +01:00 committed by GitHub
commit aaaae5b1ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 142 deletions

File diff suppressed because one or more lines are too long

View File

@ -36,7 +36,7 @@ from cookbook.helper.permission_helper import (CustomIsAdmin, CustomIsGuest, Cus
CustomIsShare, CustomIsShared, CustomIsUser, CustomIsShare, CustomIsShared, CustomIsUser,
group_required) group_required)
from cookbook.helper.recipe_html_import import get_recipe_from_source from cookbook.helper.recipe_html_import import get_recipe_from_source
from cookbook.helper.recipe_search import get_facet, search_recipes, old_search from cookbook.helper.recipe_search import get_facet, old_search, search_recipes
from cookbook.helper.recipe_url_import import get_from_scraper from cookbook.helper.recipe_url_import import get_from_scraper
from cookbook.models import (Automation, BookmarkletImport, CookLog, Food, ImportLog, Ingredient, from cookbook.models import (Automation, BookmarkletImport, CookLog, Food, ImportLog, Ingredient,
Keyword, MealPlan, MealType, Recipe, RecipeBook, RecipeBookEntry, Keyword, MealPlan, MealType, Recipe, RecipeBook, RecipeBookEntry,
@ -46,9 +46,7 @@ from cookbook.models import (Automation, BookmarkletImport, CookLog, Food, Impor
from cookbook.provider.dropbox import Dropbox from cookbook.provider.dropbox import Dropbox
from cookbook.provider.local import Local from cookbook.provider.local import Local
from cookbook.provider.nextcloud import Nextcloud from cookbook.provider.nextcloud import Nextcloud
from cookbook.schemas import FilterSchema, QueryParam, QueryParamAutoSchema, TreeSchema
from cookbook.schemas import FilterSchema, TreeSchema, QueryParamAutoSchema, QueryParam
from cookbook.serializer import (AutomationSerializer, BookmarkletImportSerializer, from cookbook.serializer import (AutomationSerializer, BookmarkletImportSerializer,
CookLogSerializer, FoodSerializer, ImportLogSerializer, CookLogSerializer, FoodSerializer, ImportLogSerializer,
IngredientSerializer, KeywordSerializer, MealPlanSerializer, IngredientSerializer, KeywordSerializer, MealPlanSerializer,
@ -985,7 +983,7 @@ def ingredient_from_string(request):
@group_required('user') @group_required('user')
def get_facets(request): def get_facets(request):
key = request.GET['hash'] key = request.GET.get('hash', None)
return JsonResponse( return JsonResponse(
{ {

View File

@ -7,24 +7,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="settings.search_input" v-bind:placeholder="$t('Search')"></b-input>
class="form-control form-control-lg form-control-borderless form-control-search"
v-model="settings.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">
<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')" @click="openRandom()"> <b-button variant="light" v-b-tooltip.hover :title="$t('Random Recipes')" @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 <b-button v-b-toggle.collapse_advanced_search v-b-tooltip.hover :title="$t('Advanced Settings')" v-bind:variant="!isAdvancedSettingsSet() ? 'primary' : 'danger'">
v-b-toggle.collapse_advanced_search
v-b-tooltip.hover
:title="$t('Advanced Settings')"
v-bind:variant="!isAdvancedSettingsSet() ? '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="!settings.advanced_search_visible"></i> <i class="fas fa-caret-down" v-if="!settings.advanced_search_visible"></i>
<i class="fas fa-caret-up" v-if="settings.advanced_search_visible"></i> <i class="fas fa-caret-up" v-if="settings.advanced_search_visible"></i>
@ -78,13 +69,7 @@
<b-form-checkbox switch v-model="settings.show_meal_plan" id="popover-input-2" size="sm"></b-form-checkbox> <b-form-checkbox switch v-model="settings.show_meal_plan" id="popover-input-2" size="sm"></b-form-checkbox>
</b-form-group> </b-form-group>
<b-form-group <b-form-group v-if="settings.show_meal_plan" v-bind:label="$t('Meal_Plan_Days')" label-for="popover-input-5" label-cols="6" class="mb-3">
v-if="settings.show_meal_plan"
v-bind:label="$t('Meal_Plan_Days')"
label-for="popover-input-5"
label-cols="6"
class="mb-3"
>
<b-form-input type="number" v-model="settings.meal_plan_days" id="popover-input-5" size="sm"></b-form-input> <b-form-input type="number" v-model="settings.meal_plan_days" id="popover-input-5" size="sm"></b-form-input>
</b-form-group> </b-form-group>
@ -99,9 +84,7 @@
</div> </div>
<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" @click="$root.$emit('bv::hide::popover')" <b-button size="sm" variant="secondary" style="margin-right: 8px" @click="$root.$emit('bv::hide::popover')">{{ $t("Close") }} </b-button>
>{{ $t("Close") }}
</b-button>
</div> </div>
</div> </div>
</b-popover> </b-popover>
@ -123,13 +106,7 @@
/> />
<b-input-group-append> <b-input-group-append>
<b-input-group-text> <b-input-group-text>
<b-form-checkbox <b-form-checkbox v-model="settings.search_keywords_or" name="check-button" @change="refreshData(false)" class="shadow-none" switch>
v-model="settings.search_keywords_or"
name="check-button"
@change="refreshData(false)"
class="shadow-none"
switch
>
<span class="text-uppercase" v-if="settings.search_keywords_or">{{ $t("or") }}</span> <span class="text-uppercase" v-if="settings.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>
@ -156,13 +133,7 @@
/> />
<b-input-group-append> <b-input-group-append>
<b-input-group-text> <b-input-group-text>
<b-form-checkbox <b-form-checkbox v-model="settings.search_foods_or" name="check-button" @change="refreshData(false)" class="shadow-none" switch>
v-model="settings.search_foods_or"
name="check-button"
@change="refreshData(false)"
class="shadow-none"
switch
>
<span class="text-uppercase" v-if="settings.search_foods_or">{{ $t("or") }}</span> <span class="text-uppercase" v-if="settings.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>
@ -187,14 +158,7 @@
></generic-multiselect> ></generic-multiselect>
<b-input-group-append> <b-input-group-append>
<b-input-group-text> <b-input-group-text>
<b-form-checkbox <b-form-checkbox v-model="settings.search_books_or" name="check-button" @change="refreshData(false)" class="shadow-none" tyle="width: 100%" switch>
v-model="settings.search_books_or"
name="check-button"
@change="refreshData(false)"
class="shadow-none"
tyle="width: 100%"
switch
>
<span class="text-uppercase" v-if="settings.search_books_or">{{ $t("or") }}</span> <span class="text-uppercase" v-if="settings.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>
@ -242,14 +206,7 @@
<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: 0.8rem"> <div 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 <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>
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>
</template> </template>
<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> <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>
</div> </div>
@ -258,8 +215,7 @@
<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="settings.pagination_page" :total-rows="pagination_count" :per-page="settings.page_count" @change="pageChange" align="center"> <b-pagination pills v-model="settings.pagination_page" :total-rows="pagination_count" :per-page="settings.page_count" @change="pageChange" align="center"> </b-pagination>
</b-pagination>
</div> </div>
</div> </div>
</div> </div>
@ -389,7 +345,7 @@ export default {
this.refreshData(false) this.refreshData(false)
}) })
this.$i18n.locale = window.CUSTOM_LOCALE this.$i18n.locale = window.CUSTOM_LOCALE
this.debug = localStorage.getItem("DEBUG") || false this.debug = localStorage.getItem("DEBUG") == "True" || false
}, },
watch: { watch: {
settings: { settings: {

View File

@ -1,45 +1,45 @@
const BundleTracker = require("webpack-bundle-tracker"); const BundleTracker = require("webpack-bundle-tracker")
const pages = { const pages = {
'recipe_search_view': { recipe_search_view: {
entry: './src/apps/RecipeSearchView/main.js', entry: "./src/apps/RecipeSearchView/main.js",
chunks: ['chunk-vendors'] chunks: ["chunk-vendors"],
}, },
'recipe_view': { recipe_view: {
entry: './src/apps/RecipeView/main.js', entry: "./src/apps/RecipeView/main.js",
chunks: ['chunk-vendors'] chunks: ["chunk-vendors"],
}, },
'offline_view': { offline_view: {
entry: './src/apps/OfflineView/main.js', entry: "./src/apps/OfflineView/main.js",
chunks: ['chunk-vendors'] chunks: ["chunk-vendors"],
}, },
'import_response_view': { import_response_view: {
entry: './src/apps/ImportResponseView/main.js', entry: "./src/apps/ImportResponseView/main.js",
chunks: ['chunk-vendors'] chunks: ["chunk-vendors"],
}, },
'supermarket_view': { supermarket_view: {
entry: './src/apps/SupermarketView/main.js', entry: "./src/apps/SupermarketView/main.js",
chunks: ['chunk-vendors'] chunks: ["chunk-vendors"],
}, },
'model_list_view': { model_list_view: {
entry: './src/apps/ModelListView/main.js', entry: "./src/apps/ModelListView/main.js",
chunks: ['chunk-vendors'] chunks: ["chunk-vendors"],
}, },
'edit_internal_recipe': { edit_internal_recipe: {
entry: './src/apps/RecipeEditView/main.js', entry: "./src/apps/RecipeEditView/main.js",
chunks: ['chunk-vendors'] chunks: ["chunk-vendors"],
}, },
'cookbook_view': { cookbook_view: {
entry: './src/apps/CookbookView/main.js', entry: "./src/apps/CookbookView/main.js",
chunks: ['chunk-vendors'] chunks: ["chunk-vendors"],
}, },
'meal_plan_view': { meal_plan_view: {
entry: './src/apps/MealPlanView/main.js', entry: "./src/apps/MealPlanView/main.js",
chunks: ['chunk-vendors'] chunks: ["chunk-vendors"],
}, },
'checklist_view': { checklist_view: {
entry: './src/apps/ChecklistView/main.js', entry: "./src/apps/ChecklistView/main.js",
chunks: ['chunk-vendors'] chunks: ["chunk-vendors"],
}, },
} }
@ -47,54 +47,51 @@ module.exports = {
pages: pages, pages: pages,
filenameHashing: false, filenameHashing: false,
productionSourceMap: false, productionSourceMap: false,
publicPath: process.env.NODE_ENV === 'production' publicPath: process.env.NODE_ENV === "production" ? "" : "http://localhost:8080/",
? '' outputDir: "../cookbook/static/vue/",
: 'http://localhost:8080/',
outputDir: '../cookbook/static/vue/',
runtimeCompiler: true, runtimeCompiler: true,
pwa: { pwa: {
name: 'Recipes', name: "Recipes",
themeColor: '#4DBA87', themeColor: "#4DBA87",
msTileColor: '#000000', msTileColor: "#000000",
appleMobileWebAppCapable: 'yes', appleMobileWebAppCapable: "yes",
appleMobileWebAppStatusBarStyle: 'black', appleMobileWebAppStatusBarStyle: "black",
workboxPluginMode: "InjectManifest",
workboxPluginMode: 'InjectManifest',
workboxOptions: { workboxOptions: {
swSrc: './src/sw.js', swSrc: "./src/sw.js",
swDest: '../../templates/sw.js', swDest: "../../templates/sw.js",
manifestTransforms: [ manifestTransforms: [
originalManifest => { (originalManifest) => {
const result = originalManifest.map(entry => new Object({url: 'static/vue/' + entry.url})) const result = originalManifest.map((entry) => new Object({ url: "static/vue/" + entry.url }))
return {manifest: result, warnings: []}; return { manifest: result, warnings: [] }
} },
], ],
} },
}, },
pluginOptions: { pluginOptions: {
i18n: { i18n: {
locale: 'en', locale: "en",
fallbackLocale: 'en', fallbackLocale: "en",
localeDir: 'locales', localeDir: "locales",
enableInSFC: true enableInSFC: true,
}
}, },
chainWebpack: config => { },
chainWebpack: (config) => {
config.optimization.splitChunks({ config.optimization.splitChunks(
{
cacheGroups: { cacheGroups: {
vendor: { vendor: {
test: /[\\/]node_modules[\\/]/, test: /[\\/]node_modules[\\/]/,
name: "chunk-vendors", name: "chunk-vendors",
chunks: "all", chunks: "all",
priority: 1 priority: 1,
}, },
}, },
}, },
// TODO make this conditional on .env DEBUG = FALSE // TODO make this conditional on .env DEBUG = FALSE
config.optimization.minimize(true) config.optimization.minimize(true)
); )
//TODO somehow remov them as they are also added to the manifest config of the service worker //TODO somehow remov them as they are also added to the manifest config of the service worker
/* /*
@ -105,19 +102,17 @@ module.exports = {
}) })
*/ */
config.plugin('BundleTracker').use(BundleTracker, [{relativePath: true, path: '../vue/'}]); config.plugin("BundleTracker").use(BundleTracker, [{ relativePath: true, path: "../vue/" }])
config.resolve.alias config.resolve.alias.set("__STATIC__", "static")
.set('__STATIC__', 'static')
config.devServer config.devServer
.public('http://localhost:8080') .public("http://localhost:8080")
.host('localhost') .host("localhost")
.port(8080) .port(8080)
.hotOnly(true) .hotOnly(true)
.watchOptions({poll: 500}) .watchOptions({ poll: 500 })
.https(false) .https(false)
.headers({"Access-Control-Allow-Origin": ["*"]}) .headers({ "Access-Control-Allow-Origin": ["*"] })
},
} }
};