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">
|
|
|
|
<MDButton variant="text" row="0" col="0" class="bx" :text="icon.back" automationText="Back" @tap="$navigateBack()" />
|
|
|
|
<FlexboxLayout row="0" col="2" alignItems="center">
|
2020-12-29 10:35:19 +00:00
|
|
|
<MDButton v-if="!filterTrylater" variant="text" class="bx" :text="recipe.tried ? icon.trylaterLine : icon.trylater" @tap="toggleTrylater" />
|
2020-12-07 14:45:00 +00:00
|
|
|
<MDButton v-else variant="text" class="bx" :text="icon.check" @tap="recipeTried" />
|
2020-12-29 10:35:19 +00:00
|
|
|
<MDButton variant="text" class="bx" :text="recipe.isFavorite ? icon.heart : icon.heartLine" @tap="toggleFavourite" />
|
2021-01-13 05:02:48 +00:00
|
|
|
<MDButton variant="text" class="bx" :text="recipe.inCart ? icon.cart : icon.emptyCart" @tap="toggleCart" />
|
2020-12-07 14:45:00 +00:00
|
|
|
<MDButton variant="text" v-if="!busy" class="bx" :text="icon.edit" @tap="editRecipe" />
|
|
|
|
<MDActivityIndicator v-else :busy="busy" />
|
|
|
|
</FlexboxLayout>
|
|
|
|
</GridLayout>
|
|
|
|
</ActionBar>
|
|
|
|
<AbsoluteLayout>
|
|
|
|
<Tabs width="100%" height="100%" :selectedIndex="selectedTabIndex" @selectedIndexChange="selectedIndexChange" class="viewRecipe">
|
|
|
|
<TabStrip :androidElevation="viewIsScrolled ? 4 : 0">
|
|
|
|
<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-13 05:02:48 +00:00
|
|
|
<ScrollView @scroll="onScroll" @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" />
|
|
|
|
<Label v-else horizontalAlignment="center" class="bx" fontSize="160" :text="icon.image" />
|
|
|
|
</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">
|
|
|
|
<Label class="rating bx" v-for="n in 5" :key="n" :text="recipe.rating < n ?icon.starLine:icon.star" @tap="setRating(n)" @longPress="setRating(n)" />
|
|
|
|
</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')}: `" />
|
2020-12-29 10:35:19 +00:00
|
|
|
<Label v-for="(tag, index) in recipe.tags" :key="index" v-if="tag" :text="tag" class="tag" textWrap="false" />
|
|
|
|
</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" />
|
|
|
|
<Label row="0" class="bx" :text="icon.item" />
|
|
|
|
<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" />
|
|
|
|
<Label row="0" class="bx" :text="icon.step" />
|
|
|
|
<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" />
|
|
|
|
<Label row="0" class="bx" :text="icon.note" />
|
|
|
|
<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" />
|
|
|
|
<Label row="0" class="bx" :text="icon.outline" />
|
|
|
|
<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>
|
|
|
|
<ScrollView @scroll="onScroll">
|
|
|
|
<GridLayout v-if="!recipe.ingredients.length" rows="*, auto, *, 88" columns="*" class="emptyStateContainer">
|
|
|
|
<StackLayout col="0" row="1" class="emptyState">
|
|
|
|
<Label class="bx icon" :text="icon.item" 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>
|
2020-12-29 10:35:19 +00:00
|
|
|
<StackLayout v-else padding="16 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-13 05:02:48 +00:00
|
|
|
<check-box v-for="(item, index) in recipe.ingredients" :key="index" class="ingredient" style="font-family: 'Orkney-Regular'" checkPadding="16" @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>
|
|
|
|
<ScrollView @scroll="onScroll">
|
|
|
|
<GridLayout v-if="!recipe.instructions.length" rows="*, auto, *, 88" columns="*" class="emptyStateContainer">
|
|
|
|
<StackLayout col="0" row="1" class="emptyState">
|
|
|
|
<Label class="bx icon" :text="icon.step" 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>
|
2020-12-29 10:35:19 +00:00
|
|
|
<StackLayout v-else padding="20 16 62">
|
2020-12-07 14:45:00 +00:00
|
|
|
<GridLayout columns="auto ,*" v-for="(instruction, index) in recipe.instructions" :key="index">
|
|
|
|
<Label col="0" colSpan="2" class="instruction" :class="{
|
|
|
|
noBorder: index === recipe.instructions.length - 1,
|
|
|
|
}" :text="instruction" textWrap="true" />
|
2020-12-29 10:35:19 +00:00
|
|
|
<Label 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>
|
|
|
|
<ScrollView @scroll="onScroll">
|
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">
|
2020-12-29 10:35:19 +00:00
|
|
|
<Label class="bx icon" :text="icon.note" 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>
|
2020-12-29 10:35:19 +00:00
|
|
|
<StackLayout v-else padding="20 16 62" @loaded="createNotes">
|
2020-12-07 14:45:00 +00:00
|
|
|
</StackLayout>
|
|
|
|
</ScrollView>
|
|
|
|
</TabContentItem>
|
|
|
|
<TabContentItem>
|
|
|
|
<ScrollView @scroll="onScroll">
|
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">
|
2020-12-29 10:35:19 +00:00
|
|
|
<Label class="bx icon" :text="icon.outline" 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-13 05:02:48 +00:00
|
|
|
<StackLayout v-else padding="8 0 80">
|
|
|
|
<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>
|
2020-12-29 10:35:19 +00:00
|
|
|
|
2020-12-07 14:45:00 +00:00
|
|
|
</Tabs>
|
|
|
|
<GridLayout id="btnFabContainer" rows="*, auto" columns="*, auto">
|
|
|
|
<transition name="dolly" appear>
|
|
|
|
<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,
|
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
|
|
|
viewIsScrolled: false,
|
2020-12-07 14:45:00 +00:00
|
|
|
isScrolled: [ false, false, false, false, false, false ],
|
2020-11-28 19:21:57 +00:00
|
|
|
hideActionBar: false,
|
2021-01-13 05:02:48 +00:00
|
|
|
overviewTab: null,
|
|
|
|
checks: [],
|
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"
|
|
|
|
},
|
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
|
2020-11-28 19:21:57 +00:00
|
|
|
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() {
|
|
|
|
feedback.hide()
|
2020-12-07 14:45:00 +00:00
|
|
|
this.keepScreenOn( false )
|
2020-11-10 18:28:48 +00:00
|
|
|
},
|
2021-01-13 05:02:48 +00:00
|
|
|
overviewLoaded( args ) {
|
|
|
|
this.overviewTab = args
|
|
|
|
},
|
2020-11-10 18:28:48 +00:00
|
|
|
// HELPERS
|
2020-12-07 14:45:00 +00:00
|
|
|
niceDates( time ) {
|
|
|
|
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-12-07 14:45:00 +00:00
|
|
|
this.viewIsScrolled = this.isScrolled[ this.selectedTabIndex ]
|
2020-11-02 11:36:53 +00:00
|
|
|
},
|
2020-11-10 18:28:48 +00:00
|
|
|
showLastTried() {
|
2020-12-07 14:45:00 +00:00
|
|
|
feedback.show( {
|
2021-01-13 05:02:48 +00:00
|
|
|
title: `${localize('triedInfo')} ${this.niceDates(
|
2020-11-02 11:36:53 +00:00
|
|
|
this.recipe.lastTried
|
2020-12-07 14:45:00 +00:00
|
|
|
)}`,
|
|
|
|
titleColor: new Color( `${this.isLightMode ? "#f1f3f5" : "#212529"}` ),
|
|
|
|
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
|
|
|
|
this.checks[ index ] = !this.checks[ index ]
|
|
|
|
},
|
2020-11-10 18:28:48 +00:00
|
|
|
// NAVIGATION HANDLERS
|
2020-12-07 14:45:00 +00:00
|
|
|
onScroll( args ) {
|
|
|
|
this.viewIsScrolled = this.isScrolled[ this.selectedTabIndex ] = args.scrollY > 8 ? true : false
|
2020-11-28 19:21:57 +00:00
|
|
|
},
|
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 ]
|
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
|
|
|
},
|
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
|
|
|
},
|
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 ) {
|
|
|
|
if ( rating !== this.recipe.rating ) {
|
|
|
|
|
|
|
|
this.setRatingAction( {
|
|
|
|
id: this.currentRecipeID,
|
|
|
|
recipe: this.recipe,
|
|
|
|
rating,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
},
|
2021-01-13 05:02:48 +00:00
|
|
|
// SHOPPINGLIST
|
|
|
|
toggleCart() {
|
|
|
|
if ( !this.recipe.inCart ) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
}
|
|
|
|
this.toggleCartAction( {
|
|
|
|
id: this.currentRecipeID,
|
|
|
|
recipe: this.recipe,
|
|
|
|
} )
|
|
|
|
},
|
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()
|
|
|
|
const firstCol = new ItemSpec( 1, "auto" )
|
|
|
|
const secondCol = new ItemSpec( 1, "star" )
|
|
|
|
const label1 = new Label()
|
|
|
|
const label2 = new Label()
|
|
|
|
label1.class = "note"
|
|
|
|
label1.textWrap = true
|
|
|
|
label2.class = "noteCount orkm"
|
|
|
|
label2.text = i + 1
|
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 ) )
|
|
|
|
} )
|
2020-12-29 10:35:19 +00:00
|
|
|
label1.formattedText = formattedString
|
|
|
|
grid.addChild( label1 )
|
|
|
|
grid.addChild( label2 )
|
|
|
|
GridLayout.setColumn( label1, 0 )
|
|
|
|
GridLayout.setColumn( label2, 0 )
|
|
|
|
GridLayout.setColumnSpan( label1, 2 )
|
|
|
|
grid.addColumn( firstCol )
|
|
|
|
grid.addColumn( secondCol )
|
|
|
|
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-13 05:02:48 +00:00
|
|
|
this.checks = this.recipe.ingredients.map( e => true )
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
2020-10-29 20:12:53 +00:00
|
|
|
mounted() {
|
|
|
|
this.showFab = true
|
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>
|