enrecipes/app/components/EditRecipe.vue

1080 lines
32 KiB
Vue
Raw Normal View History

2020-10-14 19:32:32 +00:00
<template>
2021-06-15 11:04:42 +00:00
<Page @loaded="pgLoad" @unloaded="onPageUnload" actionBarHidden="true">
<GridLayout rows="*, auto" columns="auto, *, auto">
<ScrollView rowSpan="2" colSpan="3" @scroll="!showUndo && svLoad($event)">
2021-04-01 10:55:35 +00:00
<StackLayout padding="0 16 72">
2021-06-18 12:52:03 +00:00
<RLabel
class="pTitle tw tb"
padding="16 0 24"
:text="`${title}` | L"
/>
2021-04-01 10:55:35 +00:00
<Image
2021-06-15 11:04:42 +00:00
margin="0 0 32"
2021-05-22 08:56:31 +00:00
v-if="recipe.image"
:src="recipe.image"
2021-04-01 10:55:35 +00:00
stretch="aspectFit"
class="imgHolder"
:width="screenWidth - 32"
:height="screenWidth - 32"
@tap="imageHandler"
/>
<Button
v-else
2021-06-15 11:04:42 +00:00
margin="0 0 32"
2021-04-01 10:55:35 +00:00
class="ico imgHolder"
fontSize="128"
:width="screenWidth - 32"
:height="screenWidth - 32"
:text="icon.img"
@tap="imageHandler"
/>
<!-- OVERVIEW -->
2021-06-18 12:52:03 +00:00
<StackLayout class="inputC">
<Label class="fLabel" :text="'title' | L" />
2021-03-21 17:02:04 +00:00
<TextField
:hint="'recTitle' | L"
2021-04-12 18:09:48 +00:00
v-model="recipe.title"
2021-03-21 17:02:04 +00:00
@loaded="setInputTypeText($event, 'words')"
/>
</StackLayout>
2021-06-15 11:04:42 +00:00
<RGridLayout :rtl="RTL" class="" columns="*, 8, *">
2021-06-18 12:52:03 +00:00
<StackLayout class="inputC">
<Label class="fLabel" :text="'cui' | L" />
2021-03-21 17:02:04 +00:00
<TextField
2021-06-15 11:04:42 +00:00
@loaded="setGravity"
2021-04-12 18:09:48 +00:00
:text="recipe.cuisine | L"
2021-03-21 17:02:04 +00:00
editable="false"
2021-06-15 11:04:42 +00:00
@focus="!modalOpen && showCuisine(1)"
@tap="showCuisine(0)"
2021-03-21 17:02:04 +00:00
/>
</StackLayout>
2021-06-18 12:52:03 +00:00
<StackLayout class="inputC" col="2">
<Label class="fLabel" :text="'cat' | L" />
2021-03-21 17:02:04 +00:00
<TextField
2021-06-15 11:04:42 +00:00
@loaded="setGravity"
2021-03-21 17:02:04 +00:00
ref="category"
2021-04-12 18:09:48 +00:00
:text="recipe.category | L"
2021-03-21 17:02:04 +00:00
editable="false"
2021-06-15 11:04:42 +00:00
@focus="!modalOpen && showCategories(1)"
@tap="showCategories(0)"
2021-03-21 17:02:04 +00:00
/>
</StackLayout>
2021-06-15 11:04:42 +00:00
</RGridLayout>
2021-06-18 12:52:03 +00:00
<StackLayout class="inputC">
<Label class="fLabel" :text="'ts' | L" />
2021-03-21 17:02:04 +00:00
<TextField
2021-06-15 11:04:42 +00:00
@loaded="setGravity"
2021-04-01 10:55:35 +00:00
:hint="'tsInfo' | L"
2021-03-21 17:02:04 +00:00
autocapitalizationType="words"
ref="tags"
v-model="tags"
@textChange="splitTags"
returnKeyType="next"
/>
</StackLayout>
2021-06-15 11:04:42 +00:00
<RGridLayout :rtl="RTL" columns="*, 8, *">
2021-06-18 12:52:03 +00:00
<StackLayout class="inputC">
<Label class="fLabel" :text="'prepT' | L" />
2021-03-21 17:02:04 +00:00
<TextField
2021-06-15 11:04:42 +00:00
@loaded="setGravity"
2021-03-21 17:02:04 +00:00
:text="timeRequired('prepTime')"
editable="false"
2021-06-15 11:04:42 +00:00
@focus="!modalOpen && setTimeRequired(1, 'prepTime')"
@tap="setTimeRequired(0, 'prepTime')"
2021-03-21 17:02:04 +00:00
/>
</StackLayout>
2021-06-18 12:52:03 +00:00
<StackLayout class="inputC" col="2">
<Label class="fLabel" :text="'cookT' | L" />
2021-03-21 17:02:04 +00:00
<TextField
2021-06-15 11:04:42 +00:00
@loaded="setGravity"
2021-03-21 17:02:04 +00:00
ref="cookTime"
:text="timeRequired('cookTime')"
editable="false"
2021-06-15 11:04:42 +00:00
@focus="!modalOpen && setTimeRequired(1, 'cookTime')"
@tap="setTimeRequired(0, 'cookTime')"
2021-03-21 17:02:04 +00:00
/>
</StackLayout>
2021-06-15 11:04:42 +00:00
</RGridLayout>
<RGridLayout :rtl="RTL" columns="*, 8, *">
2021-06-18 12:52:03 +00:00
<StackLayout class="inputC">
<Label class="fLabel" :text="'yieldQ' | L" />
2021-03-21 17:02:04 +00:00
<TextField
2021-06-15 11:04:42 +00:00
@loaded="setGravity"
2021-03-21 17:02:04 +00:00
ref="yieldQuantity"
2021-05-22 08:56:31 +00:00
v-model="recipe.yieldQuantity"
2021-03-21 17:02:04 +00:00
hint="1"
keyboardType="number"
returnKeyType="next"
/>
</StackLayout>
2021-06-18 12:52:03 +00:00
<StackLayout class="inputC" col="2">
<Label class="fLabel" :text="'yieldU' | L" />
2021-03-21 17:02:04 +00:00
<TextField
2021-06-15 11:04:42 +00:00
@loaded="setGravity"
2021-05-22 08:56:31 +00:00
:text="`${recipe.yieldUnit}` | L"
2021-03-21 17:02:04 +00:00
editable="false"
2021-06-15 11:04:42 +00:00
@focus="!modalOpen && showYieldUnits(1)"
@tap="showYieldUnits(0)"
2021-03-21 17:02:04 +00:00
/>
</StackLayout>
2021-06-15 11:04:42 +00:00
</RGridLayout>
2021-04-01 10:55:35 +00:00
<GridLayout columns="*, 8, *">
2021-06-18 12:52:03 +00:00
<StackLayout class="inputC" :col="RTL ? 2 : 0">
<Label class="fLabel" :text="'Difficulty level' | L" />
2021-03-21 17:02:04 +00:00
<TextField
2021-06-15 11:04:42 +00:00
@loaded="setGravity"
2021-03-21 17:02:04 +00:00
ref="difficultyLevel"
2021-04-12 18:09:48 +00:00
:text="`${recipe.difficulty}` | L"
2021-03-21 17:02:04 +00:00
editable="false"
2021-06-15 11:04:42 +00:00
@focus="!modalOpen && showDifficultyLevel(1)"
@tap="showDifficultyLevel(0)"
2021-03-21 17:02:04 +00:00
/>
</StackLayout>
</GridLayout>
2021-04-01 10:55:35 +00:00
<!-- INGREDIENTS -->
2021-03-21 17:02:04 +00:00
<Label
2021-04-01 10:55:35 +00:00
:text="getTitleCount('ings', 'ingredients')"
2021-06-18 12:52:03 +00:00
padding="0"
class="section t2 tb tw"
2021-03-21 17:02:04 +00:00
/>
2021-06-15 11:04:42 +00:00
<RGridLayout
:rtl="RTL"
2021-04-21 10:31:14 +00:00
columns="auto,8,auto,8,*,auto"
2021-04-12 18:09:48 +00:00
v-for="(ingredient, index) in recipe.ingredients"
2021-04-01 10:55:35 +00:00
:key="'ing' + index"
2021-03-21 17:02:04 +00:00
>
<TextField
2021-04-21 10:31:14 +00:00
width="52"
2021-04-12 18:09:48 +00:00
@loaded="!recipe.ingredients[index].item && focusField($event)"
v-model="recipe.ingredients[index].quantity"
2021-03-21 17:02:04 +00:00
hint="1.00"
keyboardType="number"
returnKeyType="next"
/>
2020-12-29 10:35:19 +00:00
2021-03-21 17:02:04 +00:00
<TextField
2021-04-21 10:31:14 +00:00
width="68"
2021-03-21 17:02:04 +00:00
col="2"
2021-04-12 18:09:48 +00:00
:text="`${recipe.ingredients[index].unit}` | L"
2021-03-21 17:02:04 +00:00
editable="false"
2021-06-15 11:04:42 +00:00
@focus="!modalOpen && showUnits($event, 1, index)"
@tap="showUnits($event, 0, index)"
2021-03-21 17:02:04 +00:00
/>
2020-12-29 10:35:19 +00:00
2021-03-21 17:02:04 +00:00
<TextField
ref="ingredient"
@loaded="setInputTypeText($event, 'sentence')"
col="4"
2021-04-12 18:09:48 +00:00
v-model="recipe.ingredients[index].item"
2021-03-21 17:02:04 +00:00
:hint="`${$options.filters.L('it')} ${index + 1}`"
@returnPress="
2021-04-12 18:09:48 +00:00
index + 1 == recipe.ingredients.length && addIngredient()
2021-03-21 17:02:04 +00:00
"
/>
2021-04-01 10:55:35 +00:00
<Button
2021-04-21 10:31:14 +00:00
col="5"
2021-06-18 12:52:03 +00:00
class="ico si"
2021-03-21 17:02:04 +00:00
:text="icon.x"
@tap="removeIngredient(index)"
/>
2021-06-15 11:04:42 +00:00
</RGridLayout>
2021-04-01 10:55:35 +00:00
<Button
2021-06-18 12:52:03 +00:00
class="text tb big hal fb"
2021-06-15 11:04:42 +00:00
:class="{ r: RTL }"
2021-04-01 10:55:35 +00:00
:text="'aIngBtn' | L"
2021-03-21 17:02:04 +00:00
@tap="addIngredient()"
/>
2021-04-01 10:55:35 +00:00
<!-- INSTRUCTIONS -->
<Label
:text="getTitleCount('inss', 'instructions')"
2021-06-18 12:52:03 +00:00
padding="0"
class="section t2 tb tw"
2021-04-01 10:55:35 +00:00
/>
2021-06-15 11:04:42 +00:00
<RGridLayout
:rtl="RTL"
2021-04-21 10:31:14 +00:00
columns="*,auto"
2021-04-12 18:09:48 +00:00
v-for="(instruction, index) in recipe.instructions"
2021-04-01 10:55:35 +00:00
:key="'ins' + index"
2021-03-21 17:02:04 +00:00
>
<TextView
@loaded="focusField($event, 'multiLine')"
:hint="`${$options.filters.L('stp')} ${index + 1}`"
2021-04-12 18:09:48 +00:00
v-model="recipe.instructions[index]"
2021-03-21 17:02:04 +00:00
/>
2021-04-01 10:55:35 +00:00
<Button
2021-04-21 10:31:14 +00:00
col="1"
2021-06-18 12:52:03 +00:00
class="ico si"
2021-03-21 17:02:04 +00:00
:text="icon.x"
@tap="removeInstruction(index)"
/>
2021-06-15 11:04:42 +00:00
</RGridLayout>
2021-04-01 10:55:35 +00:00
<Button
2021-06-18 12:52:03 +00:00
class="text tb big hal fb"
2021-06-15 11:04:42 +00:00
:class="{ r: RTL }"
2021-04-01 10:55:35 +00:00
:text="'aStpBtn' | L"
2021-03-21 17:02:04 +00:00
@tap="addInstruction"
/>
2021-04-01 10:55:35 +00:00
<!-- COMBINATIONS -->
<Label
:text="getTitleCount('cmbs', 'combinations')"
2021-06-18 12:52:03 +00:00
padding="0"
class="section t2 tb tw"
2021-04-01 10:55:35 +00:00
/>
2021-06-15 11:04:42 +00:00
<RGridLayout
:rtl="RTL"
2021-04-21 10:31:14 +00:00
columns="*,auto"
2021-04-12 18:09:48 +00:00
v-for="(combination, index) in recipe.combinations"
2021-04-01 10:55:35 +00:00
:key="'cmbs' + index"
2021-03-21 17:02:04 +00:00
>
2021-04-01 10:55:35 +00:00
<TextField
2021-06-15 11:04:42 +00:00
@loaded="setGravity"
2021-04-01 10:55:35 +00:00
class="combField"
:text="getCombinationTitle(combination)"
editable="false"
2021-03-21 17:02:04 +00:00
/>
2021-04-01 10:55:35 +00:00
<Button
2021-04-21 10:31:14 +00:00
col="1"
2021-06-18 12:52:03 +00:00
class="ico si"
2021-03-21 17:02:04 +00:00
:text="icon.x"
2021-04-01 10:55:35 +00:00
@tap="removeCombination(combination)"
2021-03-21 17:02:04 +00:00
/>
2021-06-15 11:04:42 +00:00
</RGridLayout>
2021-04-01 10:55:35 +00:00
<Button
2021-06-18 12:52:03 +00:00
class="text tb big hal fb"
2021-06-15 11:04:42 +00:00
:class="{ r: RTL }"
2021-04-01 10:55:35 +00:00
:text="'addCmbBtn' | L"
@tap="showCombinations"
2021-03-21 17:02:04 +00:00
/>
2021-04-01 10:55:35 +00:00
<!-- NOTES -->
2021-06-18 12:52:03 +00:00
<Label
:text="getTitleCount('nos', 'notes')"
padding="0"
class="section t2 tb tw"
/>
2021-06-15 11:04:42 +00:00
<RGridLayout
:rtl="RTL"
columns="*, auto"
2021-04-12 18:09:48 +00:00
v-for="(note, index) in recipe.notes"
2021-04-01 10:55:35 +00:00
:key="'nos' + index"
2021-03-21 17:02:04 +00:00
>
2021-04-01 10:55:35 +00:00
<TextView
@loaded="focusField($event, 'multiLine')"
:hint="`${$options.filters.L('no')} ${index + 1}`"
2021-04-12 18:09:48 +00:00
v-model="recipe.notes[index]"
2021-03-21 17:02:04 +00:00
/>
2021-04-01 10:55:35 +00:00
<Button
2021-04-21 10:31:14 +00:00
col="1"
2021-06-18 12:52:03 +00:00
class="ico si"
2021-03-21 17:02:04 +00:00
:text="icon.x"
2021-04-01 10:55:35 +00:00
@tap="removeNote(index)"
2021-03-21 17:02:04 +00:00
/>
2021-06-15 11:04:42 +00:00
</RGridLayout>
<Button
2021-06-18 12:52:03 +00:00
class="text tb big hal fb"
2021-06-15 11:04:42 +00:00
:class="{ r: RTL }"
:text="'aNoBtn' | L"
@tap="addNote"
/>
2021-03-21 17:02:04 +00:00
</StackLayout>
2021-04-01 10:55:35 +00:00
</ScrollView>
2021-06-15 11:04:42 +00:00
<RGridLayout
:rtl="RTL && hasChanges"
2021-04-01 10:55:35 +00:00
row="1"
2021-06-15 11:04:42 +00:00
@loaded="abLoad"
2021-05-22 08:56:31 +00:00
:hidden="showUndo"
2021-04-01 10:55:35 +00:00
class="appbar"
2021-06-15 11:04:42 +00:00
:col="RTL ? (hasChanges ? 0 : 2) : 0"
:colSpan="hasChanges ? 3 : 1"
2021-04-01 10:55:35 +00:00
columns="auto, *, auto"
>
2021-06-15 11:04:42 +00:00
<Button
2021-06-20 17:54:47 +00:00
class="ico end"
2021-06-15 11:04:42 +00:00
:class="{ f: RTL }"
:text="icon.back"
@tap="navigateBack(0)"
/>
2021-04-01 10:55:35 +00:00
<Button
2021-05-22 08:56:31 +00:00
v-if="hasChanges && !saving"
2021-06-20 17:54:47 +00:00
class="ico fab end"
2021-05-22 08:56:31 +00:00
:text="icon.save"
2021-04-01 10:55:35 +00:00
col="2"
2021-06-15 11:04:42 +00:00
@tap="saveOperation"
2021-04-01 10:55:35 +00:00
/>
2021-06-20 17:54:47 +00:00
<ActivityIndicator class="end" col="2" v-if="saving" :busy="saving" />
2021-06-15 11:04:42 +00:00
</RGridLayout>
2021-05-25 14:32:53 +00:00
<SnackBar
:hidden="!showUndo"
colSpan="2"
:count="countdown"
:msg="snackMsg"
:undo="undoDel"
2021-06-15 11:04:42 +00:00
:action="hideBar"
:onload="sbLoad"
2021-05-25 14:32:53 +00:00
/>
2021-06-18 12:52:03 +00:00
<Label
rowSpan="2"
colSpan="3"
class="edge hal"
:class="{ 'f r': RTL }"
@swipe="swipeBack($event, navigateBack)"
/>
<Label
rowSpan="2"
colSpan="3"
class="edge har rtl f"
@swipe="swipeBack($event, navigateBack)"
/>
2021-04-01 10:55:35 +00:00
</GridLayout>
2021-03-21 17:02:04 +00:00
</Page>
2020-10-14 19:32:32 +00:00
</template>
<script>
import {
AndroidApplication,
2020-11-10 18:28:48 +00:00
File,
getFileAccess,
2020-11-10 18:28:48 +00:00
ImageSource,
knownFolders,
2020-11-10 18:28:48 +00:00
path,
Screen,
2020-11-02 11:36:53 +00:00
Utils,
2021-03-21 17:02:04 +00:00
Observable,
2021-06-15 11:04:42 +00:00
Frame,
Application,
2021-03-21 17:02:04 +00:00
} from "@nativescript/core";
2021-06-15 11:04:42 +00:00
import { getString, setString } from "@nativescript/core/application-settings";
2021-03-21 17:02:04 +00:00
import { localize } from "@nativescript/localize";
2021-04-12 18:09:48 +00:00
import { ImageCropper } from "nativescript-imagecropper";
2021-03-21 17:02:04 +00:00
import { mapState, mapActions } from "vuex";
2021-06-15 11:04:42 +00:00
import EnRecipes from "./EnRecipes.vue";
2021-05-25 14:32:53 +00:00
import Action from "./modals/Action";
import ActionWithSearch from "./modals/ActionWithSearch";
import Confirm from "./modals/Confirm";
import Prompt from "./modals/Prompt";
import TimePickerHM from "./modals/TimePickerHM";
2021-03-21 17:02:04 +00:00
import * as utils from "~/shared/utils";
2021-05-25 14:32:53 +00:00
import SnackBar from "./sub/SnackBar";
2021-06-15 11:04:42 +00:00
let barTimer;
2020-10-14 19:32:32 +00:00
export default {
2021-05-25 14:32:53 +00:00
components: {
SnackBar,
},
2021-06-15 11:04:42 +00:00
props: ["recipeID", "filterFavourites", "filterTrylater", "dupRecipe"],
2020-10-14 19:32:32 +00:00
data() {
return {
2021-01-13 05:02:48 +00:00
title: "newRec",
2021-04-12 18:09:48 +00:00
recipe: {
2021-06-15 11:04:42 +00:00
id: this.recipeID || utils.getRandomID(0),
2021-05-22 08:56:31 +00:00
image: null,
title: null,
2020-12-29 10:35:19 +00:00
cuisine: "Undefined",
category: "Undefined",
2020-12-29 10:35:19 +00:00
tags: [],
prepTime: "00:00",
cookTime: "00:00",
2021-05-22 08:56:31 +00:00
yieldQuantity: null,
yieldUnit: "Serving",
2020-12-29 10:35:19 +00:00
difficulty: "Easy",
rating: 0,
2020-11-02 11:36:53 +00:00
ingredients: [],
instructions: [],
2020-11-15 10:51:10 +00:00
combinations: [],
2020-11-28 19:21:57 +00:00
notes: [],
2021-05-22 08:56:31 +00:00
favorite: 0,
tried: 1,
2020-11-02 11:36:53 +00:00
lastTried: null,
2020-10-26 20:49:54 +00:00
lastModified: null,
2020-12-29 10:35:19 +00:00
created: null,
2020-10-26 20:49:54 +00:00
},
2021-04-12 18:09:48 +00:00
tempRecipe: {},
2020-12-29 10:35:19 +00:00
tags: undefined,
2021-06-15 11:04:42 +00:00
modalOpen: 0,
saving: 0,
2020-11-10 18:28:48 +00:00
cacheImagePath: null,
2021-06-18 18:37:01 +00:00
unLinkCombs: [],
2021-03-21 17:02:04 +00:00
difficultyLevels: ["Easy", "Moderate", "Challenging"],
2021-04-01 10:55:35 +00:00
appbar: null,
2021-06-15 11:04:42 +00:00
snackbar: null,
2021-04-01 10:55:35 +00:00
scrollPos: 1,
countdown: 5,
snackMsg: null,
2021-06-15 11:04:42 +00:00
showUndo: 0,
undo: 0,
2021-03-21 17:02:04 +00:00
};
2020-10-14 19:32:32 +00:00
},
computed: {
2021-03-21 17:02:04 +00:00
...mapState([
"icon",
"units",
"yieldUnits",
"recipes",
"cuisines",
"categories",
2021-06-15 11:04:42 +00:00
"selCuisine",
"selCategory",
"selTag",
"theme",
"RTL",
2021-03-21 17:02:04 +00:00
]),
2020-10-14 19:32:32 +00:00
screenWidth() {
2021-03-21 17:02:04 +00:00
return Screen.mainScreen.widthDIPs;
2020-10-14 19:32:32 +00:00
},
2020-11-10 18:28:48 +00:00
hasChanges() {
2021-06-15 11:04:42 +00:00
return JSON.stringify(this.recipe) != JSON.stringify(this.tempRecipe);
},
hasBackStack() {
return Frame.topmost().backStack.length;
2020-10-14 19:32:32 +00:00
},
},
methods: {
2021-06-18 18:37:01 +00:00
...mapActions(["addR", "addLI", "unLinkCs"]),
2021-06-15 11:04:42 +00:00
pgLoad({ object }) {
2021-05-25 14:32:53 +00:00
object.bindingContext = new Observable();
2021-04-12 18:09:48 +00:00
this.hijackBackEvent();
},
2021-01-13 05:02:48 +00:00
onPageUnload() {
2021-03-21 17:02:04 +00:00
this.releaseBackEvent();
2021-04-01 10:55:35 +00:00
},
2021-06-15 11:04:42 +00:00
abLoad(args) {
this.appbar = args.object;
},
sbLoad({ object }) {
this.snackbar = object;
2021-04-01 10:55:35 +00:00
},
2021-06-15 11:04:42 +00:00
svLoad(args) {
2021-04-01 10:55:35 +00:00
let scrollUp;
let y = args.scrollY;
if (y) {
scrollUp = y < this.scrollPos;
this.scrollPos = Math.abs(y);
let ab = this.appbar.translateY;
2021-06-18 12:52:03 +00:00
if (!scrollUp && ab == 0) this.animateBar(this.appbar, 0);
else if (scrollUp && ab == 64) {
2021-04-01 10:55:35 +00:00
Utils.ad.dismissSoftInput();
2021-06-18 12:52:03 +00:00
this.animateBar(this.appbar, 1);
2021-04-01 10:55:35 +00:00
}
}
2021-01-13 05:02:48 +00:00
},
2021-04-12 18:09:48 +00:00
// PHOTO HANDLERS
imageHandler() {
2021-06-15 11:04:42 +00:00
this.clearEmptyFields(1);
2021-05-22 08:56:31 +00:00
if (this.recipe.image) {
2021-06-15 11:04:42 +00:00
this.modalOpen = 1;
2021-05-25 14:32:53 +00:00
this.$showModal(Action, {
2021-04-12 18:09:48 +00:00
props: {
title: "recPic",
2021-04-14 09:27:40 +00:00
list: ["aap", "rp"],
2021-04-12 18:09:48 +00:00
},
}).then((action) => {
2021-06-15 11:04:42 +00:00
this.modalOpen = 0;
2021-04-14 09:27:40 +00:00
switch (action) {
case "aap":
this.imagePicker();
break;
case "rp":
2021-05-22 08:56:31 +00:00
this.recipe.image = null;
2021-04-14 09:27:40 +00:00
break;
}
2021-04-12 18:09:48 +00:00
});
} else this.imagePicker();
2020-11-02 11:36:53 +00:00
},
2021-04-12 18:09:48 +00:00
imagePicker() {
2021-06-15 11:04:42 +00:00
let aT = this.theme;
2021-04-12 18:09:48 +00:00
utils.getRecipePhoto().then((uri) => {
if (uri != null) {
this.cacheImagePath = path.join(
knownFolders.temp().path,
2021-06-15 11:04:42 +00:00
`${utils.getRandomID(0)}.jpg`
2021-03-21 17:02:04 +00:00
);
2021-06-18 18:37:01 +00:00
utils
.copyPhotoToCache(uri.toString(), this.cacheImagePath)
.then((imgPath) => {
if (imgPath) {
ImageSource.fromFile(imgPath).then((image) => {
ImageCropper.prototype
.show(
image,
{
width: 1080,
height: 1080,
},
{
hideBottomControls: true,
toolbarTitle: localize("cPic"),
statusBarColor: "#ff5200",
toolbarTextColor: aT == "Light" ? "#212529" : "#f1f3f5",
toolbarColor:
aT == "Light"
? "#f1f3f5"
: aT == "Dark"
? "#212529"
: "#000000",
cropFrameColor: "#ff5200",
}
)
.then((cropped) => {
cropped.image.saveToFile(this.cacheImagePath, "jpg", 75);
this.recipe.image = this.cacheImagePath;
});
});
}
});
2020-10-21 17:54:45 +00:00
}
2021-03-21 17:02:04 +00:00
});
2020-10-14 19:32:32 +00:00
},
2021-06-15 11:04:42 +00:00
createDupImage() {
if (this.recipe.image) {
let cachePath = path.join(
knownFolders.temp().path,
`${utils.getRandomID(0)}.jpg`
);
utils.copyPhotoToCache(this.recipe.image, cachePath).then((imgPath) => {
if (imgPath) this.recipe.image = imgPath;
});
}
},
2021-04-12 18:09:48 +00:00
2020-11-02 11:36:53 +00:00
// DATA LIST
2021-03-21 17:02:04 +00:00
showCuisine(focus) {
2021-06-15 11:04:42 +00:00
this.modalOpen = 1;
2021-05-25 14:32:53 +00:00
this.$showModal(Action, {
2020-12-29 10:35:19 +00:00
props: {
2021-01-13 05:02:48 +00:00
title: "cui",
2020-12-29 10:35:19 +00:00
list: this.cuisines,
2021-01-13 05:02:48 +00:00
action: "aNBtn",
2021-06-15 11:04:42 +00:00
selected: this.recipe.cuisine,
2020-12-29 10:35:19 +00:00
},
2021-03-21 17:02:04 +00:00
}).then((action) => {
if (action == "aNBtn") {
2021-05-25 14:32:53 +00:00
this.$showModal(Prompt, {
2020-12-29 10:35:19 +00:00
props: {
2021-01-13 05:02:48 +00:00
title: "newCui",
action: "aBtn",
2020-12-29 10:35:19 +00:00
},
2021-03-21 17:02:04 +00:00
}).then((item) => {
2021-06-15 11:04:42 +00:00
this.modalOpen = 0;
2021-03-21 17:02:04 +00:00
if (item.length) {
2021-04-12 18:09:48 +00:00
this.recipe.cuisine = item;
2021-06-18 18:37:01 +00:00
this.addLI({
2020-12-29 10:35:19 +00:00
item,
2021-03-21 17:02:04 +00:00
listName: "cuisines",
});
2021-06-15 11:04:42 +00:00
if (focus) this.autoFocusField("category", 0);
2020-12-29 10:35:19 +00:00
}
2021-03-21 17:02:04 +00:00
});
2020-12-29 10:35:19 +00:00
} else {
2021-06-15 11:04:42 +00:00
this.modalOpen = 0;
2021-04-12 18:09:48 +00:00
if (action) {
this.recipe.cuisine = action;
2021-06-15 11:04:42 +00:00
if (focus) this.autoFocusField("category", 0);
2021-04-12 18:09:48 +00:00
} else
this.cuisines.includes(this.recipe.cuisine)
2021-06-18 18:37:01 +00:00
? null
2021-04-12 18:09:48 +00:00
: (this.recipe.cuisine = "Undefined");
2020-12-29 10:35:19 +00:00
}
2021-03-21 17:02:04 +00:00
});
2020-12-29 10:35:19 +00:00
},
2021-03-21 17:02:04 +00:00
showCategories(focus) {
2021-06-15 11:04:42 +00:00
this.modalOpen = 1;
2021-05-25 14:32:53 +00:00
this.$showModal(Action, {
2020-10-21 17:54:45 +00:00
props: {
2021-01-13 05:02:48 +00:00
title: "cat",
2020-12-29 10:35:19 +00:00
list: this.categories,
2021-01-13 05:02:48 +00:00
action: "aNBtn",
2021-06-15 11:04:42 +00:00
selected: this.recipe.category,
2020-10-21 17:54:45 +00:00
},
2021-03-21 17:02:04 +00:00
}).then((action) => {
if (action == "aNBtn") {
2021-05-25 14:32:53 +00:00
this.$showModal(Prompt, {
2020-10-21 17:54:45 +00:00
props: {
2021-01-13 05:02:48 +00:00
title: "nwCat",
action: "aBtn",
2020-10-21 17:54:45 +00:00
},
2021-03-21 17:02:04 +00:00
}).then((item) => {
2021-06-15 11:04:42 +00:00
this.modalOpen = 0;
2021-03-21 17:02:04 +00:00
if (item.length) {
2021-04-12 18:09:48 +00:00
this.recipe.category = item;
2021-06-18 18:37:01 +00:00
this.addLI({
2020-12-29 10:35:19 +00:00
item,
2021-03-21 17:02:04 +00:00
listName: "categories",
});
2021-06-15 11:04:42 +00:00
if (focus) this.autoFocusField("tags", 1);
2020-10-21 17:54:45 +00:00
}
2021-03-21 17:02:04 +00:00
});
} else {
2021-06-15 11:04:42 +00:00
this.modalOpen = 0;
2021-04-12 18:09:48 +00:00
if (action) {
this.recipe.category = action;
2021-06-15 11:04:42 +00:00
if (focus) this.autoFocusField("tags", 1);
2021-04-12 18:09:48 +00:00
} else
this.categories.includes(this.recipe.category)
2021-06-18 18:37:01 +00:00
? null
2021-04-12 18:09:48 +00:00
: (this.recipe.category = "Undefined");
2020-10-14 19:32:32 +00:00
}
2021-03-21 17:02:04 +00:00
});
},
2021-03-21 17:02:04 +00:00
showYieldUnits(focus) {
2021-06-15 11:04:42 +00:00
this.modalOpen = 1;
2021-05-25 14:32:53 +00:00
this.$showModal(Action, {
2020-11-02 11:36:53 +00:00
props: {
2021-01-13 05:02:48 +00:00
title: "yieldU",
2020-12-29 10:35:19 +00:00
list: this.yieldUnits,
2021-01-13 05:02:48 +00:00
action: "aNBtn",
2021-06-15 11:04:42 +00:00
selected: this.recipe.yieldUnit,
2020-11-02 11:36:53 +00:00
},
2021-03-21 17:02:04 +00:00
}).then((action) => {
if (action == "aNBtn") {
2021-05-25 14:32:53 +00:00
this.$showModal(Prompt, {
2020-11-02 11:36:53 +00:00
props: {
2021-01-13 05:02:48 +00:00
title: "nwYiU",
action: "aBtn",
2020-11-02 11:36:53 +00:00
},
2021-03-21 17:02:04 +00:00
}).then((item) => {
2021-06-15 11:04:42 +00:00
this.modalOpen = 0;
2021-03-21 17:02:04 +00:00
if (item.length) {
2021-05-22 08:56:31 +00:00
this.recipe.yieldUnit = item;
2021-06-18 18:37:01 +00:00
this.addLI({
2020-12-29 10:35:19 +00:00
item,
2021-03-21 17:02:04 +00:00
listName: "yieldUnits",
});
2021-06-15 11:04:42 +00:00
if (focus) this.autoFocusField("difficultyLevel", 0);
2020-11-02 11:36:53 +00:00
}
2021-03-21 17:02:04 +00:00
});
2020-12-29 10:35:19 +00:00
} else {
2021-06-15 11:04:42 +00:00
this.modalOpen = 0;
2021-04-12 18:09:48 +00:00
if (action) {
2021-05-22 08:56:31 +00:00
this.recipe.yieldUnit = action;
2021-06-15 11:04:42 +00:00
if (focus) this.autoFocusField("difficultyLevel", 0);
2021-04-12 18:09:48 +00:00
} else
2021-05-22 08:56:31 +00:00
this.yieldUnits.includes(this.recipe.yieldUnit)
2021-06-18 18:37:01 +00:00
? null
2021-05-22 08:56:31 +00:00
: (this.recipe.yieldUnit = "Serving");
2020-12-29 10:35:19 +00:00
}
2021-03-21 17:02:04 +00:00
});
2020-12-29 10:35:19 +00:00
},
2021-03-21 17:02:04 +00:00
showDifficultyLevel(focus) {
2021-06-15 11:04:42 +00:00
this.modalOpen = 1;
2021-05-25 14:32:53 +00:00
this.$showModal(Action, {
2020-12-29 10:35:19 +00:00
props: {
title: "Difficulty level",
list: this.difficultyLevels,
2021-06-15 11:04:42 +00:00
selected: this.recipe.difficulty,
2020-12-29 10:35:19 +00:00
},
2021-03-21 17:02:04 +00:00
}).then((action) => {
2021-06-15 11:04:42 +00:00
this.modalOpen = 0;
2021-03-21 17:02:04 +00:00
if (action) {
2021-04-12 18:09:48 +00:00
this.recipe.difficulty = action;
2021-03-21 17:02:04 +00:00
if (focus) this.addIngredient();
2021-04-12 18:09:48 +00:00
} else
this.difficultyLevels.includes(this.recipe.difficulty)
2021-06-18 18:37:01 +00:00
? null
2021-04-12 18:09:48 +00:00
: (this.recipe.difficulty = "Easy");
2021-03-21 17:02:04 +00:00
});
2020-11-02 11:36:53 +00:00
},
2021-03-21 17:02:04 +00:00
showUnits(e, focus, index) {
2021-06-15 11:04:42 +00:00
this.modalOpen = 1;
2021-05-25 14:32:53 +00:00
this.$showModal(Action, {
2020-11-02 11:36:53 +00:00
props: {
2021-01-13 05:02:48 +00:00
title: "Unit",
2020-12-29 10:35:19 +00:00
list: this.units,
2021-01-13 05:02:48 +00:00
action: "aNBtn",
2021-06-15 11:04:42 +00:00
selected: this.recipe.ingredients[index].unit,
2020-11-02 11:36:53 +00:00
},
2021-03-21 17:02:04 +00:00
}).then((action) => {
if (action == "aNBtn") {
2021-05-25 14:32:53 +00:00
this.$showModal(Prompt, {
2020-12-29 10:35:19 +00:00
props: {
2021-01-13 05:02:48 +00:00
title: "newUnit",
action: "aBtn",
2020-12-29 10:35:19 +00:00
},
2021-03-21 17:02:04 +00:00
}).then((item) => {
2021-06-15 11:04:42 +00:00
this.modalOpen = 0;
2021-03-21 17:02:04 +00:00
if (item.length) {
2021-04-12 18:09:48 +00:00
this.recipe.ingredients[index].unit = item;
2021-06-18 18:37:01 +00:00
this.addLI({
2020-12-29 10:35:19 +00:00
item,
2021-03-21 17:02:04 +00:00
listName: "units",
});
2021-04-12 18:09:48 +00:00
if (focus && this.recipe.ingredients.length - 1 === index)
2021-03-21 17:02:04 +00:00
this.autoFocusRefField("ingredient", index);
2020-11-15 21:13:06 +00:00
}
2021-03-21 17:02:04 +00:00
});
2021-04-12 18:09:48 +00:00
} else {
2021-06-15 11:04:42 +00:00
this.modalOpen = 0;
2021-04-12 18:09:48 +00:00
if (action) {
this.recipe.ingredients[index].unit = action;
if (focus && this.recipe.ingredients.length - 1 === index)
this.autoFocusRefField("ingredient", index);
}
2020-11-11 13:50:33 +00:00
}
2021-03-21 17:02:04 +00:00
});
},
2021-04-12 18:09:48 +00:00
showCombinations() {
Utils.ad.dismissSoftInput();
2021-06-15 11:04:42 +00:00
this.modalOpen = 1;
2021-04-12 18:09:48 +00:00
let existingCombinations = [...this.recipe.combinations, this.recipe.id];
let filteredRecipes = this.recipes.filter(
(e) => !existingCombinations.includes(e.id)
2021-03-21 17:02:04 +00:00
);
2021-05-25 14:32:53 +00:00
this.$showModal(ActionWithSearch, {
2020-11-06 09:07:41 +00:00
props: {
2021-04-12 18:09:48 +00:00
title: "selRec",
recipes: filteredRecipes,
2020-11-06 09:07:41 +00:00
},
2021-04-12 18:09:48 +00:00
}).then((res) => {
2021-06-15 11:04:42 +00:00
this.modalOpen = 0;
2021-04-12 18:09:48 +00:00
if (res) this.recipe.combinations.push(res);
2021-03-21 17:02:04 +00:00
});
},
2021-04-12 18:09:48 +00:00
2020-11-10 18:28:48 +00:00
// INPUT FIELD HANDLERS
2020-10-14 19:32:32 +00:00
addIngredient() {
2021-04-12 18:09:48 +00:00
let ingredients = this.recipe.ingredients;
2021-03-21 17:02:04 +00:00
let unit = ingredients.length
? ingredients[ingredients.length - 1].unit
: "unit";
2021-04-12 18:09:48 +00:00
this.recipe.ingredients.push({
2020-10-21 17:54:45 +00:00
item: "",
2020-10-14 19:32:32 +00:00
quantity: null,
2020-12-29 10:35:19 +00:00
unit,
2021-03-21 17:02:04 +00:00
});
},
removeIngredient(index) {
2021-06-15 11:04:42 +00:00
this.modalOpen = 1;
2021-04-12 18:09:48 +00:00
if (this.recipe.ingredients[index].item.length) {
let item = this.recipe.ingredients[index];
this.recipe.ingredients.splice(index, 1);
2021-04-01 10:55:35 +00:00
this.showUndoBar("rmIng").then(
2021-04-12 18:09:48 +00:00
(res) => res && this.recipe.ingredients.splice(index, 0, item)
2021-04-01 10:55:35 +00:00
);
2020-12-29 10:35:19 +00:00
} else {
2021-04-12 18:09:48 +00:00
this.recipe.ingredients.splice(index, 1);
2020-12-29 10:35:19 +00:00
}
2021-06-15 11:04:42 +00:00
setTimeout(() => (this.modalOpen = 0), 200);
2020-10-14 19:32:32 +00:00
},
addInstruction() {
2021-04-12 18:09:48 +00:00
this.recipe.instructions.push("");
2021-03-21 17:02:04 +00:00
},
removeInstruction(index) {
2021-04-12 18:09:48 +00:00
if (this.recipe.instructions[index].length) {
let item = this.recipe.instructions[index];
this.recipe.instructions.splice(index, 1);
2021-04-01 10:55:35 +00:00
this.showUndoBar("rmIns").then(
2021-04-12 18:09:48 +00:00
(res) => res && this.recipe.instructions.splice(index, 0, item)
2021-04-01 10:55:35 +00:00
);
2021-04-12 18:09:48 +00:00
} else this.recipe.instructions.splice(index, 1);
2020-10-14 19:32:32 +00:00
},
2021-01-13 05:02:48 +00:00
addNote() {
2021-04-12 18:09:48 +00:00
this.recipe.notes.push("");
2021-03-21 17:02:04 +00:00
},
removeNote(index) {
2021-04-12 18:09:48 +00:00
if (this.recipe.notes[index].length) {
let item = this.recipe.notes[index];
this.recipe.notes.splice(index, 1);
2021-04-01 10:55:35 +00:00
this.showUndoBar("rmN").then((res) =>
2021-04-12 18:09:48 +00:00
this.recipe.notes.splice(index, 0, item)
2021-04-01 10:55:35 +00:00
);
2021-04-12 18:09:48 +00:00
} else this.recipe.notes.splice(index, 1);
2021-01-13 05:02:48 +00:00
},
2021-03-21 17:02:04 +00:00
getCombinationTitle(id) {
return this.recipes.filter((e) => e.id === id)[0].title;
2020-11-15 10:51:10 +00:00
},
2021-03-21 17:02:04 +00:00
removeCombination(id) {
2021-04-12 18:09:48 +00:00
let index = this.recipe.combinations.indexOf(id);
this.recipe.combinations.splice(index, 1);
2021-06-18 18:37:01 +00:00
this.unLinkCombs.push(id);
2021-04-01 10:55:35 +00:00
this.showUndoBar("rmCmb").then((res) =>
2021-04-12 18:09:48 +00:00
this.recipe.combinations.splice(index, 0, id)
2021-04-01 10:55:35 +00:00
);
2020-11-15 10:51:10 +00:00
},
2021-04-12 18:09:48 +00:00
2020-11-10 18:28:48 +00:00
// SAVE OPERATION
2021-04-01 10:55:35 +00:00
clearEmptyFields(bool) {
2021-04-12 18:09:48 +00:00
if (!this.recipe.title && !bool) this.recipe.title = localize("untRec");
2021-05-22 08:56:31 +00:00
if (!this.recipe.yieldQuantity) this.recipe.yieldQuantity = 1;
2021-04-12 18:09:48 +00:00
this.recipe.ingredients = this.recipe.ingredients.filter((e) => e.item);
2021-03-21 17:02:04 +00:00
let vm = this;
2021-03-21 17:02:04 +00:00
function clearEmpty(arr) {
2021-04-12 18:09:48 +00:00
vm.recipe[arr] = vm.recipe[arr].filter((e) => e);
2020-11-02 11:36:53 +00:00
}
2021-03-21 17:02:04 +00:00
clearEmpty("instructions");
clearEmpty("notes");
2020-11-02 11:36:53 +00:00
},
saveOperation() {
2021-06-15 11:04:42 +00:00
this.saving = this.modalOpen = 1;
2021-03-21 17:02:04 +00:00
this.clearEmptyFields();
2021-05-22 08:56:31 +00:00
this.recipe.lastModified = new Date().getTime();
2021-06-15 11:04:42 +00:00
setString("previousCuisine", this.recipe.cuisine);
setString("previousCategory", this.recipe.category);
setString("previousYieldUnit", this.recipe.yieldUnit);
2021-03-21 17:02:04 +00:00
if (this.cacheImagePath) {
let recipeImage = path.join(
knownFolders.documents().getFolder("EnRecipes").getFolder("Images")
.path,
2021-06-15 11:04:42 +00:00
`${utils.getRandomID(0)}.jpg`
2021-03-21 17:02:04 +00:00
);
let binarySource = File.fromPath(this.cacheImagePath).readSync();
File.fromPath(recipeImage).writeSync(binarySource);
2021-05-22 08:56:31 +00:00
this.recipe.image = recipeImage;
2021-04-21 10:31:14 +00:00
knownFolders.temp().clear();
2020-11-10 18:28:48 +00:00
}
2021-05-22 08:56:31 +00:00
if (this.recipe.image) {
2021-03-21 17:02:04 +00:00
if (
2021-05-22 08:56:31 +00:00
this.tempRecipe.image &&
this.tempRecipe.image !== this.recipe.image
2021-03-21 17:02:04 +00:00
) {
2021-05-22 08:56:31 +00:00
getFileAccess().deleteFile(this.tempRecipe.image);
2020-11-10 18:28:48 +00:00
}
2021-05-22 08:56:31 +00:00
} else if (this.tempRecipe.image) {
getFileAccess().deleteFile(this.tempRecipe.image);
}
2021-06-18 18:37:01 +00:00
this.unLinkCs({
2020-11-15 10:51:10 +00:00
id: this.recipeID,
2021-06-18 18:37:01 +00:00
combs: this.unLinkCombs,
2021-03-21 17:02:04 +00:00
});
this.saveRecipe();
2020-11-02 11:36:53 +00:00
},
saveRecipe() {
2021-06-18 18:37:01 +00:00
this.addR(this.recipe);
2021-06-15 11:04:42 +00:00
this.saving = 0;
this.dupRecipe
? this.$navigateTo(EnRecipes, {
clearHistory: true,
animated: false,
})
: this.goBackAction(0);
2021-04-12 18:09:48 +00:00
},
// UNDO OPERATION
showUndoBar(message) {
2021-06-15 11:04:42 +00:00
clearInterval(barTimer);
2021-04-12 18:09:48 +00:00
return new Promise((resolve, reject) => {
2021-06-15 11:04:42 +00:00
this.animateBar(this.appbar, 0).then(() => {
this.showUndo = 1;
this.snackMsg = message;
this.countdown = 5;
2021-06-18 12:52:03 +00:00
this.animateBar(this.snackbar, 1, 1).then(() => {
2021-06-15 11:04:42 +00:00
let a = 5;
barTimer = setInterval(() => {
if (this.undo) {
this.hideBar();
resolve(1);
}
this.countdown = Math.round((a -= 0.1));
if (this.countdown < 1) {
this.hideBar();
reject(1);
}
}, 100);
2021-05-22 08:56:31 +00:00
});
});
2021-06-15 11:04:42 +00:00
});
},
hideBar() {
clearInterval(barTimer);
this.animateBar(this.snackbar, 0).then(() => {
this.showUndo = this.undo = 0;
this.animateBar(this.appbar, 1);
});
2021-05-22 08:56:31 +00:00
},
2021-04-12 18:09:48 +00:00
undoDel() {
2021-06-15 11:04:42 +00:00
this.undo = 1;
2021-04-12 18:09:48 +00:00
},
// HELPERS
autoFocusField(ref, showSoftInput) {
this.$refs[ref].nativeView.focus();
if (showSoftInput) {
setTimeout(() => {
Utils.ad.showSoftInput(this.$refs[ref].nativeView.android);
}, 100);
}
},
autoFocusRefField(ref, index) {
this.$refs[ref][index].nativeView.focus();
2021-03-21 17:02:04 +00:00
setTimeout(() => {
2021-04-12 18:09:48 +00:00
Utils.ad.showSoftInput(this.$refs[ref][index].nativeView.android);
2021-03-21 17:02:04 +00:00
}, 100);
2021-04-12 18:09:48 +00:00
},
splitTags() {
let tags = [];
let string;
if (this.tags) {
tags = this.tags
.split(" ")
.map((e) => {
string = e.replace(/^[^\w\s]+/, "");
if (/^[A-Za-z]+/.test(string)) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
})
.filter((e) => e);
}
this.recipe.tags = tags;
},
joinTags() {
this.tags = this.recipe.tags.join(" ");
},
timeRequired(time) {
let t = this.recipe[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}`;
},
focusField(args, type) {
if (type) this.setInputTypeText(args, type);
2021-06-15 11:04:42 +00:00
else this.setGravity(args);
2021-04-12 18:09:48 +00:00
if (!args.object.text) {
args.object.focus();
2021-04-21 10:31:14 +00:00
setTimeout(() => Utils.ad.showSoftInput(args.object.android), 100);
2021-04-12 18:09:48 +00:00
}
},
2021-06-15 11:04:42 +00:00
setInputTypeText({ object }, type) {
this.setGravity(object);
2021-04-12 18:09:48 +00:00
let common =
android.text.InputType.TYPE_CLASS_TEXT |
android.text.InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;
switch (type) {
case "words":
2021-06-15 11:04:42 +00:00
object.android.setInputType(
2021-04-12 18:09:48 +00:00
android.text.InputType.TYPE_TEXT_FLAG_CAP_WORDS | common
);
break;
case "sentence":
2021-06-15 11:04:42 +00:00
object.android.setInputType(
2021-04-12 18:09:48 +00:00
android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | common
);
break;
case "multiLine":
2021-06-15 11:04:42 +00:00
object.android.setInputType(
2021-04-12 18:09:48 +00:00
android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE |
android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES |
common
);
break;
}
},
setTimeRequired(focus, time) {
2021-06-15 11:04:42 +00:00
this.modalOpen = 1;
2021-04-12 18:09:48 +00:00
let t = this.recipe[time].split(":");
let hr = t[0];
let min = t[1];
2021-05-25 14:32:53 +00:00
this.$showModal(TimePickerHM, {
2021-04-12 18:09:48 +00:00
props: {
title: `${time == "prepTime" ? "prepT" : "cookT"}`,
selectedHr: hr,
selectedMin: min,
},
}).then((result) => {
2021-06-15 11:04:42 +00:00
this.modalOpen = 0;
2021-04-12 18:09:48 +00:00
if (result) {
this.recipe[time] = result;
if (focus) {
switch (time) {
case "prepTime":
2021-06-15 11:04:42 +00:00
this.autoFocusField("cookTime", 0);
2021-04-12 18:09:48 +00:00
break;
case "cookTime":
2021-06-15 11:04:42 +00:00
this.autoFocusField("yieldQuantity", 1);
2021-04-12 18:09:48 +00:00
break;
}
}
}
});
},
getTitleCount(title, type) {
let count = this.recipe[type].length;
let text = count ? ` (${count})` : "";
return localize(title) + text;
},
// NAVIGATION HANDLERS
hijackBackEvent() {
AndroidApplication.on(
AndroidApplication.activityBackPressedEvent,
this.backEvent
);
},
releaseBackEvent() {
AndroidApplication.off(
AndroidApplication.activityBackPressedEvent,
this.backEvent
);
},
backEvent(args) {
if (!this.modalOpen) {
args.cancel = true;
2021-06-15 11:04:42 +00:00
this.navigateBack(1);
2021-04-12 18:09:48 +00:00
}
},
2021-06-15 11:04:42 +00:00
goBackAction(exit) {
this.hasBackStack || this.recipeID
? this.$navigateBack()
: exit
? Application.android.foregroundActivity.finish()
: this.$navigateTo(EnRecipes, {
clearHistory: true,
animated: false,
});
},
navigateBack(hwb) {
2021-04-12 18:09:48 +00:00
if (this.hasChanges) {
2021-06-15 11:04:42 +00:00
this.modalOpen = 1;
2021-05-25 14:32:53 +00:00
this.$showModal(Confirm, {
2021-04-12 18:09:48 +00:00
props: {
title: "unsaved",
description: localize("disc"),
cancelButtonText: "disBtn",
okButtonText: "kEdit",
},
}).then((action) => {
2021-06-15 11:04:42 +00:00
this.modalOpen = 0;
if (action != null && !action) {
this.goBackAction(1);
knownFolders.temp().clear();
}
2021-04-12 18:09:48 +00:00
});
2021-06-15 11:04:42 +00:00
} else this.goBackAction(hwb);
2020-10-14 19:32:32 +00:00
},
},
2020-10-26 20:49:54 +00:00
created() {
2021-06-15 11:04:42 +00:00
this.title = this.recipeID || this.dupRecipe ? "editRec" : "newRec";
2021-03-21 17:02:04 +00:00
if (this.recipeID) {
let recipe = this.recipes.filter((e) => e.id === this.recipeID)[0];
2021-04-12 18:09:48 +00:00
Object.assign(this.recipe, JSON.parse(JSON.stringify(recipe)));
Object.assign(this.tempRecipe, JSON.parse(JSON.stringify(this.recipe)));
if (this.recipe.tags.length) this.joinTags();
2021-06-15 11:04:42 +00:00
} else if (this.dupRecipe) {
this.recipe = Object.assign({}, this.dupRecipe);
this.recipe.tried = 1;
this.recipe.lastTried = 0;
this.createDupImage();
} else {
2021-06-15 11:04:42 +00:00
this.recipe.cuisine = this.selCuisine
? /all/.test(this.selCuisine)
2021-03-21 17:02:04 +00:00
? "Undefined"
2021-06-15 11:04:42 +00:00
: this.selCuisine
: getString("previousCuisine", "Undefined");
this.recipe.category = this.selCategory
? /all/.test(this.selCategory)
2021-03-21 17:02:04 +00:00
? "Undefined"
2021-06-15 11:04:42 +00:00
: this.selCategory
: getString("previousCategory", "Undefined");
if (this.selTag && !/all/.test(this.selTag)) {
this.tags = this.selTag;
2021-03-21 17:02:04 +00:00
this.splitTags();
2020-12-29 10:35:19 +00:00
}
2021-06-15 11:04:42 +00:00
this.recipe.yieldUnit = getString("previousYieldUnit", "Serving");
if (this.filterFavourites) this.recipe.favorite = 1;
if (this.filterTrylater) this.recipe.tried = 0;
2021-05-22 08:56:31 +00:00
this.recipe.created = new Date().getTime();
2021-06-15 11:04:42 +00:00
this.tempRecipe = Object.assign({}, this.recipe);
2020-10-26 20:49:54 +00:00
}
},
2021-03-21 17:02:04 +00:00
};
2020-10-14 19:32:32 +00:00
</script>