2020-10-14 19:32:32 +00:00
|
|
|
<template>
|
2020-12-07 14:45:00 +00:00
|
|
|
<Page @loaded="onPageLoad" @unloaded="onPageUnload">
|
|
|
|
<ActionBar flat="true">
|
|
|
|
<GridLayout rows="48" columns="auto, *, auto">
|
2021-01-23 17:20:15 +00:00
|
|
|
<MDButton variant="text" row="0" col="0" class="er" :text="icon.back" automationText="Back" @tap="$navigateBack()" />
|
2020-12-07 14:45:00 +00:00
|
|
|
<FlexboxLayout row="0" col="2" alignItems="center">
|
2021-01-23 17:20:15 +00:00
|
|
|
<MDButton v-if="!filterTrylater" variant="text" class="er" :text="recipe.tried ? icon.try : icon.tried" @tap="toggleTrylater" />
|
|
|
|
<MDButton v-else variant="text" class="er" :text="icon.done" @tap="recipeTried" />
|
|
|
|
<MDButton variant="text" class="er" :text="recipe.isFavorite ? icon.faved : icon.fav" @tap="toggleFavourite" />
|
|
|
|
<!-- <MDButton variant="text" class="er" :text="recipe.inBag ? icon.bagged : icon.bag" @tap="toggleCart" /> -->
|
|
|
|
<MDButton variant="text" v-if="!busy" class="er" :text="icon.edit" @tap="editRecipe" />
|
2020-12-07 14:45:00 +00:00
|
|
|
<MDActivityIndicator v-else :busy="busy" />
|
|
|
|
</FlexboxLayout>
|
|
|
|
</GridLayout>
|
|
|
|
</ActionBar>
|
|
|
|
<AbsoluteLayout>
|
|
|
|
<Tabs width="100%" height="100%" :selectedIndex="selectedTabIndex" @selectedIndexChange="selectedIndexChange" class="viewRecipe">
|
2021-01-23 17:20:15 +00:00
|
|
|
<TabStrip androidElevation="1">
|
2020-12-07 14:45:00 +00:00
|
|
|
<TabStripItem>
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label :text="'ovw' | L"></Label>
|
2020-12-07 14:45:00 +00:00
|
|
|
</TabStripItem>
|
|
|
|
<TabStripItem>
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label :text="'ings' | L"></Label>
|
2020-12-07 14:45:00 +00:00
|
|
|
</TabStripItem>
|
|
|
|
<TabStripItem>
|
|
|
|
<Label :text="'Instructions' | L"></Label>
|
|
|
|
</TabStripItem>
|
|
|
|
<TabStripItem>
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label :text="'nos' | L"></Label>
|
2020-12-07 14:45:00 +00:00
|
|
|
</TabStripItem>
|
|
|
|
<TabStripItem>
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label :text="'cmbs' | L"></Label>
|
2020-12-07 14:45:00 +00:00
|
|
|
</TabStripItem>
|
|
|
|
</TabStrip>
|
|
|
|
<TabContentItem>
|
2021-01-23 17:20:15 +00:00
|
|
|
<ScrollView @loaded="overviewLoaded">
|
2020-12-07 14:45:00 +00:00
|
|
|
<StackLayout>
|
|
|
|
<StackLayout width="100%" :height="screenWidth" verticalAlignment="center" class="imageHolder">
|
|
|
|
<Image v-if="recipe.imageSrc" :src="recipe.imageSrc" stretch="aspectFill" width="100%" :height="screenWidth" />
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label v-else horizontalAlignment="center" class="er" fontSize="160" :text="icon.img" />
|
2020-12-07 14:45:00 +00:00
|
|
|
</StackLayout>
|
2020-12-29 10:35:19 +00:00
|
|
|
<StackLayout margin="16 4 80">
|
|
|
|
<Label class="category" :text="`${$options.filters.L(recipe.cuisine)} • ${$options.filters.L(recipe.category)}`" />
|
|
|
|
<Label class="title orkm" :text="recipe.title" textWrap="true" />
|
|
|
|
<FlexboxLayout class="ratingContainer">
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label class="rate er" :class="{'rated':recipe.rating >= n}" v-for="n in 5" :key="n" :text="recipe.rating < n ? icon.star : icon.starred" @tap="recipe.rating==1 && n==1 ? setRating(0) : setRating(n)" @longPress="setRating(n)" />
|
2020-12-29 10:35:19 +00:00
|
|
|
</FlexboxLayout>
|
|
|
|
<Label class="attr" :text="`${$options.filters.L('Difficulty level')}: ${$options.filters.L(recipe.difficulty)}`" textWrap="true" />
|
|
|
|
<Label class="attr" :text="`${$options.filters.L('Preparation time')}: ${formattedTime(recipe.prepTime)}`" textWrap="true" />
|
|
|
|
<Label class="attr" :text="`${$options.filters.L('Cooking time')}: ${formattedTime(recipe.cookTime)}`" textWrap="true" />
|
|
|
|
<FlexboxLayout v-if="recipe.tags.length" class="tagsContainer" flexWrap="wrap">
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label class="tagsTitle" :text="`${$options.filters.L('ts')}: `" />
|
2021-01-31 10:00:43 +00:00
|
|
|
<Label v-for="(tag, index) in recipe.tags" :key="index" :text="tag" class="tag" textWrap="false" />
|
2020-12-29 10:35:19 +00:00
|
|
|
</FlexboxLayout>
|
2020-12-07 14:45:00 +00:00
|
|
|
<GridLayout rows="auto, auto" columns="*, *" class="overviewContainer">
|
|
|
|
<GridLayout class="overviewItem" row="0" col="0" rows="auto, auto" columns="*">
|
|
|
|
<MDRipple rowSpan="2" @tap="selectedTabIndex = 1" />
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label row="0" class="er" :text="icon.items" />
|
2020-12-07 14:45:00 +00:00
|
|
|
<Label row="1" class="itemCount" :text="
|
2020-11-02 11:36:53 +00:00
|
|
|
`${recipe.ingredients.length} ${
|
|
|
|
recipe.ingredients.length == 1
|
2021-01-13 05:02:48 +00:00
|
|
|
? $options.filters.L('ing')
|
|
|
|
: $options.filters.L('ings')
|
2020-11-02 11:36:53 +00:00
|
|
|
}`
|
2020-12-07 14:45:00 +00:00
|
|
|
" textWrap="true" />
|
|
|
|
</GridLayout>
|
|
|
|
<GridLayout class="overviewItem" row="0" col="1" rows="auto, auto" columns="*">
|
|
|
|
<MDRipple rowSpan="2" @tap="selectedTabIndex = 2" />
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label row="0" class="er" :text="icon.steps" />
|
2020-12-07 14:45:00 +00:00
|
|
|
<Label row="1" class="itemCount" :text="
|
2020-11-02 11:36:53 +00:00
|
|
|
`${recipe.instructions.length} ${
|
2020-11-15 10:51:10 +00:00
|
|
|
recipe.instructions.length == 1
|
2020-12-07 14:45:00 +00:00
|
|
|
? $options.filters.L('Instruction')
|
|
|
|
: $options.filters.L('Instructions')
|
2020-11-02 11:36:53 +00:00
|
|
|
}`
|
2020-12-07 14:45:00 +00:00
|
|
|
" textWrap="true" />
|
|
|
|
</GridLayout>
|
|
|
|
<GridLayout class="overviewItem" row="1" col="0" rows="auto, auto" columns="*">
|
|
|
|
<MDRipple rowSpan="2" @tap="selectedTabIndex = 3" />
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label row="0" class="er" :text="icon.notes" />
|
2020-12-07 14:45:00 +00:00
|
|
|
<Label row="1" class="itemCount" :text="
|
2020-11-28 19:21:57 +00:00
|
|
|
`${recipe.notes.length} ${
|
2020-12-07 14:45:00 +00:00
|
|
|
recipe.notes.length == 1
|
2021-01-13 05:02:48 +00:00
|
|
|
? $options.filters.L('no')
|
|
|
|
: $options.filters.L('nos')
|
2020-11-15 10:51:10 +00:00
|
|
|
}`
|
2020-12-07 14:45:00 +00:00
|
|
|
" textWrap="true" />
|
2020-11-02 11:36:53 +00:00
|
|
|
</GridLayout>
|
2020-12-29 10:35:19 +00:00
|
|
|
<GridLayout class="overviewItem" row="1" col="1" rows="auto, auto" columns="*">
|
|
|
|
<MDRipple rowSpan="2" @tap="selectedTabIndex = 4" />
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label row="0" class="er" :text="icon.comb" />
|
2020-12-29 10:35:19 +00:00
|
|
|
<Label row="1" class="itemCount" :text="
|
|
|
|
`${recipe.combinations.length} ${
|
|
|
|
recipe.combinations.length == 1
|
2021-01-13 05:02:48 +00:00
|
|
|
? $options.filters.L('cmb')
|
|
|
|
: $options.filters.L('cmbs')
|
2020-12-29 10:35:19 +00:00
|
|
|
}`
|
|
|
|
" textWrap="true" />
|
|
|
|
</GridLayout>
|
2020-12-07 14:45:00 +00:00
|
|
|
</GridLayout>
|
2020-12-29 10:35:19 +00:00
|
|
|
<Label class="attr small" :text="`${$options.filters.L('Last updated')}: ${formattedDate(recipe.lastModified)}`" textWrap="true" />
|
|
|
|
<Label class="attr small" :text="`${$options.filters.L('Created')}: ${formattedDate(recipe.created)}`" textWrap="true" />
|
2020-10-14 19:32:32 +00:00
|
|
|
</StackLayout>
|
2020-12-07 14:45:00 +00:00
|
|
|
</StackLayout>
|
|
|
|
</ScrollView>
|
|
|
|
</TabContentItem>
|
|
|
|
<TabContentItem>
|
2021-01-23 17:20:15 +00:00
|
|
|
<ScrollView>
|
2020-12-07 14:45:00 +00:00
|
|
|
<GridLayout v-if="!recipe.ingredients.length" rows="*, auto, *, 88" columns="*" class="emptyStateContainer">
|
|
|
|
<StackLayout col="0" row="1" class="emptyState">
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label class="er icon" :text="icon.items" textWrap="true" />
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label class="title orkm" :text="'pAIng' | L" textWrap="true" />
|
2020-12-07 14:45:00 +00:00
|
|
|
</StackLayout>
|
|
|
|
</GridLayout>
|
2021-01-23 17:20:15 +00:00
|
|
|
<StackLayout v-else padding="24 16 72">
|
2020-12-07 14:45:00 +00:00
|
|
|
<AbsoluteLayout class="inputField">
|
|
|
|
<TextField width="50%" v-model="yieldMultiplier" keyboardType="number" />
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label top="0" class="fieldLabel" :text="`${$options.filters.L('req')} ${$options.filters.L(recipe.yield.unit)}`" />
|
2020-12-07 14:45:00 +00:00
|
|
|
</AbsoluteLayout>
|
2020-12-29 10:35:19 +00:00
|
|
|
<Label padding="16 0 8" class="title orkm" :text="
|
2021-01-13 05:02:48 +00:00
|
|
|
`${$options.filters.L('ings')} (${positiveYieldMultiplier} ${$options.filters.L(recipe.yield.unit)})`
|
2020-12-07 14:45:00 +00:00
|
|
|
" textWrap="true" />
|
2021-01-23 17:20:15 +00:00
|
|
|
<check-box v-for="(item, index) in recipe.ingredients" :key="index" class="ingredient" :color="isLightMode ? '#1A1A1A' : '#e0e0e0'" style="font-family: 'Orkney-Regular'" :checkPadding="checkPadding" marginLeft="4"
|
|
|
|
@checkedChange="checkChange" :text="
|
2020-11-02 11:36:53 +00:00
|
|
|
`${
|
|
|
|
roundedQuantity(item.quantity)
|
|
|
|
? roundedQuantity(item.quantity) + ' '
|
|
|
|
: ''
|
2020-12-07 14:45:00 +00:00
|
|
|
}${roundedQuantity(item.quantity) ? $options.filters.L(item.unit) + ' ' : ''}${
|
2020-11-02 11:36:53 +00:00
|
|
|
item.item
|
|
|
|
}`
|
2020-12-07 14:45:00 +00:00
|
|
|
" />
|
|
|
|
</StackLayout>
|
|
|
|
</ScrollView>
|
|
|
|
</TabContentItem>
|
|
|
|
<TabContentItem>
|
2021-01-23 17:20:15 +00:00
|
|
|
<ScrollView>
|
2020-12-07 14:45:00 +00:00
|
|
|
<GridLayout v-if="!recipe.instructions.length" rows="*, auto, *, 88" columns="*" class="emptyStateContainer">
|
|
|
|
<StackLayout col="0" row="1" class="emptyState">
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label class="er icon" :text="icon.steps" textWrap="true" />
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label class="title orkm" :text="'pAIns' | L" textWrap="true" />
|
2020-10-14 19:32:32 +00:00
|
|
|
</StackLayout>
|
2020-12-07 14:45:00 +00:00
|
|
|
</GridLayout>
|
2021-01-23 17:20:15 +00:00
|
|
|
<StackLayout v-else padding="28 16 62">
|
|
|
|
<GridLayout @tap="stepDone" columns="auto ,*" v-for="(instruction, index) in recipe.instructions" :key="index">
|
2020-12-07 14:45:00 +00:00
|
|
|
<Label col="0" colSpan="2" class="instruction" :class="{
|
|
|
|
noBorder: index === recipe.instructions.length - 1,
|
|
|
|
}" :text="instruction" textWrap="true" />
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label @loaded="centerLabel" class="count orkm" col="0" :text="index + 1" />
|
2020-11-02 11:36:53 +00:00
|
|
|
</GridLayout>
|
2020-12-07 14:45:00 +00:00
|
|
|
</StackLayout>
|
|
|
|
</ScrollView>
|
|
|
|
</TabContentItem>
|
|
|
|
<TabContentItem>
|
2021-01-23 17:20:15 +00:00
|
|
|
<ScrollView>
|
2020-12-29 10:35:19 +00:00
|
|
|
<GridLayout v-if="!recipe.notes.length" rows="*, auto, *, 88" columns="*" class="emptyStateContainer">
|
2020-12-07 14:45:00 +00:00
|
|
|
<StackLayout col="0" row="1" class="emptyState">
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label class="er icon" :text="icon.notes" textWrap="true" />
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label class="title orkm" :text="'pANo' | L" textWrap="true" />
|
2020-10-14 19:32:32 +00:00
|
|
|
</StackLayout>
|
2020-12-07 14:45:00 +00:00
|
|
|
</GridLayout>
|
2021-01-23 17:20:15 +00:00
|
|
|
<StackLayout v-else padding="16 16 62" @loaded="createNotes">
|
2020-12-07 14:45:00 +00:00
|
|
|
</StackLayout>
|
|
|
|
</ScrollView>
|
|
|
|
</TabContentItem>
|
|
|
|
<TabContentItem>
|
2021-01-23 17:20:15 +00:00
|
|
|
<ScrollView>
|
2020-12-29 10:35:19 +00:00
|
|
|
<GridLayout v-if="!recipe.combinations.length" rows="*, auto, *, 88" columns="*" class="emptyStateContainer">
|
2020-12-07 14:45:00 +00:00
|
|
|
<StackLayout col="0" row="1" class="emptyState">
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label class="er icon" :text="icon.comb" textWrap="true" />
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label class="title orkm" :text="'pACmb' | L" textWrap="true" />
|
2020-10-14 19:32:32 +00:00
|
|
|
</StackLayout>
|
2020-12-07 14:45:00 +00:00
|
|
|
</GridLayout>
|
2021-01-23 17:20:15 +00:00
|
|
|
<StackLayout v-else padding="16 0 80">
|
2021-01-13 05:02:48 +00:00
|
|
|
<GridLayout columns="*" v-for="(combination, index) in recipe.combinations" :key="index" androidElevation="1" class="combination">
|
|
|
|
<MDRipple @tap="viewCombination(combination)" />
|
|
|
|
<Label verticalAlignment="center" class="combinationTitle" :text="getCombinationTitle(combination)" textWrap="true" />
|
2020-12-29 10:35:19 +00:00
|
|
|
</GridLayout>
|
2020-12-07 14:45:00 +00:00
|
|
|
</StackLayout>
|
|
|
|
</ScrollView>
|
|
|
|
</TabContentItem>
|
|
|
|
</Tabs>
|
|
|
|
<GridLayout id="btnFabContainer" rows="*, auto" columns="*, auto">
|
2021-01-23 17:20:15 +00:00
|
|
|
<transition name="bounce" appear>
|
2020-12-07 14:45:00 +00:00
|
|
|
<MDFloatingActionButton row="1" col="1" src="res://share" @tap="shareHandler" v-if="showFab" />
|
|
|
|
</transition>
|
|
|
|
</GridLayout>
|
|
|
|
</AbsoluteLayout>
|
|
|
|
</Page>
|
2020-10-14 19:32:32 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-11-02 11:36:53 +00:00
|
|
|
import {
|
2020-12-02 10:37:45 +00:00
|
|
|
Application,
|
2020-11-10 18:28:48 +00:00
|
|
|
Color,
|
|
|
|
ImageSource,
|
|
|
|
Screen,
|
|
|
|
Utils,
|
2020-12-02 09:46:25 +00:00
|
|
|
Span,
|
|
|
|
FormattedString,
|
|
|
|
Label,
|
2020-12-29 10:35:19 +00:00
|
|
|
GridLayout,
|
|
|
|
ItemSpec,
|
|
|
|
Observable,
|
2021-01-23 17:20:15 +00:00
|
|
|
GestureTypes
|
2020-12-07 14:45:00 +00:00
|
|
|
}
|
|
|
|
from "@nativescript/core"
|
|
|
|
import {
|
|
|
|
Feedback,
|
|
|
|
FeedbackType,
|
|
|
|
FeedbackPosition
|
|
|
|
}
|
|
|
|
from "nativescript-feedback"
|
2020-10-21 17:54:45 +00:00
|
|
|
import * as Toast from "nativescript-toast"
|
2020-11-10 18:28:48 +00:00
|
|
|
import * as SocialShare from "@nativescript/social-share"
|
2020-12-07 14:45:00 +00:00
|
|
|
import {
|
|
|
|
localize
|
|
|
|
}
|
|
|
|
from "@nativescript/localize"
|
2020-12-29 10:35:19 +00:00
|
|
|
const intl = require( "nativescript-intl" );
|
2020-12-07 14:45:00 +00:00
|
|
|
import {
|
|
|
|
mapActions,
|
|
|
|
mapState
|
|
|
|
}
|
|
|
|
from "vuex"
|
2020-10-22 18:36:50 +00:00
|
|
|
import EditRecipe from "./EditRecipe.vue"
|
2020-11-15 10:51:10 +00:00
|
|
|
import ViewRecipe from "./ViewRecipe.vue"
|
2020-11-10 18:28:48 +00:00
|
|
|
import ShareChooser from "./modal/ShareChooser.vue"
|
2020-11-03 19:57:31 +00:00
|
|
|
let feedback = new Feedback()
|
2020-10-14 19:32:32 +00:00
|
|
|
export default {
|
2020-12-07 14:45:00 +00:00
|
|
|
props: [ "filterTrylater", "recipeID" ],
|
2020-10-14 19:32:32 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2020-10-21 17:54:45 +00:00
|
|
|
busy: false,
|
2020-11-02 11:36:53 +00:00
|
|
|
yieldMultiplier: 1,
|
2020-10-24 18:02:35 +00:00
|
|
|
recipe: null,
|
2020-10-29 20:12:53 +00:00
|
|
|
showFab: false,
|
2020-11-02 11:36:53 +00:00
|
|
|
selectedTabIndex: 0,
|
2020-11-15 10:51:10 +00:00
|
|
|
currentRecipeID: this.recipeID,
|
2020-11-28 19:21:57 +00:00
|
|
|
hideActionBar: false,
|
2021-01-13 05:02:48 +00:00
|
|
|
overviewTab: null,
|
|
|
|
checks: [],
|
2021-01-23 17:20:15 +00:00
|
|
|
checkboxes: [],
|
|
|
|
steps: [],
|
2020-10-14 19:32:32 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2020-12-07 14:45:00 +00:00
|
|
|
...mapState( [ "icon", "recipes" ] ),
|
2020-10-14 19:32:32 +00:00
|
|
|
screenWidth() {
|
2020-10-22 18:36:50 +00:00
|
|
|
return Screen.mainScreen.widthDIPs
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
2020-11-11 13:50:33 +00:00
|
|
|
positiveYieldMultiplier() {
|
2020-12-07 14:45:00 +00:00
|
|
|
return Math.abs( this.yieldMultiplier ) > 0 ? Math.abs( parseFloat( this.yieldMultiplier ) ) : 1
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
2020-11-02 11:36:53 +00:00
|
|
|
isLightMode() {
|
|
|
|
return Application.systemAppearance() === "light"
|
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
checkPadding() {
|
|
|
|
return `${Math.round( 20 * Utils.layout.getDisplayDensity() )},0,0,0`;
|
|
|
|
},
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2021-01-13 05:02:48 +00:00
|
|
|
...mapActions( [ "toggleStateAction", "setCurrentComponentAction", "overwriteRecipeAction", "setRecipeAsTriedAction", "setRatingAction", "toggleCartAction" ] ),
|
2020-12-07 14:45:00 +00:00
|
|
|
onPageLoad( args ) {
|
|
|
|
const page = args.object;
|
|
|
|
page.bindingContext = new Observable();
|
2020-10-24 18:02:35 +00:00
|
|
|
this.busy = false
|
2020-12-07 14:45:00 +00:00
|
|
|
setTimeout( ( e ) => {
|
|
|
|
this.setCurrentComponentAction( "ViewRecipe" )
|
|
|
|
}, 500 )
|
2020-10-29 20:12:53 +00:00
|
|
|
this.showFab = true
|
2021-01-23 17:20:15 +00:00
|
|
|
if ( this.yieldMultiplier == this.recipe.yield.quantity ) this.yieldMultiplier = this.recipe.yield.quantity
|
2020-12-07 14:45:00 +00:00
|
|
|
this.keepScreenOn( true )
|
2020-11-15 10:51:10 +00:00
|
|
|
this.syncCombinations()
|
2020-10-29 20:12:53 +00:00
|
|
|
},
|
2020-11-10 18:28:48 +00:00
|
|
|
onPageUnload() {
|
2020-12-07 14:45:00 +00:00
|
|
|
this.keepScreenOn( false )
|
2021-01-23 17:20:15 +00:00
|
|
|
feedback.hide()
|
2020-11-10 18:28:48 +00:00
|
|
|
},
|
2021-01-13 05:02:48 +00:00
|
|
|
overviewLoaded( args ) {
|
|
|
|
this.overviewTab = args
|
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
|
2020-11-10 18:28:48 +00:00
|
|
|
// HELPERS
|
2021-01-23 17:20:15 +00:00
|
|
|
niceDate( time ) {
|
2020-12-07 14:45:00 +00:00
|
|
|
let lastTried = new Date( time ).getTime()
|
2020-11-02 11:36:53 +00:00
|
|
|
let now = new Date().getTime()
|
2020-12-07 14:45:00 +00:00
|
|
|
let midnight = new Date().setHours( 0, 0, 0, 0 )
|
|
|
|
let diff = ( now - lastTried ) / 1000
|
|
|
|
let dayDiff = Math.ceil( diff / 86400 )
|
|
|
|
if ( isNaN( dayDiff ) || dayDiff < 0 ) return ""
|
|
|
|
|
|
|
|
function duration( value ) {
|
|
|
|
return localize( value )
|
|
|
|
}
|
2020-10-29 20:12:53 +00:00
|
|
|
return (
|
2021-01-13 05:02:48 +00:00
|
|
|
( diff < 86400 && lastTried > midnight && duration( "today" ) ) || ( dayDiff == 1 && "yesterday" ) || ( dayDiff < 7 && dayDiff + " " + duration( "dAgo" ) ) || ( dayDiff < 31 && Math.round( dayDiff / 7 ) + " " + duration(
|
|
|
|
"wAgo" ) ) || ( dayDiff < 366 && Math.round( dayDiff / 30 ) + " " + duration( "mAgo" ) ) || ( dayDiff > 365 && duration( "ltAgo" ) ) )
|
2020-10-29 20:12:53 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
selectedIndexChange( args ) {
|
2020-11-02 11:36:53 +00:00
|
|
|
this.selectedTabIndex = args.object.selectedIndex
|
|
|
|
},
|
2020-11-10 18:28:48 +00:00
|
|
|
showLastTried() {
|
2020-12-07 14:45:00 +00:00
|
|
|
feedback.show( {
|
2021-01-23 17:20:15 +00:00
|
|
|
title: `${localize('triedInfo')} ${this.niceDate(
|
2020-11-02 11:36:53 +00:00
|
|
|
this.recipe.lastTried
|
2020-12-07 14:45:00 +00:00
|
|
|
)}`,
|
2021-01-23 17:20:15 +00:00
|
|
|
titleColor: new Color( `${this.isLightMode ? "#fff" : "#1A1A1A"}` ),
|
2020-12-07 14:45:00 +00:00
|
|
|
backgroundColor: new Color( "#ff5200" ),
|
|
|
|
} )
|
2020-10-29 20:12:53 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
roundedQuantity( quantity ) {
|
|
|
|
return Math.abs( Math.round(
|
|
|
|
( quantity / this.recipe.yield.quantity ) * this.positiveYieldMultiplier * 100 ) / 100 )
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
keepScreenOn( boolean ) {
|
|
|
|
let activity = Application.android.foregroundActivity || Application.android.startActivity
|
2020-11-10 18:28:48 +00:00
|
|
|
let window = activity.getWindow()
|
2020-12-07 14:45:00 +00:00
|
|
|
if ( boolean ) window.addFlags( android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON )
|
|
|
|
else window.clearFlags( android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON )
|
2020-11-10 18:28:48 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
formattedTime( time ) {
|
|
|
|
let t = time.split( ":" )
|
|
|
|
let h = parseInt( t[ 0 ] )
|
|
|
|
let m = parseInt( t[ 1 ] )
|
|
|
|
let hr = localize( 'hr' )
|
|
|
|
let min = localize( 'min' )
|
|
|
|
return h ? ( m ? `${h} ${hr} ${m} ${min}` : `${h} ${hr}` ) : `${m} ${min}`
|
2020-11-10 18:28:48 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
formattedDate( date ) {
|
|
|
|
let d = new Date( date )
|
|
|
|
var dateFormat = new intl.DateTimeFormat( null, {
|
|
|
|
'year': 'numeric',
|
|
|
|
'month': 'long',
|
|
|
|
'day': 'numeric',
|
|
|
|
'hour': 'numeric',
|
|
|
|
'minute': 'numeric',
|
|
|
|
} ).format( d );
|
|
|
|
return `${dateFormat}`
|
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
isValidURL( string ) {
|
|
|
|
let pattern = new RegExp( "^https?|^www", "ig" )
|
|
|
|
return pattern.test( string )
|
2020-11-10 18:28:48 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
getCombinationTitle( id ) {
|
|
|
|
return this.recipes.filter( ( e ) => e.id === id )[ 0 ].title
|
2020-11-15 10:51:10 +00:00
|
|
|
},
|
|
|
|
syncCombinations() {
|
2020-12-07 14:45:00 +00:00
|
|
|
let combinationForOtherRecipes = this.recipes.filter(
|
|
|
|
( e ) => e.combinations.indexOf( this.currentRecipeID ) >= 0 || this.recipe.combinations.includes( e.id ) ).map( ( e ) => e.id )
|
2020-11-15 10:51:10 +00:00
|
|
|
this.recipe.combinations = combinationForOtherRecipes
|
2020-12-07 14:45:00 +00:00
|
|
|
this.overwriteRecipeAction( {
|
2020-11-15 10:51:10 +00:00
|
|
|
id: this.currentRecipeID,
|
|
|
|
recipe: this.recipe,
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-11-15 10:51:10 +00:00
|
|
|
},
|
2021-01-13 05:02:48 +00:00
|
|
|
checkChange( args, index ) {
|
|
|
|
let check = args.object
|
2021-01-23 17:20:15 +00:00
|
|
|
this.checkboxes.push( check )
|
2021-01-13 05:02:48 +00:00
|
|
|
this.checks[ index ] = !this.checks[ index ]
|
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
stepDone( args ) {
|
|
|
|
let a = args.object
|
|
|
|
this.steps.push( a )
|
|
|
|
if ( a.className !== "done" ) a.className = "done"
|
|
|
|
else a.className = ""
|
|
|
|
},
|
|
|
|
centerLabel( args ) {
|
|
|
|
args.object.android.setGravity( 17 )
|
|
|
|
},
|
|
|
|
clearChecks() {
|
|
|
|
this.checkboxes.forEach( e => {
|
|
|
|
if ( e.checked ) e.checked = false
|
|
|
|
} )
|
|
|
|
this.checkboxes = []
|
2020-11-28 19:21:57 +00:00
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
clearSteps() {
|
|
|
|
this.steps.forEach( e => {
|
|
|
|
if ( e.className === "done" ) e.className = ""
|
|
|
|
} )
|
|
|
|
this.steps = []
|
|
|
|
},
|
|
|
|
|
|
|
|
// NAVIGATION HANDLERS
|
2020-10-14 19:32:32 +00:00
|
|
|
editRecipe() {
|
2020-10-29 20:12:53 +00:00
|
|
|
this.showFab = false
|
2020-10-21 17:54:45 +00:00
|
|
|
this.busy = true
|
2020-12-07 14:45:00 +00:00
|
|
|
this.$navigateTo( EditRecipe, {
|
2020-10-21 17:54:45 +00:00
|
|
|
props: {
|
2020-11-28 19:21:57 +00:00
|
|
|
navigationFromView: true,
|
|
|
|
filterTrylater: this.filterTrylater,
|
2020-11-15 10:51:10 +00:00
|
|
|
recipeID: this.currentRecipeID,
|
2020-10-21 17:54:45 +00:00
|
|
|
},
|
2020-11-28 19:21:57 +00:00
|
|
|
backstackVisible: false,
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
viewCombination( combination ) {
|
|
|
|
this.recipe = this.recipes.filter( ( e ) => e.id === combination )[ 0 ]
|
2021-01-23 17:20:15 +00:00
|
|
|
this.recipe.ingredients.forEach( e => this.checks.push( false ) )
|
|
|
|
this.clearChecks()
|
|
|
|
this.clearSteps()
|
2020-11-15 10:51:10 +00:00
|
|
|
this.currentRecipeID = combination
|
|
|
|
this.syncCombinations()
|
|
|
|
this.selectedTabIndex = 0
|
2021-01-13 05:02:48 +00:00
|
|
|
this.overviewTab.object.scrollToVerticalOffset( 0, true )
|
2020-11-15 10:51:10 +00:00
|
|
|
setTimeout(
|
2020-12-07 14:45:00 +00:00
|
|
|
( e ) => this.recipe.tried && this.recipe.lastTried && this.showLastTried(), 500 )
|
2020-11-15 10:51:10 +00:00
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
|
2020-11-10 18:28:48 +00:00
|
|
|
// SHARE ACTION
|
|
|
|
shareHandler() {
|
2020-12-07 14:45:00 +00:00
|
|
|
if ( this.recipe.imageSrc ) {
|
|
|
|
this.$showModal( ShareChooser, {
|
2020-11-10 18:28:48 +00:00
|
|
|
props: {
|
2021-01-13 05:02:48 +00:00
|
|
|
title: "shr",
|
|
|
|
helpIcon: 'share',
|
2020-11-10 18:28:48 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
} ).then( ( result ) => {
|
|
|
|
switch ( result ) {
|
2020-11-10 18:28:48 +00:00
|
|
|
case "photo":
|
2020-12-07 14:45:00 +00:00
|
|
|
ImageSource.fromFile( this.recipe.imageSrc ).then( ( res ) => {
|
|
|
|
SocialShare.shareImage( res, "Share recipe photo using" )
|
|
|
|
} )
|
2020-11-10 18:28:48 +00:00
|
|
|
break
|
|
|
|
case "recipe":
|
|
|
|
this.shareRecipe()
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-12-29 10:35:19 +00:00
|
|
|
} else {
|
2020-11-10 18:28:48 +00:00
|
|
|
this.shareRecipe()
|
|
|
|
}
|
|
|
|
},
|
2020-10-29 20:12:53 +00:00
|
|
|
shareRecipe() {
|
|
|
|
let overview = `${
|
|
|
|
this.recipe.title
|
2021-01-13 05:02:48 +00:00
|
|
|
}\n\n${localize( "Cuisine" )}: ${localize( this.recipe.cuisine)}\n${localize( "Category" )}: ${localize( this.recipe.category)}\n${localize( "ts" )}: ${this.recipe.tags.join(", ")}\n${localize( "stars" )}: ${this.recipe.rating}\n${localize( "Difficulty level" )}: ${localize( this.recipe.difficulty)}\n${localize("Preparation time")}: ${this.formattedTime(
|
2020-12-01 09:22:22 +00:00
|
|
|
this.recipe.prepTime
|
2020-12-07 14:45:00 +00:00
|
|
|
)}\n${localize( "Cooking time" )}: ${this.formattedTime(this.recipe.cookTime)}\n`
|
2020-10-29 20:12:53 +00:00
|
|
|
let shareContent = overview
|
2020-12-07 14:45:00 +00:00
|
|
|
if ( this.recipe.ingredients.length ) {
|
2021-01-13 05:02:48 +00:00
|
|
|
let ingredients = `\n\n${localize( "ings" )} (${
|
2020-11-02 11:36:53 +00:00
|
|
|
this.yieldMultiplier
|
2020-12-29 10:35:19 +00:00
|
|
|
} ${localize( this.recipe.yield.unit )}):\n\n`
|
2020-12-07 14:45:00 +00:00
|
|
|
this.recipe.ingredients.forEach( ( e ) => {
|
2020-11-10 18:28:48 +00:00
|
|
|
ingredients += `- ${
|
|
|
|
e.quantity
|
2020-12-29 10:35:19 +00:00
|
|
|
? this.roundedQuantity(e.quantity) + " " + this.$options.filters.L(e.unit) + " "
|
2020-11-10 18:28:48 +00:00
|
|
|
: ""
|
|
|
|
}${e.item}\n`
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-10-29 20:12:53 +00:00
|
|
|
shareContent += ingredients
|
|
|
|
}
|
2020-12-07 14:45:00 +00:00
|
|
|
if ( this.recipe.instructions.length ) {
|
|
|
|
let instructions = `\n\n${localize( "Instructions" )}:\n\n`
|
|
|
|
this.recipe.instructions.forEach( ( e, i ) => {
|
|
|
|
instructions += `${i + 1}. ${e}\n\n`
|
|
|
|
} )
|
2020-10-29 20:12:53 +00:00
|
|
|
shareContent += instructions
|
|
|
|
}
|
2020-12-07 14:45:00 +00:00
|
|
|
if ( this.recipe.notes.length ) {
|
2021-01-13 05:02:48 +00:00
|
|
|
let notes = `\n${localize( "nos" )}:\n\n`
|
2020-12-07 14:45:00 +00:00
|
|
|
this.recipe.notes.forEach( ( e, i ) => {
|
2020-10-29 20:12:53 +00:00
|
|
|
notes += `${i + 1}. ${e}\n\n`
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-10-29 20:12:53 +00:00
|
|
|
shareContent += notes
|
|
|
|
}
|
2020-12-29 10:35:19 +00:00
|
|
|
if ( this.recipe.combinations.length ) {
|
2021-01-13 05:02:48 +00:00
|
|
|
let combinations = `\n${localize( "cmbs" )}:\n\n`
|
2020-12-29 10:35:19 +00:00
|
|
|
this.recipe.combinations.forEach( ( e, i ) => {
|
|
|
|
combinations += `${i + 1}. ${this.getCombinationTitle(e)}\n\n`
|
|
|
|
} )
|
|
|
|
shareContent += combinations
|
|
|
|
}
|
2021-01-13 05:02:48 +00:00
|
|
|
let sharenote = '\n' + localize( "appCrd" )
|
2020-10-29 20:12:53 +00:00
|
|
|
shareContent += sharenote
|
2020-12-07 14:45:00 +00:00
|
|
|
SocialShare.shareText( shareContent, "Share recipe using" )
|
2020-10-29 20:12:53 +00:00
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
|
2020-11-10 18:28:48 +00:00
|
|
|
// DATA HANDLERS
|
2020-12-07 14:45:00 +00:00
|
|
|
toggle( key, setDate ) {
|
|
|
|
this.toggleStateAction( {
|
2020-11-15 10:51:10 +00:00
|
|
|
id: this.currentRecipeID,
|
2020-10-26 20:49:54 +00:00
|
|
|
recipe: this.recipe,
|
|
|
|
key,
|
2020-11-02 11:36:53 +00:00
|
|
|
setDate,
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-10-26 20:49:54 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
toggleFavourite() {
|
2021-01-13 05:02:48 +00:00
|
|
|
this.recipe.isFavorite ? Toast.makeText( localize( "unfavd" ) ).show() : Toast.makeText( localize( "favd" ) ).show()
|
2020-12-07 14:45:00 +00:00
|
|
|
this.toggle( "isFavorite" )
|
2020-10-21 17:54:45 +00:00
|
|
|
},
|
2020-10-29 20:12:53 +00:00
|
|
|
toggleTrylater() {
|
2021-01-13 05:02:48 +00:00
|
|
|
this.recipe.tried ? Toast.makeText( localize( "aTry" ) ).show() : Toast.makeText( localize( "rmTry" ) ).show()
|
2020-12-07 14:45:00 +00:00
|
|
|
this.toggle( "tried" )
|
2020-10-29 20:12:53 +00:00
|
|
|
},
|
|
|
|
recipeTried() {
|
2020-12-07 14:45:00 +00:00
|
|
|
this.setRecipeAsTriedAction( {
|
2020-11-17 21:21:08 +00:00
|
|
|
id: this.currentRecipeID,
|
|
|
|
recipe: this.recipe,
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-10-29 20:12:53 +00:00
|
|
|
this.$navigateBack()
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
setRating( rating ) {
|
2021-01-23 17:20:15 +00:00
|
|
|
if ( rating !== this.recipe.rating || rating === 1 ) {
|
2020-12-29 10:35:19 +00:00
|
|
|
this.setRatingAction( {
|
|
|
|
id: this.currentRecipeID,
|
|
|
|
recipe: this.recipe,
|
|
|
|
rating,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
|
2021-01-13 05:02:48 +00:00
|
|
|
// SHOPPINGLIST
|
|
|
|
toggleCart() {
|
2021-01-23 17:20:15 +00:00
|
|
|
if ( !this.recipe.inBag ) {
|
2021-01-13 05:02:48 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
}
|
|
|
|
this.toggleCartAction( {
|
|
|
|
id: this.currentRecipeID,
|
|
|
|
recipe: this.recipe,
|
|
|
|
} )
|
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
|
2020-12-02 10:37:45 +00:00
|
|
|
// NOTES
|
2020-12-29 10:35:19 +00:00
|
|
|
createNote( note, i ) {
|
2020-12-02 09:46:25 +00:00
|
|
|
const vm = this
|
|
|
|
let regex = /(https?:\/\/[^\s]+)/g
|
2020-12-29 10:35:19 +00:00
|
|
|
const grid = new GridLayout()
|
2021-01-23 17:20:15 +00:00
|
|
|
const firstCol = new ItemSpec( 1, "star" )
|
|
|
|
const label = new Label()
|
|
|
|
label.class = "note"
|
|
|
|
label.textWrap = true
|
2020-12-02 09:46:25 +00:00
|
|
|
let formattedString = new FormattedString()
|
2020-12-07 14:45:00 +00:00
|
|
|
let textArray = note.split( regex )
|
2020-12-02 09:46:25 +00:00
|
|
|
|
2020-12-07 14:45:00 +00:00
|
|
|
function createSpan( text, isUrl ) {
|
2020-12-02 09:46:25 +00:00
|
|
|
let span = new Span()
|
|
|
|
span.text = text
|
2020-12-29 10:35:19 +00:00
|
|
|
span.fontSize = 14
|
2020-12-07 14:45:00 +00:00
|
|
|
if ( isUrl ) {
|
2020-12-02 09:46:25 +00:00
|
|
|
span.textDecoration = "underline"
|
|
|
|
span.color = "#ff5200"
|
2020-12-07 14:45:00 +00:00
|
|
|
span.on( "linkTap", () => Utils.openUrl( text ) )
|
2020-12-02 09:46:25 +00:00
|
|
|
}
|
2020-12-07 14:45:00 +00:00
|
|
|
formattedString.spans.push( span )
|
2020-12-02 09:46:25 +00:00
|
|
|
}
|
2020-12-07 14:45:00 +00:00
|
|
|
textArray.forEach( ( text ) => {
|
|
|
|
createSpan( text, regex.test( text ) )
|
|
|
|
} )
|
2021-01-23 17:20:15 +00:00
|
|
|
label.formattedText = formattedString
|
|
|
|
grid.addChild( label )
|
|
|
|
GridLayout.setColumn( label, 0 )
|
2020-12-29 10:35:19 +00:00
|
|
|
grid.addColumn( firstCol )
|
|
|
|
return grid
|
2020-12-02 09:46:25 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
createNotes( args ) {
|
2020-12-02 09:46:25 +00:00
|
|
|
const stack = args.object
|
2020-12-07 14:45:00 +00:00
|
|
|
if ( !stack.getChildrenCount() ) {
|
2020-12-29 10:35:19 +00:00
|
|
|
this.recipe.notes.forEach( ( note, i ) => {
|
|
|
|
stack.addChild( this.createNote( note, i ) )
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-12-02 09:46:25 +00:00
|
|
|
}
|
2020-10-29 20:12:53 +00:00
|
|
|
},
|
2020-10-24 18:02:35 +00:00
|
|
|
},
|
|
|
|
created() {
|
2020-12-07 14:45:00 +00:00
|
|
|
this.recipe = this.recipes.filter( ( e ) => e.id === this.currentRecipeID )[ 0 ]
|
2021-01-23 17:20:15 +00:00
|
|
|
this.recipe.ingredients.forEach( e => this.checks.push( false ) )
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
2020-10-29 20:12:53 +00:00
|
|
|
mounted() {
|
|
|
|
this.showFab = true
|
2021-01-23 17:20:15 +00:00
|
|
|
this.yieldMultiplier = this.recipe.yield.quantity
|
2020-11-10 18:28:48 +00:00
|
|
|
setTimeout(
|
2020-12-07 14:45:00 +00:00
|
|
|
( e ) => this.recipe.tried && this.recipe.lastTried && this.showLastTried(), 500 )
|
2020-10-29 20:12:53 +00:00
|
|
|
},
|
2020-10-14 19:32:32 +00:00
|
|
|
}
|
|
|
|
</script>
|