re added basic recipe activity

This commit is contained in:
vabene1111
2024-04-07 09:28:11 +02:00
parent cb8dd3bc99
commit 9bf8b615dc
2 changed files with 94 additions and 43 deletions

View File

@@ -1,55 +1,105 @@
<template> <template>
<v-container> <v-card class="mt-1">
<v-row> <v-card-title>Activity</v-card-title>
<v-col> <v-card-text>
<h2>Activity</h2>
<v-timeline side="end" align="start">
<v-timeline-item dot-color="grey" size="xsmall" v-for="c in cook_logs" :key="c.id">
<v-card>
<v-card-text class="bg-primary"><small>{{ c.createdAt }} by {{ c.createdBy.displayName }}</small></v-card-text>
<v-rating density="compact" size="small" color="tandoor" v-model="c.rating"></v-rating> <v-card v-for="c in cookLogs" :key="c.id" class="mt-1">
<span v-if="c.servings != null && c.servings > 0">{{ c.servings }} {{ recipe.servingsText }}</span> <v-card-text>
<p> <v-rating density="comfortable" size="x-small" color="tandoor" v-model="c.rating"></v-rating>
{{ c.comment }} <br/>
</p> <span v-if="c.servings != null && c.servings > 0">{{ c.servings }} <span v-if="recipe.servingsText != ''">{{ recipe.servingsText }}</span><span v-else>Servings</span></span> <br/>
</v-card>
</v-timeline-item> {{ c.comment }}
</v-timeline> </v-card-text>
</v-col> <v-divider></v-divider>
</v-row> <v-card-subtitle>
{{ DateTime.fromJSDate(c.createdAt).toLocaleString(DateTime.DATETIME_SHORT) }} by {{ c.createdBy.displayName }}
</v-card-subtitle>
</v-card>
<Vueform :endpoint="false" @submit="createCookLog" class="mt-2">
<textarea-element name="comment" label="Comment"></textarea-element>
<text-element type="number" name="rating" label="Rating" :default="5">
<template #addon-before>
<v-btn-group class="rounded-0">
<v-btn color="secondary">-</v-btn>
</v-btn-group>
</template>
<template #addon-after>
<v-btn-group class="rounded-0">
<v-btn color="primary">+</v-btn>
</v-btn-group>
</template>
</text-element>
<text-element type="number" name="servings" label="Servings" :default="recipe.servings">
<template #addon-before>
<v-btn-group class="rounded-0">
<v-btn color="secondary">-</v-btn>
</v-btn-group>
</template>
<template #addon-after>
<v-btn-group class="rounded-0">
<v-btn color="primary">+</v-btn>
</v-btn-group>
</template>
</text-element>
<button-element name="submit" :submits="true" button-label="Submit"></button-element>
</Vueform>
</v-card-text>
</v-card>
</v-container>
</template> </template>
<script lang="ts"> <script setup lang="ts">
import {defineComponent, PropType} from 'vue'
import {ApiApi, CookLog, Recipe} from "@/openapi";
export default defineComponent({ import {onMounted, PropType, ref} from "vue";
name: "RecipeActivity", import {ApiApi, CookLog, Recipe} from "@/openapi";
props: { import {DateTime} from "luxon";
recipe: {
type: Object as PropType<Recipe>, const props = defineProps({
required: true recipe: {
}, type: Object as PropType<Recipe>,
}, required: true
data() {
return {
cook_logs: [] as CookLog[]
}
},
mounted() {
const api = new ApiApi()
api.listCookLogs({recipe: this.recipe.id}).then(r => {
// TODO pagination
this.cook_logs = r.results
})
}, },
}) })
const cookLogs = ref([] as CookLog[])
function refreshActivity() {
const api = new ApiApi()
api.apiCookLogList({recipe: props.recipe.id}).then(r => {
// TODO pagination
if (r.results) {
cookLogs.value = r.results
}
})
}
function createCookLog(form: any) {
const api = new ApiApi()
let cookLog = {
recipe: props.recipe.id,
comment: form.data.comment,
servings: form.data.servings,
rating: form.data.rating,
} as CookLog
api.apiCookLogCreate({cookLogRequest: cookLog}).then(r => {
console.log('success', r)
}).catch(err => {
console.log('error', err)
})
}
onMounted(() => {
refreshActivity()
})
</script> </script>
<style scoped> <style scoped>

View File

@@ -2,8 +2,9 @@
<template v-if="recipe.name != undefined"> <template v-if="recipe.name != undefined">
<v-card class="mt-md-4"> <v-card class="mt-md-4 rounded-0">
<v-img max-height="25vh" cover lazy :src="recipe.image" v-if="recipe.image != undefined" class="align-end"> <v-img max-height="25vh" cover lazy :src="recipe.image" v-if="recipe.image != undefined" class="align-end">
<v-chip class="ms-2" color="primary" variant="flat" size="x-small">by {{ recipe.createdBy}}</v-chip>
<KeywordsComponent variant="flat" class="ms-1 mb-2" :keywords="recipe.keywords"></KeywordsComponent> <KeywordsComponent variant="flat" class="ms-1 mb-2" :keywords="recipe.keywords"></KeywordsComponent>
</v-img> </v-img>
@@ -48,7 +49,7 @@
<Step :step="step" :step-number="index+1" :ingredient_factor="ingredient_factor"></Step> <Step :step="step" :step-number="index+1" :ingredient_factor="ingredient_factor"></Step>
</v-card> </v-card>
<!-- <RecipeActivity :recipe="recipe"></RecipeActivity>--> <recipe-activity :recipe="recipe"></recipe-activity>
</template> </template>
</template> </template>