From c0c26a5a207ddfa5be1fbcc0db2cfa928cc70561 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Wed, 28 Feb 2024 21:04:43 +0100 Subject: [PATCH] recipe view timer --- vue3/package.json | 2 + vue3/src/apps/tandoor/main.ts | 2 + .../display/IngredientsTableRow.vue | 29 ++++++----- vue3/src/components/display/RecipeView.vue | 48 ++++++----------- vue3/src/components/display/Step.vue | 52 ++++++++++++++++++- vue3/yarn.lock | 10 ++++ 6 files changed, 95 insertions(+), 48 deletions(-) diff --git a/vue3/package.json b/vue3/package.json index 24c8e9b14..cefd226b6 100644 --- a/vue3/package.json +++ b/vue3/package.json @@ -10,6 +10,8 @@ }, "dependencies": { "@mdi/font": "7.2.96", + "@types/luxon": "^3.4.2", + "luxon": "^3.4.4", "pinia": "^2.1.7", "vue": "^3.4.15", "vue-router": "4", diff --git a/vue3/src/apps/tandoor/main.ts b/vue3/src/apps/tandoor/main.ts index 8128e13b4..d5baaac8b 100644 --- a/vue3/src/apps/tandoor/main.ts +++ b/vue3/src/apps/tandoor/main.ts @@ -10,6 +10,7 @@ import vuetify from "@/vuetify"; import ShoppingListPage from "@/pages/ShoppingListPage.vue"; import RecipeSearchPage from "@/pages/RecipeSearchPage.vue"; import RecipeViewPage from "@/pages/RecipeViewPage.vue"; +import luxonPlugin from "@/plugins/luxonPlugin"; const routes = [ {path: '/', redirect: '/search', name: 'index'}, @@ -33,5 +34,6 @@ const app = createApp(App) app.use(createPinia()) app.use(vuetify) app.use(router) +app.use(luxonPlugin) app.mount('#app') diff --git a/vue3/src/components/display/IngredientsTableRow.vue b/vue3/src/components/display/IngredientsTableRow.vue index 6b14efbd3..8d1306885 100644 --- a/vue3/src/components/display/IngredientsTableRow.vue +++ b/vue3/src/components/display/IngredientsTableRow.vue @@ -1,16 +1,19 @@ @@ -26,10 +29,10 @@ export default defineComponent({ required: true } }, - data(){ - return { - show_tooltip: false, - } + data() { + return { + show_tooltip: false, + } }, }) diff --git a/vue3/src/components/display/RecipeView.vue b/vue3/src/components/display/RecipeView.vue index 879ba6161..03bbc9011 100644 --- a/vue3/src/components/display/RecipeView.vue +++ b/vue3/src/components/display/RecipeView.vue @@ -1,12 +1,21 @@ - - - - {{ recipe.description }} - - - - - - - - - {{ recipe.workingTime }} min - - - - {{ recipe.waitingTime }} min - - - - {{ recipe.lastCooked }} - - - - @@ -65,7 +49,7 @@ - + @@ -85,9 +69,7 @@ export default defineComponent({ components: {RecipeActivity, Step, StepsOverview, IngredientsTable, NumberScalerDialog, KeywordsBar}, computed: {}, data() { - return { - - } + return {} }, props: { recipe: { diff --git a/vue3/src/components/display/Step.vue b/vue3/src/components/display/Step.vue index bcce0e449..a96e647f7 100644 --- a/vue3/src/components/display/Step.vue +++ b/vue3/src/components/display/Step.vue @@ -5,13 +5,18 @@ {{ step.name }} - {{ step.time }} - + {{ step.time }} + + + {{ remaining_time }} + Finished at {{ finished_at }} + + @@ -24,15 +29,58 @@ import {defineComponent, PropType} from 'vue' import IngredientsTable from "@/components/display/IngredientsTable.vue"; import {Step} from "@/openapi"; +import {DateTime, Duration, Interval} from "luxon"; export default defineComponent({ name: "Step", + computed: { + timer_color: function () { + if (this.timer_end != null) { + if (this.time_now > this.timer_end) { + return 'warning' + } + } + return '' + }, + remaining_time: function () { + if (this.timer_end != null) { + if (Interval.fromDateTimes(this.time_now, this.timer_end).length() > 0){ + return Duration.fromMillis(Interval.fromDateTimes(this.time_now, this.timer_end).length()).toFormat('hh:mm:ss') + } else { + return '00:00:00' + } + } + return '' + }, + finished_at: function () { + if (this.timer_end != null) { + return this.timer_end.toLocaleString(DateTime.TIME_SIMPLE) + } + return '' + } + }, components: {IngredientsTable}, props: { step: { type: {} as PropType, required: true, } + }, + data() { + return { + timer_end: null as null | DateTime, + time_now: DateTime.now(), + } + }, + mounted() { + setInterval(() => { + this.time_now = DateTime.now() + }, 500) + }, + methods: { + startTimer(minutes: number) { + this.timer_end = DateTime.now().plus({minutes: minutes}) + } } }) diff --git a/vue3/yarn.lock b/vue3/yarn.lock index e5be0f9dd..731dbe9ff 100644 --- a/vue3/yarn.lock +++ b/vue3/yarn.lock @@ -226,6 +226,11 @@ "@types/tough-cookie" "*" parse5 "^7.0.0" +"@types/luxon@^3.4.2": + version "3.4.2" + resolved "https://registry.yarnpkg.com/@types/luxon/-/luxon-3.4.2.tgz#e4fc7214a420173cea47739c33cdf10874694db7" + integrity sha512-TifLZlFudklWlMBfhubvgqTXRzLDI5pCbGa4P8a3wPyUQSW+1xQ5eDsreP9DWHX3tjq1ke96uYG/nwundroWcA== + "@types/node@*": version "20.11.19" resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.19.tgz#b466de054e9cb5b3831bee38938de64ac7f81195" @@ -604,6 +609,11 @@ lru-cache@^6.0.0: dependencies: yallist "^4.0.0" +luxon@^3.4.4: + version "3.4.4" + resolved "https://registry.yarnpkg.com/luxon/-/luxon-3.4.4.tgz#cf20dc27dc532ba41a169c43fdcc0063601577af" + integrity sha512-zobTr7akeGHnv7eBOXcRgMeCP6+uyYsczwmeRCauvpvaAltgNyTbLH/+VaEAPUeWBT+1GuNmz4wC/6jtQzbbVA== + magic-string@^0.30.6: version "0.30.7" resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.30.7.tgz#0cecd0527d473298679da95a2d7aeb8c64048505"