2020-12-29 10:35:19 +00:00
|
|
|
import Vue from "vue";
|
|
|
|
import Vuex from "vuex";
|
|
|
|
Vue.use(Vuex);
|
|
|
|
import {Couchbase} from "nativescript-couchbase-plugin";
|
|
|
|
import {getFileAccess, File, ApplicationSettings} from "@nativescript/core";
|
|
|
|
const EnRecipesDB = new Couchbase("EnRecipes");
|
|
|
|
const userCuisinesDB = new Couchbase("userCuisines");
|
|
|
|
const userCategoriesDB = new Couchbase("userCategories");
|
|
|
|
const userYieldUnitsDB = new Couchbase("userYieldUnits");
|
|
|
|
const userUnitsDB = new Couchbase("userUnits");
|
|
|
|
const mealPlansDB = new Couchbase("mealPlans");
|
|
|
|
const defaultCuisines = [
|
|
|
|
"American",
|
|
|
|
"Brazilian",
|
|
|
|
"British",
|
|
|
|
"Chinese",
|
|
|
|
"Danish",
|
|
|
|
"Egyptian",
|
|
|
|
"Filipino",
|
|
|
|
"French",
|
|
|
|
"German",
|
|
|
|
"Greek",
|
|
|
|
"Indian",
|
|
|
|
"Irish",
|
|
|
|
"Italian",
|
|
|
|
"Jamaican",
|
|
|
|
"Japanese",
|
|
|
|
"Jewish",
|
|
|
|
"Kenyan",
|
|
|
|
"Korean",
|
|
|
|
"Mexican",
|
|
|
|
"Nigerian",
|
|
|
|
"Portuguese",
|
|
|
|
"Russian",
|
|
|
|
"Scottish",
|
|
|
|
"Spanish",
|
|
|
|
"Sri Lankan",
|
|
|
|
"Swedish",
|
|
|
|
"Thai",
|
|
|
|
"Turkish",
|
|
|
|
"Vietnamese"
|
|
|
|
];
|
|
|
|
const defaultCategories = [
|
|
|
|
"Appetizers",
|
|
|
|
"Barbecue",
|
|
|
|
"Beverages",
|
|
|
|
"Breads",
|
|
|
|
"Breakfast",
|
|
|
|
"Desserts",
|
|
|
|
"Dinner",
|
|
|
|
"Drinks",
|
|
|
|
"Healthy",
|
|
|
|
"Lunch",
|
|
|
|
"Main dishes",
|
|
|
|
"Meat",
|
|
|
|
"Noodles",
|
|
|
|
"Pasta",
|
|
|
|
"Poultry",
|
|
|
|
"Rice",
|
|
|
|
"Salads",
|
|
|
|
"Sauces",
|
|
|
|
"Seafood",
|
|
|
|
"Side dishes",
|
|
|
|
"Snacks",
|
|
|
|
"Soups",
|
|
|
|
"Undefined",
|
|
|
|
"Vegan",
|
|
|
|
"Vegetarian"
|
|
|
|
];
|
|
|
|
const defaultYieldUnits = [
|
|
|
|
"Serving",
|
|
|
|
"Piece",
|
|
|
|
"Teaspoon",
|
|
|
|
"Tablespoon",
|
|
|
|
"Fluid Ounce",
|
|
|
|
"Ounce",
|
|
|
|
"Pound",
|
|
|
|
"Gram",
|
|
|
|
"Kilogram",
|
|
|
|
"Cup",
|
|
|
|
"Gallon",
|
|
|
|
"Millilitre",
|
|
|
|
"Litre",
|
|
|
|
"Roll",
|
|
|
|
"Patty",
|
|
|
|
"Loaf"
|
|
|
|
];
|
|
|
|
const defaultUnits = [
|
|
|
|
"unit",
|
|
|
|
"tsp",
|
|
|
|
"dsp",
|
|
|
|
"tbsp",
|
|
|
|
"fl oz",
|
|
|
|
"cup",
|
|
|
|
"pt",
|
|
|
|
"qt",
|
|
|
|
"gal",
|
|
|
|
"ml",
|
|
|
|
"l",
|
|
|
|
"oz",
|
|
|
|
"lb",
|
|
|
|
"mg",
|
|
|
|
"g",
|
|
|
|
"kg",
|
|
|
|
"cm",
|
|
|
|
"in",
|
|
|
|
"leaf",
|
|
|
|
"clove",
|
|
|
|
"piece",
|
|
|
|
"pinch",
|
|
|
|
"drop",
|
|
|
|
"dozen",
|
|
|
|
"stick",
|
|
|
|
"small",
|
|
|
|
"medium",
|
|
|
|
"large"
|
|
|
|
];
|
|
|
|
const listItems = {
|
|
|
|
cuisines: {
|
|
|
|
db: userCuisinesDB,
|
|
|
|
key: "userCuisines",
|
|
|
|
stateName: "cuisines",
|
|
|
|
sort: true,
|
|
|
|
defaultItems: defaultCuisines
|
|
|
|
},
|
|
|
|
categories: {
|
|
|
|
db: userCategoriesDB,
|
|
|
|
key: "userCategories",
|
|
|
|
stateName: "categories",
|
|
|
|
sort: true,
|
|
|
|
defaultItems: defaultCategories
|
|
|
|
},
|
|
|
|
yieldUnits: {
|
|
|
|
db: userYieldUnitsDB,
|
|
|
|
key: "userYieldUnits",
|
|
|
|
stateName: "yieldUnits",
|
|
|
|
sort: false,
|
|
|
|
defaultItems: defaultYieldUnits
|
|
|
|
},
|
|
|
|
units: {
|
|
|
|
db: userUnitsDB,
|
|
|
|
key: "userUnits",
|
|
|
|
stateName: "units",
|
|
|
|
sort: false,
|
|
|
|
defaultItems: defaultUnits
|
|
|
|
}
|
|
|
|
};
|
2020-09-15 11:10:16 +00:00
|
|
|
export default new Vuex.Store({
|
|
|
|
state: {
|
2020-11-29 12:54:21 +00:00
|
|
|
recipes: [],
|
2020-12-29 10:35:19 +00:00
|
|
|
cuisines: [],
|
2020-10-26 20:49:54 +00:00
|
|
|
categories: [],
|
2020-11-02 11:36:53 +00:00
|
|
|
yieldUnits: [],
|
2020-12-29 10:35:19 +00:00
|
|
|
units: [],
|
2020-11-23 09:49:58 +00:00
|
|
|
mealPlans: [],
|
2020-10-14 19:32:32 +00:00
|
|
|
icon: {
|
2021-01-23 17:20:15 +00:00
|
|
|
alert: "\ue900",
|
|
|
|
back: "\ue901",
|
|
|
|
bag: "\ue902",
|
|
|
|
bagged: "\ue903",
|
|
|
|
cal: "\ue904",
|
|
|
|
cam: "\ue905",
|
|
|
|
category: "\ue906",
|
|
|
|
cog: "\ue907",
|
|
|
|
comb: "\ue908",
|
|
|
|
cuisine: "\ue909",
|
|
|
|
del: "\ue90a",
|
|
|
|
diff: "\ue90b",
|
|
|
|
don: "\ue90c",
|
|
|
|
done: "\ue90d",
|
|
|
|
edit: "\ue90e",
|
|
|
|
exp: "\ue910",
|
|
|
|
fav: "\ue911",
|
|
|
|
faved: "\ue912",
|
|
|
|
folder: "\ue913",
|
|
|
|
gh: "\ue914",
|
|
|
|
help: "\ue915",
|
|
|
|
home: "\ue916",
|
|
|
|
img: "\ue917",
|
|
|
|
imp: "\ue918",
|
|
|
|
info: "\ue919",
|
|
|
|
items: "\ue91a",
|
2021-01-23 17:40:30 +00:00
|
|
|
l1: "\ue91b",
|
|
|
|
l2: "\ue91c",
|
|
|
|
l3: "\ue91d",
|
2021-01-23 17:20:15 +00:00
|
|
|
lang: "\ue91e",
|
|
|
|
left: "\ue91f",
|
|
|
|
menu: "\ue920",
|
|
|
|
noresult: "\ue921",
|
|
|
|
notes: "\ue922",
|
|
|
|
plus: "\ue923",
|
|
|
|
plusc: "\ue924",
|
2021-01-23 17:40:30 +00:00
|
|
|
price: "\ue925",
|
|
|
|
priv: "\ue926",
|
2021-01-23 17:20:15 +00:00
|
|
|
err: "\ue90f",
|
|
|
|
res: "\ue927",
|
|
|
|
reset: "\ue928",
|
|
|
|
right: "\ue929",
|
|
|
|
save: "\ue92a",
|
|
|
|
sear: "\ue92b",
|
|
|
|
selall: "\ue92c",
|
|
|
|
share: "\ue92d",
|
|
|
|
shuf: "\ue92e",
|
|
|
|
sort: "\ue92f",
|
|
|
|
star: "\ue930",
|
|
|
|
starred: "\ue931",
|
|
|
|
steps: "\ue932",
|
|
|
|
succ: "\ue933",
|
|
|
|
tag: "\ue934",
|
|
|
|
text: "\ue935",
|
|
|
|
tg: "\ue936",
|
|
|
|
theme: "\ue937",
|
|
|
|
time: "\ue938",
|
|
|
|
timer: "\ue939",
|
|
|
|
tod: "\ue93a",
|
|
|
|
trans: "\ue93b",
|
|
|
|
tried: "\ue93c",
|
|
|
|
try: "\ue93d",
|
|
|
|
unit: "\ue93e",
|
|
|
|
x: "\ue93f",
|
|
|
|
yield: "\ue940",
|
|
|
|
zip: "\ue941"
|
2020-10-14 19:32:32 +00:00
|
|
|
},
|
2020-10-21 17:54:45 +00:00
|
|
|
currentComponent: "EnRecipes",
|
2020-12-29 10:35:19 +00:00
|
|
|
sortType: "Oldest first",
|
|
|
|
language: [
|
|
|
|
{
|
|
|
|
locale: "da",
|
|
|
|
title: "Dansk"
|
|
|
|
}, {
|
|
|
|
locale: "de",
|
|
|
|
title: "Deutsch"
|
|
|
|
}, {
|
2021-01-01 20:34:45 +00:00
|
|
|
locale: "en-GB",
|
2021-01-23 17:20:15 +00:00
|
|
|
title: "English (UK)"
|
2020-12-29 10:35:19 +00:00
|
|
|
}, {
|
|
|
|
locale: "es",
|
|
|
|
title: "Español"
|
2021-01-23 17:20:15 +00:00
|
|
|
}, {
|
|
|
|
locale: "fr",
|
|
|
|
title: "Français"
|
|
|
|
}, {
|
|
|
|
locale: "fr-BE",
|
|
|
|
title: "Français (BE)"
|
|
|
|
}, {
|
|
|
|
locale: "fr-CA",
|
|
|
|
title: "Français (CA)"
|
|
|
|
}, {
|
|
|
|
locale: "fr-CH",
|
|
|
|
title: "Français (CH)"
|
|
|
|
}, {
|
|
|
|
locale: "it",
|
|
|
|
title: "Italiano"
|
|
|
|
}, {
|
|
|
|
locale: "nb-NO",
|
|
|
|
title: "Norsk bokmål"
|
2020-12-29 10:35:19 +00:00
|
|
|
}, {
|
|
|
|
locale: "nl",
|
|
|
|
title: "Nederlands"
|
|
|
|
}, {
|
|
|
|
locale: "pt",
|
|
|
|
title: "Português"
|
|
|
|
}, {
|
|
|
|
locale: "ru",
|
|
|
|
title: "Русский"
|
|
|
|
}, {
|
|
|
|
locale: "ta",
|
|
|
|
title: "தமிழ்"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
shakeEnabled: true,
|
|
|
|
importSummary: {
|
|
|
|
found: 0,
|
|
|
|
imported: 0,
|
|
|
|
updated: 0
|
|
|
|
}
|
2020-09-15 11:10:16 +00:00
|
|
|
},
|
|
|
|
mutations: {
|
2020-12-29 10:35:19 +00:00
|
|
|
setSortType(state, sortType) {
|
|
|
|
state.sortType = sortType
|
2020-10-26 20:49:54 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
initializeRecipes(state) {
|
|
|
|
EnRecipesDB.query({select: []}).forEach(r => {
|
|
|
|
if (r.timeRequired) {
|
|
|
|
r.prepTime = "00:00";
|
|
|
|
r.cookTime = r.timeRequired;
|
|
|
|
delete r.timeRequired;
|
|
|
|
}
|
|
|
|
if (!r.hasOwnProperty("cuisine"))
|
|
|
|
r.cuisine = "Undefined"
|
|
|
|
if (!r.hasOwnProperty("tags"))
|
|
|
|
r.tags = []
|
|
|
|
if (!r.hasOwnProperty("difficulty"))
|
|
|
|
r.difficulty = "Easy"
|
|
|
|
if (!r.hasOwnProperty("rating"))
|
|
|
|
r.rating = 0
|
|
|
|
if (!r.hasOwnProperty("created"))
|
|
|
|
r.created = r.lastModified
|
2021-01-23 17:40:30 +00:00
|
|
|
// if (!r.hasOwnProperty("inBag"))
|
2021-01-23 17:20:15 +00:00
|
|
|
// r.inBag = false
|
2020-12-29 10:35:19 +00:00
|
|
|
state.recipes.push(r);
|
|
|
|
});
|
|
|
|
state.shakeEnabled = ApplicationSettings.getBoolean("shakeEnabled", true)
|
|
|
|
state.sortType = ApplicationSettings.getString("sortType", "Oldest first")
|
2020-11-06 09:07:41 +00:00
|
|
|
},
|
|
|
|
importRecipes(state, recipes) {
|
2020-12-29 10:35:19 +00:00
|
|
|
let localRecipesIDs,
|
|
|
|
partition
|
|
|
|
let imported = 0
|
|
|
|
let updated = 0
|
2020-12-01 09:22:22 +00:00
|
|
|
function getUpdatedData(data) {
|
2020-12-29 10:35:19 +00:00
|
|
|
return data.map(recipe => {
|
|
|
|
let r = Object.assign({}, recipe);
|
2020-12-01 09:22:22 +00:00
|
|
|
if (r.timeRequired) {
|
2020-12-29 10:35:19 +00:00
|
|
|
r.prepTime = "00:00";
|
|
|
|
r.cookTime = r.timeRequired;
|
|
|
|
delete r.timeRequired;
|
2020-12-01 09:22:22 +00:00
|
|
|
}
|
2020-12-29 10:35:19 +00:00
|
|
|
if (!r.hasOwnProperty("cuisine"))
|
|
|
|
r.cuisine = "Undefined"
|
|
|
|
if (!r.hasOwnProperty("tags"))
|
|
|
|
r.tags = []
|
|
|
|
if (!r.hasOwnProperty("difficulty"))
|
|
|
|
r.difficulty = "Easy"
|
|
|
|
if (!r.hasOwnProperty("rating"))
|
|
|
|
r.rating = 0
|
|
|
|
if (!r.hasOwnProperty("created"))
|
|
|
|
r.created = r.lastModified
|
2021-01-23 17:40:30 +00:00
|
|
|
// if (!r.hasOwnProperty("inBag"))
|
2021-01-23 17:20:15 +00:00
|
|
|
// r.inBag = false
|
2020-12-29 10:35:19 +00:00
|
|
|
return r;
|
|
|
|
});
|
2020-12-01 09:22:22 +00:00
|
|
|
}
|
2020-11-06 09:07:41 +00:00
|
|
|
function createDocuments(data) {
|
2020-12-29 10:35:19 +00:00
|
|
|
data = getUpdatedData(data);
|
|
|
|
state.recipes = [
|
|
|
|
...state.recipes,
|
|
|
|
...data
|
|
|
|
];
|
|
|
|
data.forEach(recipe => {
|
|
|
|
imported++
|
|
|
|
EnRecipesDB.createDocument(recipe, recipe.id);
|
|
|
|
});
|
2020-11-06 09:07:41 +00:00
|
|
|
}
|
|
|
|
function updateDocuments(data) {
|
2020-12-29 10:35:19 +00:00
|
|
|
data = getUpdatedData(data);
|
|
|
|
data.forEach(recipe => {
|
2020-12-12 18:06:10 +00:00
|
|
|
let recipeIndex = state.recipes.map((e, i) => {
|
2020-12-29 10:35:19 +00:00
|
|
|
let d1 = new Date(e.lastModified).getTime();
|
|
|
|
let d2 = new Date(recipe.lastModified).getTime();
|
|
|
|
return e.id === recipe.id && d1 < d2
|
|
|
|
? i
|
|
|
|
: -1;
|
|
|
|
}).filter(e => e >= 0)[0];
|
2020-11-23 09:49:58 +00:00
|
|
|
if (recipeIndex >= 0) {
|
2020-12-29 10:35:19 +00:00
|
|
|
updated++
|
|
|
|
Object.assign(state.recipes[recipeIndex], recipe);
|
|
|
|
EnRecipesDB.updateDocument(recipe.id, recipe);
|
2020-11-23 09:49:58 +00:00
|
|
|
}
|
2020-12-29 10:35:19 +00:00
|
|
|
});
|
2020-11-02 11:36:53 +00:00
|
|
|
}
|
2020-12-29 10:35:19 +00:00
|
|
|
if (state.recipes.length) {
|
|
|
|
localRecipesIDs = state.recipes.map(e => e.id);
|
|
|
|
partition = recipes.reduce((result, recipe, i) => {
|
|
|
|
localRecipesIDs.indexOf(recipe.id) < 0
|
|
|
|
? result[0].push(recipe) // create candidates
|
|
|
|
: result[1].push(recipe); // update candidates
|
|
|
|
return result;
|
|
|
|
}, [[], []]);
|
|
|
|
if (partition[0].length)
|
|
|
|
createDocuments(partition[0]);
|
|
|
|
if (partition[1].length)
|
|
|
|
updateDocuments(partition[1]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
createDocuments(recipes);
|
2020-10-26 20:49:54 +00:00
|
|
|
}
|
2020-12-29 10:35:19 +00:00
|
|
|
state.importSummary.found = recipes.length
|
|
|
|
state.importSummary.imported = imported
|
|
|
|
state.importSummary.updated = updated
|
|
|
|
},
|
|
|
|
addRecipe(state, {id, recipe}) {
|
|
|
|
state.recipes.push(recipe);
|
|
|
|
EnRecipesDB.createDocument(recipe, id);
|
|
|
|
},
|
|
|
|
overwriteRecipe(state, {id, recipe}) {
|
|
|
|
let index = state.recipes.indexOf(state.recipes.filter(e => e.id === id)[0]);
|
|
|
|
Object.assign(state.recipes[index], recipe);
|
|
|
|
EnRecipesDB.updateDocument(id, recipe);
|
|
|
|
},
|
|
|
|
deleteRecipe(state, {index, id}) {
|
|
|
|
getFileAccess().deleteFile(state.recipes[index].imageSrc);
|
|
|
|
state.recipes.splice(index, 1);
|
|
|
|
EnRecipesDB.deleteDocument(id);
|
2020-11-15 10:51:10 +00:00
|
|
|
state.recipes.forEach((e, i) => {
|
|
|
|
if (e.combinations.includes(id)) {
|
2020-12-29 10:35:19 +00:00
|
|
|
state.recipes[i].combinations.splice(e.combinations.indexOf(id), 1);
|
|
|
|
EnRecipesDB.updateDocument(state.recipes[i].id, state.recipes[i]);
|
2020-11-15 10:51:10 +00:00
|
|
|
}
|
2020-12-29 10:35:19 +00:00
|
|
|
});
|
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
deleteRecipes(state, ids) {
|
|
|
|
ids.forEach(id => {
|
|
|
|
let index = state.recipes.findIndex(e => e.id === id)
|
|
|
|
getFileAccess().deleteFile(state.recipes[index].imageSrc);
|
|
|
|
state.recipes.splice(index, 1);
|
|
|
|
EnRecipesDB.deleteDocument(id);
|
|
|
|
state.recipes.forEach((e, i) => {
|
|
|
|
if (e.combinations.includes(id)) {
|
|
|
|
state.recipes[i].combinations.splice(e.combinations.indexOf(id), 1);
|
|
|
|
EnRecipesDB.updateDocument(state.recipes[i].id, state.recipes[i]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
initializeListItems(state) {
|
|
|
|
function initialize(listName) {
|
|
|
|
let userItems;
|
|
|
|
let db = listItems[listName].db;
|
|
|
|
let key = listItems[listName].key;
|
|
|
|
let stateName = listItems[listName].stateName;
|
|
|
|
let defaultItems = listItems[listName].defaultItems;
|
|
|
|
if (!state[stateName].length) {
|
|
|
|
let isStored = db.query({select: []}).length;
|
|
|
|
if (isStored) {
|
|
|
|
userItems = db.getDocument(key)[key];
|
|
|
|
if (userItems.some(e => defaultItems.includes(e)))
|
|
|
|
state[stateName] = userItems;
|
|
|
|
else
|
|
|
|
state[stateName] = [
|
|
|
|
...defaultItems,
|
|
|
|
...userItems
|
|
|
|
];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (listItems[listName].sort) {
|
|
|
|
state[stateName].sort();
|
|
|
|
}
|
|
|
|
state[stateName] = defaultItems;
|
|
|
|
db.createDocument({
|
|
|
|
[key]: []
|
|
|
|
}, key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}["cuisines", "categories", "yieldUnits", "units"].forEach(item => {
|
|
|
|
initialize(item);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
importListItems(state, {data, listName}) {
|
|
|
|
let db = listItems[listName].db;
|
|
|
|
let key = listItems[listName].key;
|
|
|
|
let stateName = listItems[listName].stateName;
|
|
|
|
let items = new Set([
|
|
|
|
...state[stateName],
|
|
|
|
...data
|
|
|
|
]);
|
|
|
|
state[stateName] = [...items];
|
|
|
|
if (listItems[listName].sort)
|
|
|
|
state[stateName].sort();
|
|
|
|
db.updateDocument(key, {[key]: state[stateName]});
|
|
|
|
},
|
|
|
|
addListItem(state, {item, listName}) {
|
|
|
|
let db = listItems[listName].db;
|
|
|
|
let key = listItems[listName].key;
|
|
|
|
let stateName = listItems[listName].stateName;
|
|
|
|
let lowercase = state[stateName].map(e => e.toLowerCase());
|
|
|
|
if (lowercase.indexOf(item.toLowerCase()) == -1) {
|
|
|
|
state[stateName].push(item);
|
|
|
|
db.updateDocument(key, {[key]: state[stateName]});
|
|
|
|
if (listItems[listName].sort)
|
2021-01-23 17:40:30 +00:00
|
|
|
state[stateName].sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()))
|
|
|
|
}
|
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
removeListItem(state, {item, listName}) {
|
|
|
|
let db = listItems[listName].db;
|
|
|
|
let key = listItems[listName].key;
|
|
|
|
let stateName = listItems[listName].stateName;
|
|
|
|
let index = state[stateName].indexOf(item);
|
|
|
|
state[stateName].splice(index, 1);
|
|
|
|
db.updateDocument(key, {[key]: state[stateName]});
|
|
|
|
if (listItems[listName].sort)
|
|
|
|
state[stateName].sort();
|
|
|
|
}
|
|
|
|
,
|
|
|
|
resetListItems(state, listName) {
|
|
|
|
let stateName = listItems[listName].stateName;
|
|
|
|
let defaultItems = listItems[listName].defaultItems;
|
2021-01-13 05:02:48 +00:00
|
|
|
state[listName] = [...defaultItems];
|
2020-12-29 10:35:19 +00:00
|
|
|
if (listItems[listName].sort) {
|
|
|
|
state[stateName].sort();
|
|
|
|
}
|
2020-10-26 20:49:54 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
initializeMealPlans(state) {
|
|
|
|
let isMealPlansDBStored = mealPlansDB.query({select: []}).length;
|
|
|
|
if (isMealPlansDBStored) {
|
2021-01-23 17:20:15 +00:00
|
|
|
let plans = mealPlansDB.getDocument("mealPlans").mealPlans
|
|
|
|
if (plans.length && plans[0].hasOwnProperty("eventColor")) {
|
|
|
|
plans.forEach(p => {
|
|
|
|
let d = new Date(p.startDate)
|
|
|
|
p.date = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0).getTime()
|
|
|
|
switch (new Date(p.date).getHours()) {
|
|
|
|
case 0:
|
|
|
|
p.type = "breakfast"
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
p.type = "lunch"
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
p.type = "dinner"
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
p.type = "snacks"
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
delete p.startDate
|
|
|
|
delete p.endDate
|
|
|
|
delete p.eventColor
|
|
|
|
state.mealPlans.push(p)
|
|
|
|
})
|
|
|
|
mealPlansDB.updateDocument("mealPlans", {mealPlans: state.mealPlans})
|
|
|
|
} else
|
|
|
|
state.mealPlans = [...plans]
|
2020-12-29 10:35:19 +00:00
|
|
|
} else {
|
|
|
|
mealPlansDB.createDocument({
|
|
|
|
mealPlans: []
|
2021-01-23 17:20:15 +00:00
|
|
|
}, "mealPlans")
|
2020-12-29 10:35:19 +00:00
|
|
|
}
|
2020-11-23 09:49:58 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
importMealPlans(state, mealPlans) {
|
2021-01-23 17:20:15 +00:00
|
|
|
let newMealPlans = mealPlans.filter(e => {
|
|
|
|
if (e.hasOwnProperty("eventColor")) {
|
|
|
|
return !state.mealPlans.some(f => {
|
|
|
|
let d = new Date(e.startDate)
|
|
|
|
let date = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0).getTime()
|
|
|
|
let type
|
|
|
|
switch (d.getHours()) {
|
|
|
|
case 0:
|
|
|
|
type = "breakfast"
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
type = "lunch"
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
type = "dinner"
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
type = "snacks"
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return f.title === e.title && f.date === date && f.type === type
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
return !state.mealPlans.some(f => f.title === e.title && f.date === e.date && f.type === e.type)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
let updatedMealPlans = []
|
|
|
|
if (newMealPlans[0].hasOwnProperty("eventColor")) {
|
|
|
|
newMealPlans.forEach(p => {
|
|
|
|
let d = new Date(p.startDate)
|
|
|
|
p.date = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0).getTime()
|
|
|
|
switch (d.getHours()) {
|
|
|
|
case 0:
|
|
|
|
p.type = "breakfast"
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
p.type = "lunch"
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
p.type = "dinner"
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
p.type = "snacks"
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
delete p.startDate
|
|
|
|
delete p.endDate
|
|
|
|
delete p.eventColor
|
|
|
|
updatedMealPlans.push(p)
|
|
|
|
});
|
|
|
|
}
|
2020-12-29 10:35:19 +00:00
|
|
|
state.mealPlans = [
|
|
|
|
...state.mealPlans,
|
2021-01-23 17:20:15 +00:00
|
|
|
...updatedMealPlans
|
2020-12-29 10:35:19 +00:00
|
|
|
];
|
|
|
|
mealPlansDB.updateDocument("mealPlans", {mealPlans: state.mealPlans});
|
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
addMealPlan(state, {title, date, type, index}) {
|
2021-01-13 05:02:48 +00:00
|
|
|
let mealPlan = {
|
2021-01-23 17:20:15 +00:00
|
|
|
title,
|
|
|
|
date,
|
|
|
|
type
|
2021-01-13 05:02:48 +00:00
|
|
|
}
|
|
|
|
if (index != null)
|
|
|
|
state.mealPlans.splice(index, 0, mealPlan);
|
|
|
|
else
|
|
|
|
state.mealPlans.push(mealPlan);
|
2020-12-29 10:35:19 +00:00
|
|
|
mealPlansDB.updateDocument("mealPlans", {
|
|
|
|
mealPlans: [...state.mealPlans]
|
|
|
|
});
|
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
deleteMealPlan(state, {title, date, type, index}) {
|
2020-12-29 10:35:19 +00:00
|
|
|
state.mealPlans.splice(index, 1);
|
|
|
|
state.mealPlans = [...state.mealPlans];
|
|
|
|
mealPlansDB.updateDocument("mealPlans", {
|
2021-01-23 17:20:15 +00:00
|
|
|
mealPlans: [...state.mealPlans]
|
2020-12-29 10:35:19 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
toggleState(state, {id, recipe, key, setDate}) {
|
|
|
|
let index = state.recipes.indexOf(state.recipes.filter(e => e.id === id)[0]);
|
|
|
|
state.recipes[index][key] = !state.recipes[index][key];
|
|
|
|
if (setDate)
|
|
|
|
state.recipes[index].lastTried = new Date();
|
|
|
|
EnRecipesDB.updateDocument(id, recipe);
|
|
|
|
},
|
|
|
|
setRecipeAsTried(state, {id, recipe}) {
|
|
|
|
let index = state.recipes.indexOf(state.recipes.filter(e => e.id === id)[0]);
|
|
|
|
state.recipes[index].tried = true;
|
|
|
|
state.recipes[index].lastTried = new Date();
|
|
|
|
EnRecipesDB.updateDocument(id, recipe);
|
2020-11-17 21:21:08 +00:00
|
|
|
},
|
2020-11-02 11:36:53 +00:00
|
|
|
setLastTriedDate(state, index) {
|
2020-12-29 10:35:19 +00:00
|
|
|
state.recipes[index].lastTried = new Date();
|
|
|
|
EnRecipesDB.updateDocument(state.recipes[index].id, state.recipes[index]);
|
2020-10-26 20:49:54 +00:00
|
|
|
},
|
2020-11-23 09:49:58 +00:00
|
|
|
setCurrentComponent(state, comp) {
|
2020-12-29 10:35:19 +00:00
|
|
|
state.currentComponent = comp;
|
2020-11-23 09:49:58 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
unSyncCombinations(state, {id, combinations}) {
|
2020-11-15 10:51:10 +00:00
|
|
|
state.recipes.forEach((e, i) => {
|
|
|
|
if (combinations.includes(e.id)) {
|
2020-12-29 10:35:19 +00:00
|
|
|
state.recipes[i].combinations.splice(e.combinations.indexOf(id), 1);
|
|
|
|
EnRecipesDB.updateDocument(state.recipes[i].id, state.recipes[i]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
setShake(state, shake) {
|
|
|
|
state.shakeEnabled = shake;
|
|
|
|
},
|
|
|
|
setRating(state, {id, recipe, rating}) {
|
|
|
|
let index = state.recipes.indexOf(state.recipes.filter(e => e.id === id)[0]);
|
|
|
|
state.recipes[index].rating = rating
|
|
|
|
EnRecipesDB.updateDocument(id, recipe);
|
|
|
|
},
|
2021-01-13 05:02:48 +00:00
|
|
|
toggleCart(state, {id, recipe}) {
|
|
|
|
let index = state.recipes.indexOf(state.recipes.filter(e => e.id === id)[0]);
|
2021-01-23 17:20:15 +00:00
|
|
|
state.recipes[index].inBag = !state.recipes[index].inBag
|
2021-01-13 05:02:48 +00:00
|
|
|
EnRecipesDB.updateDocument(id, recipe);
|
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
unlinkBrokenImages(state) {
|
|
|
|
state.recipes.forEach((r, i) => {
|
|
|
|
if (r.imageSrc && !File.exists(r.imageSrc)) {
|
|
|
|
r.imageSrc = null
|
|
|
|
Object.assign(state.recipes[i], r);
|
|
|
|
EnRecipesDB.updateDocument(r.id, r);
|
2020-11-15 10:51:10 +00:00
|
|
|
}
|
|
|
|
})
|
2020-12-29 10:35:19 +00:00
|
|
|
}
|
2020-09-15 11:10:16 +00:00
|
|
|
},
|
|
|
|
actions: {
|
2020-12-29 10:35:19 +00:00
|
|
|
setSortTypeAction({
|
2020-12-07 14:45:00 +00:00
|
|
|
commit
|
2020-12-29 10:35:19 +00:00
|
|
|
}, sortType) {
|
|
|
|
commit("setSortType", sortType)
|
2020-10-26 20:49:54 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
initializeRecipes({commit}) {
|
|
|
|
commit("initializeRecipes");
|
2020-10-26 20:49:54 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
importRecipesAction({
|
2020-12-07 14:45:00 +00:00
|
|
|
commit
|
2020-12-29 10:35:19 +00:00
|
|
|
}, recipes) {
|
|
|
|
commit("importRecipes", recipes);
|
2020-11-02 11:36:53 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
addRecipeAction({
|
2020-12-07 14:45:00 +00:00
|
|
|
commit
|
2020-12-29 10:35:19 +00:00
|
|
|
}, recipe) {
|
|
|
|
commit("addRecipe", recipe);
|
2020-10-26 20:49:54 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
overwriteRecipeAction({
|
2020-12-07 14:45:00 +00:00
|
|
|
commit
|
2020-12-29 10:35:19 +00:00
|
|
|
}, updatedRecipe) {
|
|
|
|
commit("overwriteRecipe", updatedRecipe);
|
2020-11-06 09:07:41 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
deleteRecipeAction({
|
2020-12-07 14:45:00 +00:00
|
|
|
commit
|
2020-12-29 10:35:19 +00:00
|
|
|
}, recipe) {
|
|
|
|
commit("deleteRecipe", recipe);
|
|
|
|
},
|
2021-01-23 17:20:15 +00:00
|
|
|
deleteRecipesAction({
|
|
|
|
commit
|
|
|
|
}, ids) {
|
|
|
|
commit("deleteRecipes", ids);
|
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
initializeListItems({commit}) {
|
|
|
|
commit("initializeListItems");
|
2020-11-06 09:07:41 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
importListItemsAction({
|
2020-12-07 14:45:00 +00:00
|
|
|
commit
|
2020-12-29 10:35:19 +00:00
|
|
|
}, data) {
|
|
|
|
commit("importListItems", data);
|
2020-11-23 09:49:58 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
addListItemAction({
|
2020-12-07 14:45:00 +00:00
|
|
|
commit
|
2020-12-29 10:35:19 +00:00
|
|
|
}, item) {
|
|
|
|
commit("addListItem", item);
|
2020-11-23 09:49:58 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
removeListItemAction({
|
2020-12-07 14:45:00 +00:00
|
|
|
commit
|
2020-12-29 10:35:19 +00:00
|
|
|
}, item) {
|
|
|
|
commit("removeListItem", item);
|
2020-11-23 09:49:58 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
resetListItemsAction({
|
2020-12-07 14:45:00 +00:00
|
|
|
commit
|
2020-12-29 10:35:19 +00:00
|
|
|
}, listName) {
|
|
|
|
commit("resetListItems", listName);
|
|
|
|
},
|
|
|
|
initializeMealPlans({commit}) {
|
|
|
|
commit("initializeMealPlans");
|
2020-11-02 11:36:53 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
importMealPlansAction({
|
2020-12-07 14:45:00 +00:00
|
|
|
commit
|
2020-12-29 10:35:19 +00:00
|
|
|
}, mealPlans) {
|
|
|
|
commit("importMealPlans", mealPlans);
|
2020-11-06 09:07:41 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
addMealPlanAction({
|
|
|
|
commit
|
|
|
|
}, mealPlan) {
|
2020-12-29 10:35:19 +00:00
|
|
|
commit("addMealPlan", mealPlan);
|
2020-11-23 09:49:58 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
deleteMealPlanAction({
|
|
|
|
commit
|
|
|
|
}, mealPlan) {
|
2020-12-29 10:35:19 +00:00
|
|
|
commit("deleteMealPlan", mealPlan);
|
2020-11-23 09:49:58 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
toggleStateAction({
|
|
|
|
commit
|
|
|
|
}, toggledRecipe) {
|
2020-12-29 10:35:19 +00:00
|
|
|
commit("toggleState", toggledRecipe);
|
2020-10-26 20:49:54 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
setRecipeAsTriedAction({
|
|
|
|
commit
|
|
|
|
}, recipe) {
|
2020-12-29 10:35:19 +00:00
|
|
|
commit("setRecipeAsTried", recipe);
|
2020-11-17 21:21:08 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
setLastTriedDateAction({
|
|
|
|
commit
|
|
|
|
}, index) {
|
2020-12-29 10:35:19 +00:00
|
|
|
commit("setLastTriedDate", index);
|
2020-10-26 20:49:54 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
setCurrentComponentAction({
|
|
|
|
commit
|
|
|
|
}, comp) {
|
2020-12-29 10:35:19 +00:00
|
|
|
commit("setCurrentComponent", comp);
|
2020-11-23 09:49:58 +00:00
|
|
|
},
|
2020-12-07 14:45:00 +00:00
|
|
|
unSyncCombinationsAction({
|
|
|
|
commit
|
|
|
|
}, combinations) {
|
2020-12-29 10:35:19 +00:00
|
|
|
commit("unSyncCombinations", combinations);
|
2020-11-15 10:51:10 +00:00
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
setShakeAction({
|
|
|
|
commit
|
|
|
|
}, shake) {
|
|
|
|
commit("setShake", shake);
|
|
|
|
},
|
|
|
|
setRatingAction({
|
|
|
|
commit
|
|
|
|
}, rating) {
|
|
|
|
commit("setRating", rating);
|
|
|
|
},
|
2021-01-13 05:02:48 +00:00
|
|
|
toggleCartAction({
|
|
|
|
commit
|
|
|
|
}, recipe) {
|
|
|
|
commit("toggleCart", recipe);
|
|
|
|
},
|
2020-12-29 10:35:19 +00:00
|
|
|
unlinkBrokenImages({commit}) {
|
|
|
|
commit("unlinkBrokenImages");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|