saerch dialogh

This commit is contained in:
vabene1111
2024-02-26 21:54:38 +01:00
parent 0ddb013e94
commit 79c71bd5d9
8 changed files with 4530 additions and 96 deletions

View File

@@ -614,6 +614,21 @@ class RecipeSimpleSerializer(WritableNestedModelSerializer):
fields = ('id', 'name', 'url') fields = ('id', 'name', 'url')
class RecipeFlatSerializer(WritableNestedModelSerializer):
def create(self, validated_data):
# don't allow writing to Recipe via this API
return Recipe.objects.get(**validated_data)
def update(self, instance, validated_data):
# don't allow writing to Recipe via this API
return Recipe.objects.get(**validated_data)
class Meta:
model = Recipe
fields = ('id', 'name', 'image')
class FoodSimpleSerializer(serializers.ModelSerializer): class FoodSimpleSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Food model = Food

View File

@@ -104,7 +104,7 @@ from cookbook.serializer import (AccessTokenSerializer, AutomationSerializer,
SyncLogSerializer, SyncSerializer, UnitConversionSerializer, SyncLogSerializer, SyncSerializer, UnitConversionSerializer,
UnitSerializer, UserFileSerializer, UserPreferenceSerializer, UnitSerializer, UserFileSerializer, UserPreferenceSerializer,
UserSerializer, UserSpaceSerializer, ViewLogSerializer, UserSerializer, UserSpaceSerializer, ViewLogSerializer,
ShoppingListEntryBulkSerializer, ConnectorConfigConfigSerializer) ShoppingListEntryBulkSerializer, ConnectorConfigConfigSerializer, RecipeFlatSerializer)
from cookbook.views.import_export import get_integration from cookbook.views.import_export import get_integration
from recipes import settings from recipes import settings
from recipes.settings import FDC_API_KEY, DRF_THROTTLE_RECIPE_URL_IMPORT from recipes.settings import FDC_API_KEY, DRF_THROTTLE_RECIPE_URL_IMPORT
@@ -1107,11 +1107,13 @@ class RecipeViewSet(viewsets.ModelViewSet):
@decorators.action( @decorators.action(
detail=False, detail=False,
methods=['GET'], methods=['GET'],
serializer_class=RecipeFlatSerializer,
) )
def flat(self, request): def flat(self, request):
return JsonResponse({'data': list(Recipe.objects.filter(space=request.space).filter( qs = Recipe.objects.filter(
Q(private=False) | (Q(private=True) & (Q(created_by=self.request.user) | Q(shared=self.request.user))) space=request.space).filter(Q(private=False) | (Q(private=True) & (Q(created_by=self.request.user) | Q(shared=self.request.user)))).all() # TODO limit fields retrieved but .values() kills image
).values_list('name', flat=True))})
return Response(self.serializer_class(qs, many=True).data)
class UnitConversionViewSet(viewsets.ModelViewSet): class UnitConversionViewSet(viewsets.ModelViewSet):

File diff suppressed because it is too large Load Diff

View File

@@ -6,9 +6,9 @@
<template v-slot:prepend> <template v-slot:prepend>
Tandoor Brand Logo Tandoor Brand Logo
</template> </template>
<div id="id_dialog_anchor"></div>
<v-spacer></v-spacer> <v-spacer></v-spacer>
<v-btn density="compact" icon="fas fa-search"></v-btn> <global-search-dialog></global-search-dialog>
<v-btn density="compact" icon="fas fa-ellipsis-v"></v-btn> <v-btn density="compact" icon="fas fa-ellipsis-v"></v-btn>
</v-app-bar> </v-app-bar>
@@ -51,9 +51,10 @@
<script lang="ts"> <script lang="ts">
import {defineComponent} from 'vue' import {defineComponent} from 'vue'
import GlobalSearchDialog from "@/components/inputs/GlobalSearchDialog.vue";
export default defineComponent({ export default defineComponent({
components: {}, components: {GlobalSearchDialog},
mixins: [], mixins: [],
data() { data() {
return { return {

View File

@@ -5,7 +5,7 @@
</template> </template>
<td>{{ ingredient.amount }}</td> <td>{{ ingredient.amount }}</td>
<td><span v-if="ingredient.unit != null">{{ ingredient.unit.name }}</span></td> <td><span v-if="ingredient.unit != null">{{ ingredient.unit.name }}</span></td>
<td>{{ ingredient.food.name }}</td> <td ><span v-if="ingredient.food != null">{{ ingredient.food.name }}</span></td>
<td> <td>
<v-icon class="far fa-comment" v-if="ingredient.note != ''" @click="show_tooltip = !show_tooltip"> <v-icon class="far fa-comment" v-if="ingredient.note != ''" @click="show_tooltip = !show_tooltip">
<v-tooltip v-model="show_tooltip" activator="parent" location="start">{{ ingredient.note }}</v-tooltip> <v-tooltip v-model="show_tooltip" activator="parent" location="start">{{ ingredient.note }}</v-tooltip>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,14 @@
export interface SearchResult {
name: string,
recipe_id?: number,
suffix?: string,
description?: string,
icon?: string,
image?: string,
}
export interface FlatRecipe{
id: number,
name: string,
image:string|null,
}