2020-10-14 19:32:32 +00:00
|
|
|
<template>
|
2020-10-22 18:36:50 +00:00
|
|
|
<Page @loaded="initializePage">
|
2020-10-21 17:54:45 +00:00
|
|
|
<ActionBar height="128" margin="0" flat="true">
|
2020-10-14 19:32:32 +00:00
|
|
|
<GridLayout
|
2020-10-21 17:54:45 +00:00
|
|
|
rows="64, 64"
|
|
|
|
columns="auto, *, auto,auto, auto"
|
2020-10-14 19:32:32 +00:00
|
|
|
class="actionBarContainer"
|
|
|
|
>
|
|
|
|
<Label
|
2020-10-21 17:54:45 +00:00
|
|
|
row="0"
|
2020-10-14 19:32:32 +00:00
|
|
|
col="0"
|
|
|
|
class="bx leftAction"
|
|
|
|
:text="icon.back"
|
|
|
|
automationText="Back"
|
2020-10-21 17:54:45 +00:00
|
|
|
@tap="$navigateBack()"
|
2020-10-14 19:32:32 +00:00
|
|
|
/>
|
2020-10-21 17:54:45 +00:00
|
|
|
<ScrollView
|
|
|
|
row="1"
|
2020-10-14 19:32:32 +00:00
|
|
|
col="1"
|
2020-10-21 17:54:45 +00:00
|
|
|
colSpan="3"
|
|
|
|
orientation="horizontal"
|
|
|
|
scrollBarIndicatorVisible="false"
|
|
|
|
>
|
|
|
|
<Label
|
|
|
|
class="title orkm"
|
|
|
|
:text="recipe.title"
|
|
|
|
verticalAlignment="bottom"
|
|
|
|
/>
|
|
|
|
</ScrollView>
|
|
|
|
<Label row="0" col="2" class="bx" :text="icon.share" @tap="" />
|
2020-10-14 19:32:32 +00:00
|
|
|
<Label
|
2020-10-21 17:54:45 +00:00
|
|
|
row="0"
|
2020-10-14 19:32:32 +00:00
|
|
|
col="3"
|
|
|
|
class="bx"
|
|
|
|
:class="{ 'view-favorited': recipe.isFavorite }"
|
|
|
|
:text="recipe.isFavorite ? icon.heart : icon.heartOutline"
|
|
|
|
@tap="toggleFavorite"
|
2020-10-21 17:54:45 +00:00
|
|
|
/>
|
|
|
|
<Label
|
|
|
|
row="0"
|
|
|
|
col="4"
|
|
|
|
class="bx"
|
|
|
|
:class="{ 'view-favorited': !recipe.tried }"
|
|
|
|
:text="recipe.tried ? icon.musttryOutline : icon.musttry"
|
|
|
|
@tap="toggleMustTry"
|
2020-10-14 19:32:32 +00:00
|
|
|
/>
|
|
|
|
</GridLayout>
|
|
|
|
</ActionBar>
|
|
|
|
<AbsoluteLayout>
|
|
|
|
<TabView androidElevation="0" width="100%" height="100%">
|
|
|
|
<TabViewItem title="Overview">
|
|
|
|
<ScrollView scrollBarIndicatorVisible="false">
|
2020-10-21 17:54:45 +00:00
|
|
|
<StackLayout>
|
2020-10-14 19:32:32 +00:00
|
|
|
<StackLayout
|
|
|
|
width="100%"
|
|
|
|
:height="screenWidth"
|
|
|
|
verticalAlignment="center"
|
|
|
|
class="view-imageHolder"
|
|
|
|
>
|
|
|
|
<Image
|
|
|
|
v-if="recipe.imageSrc"
|
|
|
|
:src="recipe.imageSrc"
|
|
|
|
stretch="aspectFill"
|
|
|
|
width="100%"
|
|
|
|
:height="screenWidth"
|
|
|
|
/>
|
|
|
|
<Label
|
|
|
|
v-else
|
|
|
|
horizontalAlignment="center"
|
|
|
|
class="bx"
|
|
|
|
fontSize="160"
|
2020-10-21 17:54:45 +00:00
|
|
|
:text="icon.image"
|
2020-10-14 19:32:32 +00:00
|
|
|
/>
|
|
|
|
</StackLayout>
|
2020-10-21 17:54:45 +00:00
|
|
|
<StackLayout margin="16 16 144">
|
2020-10-14 19:32:32 +00:00
|
|
|
<Label class="view-cat orkm" :text="recipe.category" />
|
|
|
|
<Label
|
2020-10-21 17:54:45 +00:00
|
|
|
class="view-title orkm"
|
2020-10-14 19:32:32 +00:00
|
|
|
:text="recipe.title"
|
|
|
|
textWrap="true"
|
|
|
|
/>
|
|
|
|
<Label
|
|
|
|
class="view-other"
|
|
|
|
:text="`Preparation time: ${getTime(recipe.prepTime)}`"
|
|
|
|
/>
|
|
|
|
<Label
|
|
|
|
class="view-other"
|
|
|
|
:text="`Cooking time: ${getTime(recipe.cookTime)}`"
|
|
|
|
/>
|
|
|
|
<Label
|
|
|
|
class="view-other"
|
|
|
|
:text="`Portion size: ${recipe.portionSize}`"
|
|
|
|
/>
|
|
|
|
</StackLayout>
|
|
|
|
</StackLayout>
|
|
|
|
</ScrollView>
|
|
|
|
</TabViewItem>
|
2020-10-24 18:02:35 +00:00
|
|
|
<TabViewItem title="Ingredients">
|
2020-10-14 19:32:32 +00:00
|
|
|
<ScrollView scrollBarIndicatorVisible="false">
|
2020-10-24 18:02:35 +00:00
|
|
|
<Label
|
|
|
|
v-if="!recipe.ingredients.length"
|
|
|
|
class="noResults"
|
|
|
|
text="Click the edit button to add ingredients to this recipe"
|
|
|
|
textWrap="true"
|
|
|
|
/>
|
|
|
|
<StackLayout v-else padding="16 16 124">
|
2020-10-14 19:32:32 +00:00
|
|
|
<AbsoluteLayout class="inputField">
|
|
|
|
<TextField
|
|
|
|
width="50%"
|
|
|
|
v-model="portionScale"
|
|
|
|
keyboardType="number"
|
|
|
|
/>
|
|
|
|
<Label top="0" class="fieldLabel" text="Set portion size" />
|
|
|
|
</AbsoluteLayout>
|
|
|
|
<StackLayout margin="24 0 8 0">
|
|
|
|
<Label
|
2020-10-21 17:54:45 +00:00
|
|
|
class="view-title orkm"
|
2020-10-14 19:32:32 +00:00
|
|
|
:text="
|
|
|
|
`Ingredients for ${portionScale}${
|
|
|
|
portionScale > 1
|
|
|
|
? ' portions'
|
|
|
|
: portionScale == 0
|
|
|
|
? '1 portion'
|
|
|
|
: ' portion'
|
|
|
|
}`
|
|
|
|
"
|
|
|
|
textWrap="true"
|
|
|
|
/>
|
|
|
|
<Label
|
|
|
|
class="view-ingredient"
|
|
|
|
v-for="(item, index) in recipe.ingredients"
|
|
|
|
:key="index"
|
|
|
|
:text="
|
|
|
|
`${roundedQuantity(item.quantity)}${
|
|
|
|
item.unit ? ' ' + item.unit : ''
|
|
|
|
} ${item.item}`
|
|
|
|
"
|
|
|
|
textWrap="true"
|
|
|
|
/>
|
|
|
|
</StackLayout>
|
|
|
|
</StackLayout>
|
|
|
|
</ScrollView>
|
|
|
|
</TabViewItem>
|
2020-10-24 18:02:35 +00:00
|
|
|
<TabViewItem title="Instructions">
|
2020-10-14 19:32:32 +00:00
|
|
|
<ScrollView scrollBarIndicatorVisible="false">
|
2020-10-24 18:02:35 +00:00
|
|
|
<Label
|
|
|
|
v-if="!recipe.instructions.length"
|
|
|
|
class="noResults"
|
|
|
|
text="Click the edit button to add instructions to this recipe"
|
|
|
|
textWrap="true"
|
|
|
|
/>
|
|
|
|
<StackLayout v-else padding="32 16 132">
|
2020-10-14 19:32:32 +00:00
|
|
|
<GridLayout
|
|
|
|
columns="auto ,*"
|
|
|
|
v-for="(instruction, index) in recipe.instructions"
|
|
|
|
:key="index"
|
|
|
|
>
|
|
|
|
<Label
|
|
|
|
col="0"
|
|
|
|
colSpan="2"
|
|
|
|
class="view-instruction"
|
|
|
|
:class="{
|
|
|
|
instructionWOBorder:
|
|
|
|
index === recipe.instructions.length - 1,
|
|
|
|
}"
|
|
|
|
:text="instruction"
|
|
|
|
textWrap="true"
|
|
|
|
/>
|
|
|
|
<Label
|
|
|
|
verticalAlignment="top"
|
|
|
|
horizontalAlignment="center"
|
|
|
|
class="view-count orkb"
|
|
|
|
col="0"
|
|
|
|
:text="index + 1"
|
|
|
|
/>
|
|
|
|
</GridLayout>
|
|
|
|
</StackLayout>
|
|
|
|
</ScrollView>
|
|
|
|
</TabViewItem>
|
2020-10-24 18:02:35 +00:00
|
|
|
<TabViewItem title="Notes">
|
2020-10-14 19:32:32 +00:00
|
|
|
<ScrollView scrollBarIndicatorVisible="false">
|
2020-10-24 18:02:35 +00:00
|
|
|
<Label
|
|
|
|
v-if="!recipe.notes.length"
|
|
|
|
class="noResults"
|
|
|
|
text="Click the edit button to add notes to this recipe"
|
|
|
|
textWrap="true"
|
|
|
|
/>
|
|
|
|
<StackLayout v-else padding="32 16 132">
|
2020-10-14 19:32:32 +00:00
|
|
|
<GridLayout
|
|
|
|
columns="auto ,*"
|
|
|
|
v-for="(note, index) in recipe.notes"
|
|
|
|
:key="index"
|
|
|
|
>
|
|
|
|
<Label
|
|
|
|
col="0"
|
|
|
|
colSpan="2"
|
|
|
|
class="view-note"
|
|
|
|
:text="note"
|
|
|
|
textWrap="true"
|
|
|
|
/>
|
|
|
|
<Label
|
|
|
|
verticalAlignment="top"
|
|
|
|
horizontalAlignment="center"
|
|
|
|
class="view-count orkb"
|
|
|
|
col="0"
|
|
|
|
:text="index + 1"
|
|
|
|
/>
|
|
|
|
</GridLayout>
|
|
|
|
</StackLayout>
|
|
|
|
</ScrollView>
|
|
|
|
</TabViewItem>
|
2020-10-24 18:02:35 +00:00
|
|
|
<TabViewItem title="References">
|
2020-10-14 19:32:32 +00:00
|
|
|
<ScrollView scrollBarIndicatorVisible="false">
|
2020-10-24 18:02:35 +00:00
|
|
|
<Label
|
|
|
|
v-if="!recipe.references.length"
|
|
|
|
class="noResults"
|
|
|
|
text="Click the edit button to add references to this recipe"
|
|
|
|
textWrap="true"
|
|
|
|
/>
|
|
|
|
<StackLayout v-else padding="32 16 132">
|
2020-10-14 19:32:32 +00:00
|
|
|
<GridLayout
|
|
|
|
columns="auto ,*"
|
|
|
|
v-for="(reference, index) in recipe.references"
|
|
|
|
:key="index"
|
|
|
|
@tap="openURL($event, reference)"
|
|
|
|
>
|
|
|
|
<Label
|
|
|
|
col="0"
|
|
|
|
colSpan="2"
|
|
|
|
class="view-reference"
|
|
|
|
:text="reference"
|
|
|
|
textWrap="true"
|
|
|
|
/>
|
|
|
|
<Label
|
|
|
|
verticalAlignment="top"
|
|
|
|
horizontalAlignment="center"
|
|
|
|
class="orkb view-count"
|
|
|
|
col="0"
|
|
|
|
:text="index + 1"
|
|
|
|
/>
|
|
|
|
</GridLayout>
|
|
|
|
</StackLayout>
|
|
|
|
</ScrollView>
|
|
|
|
</TabViewItem>
|
|
|
|
</TabView>
|
|
|
|
<GridLayout id="btnFabContainer" rows="*,88" columns="*,88">
|
|
|
|
<Label
|
2020-10-21 17:54:45 +00:00
|
|
|
v-if="!busy"
|
2020-10-22 18:36:50 +00:00
|
|
|
@tap="editRecipe"
|
2020-10-14 19:32:32 +00:00
|
|
|
row="1"
|
|
|
|
col="1"
|
2020-10-22 18:36:50 +00:00
|
|
|
class="bx fab-button"
|
2020-10-14 19:32:32 +00:00
|
|
|
:text="icon.edit"
|
|
|
|
androidElevation="8"
|
|
|
|
/>
|
2020-10-21 17:54:45 +00:00
|
|
|
<ActivityIndicator v-else row="1" col="1" :busy="busy" />
|
2020-10-14 19:32:32 +00:00
|
|
|
</GridLayout>
|
|
|
|
</AbsoluteLayout>
|
|
|
|
</Page>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-10-22 18:36:50 +00:00
|
|
|
import { Screen, Utils } from "@nativescript/core"
|
2020-10-21 17:54:45 +00:00
|
|
|
import * as Toast from "nativescript-toast"
|
|
|
|
|
2020-10-14 19:32:32 +00:00
|
|
|
import { mapState, mapActions } from "vuex"
|
|
|
|
|
2020-10-22 18:36:50 +00:00
|
|
|
import EditRecipe from "./EditRecipe.vue"
|
|
|
|
|
2020-10-24 18:02:35 +00:00
|
|
|
import { Couchbase } from "nativescript-couchbase-plugin"
|
|
|
|
const cb = new Couchbase("enrecipes")
|
|
|
|
|
2020-10-14 19:32:32 +00:00
|
|
|
export default {
|
2020-10-24 18:02:35 +00:00
|
|
|
props: ["recipeID", "hijackGlobalBackEvent", "releaseGlobalBackEvent"],
|
2020-10-14 19:32:32 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2020-10-21 17:54:45 +00:00
|
|
|
busy: false,
|
2020-10-14 19:32:32 +00:00
|
|
|
portionScale: 1,
|
2020-10-24 18:02:35 +00:00
|
|
|
recipe: null,
|
2020-10-14 19:32:32 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2020-10-24 18:02:35 +00:00
|
|
|
...mapState(["icon"]),
|
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
|
|
|
},
|
|
|
|
isPortionScalePositive() {
|
|
|
|
return this.portionScale && !isNaN(this.portionScale)
|
|
|
|
? parseFloat(this.portionScale)
|
|
|
|
: 1
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
2020-10-24 18:02:35 +00:00
|
|
|
...mapActions(["toggleMustTryAction", "setCurrentComponentAction"]),
|
|
|
|
initializePage() {
|
|
|
|
this.recipe = cb.getDocument(this.recipeID)
|
|
|
|
this.releaseGlobalBackEvent()
|
|
|
|
this.busy = false
|
|
|
|
setTimeout((e) => {
|
|
|
|
this.setCurrentComponentAction("ViewRecipe")
|
|
|
|
}, 500)
|
|
|
|
},
|
2020-10-14 19:32:32 +00:00
|
|
|
roundedQuantity(quantity, unit) {
|
|
|
|
return Math.round(quantity * this.isPortionScalePositive * 100) / 100
|
|
|
|
},
|
|
|
|
editRecipe() {
|
2020-10-21 17:54:45 +00:00
|
|
|
this.busy = true
|
|
|
|
this.$navigateTo(EditRecipe, {
|
|
|
|
transition: {
|
|
|
|
name: "slide",
|
|
|
|
duration: 250,
|
|
|
|
curve: "easeIn",
|
|
|
|
},
|
|
|
|
props: {
|
2020-10-24 18:02:35 +00:00
|
|
|
recipeID: this.recipeID,
|
2020-10-21 17:54:45 +00:00
|
|
|
},
|
|
|
|
// backstackVisible: false,
|
|
|
|
})
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
2020-10-24 18:02:35 +00:00
|
|
|
toggle(key) {
|
|
|
|
this.recipe[key] = !this.recipe[key]
|
|
|
|
cb.updateDocument(this.recipeID, this.recipe)
|
|
|
|
this.recipe = cb.getDocument(this.recipeID)
|
|
|
|
},
|
2020-10-14 19:32:32 +00:00
|
|
|
toggleFavorite() {
|
2020-10-21 17:54:45 +00:00
|
|
|
this.recipe.isFavorite
|
|
|
|
? Toast.makeText("Removed from Favorites").show()
|
|
|
|
: Toast.makeText("Added to Favorites").show()
|
2020-10-24 18:02:35 +00:00
|
|
|
this.toggle("isFavorite")
|
2020-10-21 17:54:45 +00:00
|
|
|
},
|
|
|
|
toggleMustTry() {
|
|
|
|
this.recipe.tried
|
|
|
|
? Toast.makeText("Added to Must-Try").show()
|
|
|
|
: Toast.makeText("Removed from Must-Try").show()
|
2020-10-24 18:02:35 +00:00
|
|
|
this.toggle("tried")
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
|
|
|
getTime(time) {
|
|
|
|
let t = time.split(":")
|
|
|
|
let h = t[0]
|
|
|
|
let m = t[1]
|
|
|
|
return h !== "00" ? `${h}h ${m}m` : `${m}m`
|
|
|
|
},
|
|
|
|
openURL(args, url) {
|
2020-10-22 18:36:50 +00:00
|
|
|
Utils.openUrl(url)
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
2020-10-24 18:02:35 +00:00
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.recipe = cb.getDocument(this.recipeID)
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|