2020-10-14 19:32:32 +00:00
|
|
|
<template>
|
2020-10-29 20:12:53 +00:00
|
|
|
<Page @loaded="initialize" @unloaded="releaseBackEvent">
|
2020-10-14 19:32:32 +00:00
|
|
|
<ActionBar :flat="viewIsScrolled ? false : true">
|
2020-11-02 11:36:53 +00:00
|
|
|
<GridLayout rows="*" columns="auto, *, auto">
|
2020-10-14 19:32:32 +00:00
|
|
|
<Label
|
2020-11-02 11:36:53 +00:00
|
|
|
class="bx"
|
2020-10-14 19:32:32 +00:00
|
|
|
:text="icon.back"
|
|
|
|
automationText="Back"
|
|
|
|
col="0"
|
|
|
|
@tap="navigateBack"
|
|
|
|
/>
|
2020-10-21 17:54:45 +00:00
|
|
|
<Label class="title orkm" :text="title" col="1" />
|
2020-10-14 19:32:32 +00:00
|
|
|
<Label
|
2020-11-02 11:36:53 +00:00
|
|
|
v-if="hasEnoughDetails && !imageLoading"
|
2020-10-14 19:32:32 +00:00
|
|
|
class="bx"
|
|
|
|
:text="icon.save"
|
|
|
|
col="2"
|
2020-11-02 11:36:53 +00:00
|
|
|
@tap="saveOperation"
|
2020-10-14 19:32:32 +00:00
|
|
|
/>
|
2020-11-02 11:36:53 +00:00
|
|
|
<ActivityIndicator col="2" v-if="imageLoading" :busy="imageLoading" />
|
2020-10-14 19:32:32 +00:00
|
|
|
</GridLayout>
|
|
|
|
</ActionBar>
|
2020-11-02 11:36:53 +00:00
|
|
|
<GridLayout rows="*" columns="*">
|
2020-10-29 20:12:53 +00:00
|
|
|
<ScrollView
|
2020-11-02 11:36:53 +00:00
|
|
|
row="0"
|
|
|
|
col="0"
|
|
|
|
@scroll="onScroll"
|
2020-10-29 20:12:53 +00:00
|
|
|
scrollBarIndicatorVisible="false"
|
|
|
|
>
|
|
|
|
<StackLayout width="100%" padding="0 0 128">
|
|
|
|
<!-- Image and camera btn -->
|
|
|
|
<AbsoluteLayout>
|
|
|
|
<StackLayout
|
2020-10-14 19:32:32 +00:00
|
|
|
width="100%"
|
|
|
|
:height="screenWidth"
|
2020-11-02 11:36:53 +00:00
|
|
|
class="imageHolder"
|
2020-10-29 20:12:53 +00:00
|
|
|
verticalAlignment="center"
|
|
|
|
>
|
|
|
|
<Image
|
|
|
|
v-if="recipeContent.imageSrc"
|
|
|
|
:src="recipeContent.imageSrc"
|
|
|
|
stretch="aspectFill"
|
|
|
|
width="100%"
|
|
|
|
:height="screenWidth"
|
2020-10-26 20:49:54 +00:00
|
|
|
/>
|
|
|
|
<Label
|
2020-10-29 20:12:53 +00:00
|
|
|
v-else
|
|
|
|
horizontalAlignment="center"
|
|
|
|
class="bx"
|
|
|
|
fontSize="160"
|
2020-11-02 11:36:53 +00:00
|
|
|
:text="icon.food"
|
2020-10-26 20:49:54 +00:00
|
|
|
/>
|
2020-10-29 20:12:53 +00:00
|
|
|
</StackLayout>
|
|
|
|
<StackLayout width="100%" :top="screenWidth - 42">
|
|
|
|
<transition :name="recipeContent.imageSrc ? 'null' : 'bounce'">
|
|
|
|
<Label
|
|
|
|
v-if="showFab"
|
|
|
|
horizontalAlignment="right"
|
2020-11-02 11:36:53 +00:00
|
|
|
@tap="imageHandler"
|
2020-10-29 20:12:53 +00:00
|
|
|
class="bx fab-button"
|
|
|
|
:text="icon.camera"
|
|
|
|
androidElevation="6"
|
|
|
|
/>
|
|
|
|
</transition>
|
|
|
|
</StackLayout>
|
2020-10-14 19:32:32 +00:00
|
|
|
</AbsoluteLayout>
|
2020-10-29 20:12:53 +00:00
|
|
|
|
|
|
|
<!-- Primary information -->
|
|
|
|
<StackLayout margin="0 16">
|
|
|
|
<AbsoluteLayout class="inputField">
|
|
|
|
<TextField
|
|
|
|
hint="My Healthy Recipe"
|
|
|
|
v-model="recipeContent.title"
|
|
|
|
autocapitalizationType="words"
|
|
|
|
/>
|
|
|
|
<Label top="0" class="fieldLabel" text="Title" />
|
2020-10-14 19:32:32 +00:00
|
|
|
</AbsoluteLayout>
|
2020-10-29 20:12:53 +00:00
|
|
|
<AbsoluteLayout class="inputField">
|
2020-10-14 19:32:32 +00:00
|
|
|
<TextField
|
2020-11-02 11:36:53 +00:00
|
|
|
:text="recipeContent.category"
|
2020-10-29 20:12:53 +00:00
|
|
|
editable="false"
|
2020-11-02 11:36:53 +00:00
|
|
|
@tap="showCategories"
|
2020-10-14 19:32:32 +00:00
|
|
|
/>
|
2020-10-29 20:12:53 +00:00
|
|
|
<Label top="0" class="fieldLabel" text="Category" />
|
2020-10-14 19:32:32 +00:00
|
|
|
</AbsoluteLayout>
|
2020-10-29 20:12:53 +00:00
|
|
|
<GridLayout columns="*, 8, *">
|
|
|
|
<AbsoluteLayout class="inputField" col="0">
|
2020-11-02 11:36:53 +00:00
|
|
|
<TextField
|
|
|
|
v-model="recipeContent.yield.quantity"
|
|
|
|
hint="1"
|
|
|
|
keyboardType="number"
|
|
|
|
/>
|
|
|
|
<Label top="0" class="fieldLabel" text="Yield quantity" />
|
2020-10-29 20:12:53 +00:00
|
|
|
</AbsoluteLayout>
|
|
|
|
<AbsoluteLayout class="inputField" col="2">
|
2020-11-02 11:36:53 +00:00
|
|
|
<TextField
|
|
|
|
:text="recipeContent.yield.unit"
|
|
|
|
editable="false"
|
|
|
|
@tap="showYieldUnits"
|
|
|
|
/>
|
|
|
|
<Label top="0" class="fieldLabel" text="Yield measured in" />
|
2020-10-29 20:12:53 +00:00
|
|
|
</AbsoluteLayout>
|
|
|
|
</GridLayout>
|
2020-11-02 11:36:53 +00:00
|
|
|
<GridLayout columns="*, 8, *">
|
2020-10-29 20:12:53 +00:00
|
|
|
<AbsoluteLayout class="inputField" col="0">
|
|
|
|
<TextField
|
2020-11-02 11:36:53 +00:00
|
|
|
:text="formattedTimeRequired"
|
|
|
|
editable="false"
|
|
|
|
@tap="setTimeRequired"
|
2020-10-29 20:12:53 +00:00
|
|
|
/>
|
2020-11-02 11:36:53 +00:00
|
|
|
<Label top="0" class="fieldLabel" text="Time required" />
|
2020-10-29 20:12:53 +00:00
|
|
|
</AbsoluteLayout>
|
|
|
|
</GridLayout>
|
2020-11-02 11:36:53 +00:00
|
|
|
|
2020-10-29 20:12:53 +00:00
|
|
|
<StackLayout class="hr" margin="24 16"></StackLayout>
|
|
|
|
</StackLayout>
|
2020-10-14 19:32:32 +00:00
|
|
|
|
2020-10-29 20:12:53 +00:00
|
|
|
<!-- Ingredients section -->
|
|
|
|
<StackLayout margin="0 16">
|
|
|
|
<Label text="Ingredients" class="sectionTitle" />
|
|
|
|
<GridLayout
|
|
|
|
columns="*,8,auto,8,auto,8,auto"
|
|
|
|
v-for="(ingredient, index) in recipeContent.ingredients"
|
|
|
|
:key="index"
|
|
|
|
>
|
|
|
|
<TextField
|
2020-11-02 11:36:53 +00:00
|
|
|
@loaded="focusField"
|
2020-10-29 20:12:53 +00:00
|
|
|
col="0"
|
|
|
|
v-model="recipeContent.ingredients[index].item"
|
|
|
|
:hint="`Item ${index + 1}`"
|
|
|
|
autocapitalizationType="words"
|
|
|
|
/>
|
|
|
|
<TextField
|
|
|
|
width="72"
|
|
|
|
col="2"
|
|
|
|
v-model="recipeContent.ingredients[index].quantity"
|
|
|
|
hint="1.000"
|
|
|
|
keyboardType="number"
|
|
|
|
/>
|
|
|
|
<TextField
|
|
|
|
width="64"
|
|
|
|
col="4"
|
|
|
|
v-model="recipeContent.ingredients[index].unit"
|
|
|
|
hint="Unit"
|
|
|
|
editable="false"
|
|
|
|
@tap="showUnits($event)"
|
|
|
|
/>
|
|
|
|
<Label
|
|
|
|
col="6"
|
|
|
|
class="bx closeBtn"
|
|
|
|
:text="icon.close"
|
|
|
|
@tap="removeIngredient(index)"
|
|
|
|
/>
|
|
|
|
</GridLayout>
|
2020-10-14 19:32:32 +00:00
|
|
|
<Label
|
2020-11-02 11:36:53 +00:00
|
|
|
class="text-btn orkm"
|
2020-10-29 20:12:53 +00:00
|
|
|
text="+ ADD INGREDIENT"
|
|
|
|
@tap="addIngredient()"
|
2020-10-14 19:32:32 +00:00
|
|
|
/>
|
|
|
|
|
2020-10-29 20:12:53 +00:00
|
|
|
<StackLayout class="hr" margin="24 16"></StackLayout>
|
|
|
|
</StackLayout>
|
2020-10-14 19:32:32 +00:00
|
|
|
|
2020-10-29 20:12:53 +00:00
|
|
|
<!-- Instructions section -->
|
|
|
|
<StackLayout margin="0 16">
|
|
|
|
<Label text="Instructions" class="sectionTitle" />
|
|
|
|
<GridLayout
|
|
|
|
columns="*,8,auto"
|
|
|
|
v-for="(instruction, index) in recipeContent.instructions"
|
|
|
|
:key="index"
|
|
|
|
>
|
|
|
|
<TextView
|
2020-11-02 11:36:53 +00:00
|
|
|
@loaded="focusField"
|
2020-10-29 20:12:53 +00:00
|
|
|
col="0"
|
|
|
|
:hint="`Step ${index + 1}`"
|
|
|
|
v-model="recipeContent.instructions[index]"
|
|
|
|
editable="true"
|
|
|
|
/>
|
|
|
|
<Label
|
|
|
|
col="2"
|
|
|
|
class="bx closeBtn"
|
|
|
|
:text="icon.close"
|
|
|
|
@tap="removeInstruction(index)"
|
|
|
|
/>
|
|
|
|
</GridLayout>
|
2020-10-14 19:32:32 +00:00
|
|
|
<Label
|
2020-11-02 11:36:53 +00:00
|
|
|
class="text-btn orkm"
|
2020-10-29 20:12:53 +00:00
|
|
|
text="+ ADD STEP"
|
|
|
|
@tap="addInstruction()"
|
2020-10-14 19:32:32 +00:00
|
|
|
/>
|
2020-10-29 20:12:53 +00:00
|
|
|
<StackLayout class="hr" margin="24 16"></StackLayout>
|
|
|
|
</StackLayout>
|
2020-10-14 19:32:32 +00:00
|
|
|
|
2020-10-29 20:12:53 +00:00
|
|
|
<!-- Notes section -->
|
|
|
|
<StackLayout margin="0 16">
|
|
|
|
<Label text="Notes" class="sectionTitle" />
|
|
|
|
<GridLayout
|
|
|
|
columns="*,8,auto"
|
|
|
|
v-for="(note, index) in recipeContent.notes"
|
|
|
|
:key="index"
|
|
|
|
>
|
|
|
|
<TextView
|
2020-11-02 11:36:53 +00:00
|
|
|
@loaded="focusField"
|
2020-10-29 20:12:53 +00:00
|
|
|
col="0"
|
|
|
|
v-model="recipeContent.notes[index]"
|
|
|
|
:hint="`Note ${index + 1}`"
|
|
|
|
editable="true"
|
|
|
|
/>
|
|
|
|
<Label
|
|
|
|
col="2"
|
|
|
|
class="bx closeBtn"
|
|
|
|
:text="icon.close"
|
|
|
|
@tap="removeNote(index)"
|
|
|
|
/>
|
|
|
|
</GridLayout>
|
2020-11-02 11:36:53 +00:00
|
|
|
<Label class="text-btn orkm" text="+ ADD NOTE" @tap="addNote()" />
|
2020-10-29 20:12:53 +00:00
|
|
|
<StackLayout class="hr" margin="24 16"></StackLayout>
|
|
|
|
</StackLayout>
|
2020-10-14 19:32:32 +00:00
|
|
|
|
2020-10-29 20:12:53 +00:00
|
|
|
<!-- References section -->
|
|
|
|
<StackLayout margin="0 16">
|
|
|
|
<Label text="References" class="sectionTitle" />
|
|
|
|
<GridLayout
|
|
|
|
columns="*,8,auto"
|
|
|
|
v-for="(reference, index) in recipeContent.references"
|
|
|
|
:key="index"
|
|
|
|
>
|
|
|
|
<TextView
|
2020-11-02 11:36:53 +00:00
|
|
|
@loaded="focusField"
|
2020-10-29 20:12:53 +00:00
|
|
|
col="0"
|
|
|
|
v-model="recipeContent.references[index]"
|
|
|
|
hint="Text or Website/Video URL"
|
|
|
|
editable="true"
|
|
|
|
/>
|
|
|
|
<Label
|
|
|
|
col="2"
|
|
|
|
class="bx closeBtn"
|
|
|
|
:text="icon.close"
|
|
|
|
@tap="removeReference(index)"
|
|
|
|
/>
|
|
|
|
</GridLayout>
|
2020-10-14 19:32:32 +00:00
|
|
|
<Label
|
2020-11-02 11:36:53 +00:00
|
|
|
class="text-btn orkm"
|
2020-10-29 20:12:53 +00:00
|
|
|
text="+ ADD REFERENCE"
|
|
|
|
@tap="addReference()"
|
2020-10-14 19:32:32 +00:00
|
|
|
/>
|
2020-10-29 20:12:53 +00:00
|
|
|
<StackLayout margin="32"></StackLayout>
|
|
|
|
</StackLayout>
|
2020-10-14 19:32:32 +00:00
|
|
|
</StackLayout>
|
2020-10-29 20:12:53 +00:00
|
|
|
</ScrollView>
|
2020-11-02 11:36:53 +00:00
|
|
|
</GridLayout>
|
2020-10-14 19:32:32 +00:00
|
|
|
</Page>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-11-02 11:36:53 +00:00
|
|
|
import { WorkerService } from "../worker.service"
|
|
|
|
var workerService = new WorkerService()
|
|
|
|
|
2020-10-24 18:02:35 +00:00
|
|
|
import {
|
|
|
|
Screen,
|
|
|
|
AndroidApplication,
|
|
|
|
ImageSource,
|
|
|
|
path,
|
|
|
|
getFileAccess,
|
|
|
|
knownFolders,
|
2020-11-02 11:36:53 +00:00
|
|
|
Utils,
|
|
|
|
File,
|
2020-10-24 18:02:35 +00:00
|
|
|
} from "@nativescript/core"
|
2020-10-29 20:12:53 +00:00
|
|
|
import { Mediafilepicker } from "nativescript-mediafilepicker"
|
2020-10-22 18:36:50 +00:00
|
|
|
|
2020-11-02 11:36:53 +00:00
|
|
|
import { DateTimePicker, TimePickerField } from "@nativescript/datetimepicker"
|
|
|
|
|
2020-10-14 19:32:32 +00:00
|
|
|
import { mapState, mapActions } from "vuex"
|
2020-10-22 18:36:50 +00:00
|
|
|
|
2020-10-21 17:54:45 +00:00
|
|
|
import ActionDialog from "./modal/ActionDialog.vue"
|
|
|
|
import ConfirmDialog from "./modal/ConfirmDialog.vue"
|
2020-10-29 20:12:53 +00:00
|
|
|
import PromptDialog from "./modal/PromptDialog.vue"
|
2020-11-02 11:36:53 +00:00
|
|
|
import ListPicker from "./modal/ListPicker.vue"
|
|
|
|
import { create } from "domain"
|
2020-10-21 17:54:45 +00:00
|
|
|
|
2020-10-14 19:32:32 +00:00
|
|
|
export default {
|
2020-10-26 20:49:54 +00:00
|
|
|
props: ["recipeIndex", "recipeID", "selectedCategory"],
|
2020-10-14 19:32:32 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2020-10-21 17:54:45 +00:00
|
|
|
title: "New recipe",
|
2020-10-14 19:32:32 +00:00
|
|
|
viewIsScrolled: false,
|
|
|
|
recipeContent: {
|
|
|
|
imageSrc: null,
|
2020-10-29 20:12:53 +00:00
|
|
|
title: undefined,
|
|
|
|
category: "Undefined",
|
2020-11-02 11:36:53 +00:00
|
|
|
timeRequired: "00:00",
|
|
|
|
yield: {
|
|
|
|
quantity: undefined,
|
|
|
|
unit: "Servings",
|
|
|
|
},
|
|
|
|
ingredients: [],
|
|
|
|
instructions: [],
|
|
|
|
notes: [],
|
|
|
|
references: [],
|
2020-10-26 20:49:54 +00:00
|
|
|
isFavorite: false,
|
|
|
|
tried: false,
|
2020-11-02 11:36:53 +00:00
|
|
|
lastTried: null,
|
2020-10-26 20:49:54 +00:00
|
|
|
lastModified: null,
|
|
|
|
},
|
2020-10-29 20:12:53 +00:00
|
|
|
tempRecipeContent: {},
|
2020-10-21 17:54:45 +00:00
|
|
|
blockModal: false,
|
2020-10-24 18:02:35 +00:00
|
|
|
newRecipeID: null,
|
2020-10-29 20:12:53 +00:00
|
|
|
showFab: false,
|
2020-11-02 11:36:53 +00:00
|
|
|
imageLoading: false,
|
2020-10-14 19:32:32 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2020-11-02 11:36:53 +00:00
|
|
|
...mapState([
|
|
|
|
"icon",
|
|
|
|
"units",
|
|
|
|
"yieldUnits",
|
|
|
|
"recipes",
|
|
|
|
"categories",
|
|
|
|
"currentComponent",
|
|
|
|
]),
|
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
|
|
|
},
|
|
|
|
hasEnoughDetails() {
|
2020-10-29 20:12:53 +00:00
|
|
|
return (
|
|
|
|
JSON.stringify(this.recipeContent) !==
|
|
|
|
JSON.stringify(this.tempRecipeContent)
|
|
|
|
)
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
2020-11-02 11:36:53 +00:00
|
|
|
formattedTimeRequired() {
|
|
|
|
let t = this.recipeContent.timeRequired.split(":")
|
|
|
|
let h = parseInt(t[0])
|
|
|
|
let m = parseInt(t[1])
|
|
|
|
return h ? (m ? `${h}h ${m}m` : `${h}h`) : `${m}m`
|
|
|
|
},
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2020-10-26 20:49:54 +00:00
|
|
|
...mapActions([
|
|
|
|
"setCurrentComponentAction",
|
|
|
|
"addRecipeAction",
|
|
|
|
"overwriteRecipeAction",
|
|
|
|
"addCategoryAction",
|
2020-11-02 11:36:53 +00:00
|
|
|
"addYieldUnitAction",
|
2020-10-26 20:49:54 +00:00
|
|
|
]),
|
2020-10-29 20:12:53 +00:00
|
|
|
initialize() {
|
|
|
|
this.showFab = true
|
|
|
|
},
|
2020-11-02 11:36:53 +00:00
|
|
|
|
|
|
|
// HELPERS
|
|
|
|
focusField(args) {
|
|
|
|
if (!args.object.text) {
|
|
|
|
args.object.focus()
|
|
|
|
setTimeout((e) => Utils.ad.showSoftInput(args.object.android), 1)
|
|
|
|
}
|
|
|
|
},
|
2020-10-24 18:02:35 +00:00
|
|
|
getRandomID() {
|
|
|
|
let res = ""
|
|
|
|
let chars = "abcdefghijklmnopqrstuvwxyz0123456789"
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
|
|
res += chars.charAt(Math.floor(Math.random() * chars.length))
|
|
|
|
}
|
|
|
|
return res
|
2020-10-21 17:54:45 +00:00
|
|
|
},
|
2020-11-02 11:36:53 +00:00
|
|
|
setTimeRequired() {
|
|
|
|
let time = this.recipeContent.timeRequired.split(":")
|
|
|
|
let hr = time[0]
|
|
|
|
let min = time[1]
|
|
|
|
this.$showModal(ListPicker, {
|
|
|
|
props: {
|
|
|
|
title: "Approx. time required",
|
|
|
|
action: "SET",
|
|
|
|
selectedHr: hr,
|
|
|
|
selectedMin: min,
|
|
|
|
},
|
|
|
|
}).then((result) => {
|
|
|
|
if (result) {
|
|
|
|
this.recipeContent.timeRequired = result
|
2020-10-21 17:54:45 +00:00
|
|
|
}
|
|
|
|
})
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
|
|
|
onScroll(args) {
|
|
|
|
args.scrollY
|
|
|
|
? (this.viewIsScrolled = true)
|
|
|
|
: (this.viewIsScrolled = false)
|
|
|
|
},
|
2020-11-02 11:36:53 +00:00
|
|
|
|
|
|
|
// DATA LIST
|
2020-10-14 19:32:32 +00:00
|
|
|
showCategories() {
|
2020-10-21 17:54:45 +00:00
|
|
|
this.releaseBackEvent()
|
|
|
|
this.$showModal(ActionDialog, {
|
|
|
|
props: {
|
|
|
|
title: "Category",
|
|
|
|
list: [...this.categories],
|
2020-11-02 11:36:53 +00:00
|
|
|
height: "408",
|
|
|
|
action: "CREATE NEW",
|
2020-10-21 17:54:45 +00:00
|
|
|
},
|
|
|
|
}).then((action) => {
|
2020-11-02 11:36:53 +00:00
|
|
|
if (action == "CREATE NEW") {
|
2020-10-21 17:54:45 +00:00
|
|
|
this.$showModal(PromptDialog, {
|
|
|
|
props: {
|
|
|
|
title: "New category",
|
|
|
|
action: "ADD",
|
|
|
|
},
|
2020-10-26 20:49:54 +00:00
|
|
|
}).then((category) => {
|
2020-10-21 17:54:45 +00:00
|
|
|
this.hijackBackEvent()
|
2020-10-26 20:49:54 +00:00
|
|
|
if (category.length) {
|
|
|
|
this.recipeContent.category = category
|
|
|
|
this.addCategoryAction(category)
|
2020-10-21 17:54:45 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
} else if (action) {
|
|
|
|
this.recipeContent.category = action
|
|
|
|
this.hijackBackEvent()
|
|
|
|
} else {
|
|
|
|
this.hijackBackEvent()
|
2020-10-14 19:32:32 +00:00
|
|
|
}
|
2020-10-21 17:54:45 +00:00
|
|
|
})
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
2020-11-02 11:36:53 +00:00
|
|
|
showYieldUnits() {
|
|
|
|
this.releaseBackEvent()
|
|
|
|
this.$showModal(ActionDialog, {
|
|
|
|
props: {
|
|
|
|
title: "Yield measured in",
|
|
|
|
list: [...this.yieldUnits],
|
|
|
|
height: "408",
|
|
|
|
action: "CREATE NEW",
|
|
|
|
},
|
|
|
|
}).then((action) => {
|
|
|
|
if (action == "CREATE NEW") {
|
|
|
|
this.$showModal(PromptDialog, {
|
|
|
|
props: {
|
|
|
|
title: "New yield unit",
|
|
|
|
action: "ADD",
|
|
|
|
},
|
|
|
|
}).then((yieldUnit) => {
|
|
|
|
this.hijackBackEvent()
|
|
|
|
if (yieldUnit.length) {
|
|
|
|
this.recipeContent.yield.unit = yieldUnit
|
|
|
|
this.addYieldUnitAction(yieldUnit)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else if (action) {
|
|
|
|
this.recipeContent.yield.unit = action
|
|
|
|
this.hijackBackEvent()
|
|
|
|
} else {
|
|
|
|
this.hijackBackEvent()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
showUnits(e) {
|
|
|
|
this.releaseBackEvent()
|
|
|
|
this.$showModal(ActionDialog, {
|
|
|
|
props: {
|
|
|
|
title: "Unit",
|
|
|
|
list: [...this.units],
|
|
|
|
height: "408",
|
|
|
|
},
|
|
|
|
}).then((action) => {
|
|
|
|
this.hijackBackEvent()
|
|
|
|
if (action) e.object.text = action
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
// NAVIGATION HANDLERS
|
2020-10-14 19:32:32 +00:00
|
|
|
navigateBack() {
|
2020-10-21 17:54:45 +00:00
|
|
|
if (this.hasEnoughDetails) {
|
|
|
|
this.blockModal = true
|
|
|
|
this.$showModal(ConfirmDialog, {
|
|
|
|
props: {
|
2020-10-29 20:12:53 +00:00
|
|
|
title: "Unsaved changes",
|
2020-10-21 17:54:45 +00:00
|
|
|
description:
|
2020-10-29 20:12:53 +00:00
|
|
|
"Do you want to save the changes you made in this recipe?",
|
|
|
|
cancelButtonText: "DISCARD",
|
|
|
|
okButtonText: "SAVE",
|
2020-10-21 17:54:45 +00:00
|
|
|
},
|
|
|
|
}).then((action) => {
|
|
|
|
this.blockModal = false
|
|
|
|
if (action) {
|
2020-11-02 11:36:53 +00:00
|
|
|
this.saveOperation()
|
2020-10-29 20:12:53 +00:00
|
|
|
} else if (action != null) {
|
2020-10-21 17:54:45 +00:00
|
|
|
this.$navigateBack()
|
|
|
|
this.releaseBackEvent()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.$navigateBack()
|
|
|
|
this.releaseBackEvent()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hijackBackEvent() {
|
2020-10-22 18:36:50 +00:00
|
|
|
AndroidApplication.on(
|
|
|
|
AndroidApplication.activityBackPressedEvent,
|
2020-10-21 17:54:45 +00:00
|
|
|
this.backEvent
|
|
|
|
)
|
|
|
|
},
|
|
|
|
releaseBackEvent() {
|
2020-10-22 18:36:50 +00:00
|
|
|
AndroidApplication.off(
|
|
|
|
AndroidApplication.activityBackPressedEvent,
|
2020-10-21 17:54:45 +00:00
|
|
|
this.backEvent
|
|
|
|
)
|
|
|
|
},
|
|
|
|
backEvent(args) {
|
|
|
|
if (this.hasEnoughDetails && !this.blockModal) {
|
|
|
|
args.cancel = true
|
|
|
|
this.navigateBack()
|
|
|
|
}
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
2020-11-02 11:36:53 +00:00
|
|
|
|
|
|
|
// DATA HANDLERS
|
|
|
|
imageHandler() {
|
2020-10-29 20:12:53 +00:00
|
|
|
if (this.recipeContent.imageSrc) {
|
|
|
|
this.blockModal = true
|
|
|
|
this.$showModal(ConfirmDialog, {
|
|
|
|
props: {
|
|
|
|
title: "Recipe photo",
|
|
|
|
cancelButtonText: "REMOVE",
|
|
|
|
okButtonText: "REPLACE PHOTO",
|
|
|
|
},
|
|
|
|
}).then((action) => {
|
|
|
|
this.blockModal = false
|
|
|
|
if (action) {
|
2020-11-02 11:36:53 +00:00
|
|
|
this.imagePicker()
|
2020-10-29 20:12:53 +00:00
|
|
|
} else if (action != null) {
|
2020-11-02 11:36:53 +00:00
|
|
|
this.recipeContent.imageSrc = null
|
2020-10-29 20:12:53 +00:00
|
|
|
this.releaseBackEvent()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
2020-11-02 11:36:53 +00:00
|
|
|
this.imagePicker()
|
2020-10-29 20:12:53 +00:00
|
|
|
}
|
|
|
|
},
|
2020-11-02 11:36:53 +00:00
|
|
|
imagePicker() {
|
2020-10-26 20:49:54 +00:00
|
|
|
const vm = this
|
2020-10-29 20:12:53 +00:00
|
|
|
const mediafilepicker = new Mediafilepicker()
|
|
|
|
mediafilepicker.openImagePicker({
|
|
|
|
android: {
|
|
|
|
isCaptureMood: false, // if true then camera will open directly.
|
|
|
|
isNeedCamera: true,
|
|
|
|
maxNumberFiles: 1,
|
|
|
|
isNeedFolderList: true,
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
|
|
|
})
|
2020-10-29 20:12:53 +00:00
|
|
|
mediafilepicker.on("getFiles", (image) => {
|
2020-11-02 11:36:53 +00:00
|
|
|
vm.recipeContent.imageSrc = image.object.get("results")[0].file
|
2020-10-14 19:32:32 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
addIngredient() {
|
|
|
|
this.recipeContent.ingredients.push({
|
2020-10-21 17:54:45 +00:00
|
|
|
item: "",
|
2020-10-14 19:32:32 +00:00
|
|
|
quantity: null,
|
|
|
|
unit: "unit",
|
|
|
|
})
|
|
|
|
},
|
|
|
|
removeIngredient(index) {
|
|
|
|
this.recipeContent.ingredients.splice(index, 1)
|
|
|
|
},
|
|
|
|
|
|
|
|
addInstruction() {
|
|
|
|
this.recipeContent.instructions.push("")
|
|
|
|
},
|
|
|
|
removeInstruction(index) {
|
|
|
|
this.recipeContent.instructions.splice(index, 1)
|
|
|
|
},
|
|
|
|
|
|
|
|
addNote() {
|
|
|
|
this.recipeContent.notes.push("")
|
|
|
|
},
|
|
|
|
removeNote(index) {
|
|
|
|
this.recipeContent.notes.splice(index, 1)
|
|
|
|
},
|
|
|
|
|
|
|
|
addReference() {
|
|
|
|
this.recipeContent.references.push("")
|
|
|
|
},
|
|
|
|
removeReference(index) {
|
|
|
|
this.recipeContent.references.splice(index, 1)
|
|
|
|
},
|
|
|
|
|
2020-11-02 11:36:53 +00:00
|
|
|
clearEmptyFields() {
|
|
|
|
if (!this.recipeContent.title)
|
|
|
|
this.recipeContent.title = "Untitled Recipe"
|
|
|
|
if (!this.recipeContent.yield.quantity)
|
|
|
|
this.recipeContent.yield.quantity = 1
|
|
|
|
this.recipeContent.ingredients = this.recipeContent.ingredients.filter(
|
|
|
|
(e) => e.item
|
|
|
|
)
|
|
|
|
let vm = this
|
|
|
|
function clearEmpty(arr) {
|
|
|
|
vm.recipeContent[arr] = vm.recipeContent[arr].filter((e) => e)
|
|
|
|
}
|
|
|
|
clearEmpty("instructions")
|
|
|
|
clearEmpty("notes")
|
|
|
|
clearEmpty("references")
|
|
|
|
},
|
|
|
|
saveOperation() {
|
|
|
|
this.imageLoading = true
|
|
|
|
this.clearEmptyFields()
|
|
|
|
this.recipeContent.lastModified = new Date()
|
|
|
|
if (this.recipeContent.imageSrc) {
|
|
|
|
if (this.tempRecipeContent.imageSrc) {
|
|
|
|
if (this.tempRecipeContent.imageSrc !== this.recipeContent.imageSrc) {
|
|
|
|
getFileAccess().deleteFile(this.tempRecipeContent.imageSrc)
|
|
|
|
this.imageSaveOperation()
|
|
|
|
} else this.saveRecipe()
|
|
|
|
} else this.imageSaveOperation()
|
|
|
|
} else if (this.tempRecipeContent.imageSrc) {
|
|
|
|
getFileAccess().deleteFile(this.tempRecipeContent.imageSrc)
|
|
|
|
this.saveRecipe()
|
|
|
|
} else this.saveRecipe()
|
|
|
|
},
|
|
|
|
imageSaveOperation() {
|
|
|
|
let imgSavedToPath = path.join(
|
|
|
|
knownFolders.documents().getFolder("enrecipes").path,
|
|
|
|
`${this.getRandomID()}.jpg`
|
|
|
|
)
|
|
|
|
let workerService = new WorkerService()
|
|
|
|
let ImageProcessor = workerService.initImageProcessor()
|
|
|
|
ImageProcessor.postMessage({
|
|
|
|
imgFile: this.recipeContent.imageSrc,
|
|
|
|
imgSavedToPath,
|
2020-10-21 17:54:45 +00:00
|
|
|
})
|
2020-11-02 11:36:53 +00:00
|
|
|
ImageProcessor.onmessage = ({ data }) => {
|
|
|
|
this.recipeContent.imageSrc = imgSavedToPath
|
|
|
|
this.saveRecipe()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
saveRecipe() {
|
|
|
|
if (this.recipeID) {
|
|
|
|
this.overwriteRecipeAction({
|
|
|
|
index: this.recipeIndex,
|
|
|
|
id: this.recipeID,
|
|
|
|
recipe: this.recipeContent,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.recipeContent.id = this.newRecipeID
|
|
|
|
this.addRecipeAction({
|
|
|
|
id: this.newRecipeID,
|
|
|
|
recipe: this.recipeContent,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
this.imageLoading = false
|
|
|
|
this.$navigateBack()
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
|
|
|
},
|
2020-10-26 20:49:54 +00:00
|
|
|
created() {
|
|
|
|
setTimeout((e) => {
|
|
|
|
this.setCurrentComponentAction("EditRecipe")
|
|
|
|
}, 500)
|
|
|
|
this.title = this.recipeID ? "Edit recipe" : "New recipe"
|
|
|
|
if (this.recipeID) {
|
|
|
|
let recipe = this.recipes.filter((e) => e.id === this.recipeID)[0]
|
2020-10-29 20:12:53 +00:00
|
|
|
Object.assign(this.recipeContent, JSON.parse(JSON.stringify(recipe)))
|
2020-11-02 11:36:53 +00:00
|
|
|
Object.assign(
|
|
|
|
this.tempRecipeContent,
|
|
|
|
JSON.parse(JSON.stringify(this.recipeContent))
|
|
|
|
)
|
2020-10-26 20:49:54 +00:00
|
|
|
} else {
|
2020-10-29 20:12:53 +00:00
|
|
|
Object.assign(
|
|
|
|
this.tempRecipeContent,
|
|
|
|
JSON.parse(JSON.stringify(this.recipeContent))
|
|
|
|
)
|
2020-10-26 20:49:54 +00:00
|
|
|
if (this.selectedCategory)
|
|
|
|
this.recipeContent.category = this.selectedCategory
|
|
|
|
this.newRecipeID = this.getRandomID()
|
|
|
|
}
|
|
|
|
this.hijackBackEvent()
|
|
|
|
},
|
2020-10-14 19:32:32 +00:00
|
|
|
}
|
|
|
|
</script>
|