enrecipes/app/components/EditRecipe.vue

1120 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-06-28 11:38:21 +00:00
autocapitalizationType="words"
autocorrect="true"
@returnPress="showCuisine(1)"
2021-03-21 17:02:04 +00:00
/>
</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
@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-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
@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
ref="tags"
2021-06-28 11:38:21 +00:00
autocapitalizationType="words"
autocorrect="true"
:hint="'tsInfo' | L"
2021-03-21 17:02:04 +00:00
v-model="tags"
@textChange="splitTags"
2021-06-28 11:38:21 +00:00
@loaded="setGravity"
@returnPress="setTimeRequired(1, 'prepTime')"
2021-03-21 17:02:04 +00:00
/>
</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
@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
:text="timeRequired('cookTime')"
editable="false"
2021-06-15 11:04:42 +00:00
@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-06-28 11:38:21 +00:00
ref="yieldQ"
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"
2021-06-28 11:38:21 +00:00
@returnPress="showYieldUnits(1)"
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="'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
@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-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
@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-06-28 11:38:21 +00:00
v-for="(item, i) in recipe.ingredients"
:key="item.key"
2021-03-21 17:02:04 +00:00
>
<TextField
2021-06-28 11:38:21 +00:00
v-if="item.type"
:ref="'ing' + i"
2021-04-21 10:31:14 +00:00
width="52"
2021-06-28 11:38:21 +00:00
@focus="setFocus(i)"
@blur="setFocus(-1)"
2021-03-21 17:02:04 +00:00
keyboardType="number"
returnKeyType="next"
2021-06-28 11:38:21 +00:00
hint="1.00"
v-model="recipe.ingredients[i].quantity"
2021-03-21 17:02:04 +00:00
/>
<TextField
2021-06-28 11:38:21 +00:00
v-if="item.type"
2021-04-21 10:31:14 +00:00
width="68"
2021-03-21 17:02:04 +00:00
col="2"
2021-06-28 11:38:21 +00:00
:text="`${recipe.ingredients[i].unit}` | L"
2021-03-21 17:02:04 +00:00
editable="false"
2021-06-29 11:37:19 +00:00
@focus="!modalOpen && showUnits(1, i)"
2021-06-28 11:38:21 +00:00
@tap="showUnits(0, i)"
2021-03-21 17:02:04 +00:00
/>
<TextField
2021-06-28 11:38:21 +00:00
:ref="'ing' + i"
@focus="setFocus(i)"
@blur="setFocus(-1)"
autocapitalizationType="sentence"
autocorrect="true"
returnKeyType="done"
:col="item.type ? 4 : 0"
:colSpan="item.type ? 1 : 5"
v-model="recipe.ingredients[i].value"
:hint="getIngPos(i)"
@returnPress="addIng(1)"
2021-03-21 17:02:04 +00:00
/>
2021-06-28 11:38:21 +00:00
<Button col="5" class="ico si" :text="icon.x" @tap="rmIng(i)" />
</RGridLayout>
<RStackLayout :rtl="RTL" class="ingActions">
2021-04-01 10:55:35 +00:00
<Button
2021-06-28 11:38:21 +00:00
class="text tb big hal fb"
:class="{ r: RTL }"
:text="'aIngBtn' | L"
@tap="addIng(1)"
2021-03-21 17:02:04 +00:00
/>
2021-06-28 11:38:21 +00:00
<Button
class="text tb big hal fb"
:class="{ r: RTL }"
:text="'addSectBtn' | L"
@tap="addIng(0)"
/>
</RStackLayout>
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-06-28 11:38:21 +00:00
v-for="(item, i) in recipe.instructions"
:key="item.key"
2021-03-21 17:02:04 +00:00
>
2021-06-28 11:38:21 +00:00
<TextField
:ref="'ins' + i"
v-if="!item.type"
@focus="setFocus(i)"
@blur="setFocus(-1)"
autocapitalizationType="sentence"
autocorrect="true"
:hint="getInsPos(i)"
v-model="recipe.instructions[i].value"
@returnPress="addIns(1)"
returnKeyType="done"
/>
2021-03-21 17:02:04 +00:00
<TextView
2021-06-28 11:38:21 +00:00
:ref="'ins' + i"
v-else
@focus="setFocus(i)"
@blur="setFocus(-1)"
autocapitalizationType="multiLine"
autocorrect="true"
:hint="getInsPos(i)"
v-model="recipe.instructions[i].value"
2021-03-21 17:02:04 +00:00
/>
2021-06-28 11:38:21 +00:00
<Button col="1" class="ico si" :text="icon.x" @tap="rmIns(i)" />
</RGridLayout>
<RStackLayout :rtl="RTL" class="ingActions">
2021-04-01 10:55:35 +00:00
<Button
2021-06-28 11:38:21 +00:00
class="text tb big hal fb"
:class="{ r: RTL }"
:text="'aStpBtn' | L"
@tap="addIns(1)"
2021-03-21 17:02:04 +00:00
/>
2021-06-28 11:38:21 +00:00
<Button
class="text tb big hal fb"
:class="{ r: RTL }"
:text="'addSectBtn' | L"
@tap="addIns(0)"
/>
</RStackLayout>
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-06-28 11:38:21 +00:00
v-for="(item, i) in recipe.notes"
:key="item.key"
2021-03-21 17:02:04 +00:00
>
2021-04-01 10:55:35 +00:00
<TextView
2021-06-28 11:38:21 +00:00
:ref="'note' + i"
@focus="setFocus(i)"
@blur="setFocus(-1)"
autocapitalizationType="multiLine"
autocorrect="true"
:hint="`${$options.filters.L('no')} ${i + 1}`"
v-model="recipe.notes[i].value"
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-06-28 11:38:21 +00:00
@tap="removeNote(i)"
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-28 11:38:21 +00:00
class="ico"
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-28 11:38:21 +00:00
class="ico fab"
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-28 11:38:21 +00:00
<ActivityIndicator 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-06-28 11:38:21 +00:00
fi: 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-05-22 08:56:31 +00:00
if (this.recipe.image) {
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-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-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) => {
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-28 11:38:21 +00:00
if (focus) this.showCategories(1);
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-04-12 18:09:48 +00:00
if (action) {
this.recipe.cuisine = action;
2021-06-28 11:38:21 +00:00
if (focus) this.showCategories(1);
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-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) => {
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-28 11:38:21 +00:00
if (focus) this.focusRef("tags");
2020-10-21 17:54:45 +00:00
}
2021-03-21 17:02:04 +00:00
});
} else {
2021-04-12 18:09:48 +00:00
if (action) {
this.recipe.category = action;
2021-06-28 11:38:21 +00:00
if (focus) this.focusRef("tags");
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-06-28 11:38:21 +00:00
setTimeRequired(focus, time) {
let t = this.recipe[time].split(":");
let hr = t[0];
let min = t[1];
this.$showModal(TimePickerHM, {
props: {
title: `${time == "prepTime" ? "prepT" : "cookT"}`,
selectedHr: hr,
selectedMin: min,
},
}).then((result) => {
if (result) {
this.recipe[time] = result;
if (focus) {
switch (time) {
case "prepTime":
this.setTimeRequired(1, "cookTime");
break;
case "cookTime":
this.focusRef("yieldQ");
break;
}
}
}
});
},
2021-03-21 17:02:04 +00:00
showYieldUnits(focus) {
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) => {
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-28 11:38:21 +00:00
if (focus) this.showDifficultyLevel(1);
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-04-12 18:09:48 +00:00
if (action) {
2021-05-22 08:56:31 +00:00
this.recipe.yieldUnit = action;
2021-06-28 11:38:21 +00:00
if (focus) this.showDifficultyLevel(1);
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-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) => {
if (action) {
2021-04-12 18:09:48 +00:00
this.recipe.difficulty = action;
2021-06-28 11:38:21 +00:00
if (focus) this.addIng(1);
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-06-28 11:38:21 +00:00
showUnits(focus, i) {
2021-06-29 11:37:19 +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-28 11:38:21 +00:00
selected: this.recipe.ingredients[i].unit,
2020-11-02 11:36:53 +00:00
},
2021-03-21 17:02:04 +00:00
}).then((action) => {
2021-06-29 11:37:19 +00:00
this.modalOpen = 0;
2021-03-21 17:02:04 +00:00
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) => {
if (item.length) {
2021-06-28 11:38:21 +00:00
this.recipe.ingredients[i].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-06-28 11:38:21 +00:00
if (focus) this.focusRefs("ing" + i, 1);
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 {
if (action) {
2021-06-28 11:38:21 +00:00
this.recipe.ingredients[i].unit = action;
if (focus) this.focusRefs("ing" + i, 1);
2021-04-12 18:09:48 +00:00
}
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();
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) => {
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
2021-06-28 11:38:21 +00:00
setFocus(i) {
this.fi = i;
},
addIng(type) {
let ing = {
key: utils.getRandomID(1),
type,
2020-10-14 19:32:32 +00:00
quantity: null,
2021-06-28 11:38:21 +00:00
unit: 0,
value: "",
};
let ings = this.recipe.ingredients;
if (type) {
ing.unit = ings.length
? ings[this.fi >= 0 ? this.fi : ings.length - 1].unit
? ings[this.fi >= 0 ? this.fi : ings.length - 1].unit
: "unit"
: "unit";
}
let i = this.fi >= 0 ? this.fi + 1 : ings.length;
this.recipe.ingredients.splice(i, 0, ing);
if (!ing.value || !type) this.delayFocus("ing", ings.length);
2021-03-21 17:02:04 +00:00
},
2021-06-28 11:38:21 +00:00
rmIng(i) {
if (this.recipe.ingredients[i].value.length) {
let item = this.recipe.ingredients[i];
this.recipe.ingredients.splice(i, 1);
this.showUndoBar(item.type ? "rmIng" : "sectRm").then(
(res) => res && this.recipe.ingredients.splice(i, 0, item)
2021-04-01 10:55:35 +00:00
);
2020-12-29 10:35:19 +00:00
} else {
2021-06-28 11:38:21 +00:00
this.recipe.ingredients.splice(i, 1);
2020-12-29 10:35:19 +00:00
}
2020-10-14 19:32:32 +00:00
},
2021-06-28 11:38:21 +00:00
addIns(type) {
let obj = {
key: utils.getRandomID(1),
type,
value: "",
};
let inss = this.recipe.instructions;
let i = this.fi >= 0 ? this.fi + 1 : inss.length;
this.recipe.instructions.splice(i, 0, obj);
this.delayFocus("ins", inss.length);
2021-03-21 17:02:04 +00:00
},
2021-06-28 11:38:21 +00:00
rmIns(i) {
if (this.recipe.instructions[i].value.length) {
let item = this.recipe.instructions[i];
this.recipe.instructions.splice(i, 1);
this.showUndoBar(item.type ? "rmIns" : "sectRm").then(
(res) => res && this.recipe.instructions.splice(i, 0, item)
2021-04-01 10:55:35 +00:00
);
2021-06-28 11:38:21 +00:00
} else this.recipe.instructions.splice(i, 1);
2020-10-14 19:32:32 +00:00
},
2021-01-13 05:02:48 +00:00
addNote() {
2021-06-28 11:38:21 +00:00
let obj = {
key: utils.getRandomID(1),
value: "",
};
let nos = this.recipe.notes;
let i = this.fi >= 0 ? this.fi + 1 : nos.length;
this.recipe.notes.splice(i, 0, obj);
this.delayFocus("note", nos.length);
2021-03-21 17:02:04 +00:00
},
removeNote(index) {
2021-06-28 11:38:21 +00:00
if (this.recipe.notes[index].value.length) {
2021-04-12 18:09:48 +00:00
let item = this.recipe.notes[index];
this.recipe.notes.splice(index, 1);
2021-06-28 11:38:21 +00:00
this.showUndoBar("rmN").then(() =>
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-06-28 11:38:21 +00:00
getIngPos(n) {
let a = 1;
let b = 1;
let ings = this.recipe.ingredients;
let group = ings.reduce((acc, e) => {
if (!e.type) {
a = 1;
acc.push(b++);
} else acc.push(e.type ? a++ : a - 1);
return acc;
}, []);
return localize(ings[n].type ? "it" : "sect", group[n]);
},
getInsPos(n) {
let a = 1;
let b = 1;
let ins = this.recipe.instructions;
let group = ins.reduce((acc, e) => {
if (!e.type) {
a = 1;
acc.push(b++);
} else acc.push(a++);
return acc;
}, []);
return localize(ins[n].type ? "stp" : "sect", group[n]);
},
2021-04-12 18:09:48 +00:00
2020-11-10 18:28:48 +00:00
// SAVE OPERATION
2021-06-28 11:38:21 +00:00
clearEmptyFields() {
if (!this.recipe.title) this.recipe.title = localize("untRec");
2021-05-22 08:56:31 +00:00
if (!this.recipe.yieldQuantity) this.recipe.yieldQuantity = 1;
2021-06-28 11:38:21 +00:00
const clearEmpty = (arr) => {
this.recipe[arr] = this.recipe[arr].filter((e) => e.value);
};
clearEmpty("ingredients");
2021-03-21 17:02:04 +00:00
clearEmpty("instructions");
clearEmpty("notes");
2020-11-02 11:36:53 +00:00
},
saveOperation() {
2021-06-28 11:38:21 +00:00
this.saving = 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
2021-06-28 11:38:21 +00:00
focusRef(r) {
this.$refs[r].nativeView.focus();
setTimeout(() => {
Utils.ad.showSoftInput(this.$refs[r].nativeView.android);
}, 100);
2021-04-12 18:09:48 +00:00
},
2021-06-28 11:38:21 +00:00
focusRefs(r, i) {
i = i != null ? i : 0;
this.$refs[r][i].nativeView.focus();
2021-03-21 17:02:04 +00:00
setTimeout(() => {
2021-06-28 11:38:21 +00:00
Utils.ad.showSoftInput(this.$refs[r][i].nativeView.android);
2021-03-21 17:02:04 +00:00
}, 100);
2021-04-12 18:09:48 +00:00
},
2021-06-28 11:38:21 +00:00
delayFocus(type, length) {
setTimeout(
() =>
this.focusRefs(
type + (length == 1 ? 0 : this.fi >= 0 ? this.fi + 1 : length - 1)
),
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}`;
},
2021-06-28 11:38:21 +00:00
getTitleCount(title, type) {
let c;
switch (title) {
case "ings" || "inss":
c = this.recipe[type].filter((e) => e.type).length;
2021-04-12 18:09:48 +00:00
break;
2021-06-28 11:38:21 +00:00
default:
c = this.recipe[type].length;
2021-04-12 18:09:48 +00:00
break;
}
2021-06-28 11:38:21 +00:00
let text = c ? ` (${c})` : "";
2021-04-12 18:09:48 +00:00
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>