From a01f86a14e2e07c741d1ff997377982f9adc9abc Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Sun, 31 Aug 2025 12:32:12 +0200 Subject: [PATCH] migrated comments, improved recipe activity, added editor --- .../migrations/0223_auto_20250831_1111.py | 34 ++++++ .../src/components/display/RecipeActivity.vue | 102 +++++++++++------- .../model_editors/CookLogEditor.vue | 81 ++++++++++++++ vue3/src/types/Models.ts | 7 +- 4 files changed, 182 insertions(+), 42 deletions(-) create mode 100644 cookbook/migrations/0223_auto_20250831_1111.py create mode 100644 vue3/src/components/model_editors/CookLogEditor.vue diff --git a/cookbook/migrations/0223_auto_20250831_1111.py b/cookbook/migrations/0223_auto_20250831_1111.py new file mode 100644 index 000000000..80a325e1a --- /dev/null +++ b/cookbook/migrations/0223_auto_20250831_1111.py @@ -0,0 +1,34 @@ +# Generated by Django 4.2.22 on 2025-08-31 09:11 + +from django.db import migrations +from django_scopes import scopes_disabled + + +def migrate_comments(apps, schema_editor): + with scopes_disabled(): + Comment = apps.get_model('cookbook', 'Comment') + CookLog = apps.get_model('cookbook', 'CookLog') + + cook_logs = [] + + for c in Comment.objects.all(): + cook_logs.append(CookLog( + recipe=c.recipe, + created_by=c.created_by, + created_at=c.created_at, + comment=c.text, + space=c.recipe.space, + )) + + CookLog.objects.bulk_create(cook_logs, unique_fields=('recipe', 'comment', 'created_at', 'created_by')) + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0222_alter_shoppinglistrecipe_created_by_and_more'), + ] + + operations = [ + migrations.RunPython(migrate_comments), + ] diff --git a/vue3/src/components/display/RecipeActivity.vue b/vue3/src/components/display/RecipeActivity.vue index 976c88128..e796ce696 100644 --- a/vue3/src/components/display/RecipeActivity.vue +++ b/vue3/src/components/display/RecipeActivity.vue @@ -1,40 +1,11 @@ @@ -63,6 +76,7 @@ import {DateTime} from "luxon"; import {ErrorMessageType, useMessageStore} from "@/stores/MessageStore"; import {VDateInput} from 'vuetify/labs/VDateInput' import {useUserPreferenceStore} from "@/stores/UserPreferenceStore.ts"; +import ModelEditDialog from "@/components/dialogs/ModelEditDialog.vue"; const props = defineProps({ recipe: { @@ -74,21 +88,31 @@ const props = defineProps({ const newCookLog = ref({} as CookLog); const cookLogs = ref([] as CookLog[]) +const loading = ref(false) onMounted(() => { - refreshActivity() + recLoadCookLog(props.recipe.id) resetForm() }) /** - * load cook logs from database for given recipe + * recursively load cook logs from database for given recipe */ -function refreshActivity() { +function recLoadCookLog(recipeId: number, page: number = 1) { const api = new ApiApi() - api.apiCookLogList({recipe: props.recipe.id}).then(r => { - // TODO pagination + loading.value = true + if(page == 1){ + cookLogs.value = [] + } + api.apiCookLogList({recipe: props.recipe.id, page: page}).then(r => { if (r.results) { - cookLogs.value = r.results.sort((a,b) => a.createdAt! > b.createdAt! ? 1 : -1) + cookLogs.value = cookLogs.value.concat(r.results) + if (r.next) { + recLoadCookLog(recipeId, page + 1) + } else { + cookLogs.value = cookLogs.value.sort((a, b) => a.createdAt! > b.createdAt! ? 1 : -1) + loading.value = false + } } }) } diff --git a/vue3/src/components/model_editors/CookLogEditor.vue b/vue3/src/components/model_editors/CookLogEditor.vue new file mode 100644 index 000000000..3924df390 --- /dev/null +++ b/vue3/src/components/model_editors/CookLogEditor.vue @@ -0,0 +1,81 @@ + + + + + \ No newline at end of file diff --git a/vue3/src/types/Models.ts b/vue3/src/types/Models.ts index c29ad9521..7feef10a1 100644 --- a/vue3/src/types/Models.ts +++ b/vue3/src/types/Models.ts @@ -581,10 +581,11 @@ export const TCookLog = { localizationKeyDescription: 'CookLogHelp', icon: 'fa-solid fa-table-list', - isPaginated: true, + editorComponent: defineAsyncComponent(() => import(`@/components/model_editors/CookLogEditor.vue`)), + disableCreate: true, - disableUpdate: true, - disableDelete: true, + + isPaginated: true, toStringKeys: ['recipe'], tableHeaders: [