From 999fe2bc616439d0e86538c07512ed618186dffc Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Wed, 13 Jan 2021 17:58:51 +0100 Subject: [PATCH] timers added in recipe view --- vue/src/apps/RecipeView/RecipeView.vue | 32 ++++++++----- vue/src/components/CookLog.vue | 7 +-- vue/src/components/Step.vue | 66 +++++++++++++++++++++----- vue/webpack-stats.json | 2 +- 4 files changed, 77 insertions(+), 30 deletions(-) diff --git a/vue/src/apps/RecipeView/RecipeView.vue b/vue/src/apps/RecipeView/RecipeView.vue index 78d96cae..e72b3005 100644 --- a/vue/src/apps/RecipeView/RecipeView.vue +++ b/vue/src/apps/RecipeView/RecipeView.vue @@ -7,6 +7,8 @@ + +
{{ recipe.description }} @@ -113,8 +115,6 @@
- -
@@ -125,12 +125,10 @@
- +
- - -
@@ -151,6 +149,10 @@ import PdfViewer from "@/components/PdfViewer"; import ImageViewer from "@/components/ImageViewer"; import Nutrition from "@/components/Nutrition"; +import moment from 'moment' + +Vue.prototype.moment = moment + Vue.use(BootstrapVue) export default { @@ -174,28 +176,34 @@ export default { recipe: undefined, ingredient_count: 0, servings: 1, + start_time: "" } }, mounted() { this.loadRecipe(this.recipe_id) }, methods: { - openCookLogModal: function () { - this.$bvModal.show('id_modal_cook_log') - }, loadRecipe: function (recipe_id) { apiLoadRecipe(recipe_id).then(recipe => { this.recipe = recipe this.loading = false + let total_time = 0 for (let step of this.recipe.steps) { this.ingredient_count += step.ingredients.length - if (step.time !== 0) { - this.has_times = true - } + step.time_offset = total_time + total_time += step.time + } + + // set start time only if there are any steps with timers (otherwise no timers are rendered) + if (total_time > 0) { + this.start_time = moment().format('yyyy-MM-DDTHH:mm') } }) + }, + updateStartTime: function (e) { + this.start_time = e } } } diff --git a/vue/src/components/CookLog.vue b/vue/src/components/CookLog.vue index c5f91036..8069413d 100644 --- a/vue/src/components/CookLog.vue +++ b/vue/src/components/CookLog.vue @@ -50,17 +50,12 @@ export default { recipe: this.recipe.id, servings: 0, rating: 0, - created_at: moment().format('yyyy-MM-DDTHH:MM') + created_at: moment().format('yyyy-MM-DDTHH:mm') } } }, methods: { logCook: function () { - - let obj = JSON.parse(JSON.stringify(this.logObject)) - - obj.created_at = moment(obj.created_at, 'yyyy-MM-DDTHH:MM').format('yyyy-MM-DD HH:MM') - console.log('updating: ', obj) apiLogCooking(this.logObject) }, } diff --git a/vue/src/components/Step.vue b/vue/src/components/Step.vue index 4a56bbea..45a51c19 100644 --- a/vue/src/components/Step.vue +++ b/vue/src/components/Step.vue @@ -3,16 +3,21 @@

- - - + +
+ + + +
+
+
+ Cancel + Ok +
+
+
@@ -88,6 +116,10 @@ import Ingredient from "@/components/Ingredient"; import {GettextMixin} from "@/utils/utils"; import CompileComponent from "@/components/CompileComponent"; +import Vue from "vue"; +import moment from "moment"; + +Vue.prototype.moment = moment export default { name: 'Step', @@ -103,19 +135,31 @@ export default { servings: Number, index: Number, recipe: Object, + start_time: String, }, data() { return { details_visible: true, + set_time_input: '', } }, mounted() { - + this.set_time_input = moment(this.start_time).add(this.step.time_offset, 'minutes').format('yyyy-MM-DDTHH:mm') }, methods: { calculateAmount: function (x) { // used by the jinja2 template return calculateAmount(x, this.servings) + }, + updateTime: function () { + this.$emit('update-start-time', moment(this.set_time_input).add(this.time_offset * -1, 'minutes').format('yyyy-MM-DDTHH:mm')) + this.closePopover() + }, + closePopover: function () { + this.$refs[`id_reactive_popover_${this.step.id}`].$emit('close') + }, + openPopover: function () { + this.$refs[`id_reactive_popover_${this.step.id}`].$emit('open') } } } diff --git a/vue/webpack-stats.json b/vue/webpack-stats.json index c741b6fa..ef24c538 100644 --- a/vue/webpack-stats.json +++ b/vue/webpack-stats.json @@ -1 +1 @@ -{"status":"done","publicPath":"http://localhost:8080/","chunks":{"chunk-vendors":[{"name":"js/chunk-vendors.js","publicPath":"http://localhost:8080/js/chunk-vendors.js","path":"F:\\Developement\\Django\\recipes\\cookbook\\static\\vue\\js\\chunk-vendors.js"}],"recipe_view":[{"name":"js/recipe_view.js","publicPath":"http://localhost:8080/js/recipe_view.js","path":"F:\\Developement\\Django\\recipes\\cookbook\\static\\vue\\js\\recipe_view.js"},{"name":"recipe_view.249c42bfc6c344069b28.hot-update.js","publicPath":"http://localhost:8080/recipe_view.249c42bfc6c344069b28.hot-update.js","path":"F:\\Developement\\Django\\recipes\\cookbook\\static\\vue\\recipe_view.249c42bfc6c344069b28.hot-update.js"}]},"error":"ModuleError","message":"Module Error (from ./node_modules/eslint-loader/index.js):\n\nF:\\Developement\\Django\\recipes\\vue\\src\\utils\\utils.js\n 63:8 error Parsing error: Unexpected token, expected \"(\"\n\n 61 | \n 62 | export function resolveDjangoUrl(url, params=null) {\n> 63 | if params !== null\n | ^\n 64 | return window.Urls[url](params)\n 65 | else:\n 66 | return window.Urls[url]\n\n✖ 1 problem (1 error, 0 warnings)\n"} \ No newline at end of file +{"status":"done","publicPath":"http://localhost:8080/","chunks":{"chunk-vendors":[{"name":"js/chunk-vendors.js","publicPath":"http://localhost:8080/js/chunk-vendors.js","path":"F:\\Developement\\Django\\recipes\\cookbook\\static\\vue\\js\\chunk-vendors.js"}],"recipe_view":[{"name":"js/recipe_view.js","publicPath":"http://localhost:8080/js/recipe_view.js","path":"F:\\Developement\\Django\\recipes\\cookbook\\static\\vue\\js\\recipe_view.js"},{"name":"recipe_view.04cd9a4772d145ea1f27.hot-update.js","publicPath":"http://localhost:8080/recipe_view.04cd9a4772d145ea1f27.hot-update.js","path":"F:\\Developement\\Django\\recipes\\cookbook\\static\\vue\\recipe_view.04cd9a4772d145ea1f27.hot-update.js"}]},"error":"ModuleError","message":"Module Error (from ./node_modules/eslint-loader/index.js):\n\nF:\\Developement\\Django\\recipes\\vue\\src\\components\\Step.vue\n 79:9 error '.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead vue/no-deprecated-v-bind-sync\n\n✖ 1 problem (1 error, 0 warnings)\n 1 error and 0 warnings potentially fixable with the `--fix` option.\n"} \ No newline at end of file