2020-09-15 11:10:16 +00:00
|
|
|
<template>
|
2020-12-07 14:45:00 +00:00
|
|
|
<Page @loaded="onPageLoad" @unloaded="onPageUnload">
|
2021-01-23 17:20:15 +00:00
|
|
|
<ActionBar androidElevation="1">
|
2020-12-07 14:45:00 +00:00
|
|
|
<GridLayout v-if="showSearch" columns="auto, *" verticalAlignment="center">
|
2021-01-23 17:20:15 +00:00
|
|
|
<MDButton class="er" :text="icon.back" variant="text" automationText="Back" col="0" @tap="closeSearch" />
|
|
|
|
<SearchBar col="1" :hint="'ser' | L" @textChange="updateList($event.value)" @clear="clearSearch" />
|
2020-12-07 14:45:00 +00:00
|
|
|
</GridLayout>
|
2021-01-23 17:20:15 +00:00
|
|
|
<GridLayout v-else columns="auto, *, auto, auto, auto">
|
|
|
|
<MDButton class="er" col="0" variant="text" @tap="selectMode ? clearSelection() : showDrawer()" :text="selectMode ? icon.x : icon.menu" />
|
|
|
|
<Label v-if="selectMode" class="title orkm" :text="`${selection.length} ${$options.filters.L('sltd')}`" col="1" />
|
|
|
|
<Label v-else class="title orkm" :text="`${currentComponent}` | L" col="1" />
|
|
|
|
<!-- <MDButton v-if="recipes.length" class="er" :text="layout== 1 ? icon.l1 : layout==2 ? icon.l2 : icon.l3" variant="text" col="2" @tap="switchLayout" /> -->
|
|
|
|
<MDButton v-if="recipes.length && !selectMode" class="er" :text="selectMode ? icon.export : icon.sear" variant="text" col="3" @tap="selectMode ? exportSelection() : openSearch()" />
|
|
|
|
<MDButton v-if="recipes.length" class="er" :text="selectMode ? icon.del : icon.sort" variant="text" col="4" @tap="selectMode ? deleteSelection() : sortDialog()" />
|
2020-12-07 14:45:00 +00:00
|
|
|
</GridLayout>
|
|
|
|
</ActionBar>
|
|
|
|
<AbsoluteLayout>
|
2021-01-23 17:20:15 +00:00
|
|
|
<ListView width="100%" height="100%" for="recipe in filteredRecipes" @loaded="listViewLoad" :itemTemplateSelector="getLayout">
|
|
|
|
<v-template key="one">
|
|
|
|
<GridLayout class="recipeContainer" :class="isFirstItem(recipe.id)">
|
|
|
|
<GridLayout class="recipeItem layout1" rows="104" columns="104, *" androidElevation="1">
|
|
|
|
<MDRipple colSpan="2" ref="recipe" @longPress="selectMode? viewRecipe(recipe.id) : addToSelection($event, recipe.id)" @tap="selectMode? addToSelection($event, recipe.id) : viewRecipe(recipe.id)" />
|
|
|
|
<GridLayout class="imageHolder card" rows="104" columns="104">
|
|
|
|
<Image row="0" col="0" v-if="recipe.imageSrc" :src="recipe.imageSrc" stretch="aspectFill" decodeWidth="104" decodeHeight="104" loadMode="async" />
|
|
|
|
<Label v-else row="0" col="0" horizontalAlignment="center" class="er" fontSize="56" :text="icon.img" />
|
|
|
|
</GridLayout>
|
|
|
|
<StackLayout class="recipeInfo" col="1">
|
|
|
|
<Label :text="`${$options.filters.L(recipe.cuisine)} • ${$options.filters.L(recipe.category)}`" class="category" />
|
|
|
|
<Label :text="recipe.title" class="orkm title" />
|
|
|
|
<GridLayout columns="*" rows="auto, *, auto">
|
|
|
|
<StackLayout class="attrContainer" orientation="horizontal" row="0">
|
|
|
|
<Label class="er small" :text="icon.star" />
|
|
|
|
<Label class="attr" :text="recipe.rating" />
|
|
|
|
<Label class="er small" :text="icon.diff" />
|
|
|
|
<Label class="attr" :text="`${recipe.difficulty}` | L" />
|
|
|
|
<Label class="er small" :text="icon.time" />
|
|
|
|
<Label class="attr" :text="
|
2020-12-29 10:35:19 +00:00
|
|
|
`${
|
|
|
|
formattedTotalTime(recipe.prepTime, recipe.cookTime).time
|
|
|
|
}`
|
|
|
|
" />
|
2021-01-23 17:20:15 +00:00
|
|
|
</StackLayout>
|
|
|
|
<StackLayout class="tagsContainer" orientation="horizontal" row="2">
|
|
|
|
<Label v-for="(tag, index) in recipe.tags" :key="index" v-if="tag" class="tag" :text="tag" />
|
|
|
|
</StackLayout>
|
|
|
|
</GridLayout>
|
|
|
|
</StackLayout>
|
|
|
|
</GridLayout>
|
2020-12-07 14:45:00 +00:00
|
|
|
</GridLayout>
|
|
|
|
</v-template>
|
2021-01-23 17:20:15 +00:00
|
|
|
<!-- <v-template key="two">
|
|
|
|
<GridLayout class="recipeContainer" :class="isFirstItem(recipe.id)">
|
|
|
|
<GridLayout class="recipeItem layout2" rows="auto, auto" columns="*" androidElevation="1">
|
|
|
|
<MDRipple rowSpan="2" ref="recipe" @longPress="selectMode? viewRecipe(recipe.id) : addToSelection($event, recipe.id)" @tap="selectMode? addToSelection($event, recipe.id) : viewRecipe(recipe.id)" />
|
|
|
|
<GridLayout class="imageHolder card" :rows="imgWidth" columns="*">
|
|
|
|
<Image row="0" col="0" v-if="recipe.imageSrc" :src="recipe.imageSrc" stretch="aspectFill" :decodeWidth="imgWidth" :decodeHeight="imgWidth" loadMode="async" />
|
|
|
|
<Label v-else row="0" col="0" horizontalAlignment="center" class="er" :fontSize="imgWidth / 2" :text="icon.img" />
|
|
|
|
</GridLayout>
|
|
|
|
<StackLayout class="recipeInfo" row="1">
|
|
|
|
<Label :text="`${$options.filters.L(recipe.cuisine)} • ${$options.filters.L(recipe.category)}`" class="category" />
|
|
|
|
<Label :text="recipe.title" class="orkm title" />
|
|
|
|
<StackLayout class="tagsContainer" orientation="horizontal" row="2">
|
|
|
|
<Label v-for="(tag, index) in recipe.tags" :key="index" v-if="tag" class="tag" :text="tag" />
|
|
|
|
</StackLayout>
|
|
|
|
</StackLayout>
|
|
|
|
</GridLayout>
|
2020-12-07 14:45:00 +00:00
|
|
|
</GridLayout>
|
|
|
|
</v-template>
|
2021-01-23 17:20:15 +00:00
|
|
|
<v-template key="three">
|
|
|
|
<GridLayout class="recipeContainer" :class="isFirstItem(recipe.id)">
|
|
|
|
<GridLayout class="recipeItem layout1" rows="auto" columns="*" androidElevation="1">
|
|
|
|
<MDRipple ref="recipe" @longPress="selectMode? viewRecipe(recipe.id) : addToSelection($event, recipe.id)" @tap="selectMode? addToSelection($event, recipe.id) : viewRecipe(recipe.id)" />
|
|
|
|
<StackLayout class="recipeInfo">
|
|
|
|
<Label :text="`${$options.filters.L(recipe.cuisine)} • ${$options.filters.L(recipe.category)}`" class="category" />
|
|
|
|
<Label :text="recipe.title" class="orkm title" />
|
|
|
|
<StackLayout class="tagsContainer" orientation="horizontal">
|
|
|
|
<Label v-for="(tag, index) in recipe.tags" :key="index" v-if="tag" class="tag" :text="tag" />
|
|
|
|
</StackLayout>
|
|
|
|
</StackLayout>
|
|
|
|
</GridLayout>
|
|
|
|
</GridLayout>
|
|
|
|
</v-template> -->
|
|
|
|
</ListView>
|
2020-12-07 14:45:00 +00:00
|
|
|
<GridLayout rows="*, auto, *, 88" columns="*" class="emptyStateContainer">
|
|
|
|
<StackLayout row="1" class="emptyState" v-if="
|
2020-11-10 18:28:48 +00:00
|
|
|
!recipes.length &&
|
2020-12-07 14:45:00 +00:00
|
|
|
!filterFavourites &&
|
2020-12-29 10:35:19 +00:00
|
|
|
!filterTrylater
|
2020-12-07 14:45:00 +00:00
|
|
|
" @tap="addRecipe">
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label class="er icon" :text="icon.plusc" />
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label class="title orkm" :text="'strAdd' | L" textWrap="true" />
|
2020-12-07 14:45:00 +00:00
|
|
|
<StackLayout orientation="horizontal" horizontalAlignment="center">
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label :text="'plsAdd' | L" textWrap="true" />
|
2020-11-10 18:28:48 +00:00
|
|
|
</StackLayout>
|
2020-12-07 14:45:00 +00:00
|
|
|
</StackLayout>
|
|
|
|
<StackLayout row="1" class="emptyState" v-if="!filteredRecipes.length && filterTrylater && !searchQuery">
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label class="er icon" :text="icon.try" textWrap="true" />
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label class="title orkm" :text="'aD' | L" textWrap="true" />
|
|
|
|
<Label :text="'tLInfo' | L" textWrap="true" />
|
2020-12-07 14:45:00 +00:00
|
|
|
</StackLayout>
|
|
|
|
<StackLayout row="1" class="emptyState" v-if="!filteredRecipes.length && filterFavourites && !searchQuery">
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label class="er icon" :text="icon.fav" textWrap="true" />
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label class="title orkm" :text="'noFavs' | L" textWrap="true" />
|
|
|
|
<Label :text="'fsList' | L" textWrap="true" />
|
2020-12-07 14:45:00 +00:00
|
|
|
</StackLayout>
|
|
|
|
<StackLayout row="1" class="emptyState" v-if="!filteredRecipes.length && searchQuery">
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label class="er icon" :text="icon.noresult" textWrap="true" />
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label class="title orkm" :text="`${noResultFor}` | L" textWrap="true" />
|
|
|
|
<MDButton v-if="filterFavourites || filterTrylater || selectedCuisine" variant="text" class="searchAll orkm" :text="'trySer' | L" @tap="searchAll" />
|
2020-12-07 14:45:00 +00:00
|
|
|
</StackLayout>
|
|
|
|
</GridLayout>
|
|
|
|
<GridLayout id="btnFabContainer" rows="*, auto" columns="*, auto">
|
|
|
|
<transition name="bounce">
|
2021-01-23 17:20:15 +00:00
|
|
|
<MDFloatingActionButton v-if="showFAB" row="1" col="1" class="er fab-button" src="res://plus" @tap="addRecipe" />
|
2020-12-07 14:45:00 +00:00
|
|
|
</transition>
|
|
|
|
</GridLayout>
|
|
|
|
</AbsoluteLayout>
|
|
|
|
</Page>
|
2020-09-15 11:10:16 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-12-07 14:45:00 +00:00
|
|
|
import {
|
2021-01-13 05:02:48 +00:00
|
|
|
Frame,
|
2020-12-29 10:35:19 +00:00
|
|
|
ApplicationSettings,
|
2020-12-07 14:45:00 +00:00
|
|
|
AndroidApplication,
|
|
|
|
Utils,
|
2020-12-29 10:35:19 +00:00
|
|
|
Observable,
|
|
|
|
Device,
|
2021-01-23 17:20:15 +00:00
|
|
|
ObservableArray,
|
|
|
|
GestureTypes,
|
|
|
|
Screen
|
2020-12-07 14:45:00 +00:00
|
|
|
}
|
|
|
|
from "@nativescript/core";
|
|
|
|
import {
|
|
|
|
localize
|
|
|
|
}
|
|
|
|
from "@nativescript/localize"
|
2020-12-29 10:35:19 +00:00
|
|
|
import {
|
|
|
|
time
|
|
|
|
} from "tns-core-modules/profiling"
|
|
|
|
import {
|
|
|
|
startAccelerometerUpdates,
|
|
|
|
stopAccelerometerUpdates,
|
|
|
|
} from "nativescript-accelerometer"
|
|
|
|
import {
|
|
|
|
Vibrate
|
|
|
|
} from 'nativescript-vibrate';
|
|
|
|
let vibrator = new Vibrate();
|
2020-12-07 14:45:00 +00:00
|
|
|
import {
|
|
|
|
mapActions,
|
|
|
|
mapState
|
|
|
|
}
|
|
|
|
from "vuex";
|
|
|
|
import EditRecipe from "./EditRecipe.vue";
|
|
|
|
import ViewRecipe from "./ViewRecipe.vue";
|
|
|
|
import ActionDialog from "./modal/ActionDialog.vue";
|
|
|
|
import ConfirmDialog from "./modal/ConfirmDialog.vue";
|
2020-12-29 10:35:19 +00:00
|
|
|
let lastTime = 0;
|
|
|
|
let lastShake = 0;
|
|
|
|
let lastForce = 0;
|
|
|
|
let shakeCount = 0;
|
2021-01-13 05:02:48 +00:00
|
|
|
let typingTimer;
|
2020-10-14 19:32:32 +00:00
|
|
|
export default {
|
2021-01-23 17:20:15 +00:00
|
|
|
props: [ "filterFavourites", "filterTrylater", "closeDrawer", "showDrawer", "selectedCategory", "selectedCuisine", "selectedTag", "hijackGlobalBackEvent", "releaseGlobalBackEvent" ],
|
2020-10-14 19:32:32 +00:00
|
|
|
components: {
|
|
|
|
EditRecipe,
|
2020-12-07 14:45:00 +00:00
|
|
|
ViewRecipe
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
2020-09-15 11:10:16 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2020-10-14 19:32:32 +00:00
|
|
|
searchQuery: "",
|
2020-10-21 17:54:45 +00:00
|
|
|
showSearch: false,
|
2020-10-14 19:32:32 +00:00
|
|
|
rightAction: false,
|
2020-10-24 18:02:35 +00:00
|
|
|
deletionDialogActive: false,
|
2021-01-13 05:02:48 +00:00
|
|
|
showFAB: false,
|
|
|
|
filterDone: true,
|
2021-01-23 17:20:15 +00:00
|
|
|
selection: [],
|
|
|
|
selectMode: false,
|
|
|
|
recipeList: [],
|
|
|
|
// listView: null,
|
|
|
|
layout: 1,
|
2020-12-07 14:45:00 +00:00
|
|
|
};
|
2020-09-15 11:10:16 +00:00
|
|
|
},
|
|
|
|
computed: {
|
2020-12-29 10:35:19 +00:00
|
|
|
...mapState( [ "sortType", "icon", "recipes", "currentComponent", "shakeEnabled" ] ),
|
2020-09-15 11:10:16 +00:00
|
|
|
filteredRecipes() {
|
2020-12-14 13:48:53 +00:00
|
|
|
let ingredients = this.recipes.map( e => e.ingredients.map( f => f.item.toLowerCase() ).join() ).join()
|
2020-12-29 10:35:19 +00:00
|
|
|
|
2021-01-13 05:02:48 +00:00
|
|
|
let vm = this
|
|
|
|
|
|
|
|
function getIngredients( e ) {
|
|
|
|
return e.ingredients.map( f => f.item.toLowerCase() ).join().includes( vm.searchQuery );
|
|
|
|
}
|
2021-01-23 17:20:15 +00:00
|
|
|
// if ( this.filterDone ) {
|
|
|
|
if ( this.filterFavourites ) {
|
|
|
|
return this.recipes.filter( e => e.isFavorite && ( e.title.toLowerCase().includes( this.searchQuery ) || getIngredients( e ) ) ).sort( this.sortFunction )
|
|
|
|
} else if ( this.filterTrylater ) {
|
|
|
|
return this.recipes.filter( e => !e.tried && ( e.title.toLowerCase().includes( this.searchQuery ) || getIngredients( e ) ) ).sort( this.sortFunction )
|
|
|
|
} else if ( this.selectedCuisine ) {
|
|
|
|
return this.recipes.filter( e => {
|
|
|
|
return this.recipeFilter( e ) && ( e.title.toLowerCase().includes( this.searchQuery ) || getIngredients( e ) )
|
|
|
|
} ).sort( this.sortFunction )
|
2020-12-14 13:48:53 +00:00
|
|
|
} else {
|
2021-01-23 17:20:15 +00:00
|
|
|
return this.recipes.filter( e => e.title.toLowerCase().includes( this.searchQuery ) || getIngredients( e ) ).sort( this.sortFunction )
|
2020-09-15 11:10:16 +00:00
|
|
|
}
|
2021-01-23 17:20:15 +00:00
|
|
|
// } else {
|
|
|
|
// return 0;
|
|
|
|
// }
|
2020-09-15 11:10:16 +00:00
|
|
|
},
|
2020-11-28 19:21:57 +00:00
|
|
|
noResultFor() {
|
2021-01-13 05:02:48 +00:00
|
|
|
if ( this.filterFavourites ) return "noRecsInFavs";
|
|
|
|
if ( this.filterTrylater ) return "noRecsInTL";
|
|
|
|
if ( this.selectedCuisine ) return "noRecsInFtr";
|
|
|
|
return "noRecs";
|
2020-12-29 10:35:19 +00:00
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
screenWidth() {
|
|
|
|
return Screen.mainScreen.widthDIPs
|
|
|
|
},
|
|
|
|
imgWidth() {
|
|
|
|
return Screen.mainScreen.widthDIPs / 2 - 20
|
|
|
|
},
|
|
|
|
|
2020-09-15 11:10:16 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2021-01-23 17:20:15 +00:00
|
|
|
...mapActions( [ "setCurrentComponentAction", "setSortTypeAction", "deleteRecipeAction", "deleteRecipesAction" ] ),
|
2020-12-07 14:45:00 +00:00
|
|
|
onPageLoad( args ) {
|
|
|
|
const page = args.object;
|
|
|
|
page.bindingContext = new Observable();
|
2021-01-23 17:20:15 +00:00
|
|
|
this.filterFavourites ? this.setComponent( "Favourites" ) : this.filterTrylater ? this.setComponent( "Try Later" ) : this.selectedCuisine ? this.setComponent( "Filtered recipes" ) : this.setComponent( "EnRecipes" )
|
|
|
|
if ( !this.selectMode ) this.showFAB = true
|
2020-12-29 10:35:19 +00:00
|
|
|
if ( this.shakeEnabled ) startAccelerometerUpdates( data => this.onSensorData( data ) )
|
2021-01-23 17:20:15 +00:00
|
|
|
if ( this.showSearch || this.selectMode )
|
2021-01-13 05:02:48 +00:00
|
|
|
this.hijackLocalBackEvent()
|
2021-01-23 17:20:15 +00:00
|
|
|
this.showDrawer()
|
|
|
|
this.closeDrawer()
|
2020-12-07 14:45:00 +00:00
|
|
|
},
|
|
|
|
onPageUnload() {
|
2020-12-29 10:35:19 +00:00
|
|
|
if ( this.shakeEnabled ) stopAccelerometerUpdates();
|
2020-12-07 14:45:00 +00:00
|
|
|
this.releaseGlobalBackEvent();
|
2021-01-13 05:02:48 +00:00
|
|
|
this.releaseLocalBackEvent();
|
2020-10-24 18:02:35 +00:00
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
listViewLoad( args ) {
|
|
|
|
let e = args.object.android
|
|
|
|
e.setSelector( new android.graphics.drawable.StateListDrawable() )
|
|
|
|
e.setDivider( null );
|
|
|
|
e.setDividerHeight( 1 );
|
2020-11-23 09:49:58 +00:00
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
// switchLayout() {
|
|
|
|
// if ( this.layout == 2 ) this.layout = 1
|
|
|
|
// else this.layout++
|
|
|
|
// },
|
|
|
|
getLayout() {
|
|
|
|
switch ( this.layout ) {
|
|
|
|
case 1:
|
|
|
|
return 'one';
|
|
|
|
case 2:
|
|
|
|
return 'two';
|
|
|
|
case 3:
|
|
|
|
return 'three';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// HELPERS
|
2020-10-21 17:54:45 +00:00
|
|
|
openSearch() {
|
2020-12-07 14:45:00 +00:00
|
|
|
this.showSearch = true;
|
|
|
|
this.showFAB = false;
|
|
|
|
this.hijackLocalBackEvent();
|
2020-10-21 17:54:45 +00:00
|
|
|
},
|
2020-11-10 18:28:48 +00:00
|
|
|
closeSearch() {
|
2020-12-07 14:45:00 +00:00
|
|
|
this.searchQuery = "";
|
|
|
|
Utils.ad.dismissSoftInput();
|
|
|
|
this.showSearch = false;
|
|
|
|
this.showFAB = true;
|
|
|
|
this.releaseLocalBackEvent();
|
2020-11-10 18:28:48 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
setComponent( comp ) {
|
|
|
|
this.setCurrentComponentAction( comp );
|
|
|
|
this.hijackGlobalBackEvent();
|
2020-11-10 18:28:48 +00:00
|
|
|
},
|
|
|
|
clearSearch() {
|
2021-01-23 17:20:15 +00:00
|
|
|
this.searchQuery = ""
|
|
|
|
},
|
|
|
|
updateList( value ) {
|
|
|
|
clearTimeout( typingTimer )
|
|
|
|
typingTimer = setTimeout( e => {
|
|
|
|
this.searchQuery = value
|
|
|
|
}, 750 )
|
2020-11-10 18:28:48 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
formattedTotalTime( prepTime, cookTime ) {
|
|
|
|
let t1 = prepTime.split( ":" );
|
|
|
|
let t2 = cookTime.split( ":" );
|
2020-12-29 10:35:19 +00:00
|
|
|
let minutes = parseInt( t1[ 1 ] ) + parseInt( t2[ 1 ] )
|
|
|
|
let m = minutes % 60
|
|
|
|
let h = parseInt( t1[ 0 ] ) + parseInt( t2[ 0 ] ) + Math.floor( minutes / 60 );
|
2020-12-07 14:45:00 +00:00
|
|
|
let hr = localize( 'hr' )
|
|
|
|
let min = localize( 'min' )
|
2021-01-23 17:20:15 +00:00
|
|
|
let mins = h * 60 + m
|
2020-11-10 18:28:48 +00:00
|
|
|
return {
|
2020-12-07 14:45:00 +00:00
|
|
|
time: h ? ( m ? `${h} ${hr} ${m} ${min}` : `${h} ${hr}` ) : `${m} ${min}`,
|
2021-01-23 17:20:15 +00:00
|
|
|
duration: `${mins}`
|
2020-12-07 14:45:00 +00:00
|
|
|
};
|
2020-11-10 18:28:48 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
randomRecipeID() { // TODO: show only from selected filter
|
|
|
|
let min = 0
|
|
|
|
let max = this.filteredRecipes.length - 1
|
|
|
|
let randomIndex = Math.round( Math.random() * ( max - min ) )
|
|
|
|
return this.filteredRecipes[ randomIndex ].id
|
|
|
|
},
|
|
|
|
recipeFilter( e ) {
|
|
|
|
let cuisineMatched = e.cuisine === this.selectedCuisine
|
2021-01-13 05:02:48 +00:00
|
|
|
let allCuisines = /allCuis/.test( this.selectedCuisine )
|
2020-12-29 10:35:19 +00:00
|
|
|
let categoryMatched = e.category === this.selectedCategory
|
2021-01-13 05:02:48 +00:00
|
|
|
let allCategories = /allCats/.test( this.selectedCategory )
|
2020-12-29 10:35:19 +00:00
|
|
|
let tagMatched = e.tags.includes( this.selectedTag )
|
2021-01-13 05:02:48 +00:00
|
|
|
let allTags = /allTs/.test( this.selectedTag )
|
2020-12-29 10:35:19 +00:00
|
|
|
let cuisine = cuisineMatched || allCuisines
|
|
|
|
|
|
|
|
return this.selectedTag && !allTags ? ( categoryMatched || allCategories ) && cuisine && tagMatched : this.selectedCategory && !allCategories ? cuisine && categoryMatched : cuisine
|
|
|
|
},
|
2021-01-13 05:02:48 +00:00
|
|
|
searchAll() {
|
|
|
|
this.$emit( "backToHome" )
|
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
sortFunction( a, b ) {
|
|
|
|
const titleOrder = a.title.toLowerCase().localeCompare( b.title.toLowerCase(), Device.language, {
|
|
|
|
ignorePunctuation: true
|
|
|
|
} );
|
|
|
|
let d1 = this.formattedTotalTime( a.prepTime, a.cookTime ).duration;
|
|
|
|
let d2 = this.formattedTotalTime( b.prepTime, b.cookTime ).duration;
|
|
|
|
let ld1 = new Date( a.lastModified );
|
|
|
|
let ld2 = new Date( b.lastModified );
|
|
|
|
let cd1 = new Date( a.created );
|
|
|
|
let cd2 = new Date( b.created );
|
|
|
|
let r1 = a.rating
|
|
|
|
let r2 = b.rating
|
|
|
|
|
|
|
|
function difficultyLevel( l ) {
|
|
|
|
switch ( l ) {
|
|
|
|
case "Easy":
|
|
|
|
return 1;
|
|
|
|
case "Moderate":
|
|
|
|
return 2;
|
|
|
|
case "Challenging":
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let dl1 = difficultyLevel( a.difficulty )
|
|
|
|
let dl2 = difficultyLevel( b.difficulty )
|
|
|
|
switch ( this.sortType ) {
|
|
|
|
case "Title":
|
|
|
|
return titleOrder > 0 ? 1 : titleOrder < 0 ? -1 : 0;
|
|
|
|
break;
|
|
|
|
case "Quickest first":
|
|
|
|
return d1 > d2 ? 1 : d1 < d2 ? -1 : 0;
|
|
|
|
break;
|
|
|
|
case "Slowest first":
|
|
|
|
return d1 > d2 ? -1 : d1 < d2 ? 1 : 0;
|
|
|
|
break;
|
|
|
|
case "Rating":
|
|
|
|
return r1 > r2 ? -1 : r1 < r2 ? 1 : 0;
|
|
|
|
break;
|
|
|
|
case "Difficulty level":
|
|
|
|
return dl1 > dl2 ? 1 : dl1 < dl2 ? -1 : 0;
|
|
|
|
break;
|
|
|
|
case "Last updated":
|
|
|
|
return ld1 < ld2 ? 1 : ld1 > ld2 ? -1 : 0;
|
|
|
|
break;
|
|
|
|
case "Newest first":
|
|
|
|
return cd1 < cd2 ? 1 : cd1 > cd2 ? -1 : 0;
|
|
|
|
break;
|
|
|
|
case "Oldest first":
|
|
|
|
return cd1 < cd2 ? -1 : cd1 > cd2 ? 1 : 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
isFirstItem( id ) {
|
|
|
|
let length = this.filteredRecipes.length
|
|
|
|
return id == this.filteredRecipes[ 0 ].id ? 'firstItem' : id == this.filteredRecipes[ length - 1 ].id ? 'lastItem' : ''
|
|
|
|
},
|
|
|
|
isLastItem( id ) {
|
|
|
|
let length = this.filteredRecipes.length
|
|
|
|
// let lastIsOdd = ( length - 1 ) % 2 == 0
|
|
|
|
// if ( this.filteredRecipes.length > 1 ) {
|
|
|
|
// if ( id == this.filteredRecipes[ length - 2 ].id ) {
|
|
|
|
// if ( !lastIsOdd ) return 'lastItem'
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
if ( id == this.filteredRecipes[ length - 1 ].id ) return 'lastItem'
|
|
|
|
},
|
|
|
|
|
2020-11-10 18:28:48 +00:00
|
|
|
// NAVIGATION HANDLERS
|
2020-10-21 17:54:45 +00:00
|
|
|
hijackLocalBackEvent() {
|
2020-12-07 14:45:00 +00:00
|
|
|
this.releaseGlobalBackEvent();
|
2021-01-23 17:20:15 +00:00
|
|
|
AndroidApplication.on( AndroidApplication.activityBackPressedEvent, this.localBackEvent );
|
2020-10-21 17:54:45 +00:00
|
|
|
},
|
|
|
|
releaseLocalBackEvent() {
|
2021-01-23 17:20:15 +00:00
|
|
|
AndroidApplication.off( AndroidApplication.activityBackPressedEvent, this.localBackEvent );
|
2020-12-07 14:45:00 +00:00
|
|
|
this.hijackGlobalBackEvent();
|
2020-10-21 17:54:45 +00:00
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
localBackEvent( args ) {
|
2020-12-07 14:45:00 +00:00
|
|
|
args.cancel = true;
|
2021-01-23 17:20:15 +00:00
|
|
|
if ( this.selectMode )
|
|
|
|
this.clearSelection()
|
2020-12-07 14:45:00 +00:00
|
|
|
this.closeDrawer();
|
|
|
|
this.closeSearch();
|
2020-10-21 17:54:45 +00:00
|
|
|
},
|
2020-11-10 18:28:48 +00:00
|
|
|
addRecipe() {
|
2020-12-07 14:45:00 +00:00
|
|
|
this.showFAB = false;
|
|
|
|
this.releaseGlobalBackEvent();
|
|
|
|
this.$navigateTo( EditRecipe, {
|
2020-11-10 18:28:48 +00:00
|
|
|
props: {
|
2020-12-29 10:35:19 +00:00
|
|
|
selectedCuisine: this.selectedCuisine,
|
2020-11-10 18:28:48 +00:00
|
|
|
selectedCategory: this.selectedCategory,
|
2020-12-29 10:35:19 +00:00
|
|
|
selectedTag: this.selectedTag,
|
|
|
|
filterFavourites: this.filterFavourites,
|
|
|
|
filterTrylater: this.filterTrylater,
|
2020-12-07 14:45:00 +00:00
|
|
|
}
|
|
|
|
} );
|
2020-10-21 17:54:45 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
viewRecipe( recipeID ) {
|
|
|
|
this.showFAB = false;
|
|
|
|
this.$navigateTo( ViewRecipe, {
|
2020-11-10 18:28:48 +00:00
|
|
|
props: {
|
|
|
|
filterTrylater: this.filterTrylater,
|
2020-12-07 14:45:00 +00:00
|
|
|
recipeID
|
2020-11-10 18:28:48 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
backstackVisible: false
|
|
|
|
} );
|
2020-11-10 18:28:48 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
viewRandomRecipe() {
|
|
|
|
this.showFAB = false;
|
|
|
|
this.$navigateTo( ViewRecipe, {
|
|
|
|
props: {
|
|
|
|
filterTrylater: false,
|
|
|
|
recipeID: this.randomRecipeID()
|
|
|
|
},
|
|
|
|
backstackVisible: false
|
|
|
|
} );
|
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
|
2020-11-10 18:28:48 +00:00
|
|
|
// LIST HANDLERS
|
2020-10-21 17:54:45 +00:00
|
|
|
sortDialog() {
|
2020-12-07 14:45:00 +00:00
|
|
|
this.releaseGlobalBackEvent();
|
|
|
|
this.$showModal( ActionDialog, {
|
2020-10-21 17:54:45 +00:00
|
|
|
props: {
|
2021-01-13 05:02:48 +00:00
|
|
|
title: "srt",
|
2020-12-29 10:35:19 +00:00
|
|
|
list: [ "Title", "Quickest first", "Slowest first", "Rating", "Difficulty level", "Last updated", "Newest first", "Oldest first" ],
|
2021-01-13 05:02:48 +00:00
|
|
|
stretch: false,
|
|
|
|
helpIcon: 'sort',
|
2021-01-23 17:20:15 +00:00
|
|
|
bgColor: '#858585',
|
2020-12-07 14:45:00 +00:00
|
|
|
}
|
|
|
|
} ).then( action => {
|
|
|
|
if ( action && action !== "Cancel" && this.sortType !== action ) {
|
2020-12-29 10:35:19 +00:00
|
|
|
this.setSortTypeAction( action )
|
|
|
|
ApplicationSettings.setString( "sortType", action )
|
2020-12-07 14:45:00 +00:00
|
|
|
this.updateSort();
|
2020-10-21 17:54:45 +00:00
|
|
|
}
|
2020-12-07 14:45:00 +00:00
|
|
|
this.hijackGlobalBackEvent();
|
|
|
|
} );
|
2020-10-21 17:54:45 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
|
2021-01-23 17:20:15 +00:00
|
|
|
// DATA HANDLERS
|
|
|
|
addToSelection( args, id ) {
|
|
|
|
this.showFAB = false
|
|
|
|
if ( !this.selectMode )
|
|
|
|
this.hijackLocalBackEvent()
|
|
|
|
this.selectMode = true
|
|
|
|
this.$emit( "selectModeOn", false )
|
|
|
|
let item = args.object
|
|
|
|
if ( item.className === "selected" ) {
|
|
|
|
item.className = ""
|
|
|
|
this.selection.splice( this.selection.indexOf( id ), 1 )
|
|
|
|
this.recipeList.splice( this.selection.indexOf( id ), 1 )
|
2020-12-14 13:48:53 +00:00
|
|
|
} else {
|
2021-01-23 17:20:15 +00:00
|
|
|
item.className = "selected"
|
|
|
|
this.selection.push( id )
|
|
|
|
this.recipeList.push( item )
|
2020-10-21 17:54:45 +00:00
|
|
|
}
|
2021-01-23 17:20:15 +00:00
|
|
|
if ( !this.selection.length )
|
|
|
|
this.clearSelection()
|
|
|
|
|
2020-10-21 17:54:45 +00:00
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
clearSelection() {
|
|
|
|
this.selectMode = false
|
|
|
|
this.$emit( "selectModeOn", true )
|
|
|
|
this.selection = []
|
|
|
|
this.recipeList.forEach( e => e.className = "" )
|
|
|
|
this.releaseLocalBackEvent()
|
|
|
|
this.showFAB = true
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
deleteSelection() {
|
|
|
|
this.selection.length === 1 ?
|
|
|
|
this.deleteRecipe( this.selection[ 0 ] ) :
|
|
|
|
this.deleteRecipes( this.selection )
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
exportSelection() {},
|
|
|
|
deleteRecipe( id ) {
|
2020-12-07 14:45:00 +00:00
|
|
|
this.deletionDialogActive = true;
|
2021-01-23 17:20:15 +00:00
|
|
|
let index = this.recipes.findIndex( e => e.id === id )
|
2020-12-07 14:45:00 +00:00
|
|
|
this.$showModal( ConfirmDialog, {
|
2020-10-21 17:54:45 +00:00
|
|
|
props: {
|
2021-01-13 05:02:48 +00:00
|
|
|
title: localize( "conf" ),
|
|
|
|
description: `${localize('delRecInfo')} "${this.recipes[index].title}"`,
|
|
|
|
cancelButtonText: "cBtn",
|
|
|
|
okButtonText: "dBtn",
|
2021-01-23 17:20:15 +00:00
|
|
|
helpIcon: 'del',
|
2021-01-13 05:02:48 +00:00
|
|
|
bgColor: '#c92a2a',
|
2020-10-21 17:54:45 +00:00
|
|
|
}
|
2020-12-07 14:45:00 +00:00
|
|
|
} ).then( action => {
|
|
|
|
if ( action ) {
|
|
|
|
this.deleteRecipeAction( {
|
|
|
|
index,
|
2021-01-23 17:20:15 +00:00
|
|
|
id
|
2020-12-07 14:45:00 +00:00
|
|
|
} );
|
2021-01-13 05:02:48 +00:00
|
|
|
if ( !this.filteredRecipes.length )
|
|
|
|
this.$emit( 'backToHome' )
|
2021-01-23 17:20:15 +00:00
|
|
|
this.clearSelection()
|
|
|
|
}
|
|
|
|
this.deletionDialogActive = false;
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
deleteRecipes( idsArr ) {
|
|
|
|
this.deletionDialogActive = true;
|
|
|
|
this.$showModal( ConfirmDialog, {
|
|
|
|
props: {
|
|
|
|
title: localize( "conf" ),
|
|
|
|
description: `${localize('delRecsInfo')} ${this.selection.length} ${localize('recs')}`,
|
|
|
|
cancelButtonText: "cBtn",
|
|
|
|
okButtonText: "dBtn",
|
|
|
|
helpIcon: 'del',
|
|
|
|
bgColor: '#c92a2a',
|
|
|
|
}
|
|
|
|
} ).then( action => {
|
|
|
|
if ( action ) {
|
|
|
|
this.deleteRecipesAction( idsArr );
|
|
|
|
if ( !this.filteredRecipes.length )
|
|
|
|
this.$emit( 'backToHome' )
|
|
|
|
this.clearSelection()
|
2020-12-07 14:45:00 +00:00
|
|
|
}
|
|
|
|
this.deletionDialogActive = false;
|
|
|
|
} );
|
2020-12-29 10:35:19 +00:00
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
|
2020-12-29 10:35:19 +00:00
|
|
|
// SHAKE DETECTOR
|
|
|
|
onSensorData( {
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
z
|
|
|
|
} ) {
|
|
|
|
x = x.toFixed( 2 )
|
|
|
|
y = y.toFixed( 2 )
|
|
|
|
z = z.toFixed( 2 )
|
|
|
|
const FORCE_THRESHOLD = 1;
|
|
|
|
const TIME_THRESHOLD = 150;
|
|
|
|
const SHAKE_TIMEOUT = 600;
|
|
|
|
const SHAKE_THROTTLE = 600;
|
|
|
|
const SHAKE_COUNT = 3;
|
|
|
|
const now = time()
|
|
|
|
if ( ( now - lastForce ) > SHAKE_TIMEOUT ) {
|
|
|
|
shakeCount = 0;
|
|
|
|
}
|
|
|
|
let timeDelta = now - lastTime;
|
|
|
|
if ( timeDelta > TIME_THRESHOLD ) {
|
|
|
|
let forceVector = Math.abs( Math.sqrt( Math.pow( x, 2 ) + Math.pow( y, 2 ) + Math.pow( z, 2 ) ) - 1 );
|
|
|
|
if ( forceVector > FORCE_THRESHOLD ) {
|
|
|
|
shakeCount++;
|
|
|
|
if ( ( shakeCount >= SHAKE_COUNT ) && ( now - lastShake > SHAKE_THROTTLE ) ) {
|
|
|
|
lastShake = now;
|
|
|
|
shakeCount = 0;
|
|
|
|
if ( this.filteredRecipes.length ) {
|
|
|
|
vibrator.vibrate( 100 )
|
|
|
|
this.viewRandomRecipe()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastForce = now;
|
|
|
|
}
|
|
|
|
lastTime = now;
|
|
|
|
}
|
|
|
|
},
|
2020-09-15 11:10:16 +00:00
|
|
|
},
|
2020-10-29 20:12:53 +00:00
|
|
|
mounted() {
|
2021-01-23 17:20:15 +00:00
|
|
|
this.showFAB = true
|
2020-12-07 14:45:00 +00:00
|
|
|
}
|
2021-01-23 17:20:15 +00:00
|
|
|
}
|
2020-09-15 11:10:16 +00:00
|
|
|
</script>
|