2020-09-15 11:10:16 +00:00
|
|
|
<template>
|
2020-12-07 14:45:00 +00:00
|
|
|
<Page @loaded="onPageLoad">
|
2021-01-23 17:20:15 +00:00
|
|
|
<ActionBar androidElevation="1">
|
2020-12-07 14:45:00 +00:00
|
|
|
<GridLayout rows="*" columns="auto, *">
|
2021-01-23 17:20:15 +00:00
|
|
|
<MDButton class="er left" variant="text" :text="icon.back" automationText="Back" @tap="$navigateBack()" col="0" />
|
2020-12-07 14:45:00 +00:00
|
|
|
<Label class="title orkm" :text="'Settings' | L" col="1" />
|
|
|
|
</GridLayout>
|
|
|
|
</ActionBar>
|
2021-01-23 17:20:15 +00:00
|
|
|
<ScrollView>
|
2020-12-07 14:45:00 +00:00
|
|
|
<StackLayout class="main-container">
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label :text="'intf' | L" class="group-header orkm" />
|
2020-12-07 14:45:00 +00:00
|
|
|
<GridLayout columns="auto, *" class="option">
|
|
|
|
<MDRipple colSpan="2" @tap="selectAppLanguage" />
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label col="0" verticalAlignment="center" class="er" :text="icon.lang" />
|
2020-12-07 14:45:00 +00:00
|
|
|
<StackLayout col="1">
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label :text="'lang' | L" />
|
2020-12-07 14:45:00 +00:00
|
|
|
<Label :text="appLanguage" class="info" />
|
|
|
|
</StackLayout>
|
2020-10-14 19:32:32 +00:00
|
|
|
</GridLayout>
|
2020-12-07 14:45:00 +00:00
|
|
|
<GridLayout columns="auto, *" class="option">
|
|
|
|
<MDRipple colSpan="2" @tap="selectThemes" />
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label col="0" verticalAlignment="center" class="er" :text="icon.theme" />
|
2020-12-07 14:45:00 +00:00
|
|
|
<StackLayout col="1">
|
|
|
|
<Label :text="'Theme' | L" />
|
|
|
|
<Label :text="`${appTheme}` | L" class="info" />
|
|
|
|
</StackLayout>
|
|
|
|
</GridLayout>
|
|
|
|
<StackLayout class="hr m-10"></StackLayout>
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label :text="'opts' | L" class="group-header orkm" />
|
2020-12-29 10:35:19 +00:00
|
|
|
<GridLayout columns="auto, *, auto" class="option">
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label col="0" verticalAlignment="center" class="er" :text="icon.shuf" />
|
2020-12-29 10:35:19 +00:00
|
|
|
<StackLayout col="1">
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label :text="'sVw' | L" textWrap="true" />
|
|
|
|
<Label :text="`sVwInfo` | L" class="info" textWrap="true" />
|
2020-12-29 10:35:19 +00:00
|
|
|
</StackLayout>
|
2021-01-23 17:20:15 +00:00
|
|
|
<Switch :color="shakeEnabled ? '#ff5200' : '#858585'" verticalAlignment="center" col="2" :checked="shakeEnabled" @checkedChange="toggleShake" />
|
2020-12-29 10:35:19 +00:00
|
|
|
</GridLayout>
|
|
|
|
<StackLayout class="hr m-10"></StackLayout>
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label :text="'db' | L" class="group-header orkm" />
|
2020-12-07 14:45:00 +00:00
|
|
|
<GridLayout columns="auto, *" class="option">
|
|
|
|
<MDRipple colSpan="2" @tap="exportCheck" />
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label col="0" class="er" :text="icon.exp" />
|
2020-12-07 14:45:00 +00:00
|
|
|
<StackLayout col="1">
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label :text="'expBu' | L" textWrap="true" />
|
|
|
|
<Label v-if="!backupInProgress" :text="'buInfo' | L" class="info" textWrap="true" />
|
2020-12-07 14:45:00 +00:00
|
|
|
<GridLayout class="progressContainer" v-else columns="*, 64">
|
|
|
|
<MDProgress col="0" :value="backupProgress" maxValue="100"></MDProgress>
|
|
|
|
<Label col="1" :text="` ${backupProgress}%`" />
|
|
|
|
</GridLayout>
|
|
|
|
</StackLayout>
|
|
|
|
</GridLayout>
|
|
|
|
<GridLayout columns="auto, *" class="option">
|
|
|
|
<MDRipple colSpan="2" @tap="importCheck" />
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label col="0" class="er" :text="icon.imp" />
|
2020-12-07 14:45:00 +00:00
|
|
|
<StackLayout col="1">
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label :text="'impBu' | L" textWrap="true" />
|
|
|
|
<Label :text="'impInfo' | L" class="info" textWrap="true" />
|
2020-12-07 14:45:00 +00:00
|
|
|
</StackLayout>
|
|
|
|
</GridLayout>
|
2020-12-29 10:35:19 +00:00
|
|
|
<StackLayout class="hr m-10"></StackLayout>
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label :text="'rest' | L" class="group-header orkm" />
|
2020-12-29 10:35:19 +00:00
|
|
|
<GridLayout columns="auto, *" class="option">
|
|
|
|
<MDRipple colSpan="2" @tap="resetListItems('cuisines')" />
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label col="0" class="er" :text="icon.reset" />
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label col="1" verticalAlignment="center" :text="'restCuiL' | L" textWrap="true" />
|
2020-12-29 10:35:19 +00:00
|
|
|
</GridLayout>
|
|
|
|
<GridLayout columns="auto, *" class="option">
|
|
|
|
<MDRipple colSpan="2" @tap="resetListItems('categories')" />
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label col="0" class="er" :text="icon.reset" />
|
|
|
|
<Label col="1" verticalAlignment="center" :text="'restCatL' | L" textWrap="true" />
|
2020-12-29 10:35:19 +00:00
|
|
|
</GridLayout>
|
|
|
|
<GridLayout columns="auto, *" class="option">
|
|
|
|
<MDRipple colSpan="2" @tap="resetListItems('yieldUnits')" />
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label col="0" class="er" :text="icon.reset" />
|
|
|
|
<Label col="1" verticalAlignment="center" :text="'restYUL' | L" textWrap="true" />
|
2020-12-29 10:35:19 +00:00
|
|
|
</GridLayout>
|
|
|
|
<GridLayout columns="auto, *" class="option">
|
|
|
|
<MDRipple colSpan="2" @tap="resetListItems('units')" />
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label col="0" class="er" :text="icon.reset" />
|
|
|
|
<Label col="1" verticalAlignment="center" :text="'restUL' | L" textWrap="true" />
|
2020-12-29 10:35:19 +00:00
|
|
|
</GridLayout>
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label class="group-info" :text="'restInfo' | L" textWrap="true" />
|
|
|
|
|
|
|
|
<StackLayout class="hr m-10"></StackLayout>
|
|
|
|
<Label :text="'help' | L" class="group-header orkm" />
|
|
|
|
|
|
|
|
<GridLayout columns="auto, *" class="option">
|
|
|
|
<MDRipple colSpan="2" @tap="openURL('https://t.me/enrecipes')" />
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label col="0" class="er" :text="icon.tg" />
|
2021-01-13 05:02:48 +00:00
|
|
|
<StackLayout col="1">
|
|
|
|
<Label :text="'joinTG' | L" textWrap="true" />
|
|
|
|
<Label :text="'tgInfo' | L" class="info" textWrap="true" />
|
|
|
|
</StackLayout>
|
|
|
|
</GridLayout>
|
2021-01-23 17:20:15 +00:00
|
|
|
<GridLayout columns="auto, *" class="option">
|
|
|
|
<MDRipple colSpan="2" @tap="openURL('https://github.com/vishnuraghavb/EnRecipes/wiki/User-Guide')" />
|
|
|
|
<Label col="0" class="er" :text="icon.help" />
|
|
|
|
<Label verticalAlignment="center" col="1" :text="'guide' | L" textWrap="true" />
|
|
|
|
</GridLayout>
|
|
|
|
<GridLayout columns="auto, *" class="option">
|
|
|
|
<MDRipple colSpan="2" @tap="openURL('https://github.com/vishnuraghavb/EnRecipes/blob/main/PRIVACY.md')" />
|
|
|
|
<Label col="0" class="er" :text="icon.priv" />
|
|
|
|
<Label verticalAlignment="center" col="1" :text="'priv' | L" textWrap="true" />
|
|
|
|
</GridLayout>
|
2021-01-13 05:02:48 +00:00
|
|
|
<StackLayout class="hr m-10"></StackLayout>
|
|
|
|
<Label :text="'About' | L" class="group-header orkm" />
|
|
|
|
|
|
|
|
<GridLayout columns="auto, *" class="option">
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label col="0" class="er" :text="icon.info" />
|
2021-01-13 05:02:48 +00:00
|
|
|
<StackLayout col="1">
|
|
|
|
<Label :text="'ver' | L" />
|
|
|
|
<Label :text="getVersion" class="info" textWrap="true" />
|
|
|
|
</StackLayout>
|
|
|
|
</GridLayout>
|
|
|
|
<GridLayout columns="auto, *" class="option">
|
|
|
|
<MDRipple colSpan="2" @tap="openURL('https://github.com/vishnuraghavb/enrecipes')" />
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label col="0" class="er" :text="icon.gh" />
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label verticalAlignment="center" col="1" :text="'gh' | L" textWrap="true" />
|
|
|
|
</GridLayout>
|
|
|
|
<GridLayout columns="auto, *" class="option">
|
|
|
|
<MDRipple colSpan="2" @tap="openURL('https://www.vishnuraghav.com/donate')" />
|
2021-01-23 17:20:15 +00:00
|
|
|
<Label col="0" class="er" :text="icon.don" />
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label verticalAlignment="center" col="1" :text="'donate' | L" textWrap="true" />
|
|
|
|
</GridLayout>
|
2021-01-23 17:20:15 +00:00
|
|
|
<GridLayout columns="auto, *" class="option">
|
|
|
|
<MDRipple colSpan="2" @tap="openURL('https://hosted.weblate.org/projects/enrecipes/app-translations')" />
|
|
|
|
<Label col="0" class="er" :text="icon.trans" />
|
|
|
|
<Label verticalAlignment="center" col="1" :text="'trnsl' | L" textWrap="true" />
|
|
|
|
</GridLayout>
|
2021-01-13 05:02:48 +00:00
|
|
|
<Label class="group-info" :text="'appInfo' | L" textWrap="true" />
|
2020-12-07 14:45:00 +00:00
|
|
|
</StackLayout>
|
|
|
|
</ScrollView>
|
|
|
|
</Page>
|
2020-09-15 11:10:16 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-10-24 18:02:35 +00:00
|
|
|
import {
|
2021-01-13 05:02:48 +00:00
|
|
|
Application,
|
|
|
|
Utils,
|
2020-10-24 18:02:35 +00:00
|
|
|
ApplicationSettings,
|
|
|
|
path,
|
|
|
|
knownFolders,
|
2020-11-03 19:57:31 +00:00
|
|
|
File,
|
|
|
|
Folder,
|
2020-12-07 14:45:00 +00:00
|
|
|
Observable,
|
|
|
|
Device
|
|
|
|
}
|
|
|
|
from "@nativescript/core"
|
2020-11-03 19:57:31 +00:00
|
|
|
import * as Permissions from "@nativescript-community/perms"
|
2020-12-07 14:45:00 +00:00
|
|
|
import {
|
|
|
|
Zip
|
|
|
|
}
|
|
|
|
from "@nativescript/zip"
|
2020-10-26 20:49:54 +00:00
|
|
|
import * as Toast from "nativescript-toast"
|
2020-11-03 19:57:31 +00:00
|
|
|
import * as Filepicker from "nativescript-plugin-filepicker"
|
2020-10-14 19:32:32 +00:00
|
|
|
import Theme from "@nativescript/theme"
|
2020-12-07 14:45:00 +00:00
|
|
|
import {
|
|
|
|
localize,
|
|
|
|
overrideLocale
|
|
|
|
}
|
|
|
|
from "@nativescript/localize"
|
|
|
|
import {
|
|
|
|
mapState,
|
|
|
|
mapActions
|
|
|
|
}
|
|
|
|
from "vuex"
|
2020-10-21 17:54:45 +00:00
|
|
|
import ActionDialog from "./modal/ActionDialog.vue"
|
|
|
|
import ConfirmDialog from "./modal/ConfirmDialog.vue"
|
2020-11-23 09:49:58 +00:00
|
|
|
import * as utils from "~/shared/utils"
|
2020-09-15 11:10:16 +00:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2020-11-03 19:57:31 +00:00
|
|
|
appTheme: "Light",
|
2020-12-07 14:45:00 +00:00
|
|
|
appLanguage: "English",
|
2020-11-06 09:07:41 +00:00
|
|
|
backupProgress: 0,
|
|
|
|
backupInProgress: false,
|
2020-09-15 11:10:16 +00:00
|
|
|
}
|
|
|
|
},
|
2020-10-14 19:32:32 +00:00
|
|
|
computed: {
|
2020-12-29 10:35:19 +00:00
|
|
|
...mapState( [ "icon", "recipes", "cuisines", "categories", "yieldUnits", "units", "mealPlans", "currentComponent", "language", "shakeEnabled", "importSummary" ] ),
|
2021-01-13 05:02:48 +00:00
|
|
|
getVersion() {
|
|
|
|
let ctx = Application.android.context
|
|
|
|
return ctx.getPackageManager().getPackageInfo( ctx.getPackageName(), 0 ).versionName
|
|
|
|
},
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
2020-09-15 11:10:16 +00:00
|
|
|
methods: {
|
2020-12-29 10:35:19 +00:00
|
|
|
...mapActions( [ "setCurrentComponentAction", "importListItemsAction", "importRecipesAction", "importMealPlansAction", "resetListItemsAction", "setShakeAction", "unlinkBrokenImages" ] ),
|
2020-12-07 14:45:00 +00:00
|
|
|
onPageLoad( args ) {
|
|
|
|
const page = args.object;
|
|
|
|
page.bindingContext = new Observable();
|
|
|
|
this.setCurrentComponentAction( "Settings" )
|
2020-10-21 17:54:45 +00:00
|
|
|
},
|
2020-11-10 18:28:48 +00:00
|
|
|
// HELPERS
|
2021-01-13 05:02:48 +00:00
|
|
|
openURL( url ) {
|
|
|
|
Utils.openUrl( url )
|
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
// LANGUAGE SELECTION
|
|
|
|
selectAppLanguage() {
|
|
|
|
let languages = this.language.map( e => e.title )
|
|
|
|
this.$showModal( ActionDialog, {
|
|
|
|
props: {
|
2021-01-13 05:02:48 +00:00
|
|
|
title: "lang",
|
2020-12-07 14:45:00 +00:00
|
|
|
list: [ ...languages ],
|
2020-12-29 10:35:19 +00:00
|
|
|
stretch: true,
|
2021-01-23 17:20:15 +00:00
|
|
|
helpIcon: 'lang',
|
2020-12-07 14:45:00 +00:00
|
|
|
},
|
|
|
|
} ).then( ( action ) => {
|
|
|
|
if ( action && action !== "Cancel" && this.appLanguage !== action ) {
|
|
|
|
let currentLocale = Device.language.split( '-' )[ 0 ]
|
|
|
|
let locale = this.language.filter( e => e.title === action )[ 0 ].locale
|
|
|
|
if ( currentLocale !== locale ) {
|
|
|
|
this.$showModal( ConfirmDialog, {
|
|
|
|
props: {
|
2021-01-13 05:02:48 +00:00
|
|
|
title: "appRst",
|
|
|
|
description: localize( "nLangInfo" ),
|
|
|
|
cancelButtonText: "cBtn",
|
|
|
|
okButtonText: "rst",
|
2021-01-23 17:20:15 +00:00
|
|
|
helpIcon: 'res',
|
2021-01-13 05:02:48 +00:00
|
|
|
bgColor: '#ff5200',
|
2020-12-07 14:45:00 +00:00
|
|
|
},
|
|
|
|
} ).then( ( result ) => {
|
|
|
|
if ( result ) {
|
|
|
|
this.appLanguage = action
|
|
|
|
ApplicationSettings.setString( "appLanguage", action )
|
|
|
|
overrideLocale( locale )
|
2021-01-13 05:02:48 +00:00
|
|
|
setTimeout( utils.restartApp, 250 )
|
2020-12-07 14:45:00 +00:00
|
|
|
}
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
},
|
2020-11-10 18:28:48 +00:00
|
|
|
// THEME SELECTION
|
|
|
|
selectThemes() {
|
2020-12-07 14:45:00 +00:00
|
|
|
this.$showModal( ActionDialog, {
|
2020-10-21 17:54:45 +00:00
|
|
|
props: {
|
|
|
|
title: "Theme",
|
2020-12-07 14:45:00 +00:00
|
|
|
list: [ "Light", "Dark" ],
|
2021-01-13 05:02:48 +00:00
|
|
|
stretch: false,
|
|
|
|
helpIcon: 'theme',
|
2020-10-21 17:54:45 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
} ).then( ( action ) => {
|
|
|
|
if ( action && action !== "Cancel" && this.appTheme !== action ) {
|
|
|
|
this.$showModal( ConfirmDialog, {
|
2020-10-21 17:54:45 +00:00
|
|
|
props: {
|
2021-01-13 05:02:48 +00:00
|
|
|
title: "appRst",
|
|
|
|
description: localize( "nThmInfo" ),
|
|
|
|
cancelButtonText: "cBtn",
|
|
|
|
okButtonText: "rst",
|
2021-01-23 17:20:15 +00:00
|
|
|
helpIcon: 'res',
|
2021-01-13 05:02:48 +00:00
|
|
|
bgColor: '#ff5200',
|
2020-10-21 17:54:45 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
} ).then( ( result ) => {
|
|
|
|
if ( result ) {
|
2020-11-03 19:57:31 +00:00
|
|
|
this.appTheme = action
|
2020-12-07 14:45:00 +00:00
|
|
|
ApplicationSettings.setString( "appTheme", action )
|
2021-01-13 05:02:48 +00:00
|
|
|
setTimeout( utils.restartApp, 250 )
|
2020-10-21 17:54:45 +00:00
|
|
|
}
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-10-21 17:54:45 +00:00
|
|
|
}
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-09-15 11:10:16 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
// SHAKE VIEW RANDOM RECIPE
|
|
|
|
toggleShake( args ) {
|
|
|
|
let checked = args.object.checked
|
|
|
|
// let checked = !this.shakeEnabled
|
|
|
|
ApplicationSettings.setBoolean( 'shakeEnabled', checked )
|
|
|
|
this.setShakeAction( checked )
|
|
|
|
},
|
2020-11-10 18:28:48 +00:00
|
|
|
// EXPORT HANDLERS
|
|
|
|
exportCheck() {
|
2020-12-07 14:45:00 +00:00
|
|
|
if ( !this.recipes.length ) {
|
2021-01-13 05:02:48 +00:00
|
|
|
Toast.makeText( localize( "aFBu" ) ).show()
|
2020-12-29 10:35:19 +00:00
|
|
|
} else {
|
2021-01-13 05:02:48 +00:00
|
|
|
this.permissionCheck( this.permissionConfirmation, localize( "reqAcc" ), this.exportBackup )
|
2020-11-06 09:07:41 +00:00
|
|
|
}
|
2020-11-03 19:57:31 +00:00
|
|
|
},
|
2020-11-10 18:28:48 +00:00
|
|
|
exportBackup() {
|
2020-12-07 14:45:00 +00:00
|
|
|
this.exportFiles( "create" )
|
2020-11-03 19:57:31 +00:00
|
|
|
let date = new Date()
|
2020-12-29 10:35:19 +00:00
|
|
|
let formattedDate = date.getFullYear() + "-" + ( "0" + ( date.getMonth() + 1 ) ).slice( -2 ) + "-" + ( "0" + date.getDate() ).slice( -2 ) + "_" + ( "0" + date.getHours() ).slice( -2 ) + ( "0" + date.getMinutes() ).slice( -2 ) + ( "0" + date
|
|
|
|
.getSeconds() ).slice( -2 )
|
|
|
|
const sdDownloadPath = Folder.fromPath( android.os.Environment.getExternalStorageDirectory().getAbsolutePath() ).getFolder( "Download" ).path
|
2020-12-07 14:45:00 +00:00
|
|
|
let fromPath = path.join( knownFolders.documents().path, "EnRecipes" )
|
2020-12-29 10:35:19 +00:00
|
|
|
let destPath = path.join( sdDownloadPath, `EnRecipes-Backup_${formattedDate}.zip` )
|
2020-11-06 09:07:41 +00:00
|
|
|
this.backupInProgress = true
|
2020-12-07 14:45:00 +00:00
|
|
|
Zip.zip( {
|
2020-11-03 19:57:31 +00:00
|
|
|
directory: fromPath,
|
|
|
|
archive: destPath,
|
2020-12-07 14:45:00 +00:00
|
|
|
onProgress: ( progress ) => {
|
2020-11-06 09:07:41 +00:00
|
|
|
this.backupProgress = progress
|
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
} ).then( ( success ) => {
|
2020-12-29 10:35:19 +00:00
|
|
|
Toast.makeText( "Backup file successfully saved to Download folder", "long" ).show()
|
2020-12-07 14:45:00 +00:00
|
|
|
this.exportFiles( "delete" )
|
2021-01-13 05:02:48 +00:00
|
|
|
setTimeout( e => this.backupInProgress = false, 3000 )
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-09-15 11:10:16 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
exportFiles( option ) {
|
|
|
|
const folder = path.join( knownFolders.documents().path, "EnRecipes" )
|
|
|
|
const EnRecipesFile = File.fromPath( path.join( folder, "recipes.json" ) )
|
2020-12-29 10:35:19 +00:00
|
|
|
let userCuisinesFile, userCategoriesFile, userYieldUnitsFile, userUnitsFile, mealPlansFile
|
|
|
|
if ( this.cuisines.length ) userCuisinesFile = File.fromPath( path.join( folder, "userCuisines.json" ) )
|
|
|
|
if ( this.categories.length ) userCategoriesFile = File.fromPath( path.join( folder, "userCategories.json" ) )
|
|
|
|
if ( this.yieldUnits.length ) userYieldUnitsFile = File.fromPath( path.join( folder, "userYieldUnits.json" ) )
|
|
|
|
if ( this.units.length ) userUnitsFile = File.fromPath( path.join( folder, "userUnits.json" ) )
|
|
|
|
if ( this.mealPlans.length ) mealPlansFile = File.fromPath( path.join( folder, "mealPlans.json" ) )
|
2020-12-07 14:45:00 +00:00
|
|
|
switch ( option ) {
|
2020-11-10 18:28:48 +00:00
|
|
|
case "create":
|
2020-12-07 14:45:00 +00:00
|
|
|
this.writeDataToFile( EnRecipesFile, this.recipes )
|
2020-12-29 10:35:19 +00:00
|
|
|
this.cuisines.length && this.writeDataToFile( userCuisinesFile, this.cuisines )
|
|
|
|
this.categories.length && this.writeDataToFile( userCategoriesFile, this.categories )
|
|
|
|
this.yieldUnits.length && this.writeDataToFile( userYieldUnitsFile, this.yieldUnits )
|
|
|
|
this.units.length && this.writeDataToFile( userUnitsFile, this.units )
|
|
|
|
this.mealPlans.length && this.writeDataToFile( mealPlansFile, this.mealPlans )
|
2020-11-10 18:28:48 +00:00
|
|
|
break
|
|
|
|
case "delete":
|
|
|
|
EnRecipesFile.remove()
|
2020-12-29 10:35:19 +00:00
|
|
|
this.cuisines.length && userCuisinesFile.remove()
|
|
|
|
this.categories.length && userCategoriesFile.remove()
|
|
|
|
this.yieldUnits.length && userYieldUnitsFile.remove()
|
|
|
|
this.units.length && userUnitsFile.remove()
|
2020-11-23 09:49:58 +00:00
|
|
|
this.mealPlans.length && mealPlansFile.remove()
|
2020-11-10 18:28:48 +00:00
|
|
|
break
|
|
|
|
default:
|
|
|
|
break
|
2020-11-03 19:57:31 +00:00
|
|
|
}
|
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
writeDataToFile( file, data ) {
|
|
|
|
file.writeText( JSON.stringify( data ) )
|
2020-11-03 19:57:31 +00:00
|
|
|
},
|
2020-11-10 18:28:48 +00:00
|
|
|
// IMPORT HANDLERS
|
|
|
|
importCheck() {
|
2021-01-13 05:02:48 +00:00
|
|
|
this.permissionCheck( this.permissionConfirmation, localize( "reqAcc" ), this.openFilePicker )
|
2020-11-03 19:57:31 +00:00
|
|
|
},
|
|
|
|
openFilePicker() {
|
2020-12-07 14:45:00 +00:00
|
|
|
Filepicker.create( {
|
2020-12-29 10:35:19 +00:00
|
|
|
mode: "single",
|
|
|
|
extensions: [ "zip" ],
|
|
|
|
} ).present().then( ( selection ) => {
|
2021-01-13 05:02:48 +00:00
|
|
|
Toast.makeText( localize( "vrfy" ) + '...' ).show()
|
2020-12-29 10:35:19 +00:00
|
|
|
let zipPath = selection[ 0 ]
|
|
|
|
this.validateZipContent( zipPath )
|
|
|
|
} )
|
2020-11-06 09:07:41 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
importDataToDB( data, db, zipPath ) {
|
|
|
|
switch ( db ) {
|
2020-11-06 09:07:41 +00:00
|
|
|
case "EnRecipesDB":
|
2020-12-07 14:45:00 +00:00
|
|
|
this.importImages( zipPath )
|
|
|
|
this.importRecipesAction( data )
|
2020-11-06 09:07:41 +00:00
|
|
|
break
|
2020-12-29 10:35:19 +00:00
|
|
|
case "userCuisinesDB":
|
|
|
|
this.importListItemsAction( {
|
|
|
|
data,
|
|
|
|
listName: "cuisines",
|
|
|
|
} )
|
|
|
|
break
|
2020-11-06 09:07:41 +00:00
|
|
|
case "userCategoriesDB":
|
2020-12-29 10:35:19 +00:00
|
|
|
this.importListItemsAction( {
|
|
|
|
data,
|
|
|
|
listName: "categories",
|
|
|
|
} )
|
2020-11-06 09:07:41 +00:00
|
|
|
break
|
|
|
|
case "userYieldUnitsDB":
|
2020-12-29 10:35:19 +00:00
|
|
|
this.importListItemsAction( {
|
|
|
|
data,
|
|
|
|
listName: "yieldUnits",
|
|
|
|
} )
|
|
|
|
break
|
|
|
|
case "userUnitsDB":
|
|
|
|
this.importListItemsAction( {
|
|
|
|
data,
|
|
|
|
listName: "units",
|
|
|
|
} )
|
2020-11-06 09:07:41 +00:00
|
|
|
break
|
2020-11-23 09:49:58 +00:00
|
|
|
case "mealPlansDB":
|
2020-12-07 14:45:00 +00:00
|
|
|
this.importMealPlansAction( data )
|
2020-11-23 09:49:58 +00:00
|
|
|
break
|
2020-11-06 09:07:41 +00:00
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
hasValidJSON( data ) {
|
|
|
|
try {
|
|
|
|
JSON.parse( data ) && Array.isArray( JSON.parse( data ) )
|
|
|
|
} catch ( e ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
isFileDataValid( file ) {
|
2020-12-29 10:35:19 +00:00
|
|
|
const files = file.filter( e => File.exists( e.path ) )
|
|
|
|
if ( files.length ) {
|
|
|
|
let isValid = files.map( e => false )
|
|
|
|
files.forEach( ( file, i ) => {
|
|
|
|
File.fromPath( file.path ).readText().then( ( data ) => {
|
|
|
|
isValid[ i ] = this.hasValidJSON( data )
|
|
|
|
if ( !isValid[ i ] ) {
|
2021-01-13 05:02:48 +00:00
|
|
|
this.failedImport( `${localize("buMod")}\n\n${localize("invFile")}: ${file.file}` )
|
2020-12-29 10:35:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ( isValid.every( e => e === true ) ) {
|
|
|
|
files.forEach( ( file, i ) => {
|
|
|
|
File.fromPath( file.path ).readText().then( ( data ) => {
|
|
|
|
this.importDataToDB( JSON.parse( data ), file.db, file.zipPath )
|
|
|
|
} )
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
} )
|
|
|
|
} else {
|
2021-01-13 05:02:48 +00:00
|
|
|
this.failedImport( localize( "buEmp" ) )
|
2020-12-29 10:35:19 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
failedImport( description ) {
|
|
|
|
this.$showModal( ConfirmDialog, {
|
|
|
|
props: {
|
2021-01-13 05:02:48 +00:00
|
|
|
title: "impFail",
|
2020-12-29 10:35:19 +00:00
|
|
|
description,
|
|
|
|
okButtonText: "OK",
|
2021-01-23 17:20:15 +00:00
|
|
|
helpIcon: 'alert',
|
2021-01-13 05:02:48 +00:00
|
|
|
bgColor: '#c92a2a',
|
2020-12-29 10:35:19 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-11-03 19:57:31 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
validateZipContent( zipPath ) {
|
|
|
|
Zip.unzip( {
|
2020-11-03 19:57:31 +00:00
|
|
|
archive: zipPath,
|
|
|
|
overwrite: true,
|
2020-12-07 14:45:00 +00:00
|
|
|
} ).then( ( extractedFolderPath ) => {
|
2020-11-06 09:07:41 +00:00
|
|
|
let cacheFolderPath = extractedFolderPath + "/EnRecipes"
|
2020-11-23 09:49:58 +00:00
|
|
|
const EnRecipesFilePath = cacheFolderPath + "/recipes.json"
|
2020-12-29 10:35:19 +00:00
|
|
|
const userCuisinesFilePath = cacheFolderPath + "/userCuisines.json"
|
2020-11-03 19:57:31 +00:00
|
|
|
const userCategoriesFilePath = cacheFolderPath + "/userCategories.json"
|
|
|
|
const userYieldUnitsFilePath = cacheFolderPath + "/userYieldUnits.json"
|
2020-12-29 10:35:19 +00:00
|
|
|
const userUnitsFilePath = cacheFolderPath + "/userUnits.json"
|
2020-11-23 09:49:58 +00:00
|
|
|
const mealPlansFilePath = cacheFolderPath + "/mealPlans.json"
|
2020-12-07 14:45:00 +00:00
|
|
|
if ( Folder.exists( cacheFolderPath ) ) {
|
|
|
|
this.isFileDataValid( [ {
|
2020-12-29 10:35:19 +00:00
|
|
|
zipPath,
|
|
|
|
path: EnRecipesFilePath,
|
|
|
|
db: "EnRecipesDB",
|
|
|
|
file: "recipes.json"
|
|
|
|
}, {
|
|
|
|
zipPath,
|
|
|
|
path: userCuisinesFilePath,
|
|
|
|
db: "userCuisinesDB",
|
|
|
|
file: "userCuisines.json"
|
|
|
|
}, {
|
|
|
|
zipPath,
|
|
|
|
path: userCategoriesFilePath,
|
|
|
|
db: "userCategoriesDB",
|
|
|
|
file: "userCategories.json"
|
|
|
|
}, {
|
|
|
|
zipPath,
|
|
|
|
path: userYieldUnitsFilePath,
|
|
|
|
db: "userYieldUnitsDB",
|
|
|
|
file: "userYieldUnits.json"
|
|
|
|
}, {
|
|
|
|
zipPath,
|
|
|
|
path: userUnitsFilePath,
|
|
|
|
db: "userUnitsDB",
|
|
|
|
file: "userUnits.json"
|
|
|
|
}, {
|
|
|
|
zipPath,
|
|
|
|
path: mealPlansFilePath,
|
|
|
|
db: "mealPlansDB",
|
|
|
|
file: "mealPlans.json"
|
|
|
|
}, ] )
|
|
|
|
} else {
|
2020-12-07 14:45:00 +00:00
|
|
|
Folder.fromPath( extractedFolderPath ).remove()
|
2021-01-13 05:02:48 +00:00
|
|
|
this.failedImport( localize( "buInc" ) )
|
2020-11-06 09:07:41 +00:00
|
|
|
}
|
2020-12-07 14:45:00 +00:00
|
|
|
if ( Folder.exists( cacheFolderPath + "/Images" ) ) {
|
|
|
|
this.importImages( cacheFolderPath + "/Images" )
|
2020-11-03 19:57:31 +00:00
|
|
|
}
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-11-03 19:57:31 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
importImages( sourcePath ) {
|
2020-11-06 09:07:41 +00:00
|
|
|
let dest = knownFolders.documents().path
|
2020-12-07 14:45:00 +00:00
|
|
|
Zip.unzip( {
|
2020-11-06 09:07:41 +00:00
|
|
|
archive: sourcePath,
|
|
|
|
directory: dest,
|
|
|
|
overwrite: true,
|
2020-12-07 14:45:00 +00:00
|
|
|
} ).then( ( res ) => {
|
2020-12-29 10:35:19 +00:00
|
|
|
this.showImportSummary()
|
|
|
|
this.unlinkBrokenImages()
|
|
|
|
} )
|
|
|
|
},
|
|
|
|
showImportSummary() {
|
|
|
|
let {
|
|
|
|
found,
|
|
|
|
imported,
|
|
|
|
updated
|
|
|
|
} = this.importSummary
|
2021-01-13 05:02:48 +00:00
|
|
|
let exists = Math.abs( found - imported - updated ) + updated
|
|
|
|
let importedNote = `\n${imported} ${localize('recI')}`
|
|
|
|
let existsNote = `\n${exists} ${localize('recE')}`
|
|
|
|
let updatedNote = `\n${updated} ${localize('recU')}`
|
2020-12-29 10:35:19 +00:00
|
|
|
this.$showModal( ConfirmDialog, {
|
|
|
|
props: {
|
2021-01-13 05:02:48 +00:00
|
|
|
title: "impSuc",
|
|
|
|
description: `${found} ${localize('recF')}${ importedNote}${existsNote}${updatedNote}`,
|
2020-12-29 10:35:19 +00:00
|
|
|
okButtonText: "OK",
|
2021-01-23 17:20:15 +00:00
|
|
|
helpIcon: 'succ',
|
|
|
|
bgColor: '#69db7c',
|
2020-12-29 10:35:19 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-11-03 19:57:31 +00:00
|
|
|
},
|
2020-11-10 18:28:48 +00:00
|
|
|
// PERMISSIONS HANDLER
|
2020-12-07 14:45:00 +00:00
|
|
|
permissionCheck( confirmation, description, action ) {
|
|
|
|
if ( !ApplicationSettings.getBoolean( "storagePermissionAsked", false ) ) {
|
|
|
|
confirmation( description ).then( ( e ) => {
|
|
|
|
if ( e ) {
|
|
|
|
Permissions.request( "photo" ).then( ( res ) => {
|
|
|
|
let status = res[ Object.keys( res )[ 0 ] ]
|
|
|
|
if ( status === "authorized" ) action()
|
2020-12-29 10:35:19 +00:00
|
|
|
if ( status !== "denied" ) ApplicationSettings.setBoolean( "storagePermissionAsked", true )
|
2021-01-13 05:02:48 +00:00
|
|
|
else Toast.makeText( localize( "dend" ) ).show()
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-11-03 19:57:31 +00:00
|
|
|
}
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-12-29 10:35:19 +00:00
|
|
|
} else {
|
2020-12-07 14:45:00 +00:00
|
|
|
Permissions.check( "photo" ).then( ( res ) => {
|
|
|
|
let status = res[ Object.keys( res )[ 0 ] ]
|
|
|
|
if ( status !== "authorized" ) {
|
|
|
|
confirmation( description ).then( ( e ) => {
|
2020-11-23 09:49:58 +00:00
|
|
|
e && utils.openAppSettingsPage()
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-12-29 10:35:19 +00:00
|
|
|
} else action()
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-11-03 19:57:31 +00:00
|
|
|
}
|
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
permissionConfirmation( description ) {
|
|
|
|
return this.$showModal( ConfirmDialog, {
|
2020-11-10 18:28:48 +00:00
|
|
|
props: {
|
2021-01-13 05:02:48 +00:00
|
|
|
title: "grant",
|
2020-11-10 18:28:48 +00:00
|
|
|
description,
|
2021-01-13 05:02:48 +00:00
|
|
|
cancelButtonText: "nNBtn",
|
|
|
|
okButtonText: "conBtn",
|
|
|
|
helpIcon: 'folder',
|
|
|
|
bgColor: '#ff5200',
|
2020-11-10 18:28:48 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
} )
|
2020-11-10 18:28:48 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
// RESET
|
|
|
|
resetListItems( listName ) {
|
|
|
|
this.resetListItemsAction( listName )
|
2021-01-13 05:02:48 +00:00
|
|
|
Toast.makeText( localize( "restDone" ) ).show()
|
2020-12-29 10:35:19 +00:00
|
|
|
}
|
2021-01-13 05:02:48 +00:00
|
|
|
|
2020-09-15 11:10:16 +00:00
|
|
|
},
|
2020-11-23 09:49:58 +00:00
|
|
|
mounted() {
|
2020-12-07 14:45:00 +00:00
|
|
|
this.appTheme = ApplicationSettings.getString( "appTheme", "Light" )
|
2021-01-13 05:02:48 +00:00
|
|
|
this.appLanguage = ApplicationSettings.getString( "appLanguage", localize( "sysDef" ) )
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
2020-09-15 11:10:16 +00:00
|
|
|
}
|
|
|
|
</script>
|