Skip to content

Commit

Permalink
various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vabene1111 committed Jan 30, 2025
1 parent fcbc4cb commit 3880f20
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 34 deletions.
12 changes: 10 additions & 2 deletions cookbook/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ class RecipeImageSerializer(WritableNestedModelSerializer):
def create(self, validated_data):
if 'image' in validated_data and not is_file_type_allowed(validated_data['image'].name, image_only=True):
return None
return super().create( validated_data)
return super().create(validated_data)

def update(self, instance, validated_data):
if 'image' in validated_data and not is_file_type_allowed(validated_data['image'].name, image_only=True):
Expand Down Expand Up @@ -1151,6 +1151,13 @@ def create(self, validated_data):
SLR.create(mealplan=mealplan, servings=validated_data['servings'])
return mealplan

def update(self, obj, validated_data):
if sr := ShoppingListRecipe.objects.filter(mealplan=obj.id).first():
SLR = RecipeShoppingEditor(user=obj.created_by, space=obj.space, id=sr.id)
SLR.edit(mealplan=obj, servings=validated_data['servings'])

return super().update(obj, validated_data)

class Meta:
model = MealPlan
fields = (
Expand Down Expand Up @@ -1311,7 +1318,8 @@ def create(self, validated_data):
validated_data['created_by'] = self.context['request'].user
validated_data['space'] = self.context['request'].space

view_log = ViewLog.objects.filter(recipe=validated_data['recipe'], created_by=self.context['request'].user, created_at__gt=(timezone.now() - timezone.timedelta(minutes=5)), space=self.context['request'].space).first()
view_log = ViewLog.objects.filter(recipe=validated_data['recipe'], created_by=self.context['request'].user, created_at__gt=(timezone.now() - timezone.timedelta(minutes=5)),
space=self.context['request'].space).first()
if not view_log:
view_log = ViewLog.objects.create(recipe=validated_data['recipe'], created_by=self.context['request'].user, space=self.context['request'].space)

Expand Down
13 changes: 7 additions & 6 deletions cookbook/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,14 +533,14 @@ def web_manifest(request):
"url": "./mealplan",
"icons": [
{
"src": static('logo_color_plan.svg'),
"src": static('assets/logo_color_plan.svg'),
"sizes": "any"
}, {
"src": static('logo_color_plan_144.png'),
"src": static('assets/logo_color_plan_144.png'),
"type": "image/png",
"sizes": "144x144"
}, {
"src": static('logo_color_plan_512.png'),
"src": static('assets/logo_color_plan_512.png'),
"type": "image/png",
"sizes": "512x512"
}
Expand All @@ -552,14 +552,14 @@ def web_manifest(request):
"url": "./shopping",
"icons": [
{
"src": static('logo_color_shopping.svg'),
"src": static('assets/logo_color_shopping.svg'),
"sizes": "any"
}, {
"src": static('logo_color_shopping_144.png'),
"src": static('assets/logo_color_shopping_144.png'),
"type": "image/png",
"sizes": "144x144"
}, {
"src": static('logo_color_shopping_512.png'),
"src": static('assets/logo_color_shopping_512.png'),
"type": "image/png",
"sizes": "512x512"
}
Expand All @@ -568,6 +568,7 @@ def web_manifest(request):
"share_target": {
"action": "/recipe/import",
"method": "GET",
"enctype": "application/x-www-form-urlencoded",
"params": {
"title": "title",
"url": "url",
Expand Down
13 changes: 8 additions & 5 deletions vue3/src/components/dialogs/ShoppingLineItemDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,27 @@
<!-- </template>-->

<v-btn-group divided border>
<v-btn icon="" @click="e.amount = e.amount / 2; updateEntryAmount(e)">
<v-btn icon="" @click="e.amount = e.amount / 2; updateEntryAmount(e)" v-if="!e.listRecipeData">
<v-icon icon="fa-solid fa-divide"></v-icon>
</v-btn>
<v-btn icon="" @click="e.amount--; updateEntryAmount(e)">
<v-btn icon="" @click="e.amount--; updateEntryAmount(e)" v-if="!e.listRecipeData">
<v-icon icon="fa-solid fa-minus"></v-icon>
</v-btn>
<v-btn icon="" @click="e.amount++; updateEntryAmount(e)">
<v-btn icon="" @click="e.amount++; updateEntryAmount(e)" v-if="!e.listRecipeData">
<v-icon icon="fa-solid fa-plus"></v-icon>
</v-btn>

<v-btn icon="" @click="e.amount = e.amount * 2; updateEntryAmount(e)">
<v-btn icon="" @click="e.amount = e.amount * 2; updateEntryAmount(e)" v-if="!e.listRecipeData">
<v-icon icon="fa-solid fa-times"></v-icon>
</v-btn>
<v-btn color="edit" icon="$edit" v-if="!e.recipeMealplan">
<v-btn color="edit" icon="$edit" v-if="!e.listRecipeData">
<v-icon icon="$edit"></v-icon>
<model-edit-dialog model="ShoppingListEntry" :item="e" @delete="useShoppingStore().entries.delete(e.id); shoppingListFood.entries.delete(e.id)"
@save="(args: ShoppingListEntry) => (shoppingListFood.entries.set(e.id, args))"></model-edit-dialog>
</v-btn>
<v-btn color="edit" icon="$recipes" v-if="e.listRecipe && e.listRecipeData.recipe" :to="{name: 'view_recipe', params: {id: e.listRecipeData.recipe}}">
<v-icon icon="$recipes"></v-icon>
</v-btn>
<v-btn icon="" @click="useShoppingStore().deleteObject(e, true); shoppingListFood.entries.delete(e.id)" color="delete">
<v-icon icon="$delete"></v-icon>
</v-btn>
Expand Down
2 changes: 1 addition & 1 deletion vue3/src/components/display/ShoppingListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
<v-list>
<v-list-item v-for="r in useShoppingStore().getAssociatedRecipes()">
<template #prepend>
<v-btn color="edit" icon>
<v-btn color="edit" icon :disabled="r.mealplan">
{{ r.servings }}
<number-scaler-dialog :number="r.servings"
@confirm="(servings: number) => {updateRecipeServings(r, servings)}"></number-scaler-dialog>
Expand Down
8 changes: 4 additions & 4 deletions vue3/src/components/display/VSnackbarQueued.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
:close-on-back="false"
multi-line
>
<small>{{ DateTime.fromSeconds(visibleMessage.createdAt).toLocaleString(DateTime.DATETIME_MED) }}</small> <br/>
<!-- <small>{{ DateTime.fromSeconds(visibleMessage.createdAt).toLocaleString(DateTime.DATETIME_MED) }}</small> <br/>-->
<h3 v-if="visibleMessage.msg.title">{{ visibleMessage.msg.title }}</h3>
<span class="text-pre">{{ visibleMessage.msg.text }}</span>

<template v-slot:actions>

<v-btn ref="ref_btn_view">View</v-btn>
<v-btn ref="ref_btn_view">{{$t('View')}}</v-btn>
<v-btn variant="text" @click="removeItem()">
<span v-if="useMessageStore().snackbarQueue.length > 1">Next ({{ useMessageStore().snackbarQueue.length - 1 }})</span>
<span v-else>Close</span>
<span v-if="useMessageStore().snackbarQueue.length > 1">{{$t('Next')}} ({{ useMessageStore().snackbarQueue.length - 1 }})</span>
<span v-else>{{$t('Close')}}</span>
</v-btn>
</template>
</v-snackbar>
Expand Down
23 changes: 12 additions & 11 deletions vue3/src/components/inputs/NumberScalerDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<v-card-text>

<v-number-input v-model="mutable_number" @update:modelValue="updateNumber('set')" control-variant="split" :min="0">
<v-number-input v-model="mutableNumber" @update:modelValue="updateNumber('set')" control-variant="split" :min="0">
</v-number-input>

<v-btn-group divided class="d-flex">
Expand All @@ -21,7 +21,7 @@
</v-card-text>
<v-card-actions>
<v-btn @click=" dialog=false">{{ $t('Close') }}</v-btn>
<v-btn color="save" prepend-icon="$save" @click="emit('confirm', mutable_number); dialog=false">{{ $t('Save') }}</v-btn>
<v-btn color="save" prepend-icon="$save" @click="emit('confirm', mutableNumber); dialog=false">{{ $t('Save') }}</v-btn>
</v-card-actions>
</v-card>

Expand Down Expand Up @@ -49,14 +49,15 @@ const props = defineProps({
})
const dialog = ref(false)
const mutable_number = ref(0)
const mutableNumber = ref(0)
watch(() => props.number, (newVal) => {
mutable_number.value = newVal
mutableNumber.value = newVal
console.log('prop updated')
})
onMounted(() => {
mutable_number.value = props.number
mutableNumber.value = props.number
})
/**
Expand All @@ -65,19 +66,19 @@ onMounted(() => {
*/
function updateNumber(operation: string) {
if (operation === 'half') {
mutable_number.value = props.number / 2
mutableNumber.value = mutableNumber.value / 2
}
if (operation === 'double') {
mutable_number.value = props.number * 2
mutableNumber.value = mutableNumber.value * 2
}
if (operation === 'add') {
mutable_number.value = props.number + 1
mutableNumber.value = mutableNumber.value + 1
}
if (operation === 'sub') {
mutable_number.value = props.number - 1
mutableNumber.value = mutableNumber.value - 1
}
emit('change', mutable_number.value)
console.log('change emitted')
emit('change', mutableNumber.value)
}
</script>

Expand Down
1 change: 1 addition & 0 deletions vue3/src/components/inputs/StepEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
@update:modelValue="step.ingredients[editingIngredientIndex].unit = null; step.ingredients[editingIngredientIndex].food = null; step.ingredients[editingIngredientIndex].amount = 0"
></v-checkbox>
</v-form>
<v-btn color="info" class="mt-2" @click="dialogIngredientEditor = false; dialogIngredientSorter = true" prepend-icon="fa-solid fa-sort">{{ $t('Move') }}</v-btn>
</v-card-text>
<v-card-actions>
<v-btn @click="dialogIngredientEditor = false; deleteIngredientAtIndex(editingIngredientIndex); editingIngredientIndex = -1" color="delete" prepend-icon="$delete">
Expand Down
10 changes: 5 additions & 5 deletions vue3/src/stores/MessageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,19 @@ export const useMessageStore = defineStore('message_store', () => {
*/
function addPreparedMessage(preparedMessage: PreparedMessage, data?: any) {
if (preparedMessage == PreparedMessage.UPDATE_SUCCESS) {
addMessage(MessageType.SUCCESS, {title: t('Updated'), text: ''} as StructuredMessage, 6000, data)
addMessage(MessageType.SUCCESS, {title: t('Updated'), text: ''} as StructuredMessage, 1500, data)
}
if (preparedMessage == PreparedMessage.DELETE_SUCCESS) {
addMessage(MessageType.SUCCESS, {title: t('Deleted'), text: ''} as StructuredMessage, 6000, data)
addMessage(MessageType.SUCCESS, {title: t('Deleted'), text: ''} as StructuredMessage, 1500, data)
}
if (preparedMessage == PreparedMessage.CREATE_SUCCESS) {
addMessage(MessageType.SUCCESS, {title: t('Created'), text: ''} as StructuredMessage, 6000, data)
addMessage(MessageType.SUCCESS, {title: t('Created'), text: ''} as StructuredMessage, 1500, data)
}
if (preparedMessage == PreparedMessage.MERGE_SUCCESS) {
addMessage(MessageType.SUCCESS, {title: t('Merge'), text: ''} as StructuredMessage, 6000, data)
addMessage(MessageType.SUCCESS, {title: t('Merge'), text: ''} as StructuredMessage, 1500, data)
}
if (preparedMessage == PreparedMessage.MOVE_SUCCESS) {
addMessage(MessageType.SUCCESS, {title: t('Move'), text: ''} as StructuredMessage, 6000, data)
addMessage(MessageType.SUCCESS, {title: t('Move'), text: ''} as StructuredMessage, 1500, data)
}
if (preparedMessage == PreparedMessage.NOT_FOUND) {
addMessage(MessageType.WARNING, {title: t('NotFound'), text: t('NotFoundHelp')} as StructuredMessage, 6000, data)
Expand Down
5 changes: 5 additions & 0 deletions vue3/src/utils/model_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import {Ingredient} from "@/openapi";
*/
export function ingredientToString(ingredient: Ingredient) {
let content = []

if(ingredient == undefined){
return ''
}

if(ingredient.amount != 0){
content.push(ingredient.amount)
}
Expand Down

0 comments on commit 3880f20

Please sign in to comment.