cleaned store
This commit is contained in:
parent
7889eceea4
commit
ffb069d20f
1 changed files with 312 additions and 231 deletions
543
app/store.ts
543
app/store.ts
|
@ -169,6 +169,44 @@ const listItems = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IRecipe {
|
||||||
|
id: string
|
||||||
|
image: string
|
||||||
|
title: string
|
||||||
|
cuisine: string
|
||||||
|
category: string
|
||||||
|
tags: string[]
|
||||||
|
prepTime: string
|
||||||
|
cookTime: string
|
||||||
|
yieldQuantity: number
|
||||||
|
yieldUnit: string
|
||||||
|
difficulty: string
|
||||||
|
rating: number
|
||||||
|
ingredients: string[]
|
||||||
|
instructions: string[]
|
||||||
|
combinations: string[]
|
||||||
|
notes: string[]
|
||||||
|
favorite: 0 | 1
|
||||||
|
tried: 0 | 1
|
||||||
|
lastTried: number | null
|
||||||
|
lastModified: number | null
|
||||||
|
created: number | null
|
||||||
|
}
|
||||||
|
interface IMealPlan {
|
||||||
|
id: string
|
||||||
|
date: number
|
||||||
|
mealType: string
|
||||||
|
recipeID: string
|
||||||
|
quantity: number
|
||||||
|
note: string
|
||||||
|
}
|
||||||
|
interface IMealPlanOld {
|
||||||
|
title: string
|
||||||
|
startDate: number
|
||||||
|
type: string
|
||||||
|
eventColor: string
|
||||||
|
}
|
||||||
|
|
||||||
export default new Vuex.Store({
|
export default new Vuex.Store({
|
||||||
state: {
|
state: {
|
||||||
recipes: [],
|
recipes: [],
|
||||||
|
@ -249,8 +287,8 @@ export default new Vuex.Store({
|
||||||
awake: '\ue944',
|
awake: '\ue944',
|
||||||
edge: '\ue945',
|
edge: '\ue945',
|
||||||
},
|
},
|
||||||
sortType: 'random',
|
sortT: 'random', // SortType
|
||||||
language: [
|
langs: [
|
||||||
{
|
{
|
||||||
locale: 'ar',
|
locale: 'ar',
|
||||||
title: 'العربية',
|
title: 'العربية',
|
||||||
|
@ -345,70 +383,80 @@ export default new Vuex.Store({
|
||||||
title: 'తెలుగు',
|
title: 'తెలుగు',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
shake: getNumber('shake', 1),
|
shake: getNumber('shake', 1), // ShakeViewRandomRecipe
|
||||||
importSummary: {
|
impSum: {
|
||||||
|
// ImportSummary
|
||||||
found: 0,
|
found: 0,
|
||||||
imported: 0,
|
imported: 0,
|
||||||
updated: 0,
|
updated: 0,
|
||||||
},
|
},
|
||||||
layout: getString('layout', 'detailed'),
|
layout: getString('layout', 'detailed'),
|
||||||
selCuisine: null,
|
selCuisine: null, // SelectedCuisine
|
||||||
selCategory: null,
|
selCategory: null, // SelectedCategory
|
||||||
selTag: null,
|
selTag: null, // SelectedTag
|
||||||
theme: 'sysDef',
|
theme: 'sysDef',
|
||||||
mondayFirst: getNumber('mondayFirst', 0),
|
startMon: getNumber('startMon', 0), // StartWithMonday
|
||||||
timerDelay: getNumber('timerDelay', 1),
|
timerD: getNumber('timerD', 1), // TimerDelay
|
||||||
timerSound: {},
|
timerS: {}, // TimerSound
|
||||||
timerVibrate: getNumber('timerVibrate', 0),
|
timerV: getNumber('timerV', 0), // TimerVibrate
|
||||||
timerPresets: [],
|
timerPs: [], // TimerPresets
|
||||||
activeTimers: [],
|
activeTs: [], // ActiveTimers
|
||||||
FGService: 0,
|
FGS: 0, // ForeGroundService
|
||||||
RTL: getNumber('RTL', 0),
|
RTL: getNumber('RTL', 0),
|
||||||
plannerView: getString('plannerView', 'wk'),
|
plannerV: getString('plannerV', 'wk'), // PlannerViewMode
|
||||||
planDeletion: getString('planDeletion', 'nvr'),
|
planDel: getString('planDel', 'nvr'), // PlanDeletionCriteria
|
||||||
edgeSwipe: getNumber('edgeSwipe', 1),
|
edgeS: getNumber('edgeS', 1), // EdgeSwipe
|
||||||
awakeViewer: getNumber('awakeViewer', 1),
|
awakeV: getNumber('awakeV', 1), // AwakeViewer
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
toggleAwakeViewer(state) {
|
// ToggleKeepAwakeOnRecipeViewer
|
||||||
state.awakeViewer = +!state.awakeViewer
|
toggleAwakeV(state) {
|
||||||
setNumber('awakeViewer', state.awakeViewer)
|
state.awakeV = +!state.awakeV
|
||||||
|
setNumber('awakeV', state.awakeV)
|
||||||
},
|
},
|
||||||
toggleEdgeSwipe(state) {
|
// ToggleEdgeSwipe
|
||||||
state.edgeSwipe = +!state.edgeSwipe
|
toggleEdgeS(state) {
|
||||||
setNumber('edgeSwipe', state.edgeSwipe)
|
state.edgeS = +!state.edgeS
|
||||||
|
setNumber('edgeS', state.edgeS)
|
||||||
},
|
},
|
||||||
setPlanDeletion(state, s) {
|
// SetPlanDeletionCriteria
|
||||||
state.planDeletion = s
|
setPlanDel(state, s: string) {
|
||||||
setString('planDeletion', s)
|
state.planDel = s
|
||||||
|
setString('planDel', s)
|
||||||
},
|
},
|
||||||
setPlannerView(state, s) {
|
// SetPlannerViewMode
|
||||||
state.plannerView = s
|
setPlannerV(state, s: string) {
|
||||||
setString('plannerView', s)
|
state.plannerV = s
|
||||||
|
setString('plannerV', s)
|
||||||
},
|
},
|
||||||
|
// SetRTLLayout
|
||||||
setRTL(state) {
|
setRTL(state) {
|
||||||
state.RTL = getNumber('RTL', 0)
|
state.RTL = getNumber('RTL', 0)
|
||||||
},
|
},
|
||||||
setFGService(state, val) {
|
// SetForegroundService
|
||||||
state.FGService = val
|
setFgS(state, n: number) {
|
||||||
|
state.FGS = n
|
||||||
},
|
},
|
||||||
addTimerPreset(state, timer) {
|
// AddTimerPreset
|
||||||
let i = state.timerPresets.findIndex((e) => e.id == timer.id)
|
addTP(state, o) {
|
||||||
if (state.timerPresets.some((e) => e.id == timer.id)) {
|
let i = state.timerPs.findIndex((e) => e.id == o.id)
|
||||||
state.timerPresets.splice(i, 1, timer)
|
if (state.timerPs.some((e) => e.id == o.id)) {
|
||||||
} else state.timerPresets.push(timer)
|
state.timerPs.splice(i, 1, o)
|
||||||
|
} else state.timerPs.push(o)
|
||||||
db.execute(
|
db.execute(
|
||||||
`REPLACE INTO timerPresets (id, label, time) VALUES (?, ?, ?)`,
|
`REPLACE INTO timerPresets (id, label, time) VALUES (?, ?, ?)`,
|
||||||
[timer.id, timer.label, timer.time]
|
[o.id, o.label, o.time]
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
deleteTimerPreset(state, i) {
|
// DeleteTimerPreset
|
||||||
let id = state.timerPresets[i]
|
deleteTP(state, n: number) {
|
||||||
state.timerPresets.splice(i, 1)
|
let id = state.timerPs[n]
|
||||||
|
state.timerPs.splice(n, 1)
|
||||||
db.execute(`DELETE FROM timerPresets WHERE id = ${id}`)
|
db.execute(`DELETE FROM timerPresets WHERE id = ${id}`)
|
||||||
},
|
},
|
||||||
initTimerPresets(state) {
|
// InitialiseTimerPreset
|
||||||
if (!state.timerPresets.length)
|
initTPs(state) {
|
||||||
|
if (!state.timerPs.length)
|
||||||
db.select(`SELECT * FROM timerPresets`).then((res) => {
|
db.select(`SELECT * FROM timerPresets`).then((res) => {
|
||||||
res.forEach((t) => {
|
res.forEach((t) => {
|
||||||
t.recipeID = 0
|
t.recipeID = 0
|
||||||
|
@ -416,66 +464,78 @@ export default new Vuex.Store({
|
||||||
t.isPaused = 0
|
t.isPaused = 0
|
||||||
t.preset = 1
|
t.preset = 1
|
||||||
t.done = 0
|
t.done = 0
|
||||||
state.timerPresets.push(t)
|
state.timerPs.push(t)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
importTimerPresets(state, timers) {
|
// ImportTimerPresets
|
||||||
let newPresets = timers.filter(
|
importTPs(state, ao) {
|
||||||
(e) => !state.timerPresets.some((f) => f.id === e.id)
|
let newPresets = ao.filter(
|
||||||
|
(e) => !state.timerPs.some((f) => f.id === e.id)
|
||||||
)
|
)
|
||||||
newPresets.forEach((t) => {
|
newPresets.forEach((t) => {
|
||||||
db.execute(
|
db.execute(
|
||||||
`INSERT INTO timerPresets (id, label, time) VALUES (?, ?, ?)`,
|
`INSERT INTO timerPresets (id, label, time) VALUES (?, ?, ?)`,
|
||||||
[t.id, t.label, t.time]
|
[t.id, t.label, t.time]
|
||||||
)
|
)
|
||||||
state.timerPresets.push(t)
|
state.timerPs.push(t)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
clearTimerInterval(state) {
|
// ClearActiveTimerInterval
|
||||||
state.activeTimers.forEach((e) => {
|
clearATIs(state) {
|
||||||
|
state.activeTs.forEach((e) => {
|
||||||
clearInterval(e.timerInt)
|
clearInterval(e.timerInt)
|
||||||
e.timerInt = 0
|
e.timerInt = 0
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
addActiveTimer(state, { timer, i }) {
|
// AddActiveTimer
|
||||||
state.activeTimers.splice(i, 0, timer)
|
addAT(state, { timer, i }) {
|
||||||
|
state.activeTs.splice(i, 0, timer)
|
||||||
},
|
},
|
||||||
sortActiveTimers(state) {
|
// SortActiveTimers
|
||||||
let a = state.activeTimers.reduce((acc, e) => {
|
sortATs(state) {
|
||||||
|
let a = state.activeTs.reduce((acc, e) => {
|
||||||
;(acc[e.recipeID] = acc[e.recipeID] || []).push(e)
|
;(acc[e.recipeID] = acc[e.recipeID] || []).push(e)
|
||||||
return acc
|
return acc
|
||||||
}, {})
|
}, {})
|
||||||
state.activeTimers = [...(<any>Object).values(a).flat(2)]
|
state.activeTs = [...(<any>Object).values(a).flat(2)]
|
||||||
},
|
},
|
||||||
updateActiveTimer(state, timer) {
|
// UpdateActiveTimer
|
||||||
let i = state.activeTimers.findIndex((e) => e.id == timer.id)
|
updateAT(state, o) {
|
||||||
state.activeTimers.splice(i, 1, timer)
|
let i = state.activeTs.findIndex((e) => e.id == o.id)
|
||||||
|
state.activeTs.splice(i, 1, o)
|
||||||
},
|
},
|
||||||
removeActiveTimer(state, i) {
|
// RemoveActiveTimer
|
||||||
state.activeTimers.splice(i, 1)
|
removeAT(state, n: number) {
|
||||||
|
state.activeTs.splice(n, 1)
|
||||||
},
|
},
|
||||||
setTimerDelay(state, n: number) {
|
// SetTimerDelay
|
||||||
state.timerDelay = n
|
setTD(state, n: number) {
|
||||||
setNumber('timerDelay', n)
|
state.timerD = n
|
||||||
|
setNumber('timerD', n)
|
||||||
},
|
},
|
||||||
setTimerSound(state, sound) {
|
// SetTimerSound
|
||||||
state.timerSound = sound
|
setTS(state, s: string) {
|
||||||
setString('timerSound', JSON.stringify(sound))
|
state.timerS = s
|
||||||
|
setString('timerS', JSON.stringify(s))
|
||||||
},
|
},
|
||||||
setTimerVibrate(state, n) {
|
// SetTimerVibrate
|
||||||
state.timerVibrate = n
|
setTV(state, n: number) {
|
||||||
setNumber('timerVibrate', n)
|
state.timerV = n
|
||||||
|
setNumber('timerV', n)
|
||||||
},
|
},
|
||||||
clearImportSummary(state) {
|
// ClearImportSummary
|
||||||
for (const key in state.importSummary) state.importSummary[key] = 0
|
clearIS(state) {
|
||||||
|
for (const key in state.impSum) state.impSum[key] = 0
|
||||||
},
|
},
|
||||||
setFirstDay(state, n) {
|
// SetFirstDayMonday
|
||||||
state.mondayFirst = n
|
setFD(state, n: number) {
|
||||||
setNumber('mondayFirst', n)
|
state.startMon = n
|
||||||
|
setNumber('startMon', n)
|
||||||
},
|
},
|
||||||
setTheme(state, theme) {
|
// SetTheme
|
||||||
switch (theme) {
|
setT(state, s: string) {
|
||||||
|
switch (s) {
|
||||||
case 'sysDef':
|
case 'sysDef':
|
||||||
state.theme =
|
state.theme =
|
||||||
Application.systemAppearance() == 'dark' ? 'Dark' : 'Light'
|
Application.systemAppearance() == 'dark' ? 'Dark' : 'Light'
|
||||||
|
@ -485,22 +545,26 @@ export default new Vuex.Store({
|
||||||
Application.systemAppearance() == 'dark' ? 'Black' : 'Light'
|
Application.systemAppearance() == 'dark' ? 'Black' : 'Light'
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
state.theme = theme
|
state.theme = s
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
setString('theme', theme)
|
setString('theme', s)
|
||||||
},
|
},
|
||||||
clearFilter(state) {
|
// ClearFilter
|
||||||
|
clearF(state) {
|
||||||
state.selCuisine = state.selCategory = state.selTag = null
|
state.selCuisine = state.selCategory = state.selTag = null
|
||||||
},
|
},
|
||||||
setLayout(state, type) {
|
// SetLayout
|
||||||
state.layout = type
|
setL(state, s: string) {
|
||||||
setString('layout', type)
|
state.layout = s
|
||||||
|
setString('layout', s)
|
||||||
},
|
},
|
||||||
setSortType(state, sortType) {
|
// SetSortType
|
||||||
state.sortType = sortType
|
setST(state, s: string) {
|
||||||
|
state.sortT = s
|
||||||
},
|
},
|
||||||
initRecipes(state) {
|
// InitialiseRecipes
|
||||||
|
initRs(state) {
|
||||||
if (!state.recipes.length) {
|
if (!state.recipes.length) {
|
||||||
db.select('SELECT * FROM recipes').then((res) => {
|
db.select('SELECT * FROM recipes').then((res) => {
|
||||||
res.forEach((e) => {
|
res.forEach((e) => {
|
||||||
|
@ -514,9 +578,10 @@ export default new Vuex.Store({
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
state.shake = getNumber('shake', 1)
|
state.shake = getNumber('shake', 1)
|
||||||
state.sortType = getString('sortType', 'random')
|
state.sortT = getString('sortT', 'random')
|
||||||
},
|
},
|
||||||
importRecipesFromJSON(state, recipes) {
|
// ImportRecipesFromJSON
|
||||||
|
importRsJSON(state, ao) {
|
||||||
let localRecipesIDs, partition
|
let localRecipesIDs, partition
|
||||||
let imported = 0
|
let imported = 0
|
||||||
let updated = 0
|
let updated = 0
|
||||||
|
@ -628,7 +693,7 @@ export default new Vuex.Store({
|
||||||
}
|
}
|
||||||
if (state.recipes.length) {
|
if (state.recipes.length) {
|
||||||
localRecipesIDs = state.recipes.map((e) => e.id)
|
localRecipesIDs = state.recipes.map((e) => e.id)
|
||||||
partition = recipes.reduce(
|
partition = ao.reduce(
|
||||||
(result, recipe) => {
|
(result, recipe) => {
|
||||||
localRecipesIDs.indexOf(recipe.id) < 0
|
localRecipesIDs.indexOf(recipe.id) < 0
|
||||||
? result[0].push(recipe) // create candidates
|
? result[0].push(recipe) // create candidates
|
||||||
|
@ -640,13 +705,14 @@ export default new Vuex.Store({
|
||||||
if (partition[0].length) createDocuments(partition[0])
|
if (partition[0].length) createDocuments(partition[0])
|
||||||
if (partition[1].length) updateDocuments(partition[1])
|
if (partition[1].length) updateDocuments(partition[1])
|
||||||
} else {
|
} else {
|
||||||
createDocuments(recipes)
|
createDocuments(ao)
|
||||||
}
|
}
|
||||||
state.importSummary.found = recipes.length
|
state.impSum.found = ao.length
|
||||||
state.importSummary.imported = imported
|
state.impSum.imported = imported
|
||||||
state.importSummary.updated = updated
|
state.impSum.updated = updated
|
||||||
},
|
},
|
||||||
importRecipesFromDB(state, recipes) {
|
// ImportRecipesFromDB
|
||||||
|
importRsDB(state, ao) {
|
||||||
let localRecipesIDs: string[], partition: any[]
|
let localRecipesIDs: string[], partition: any[]
|
||||||
let imported = 0
|
let imported = 0
|
||||||
let updated = 0
|
let updated = 0
|
||||||
|
@ -699,7 +765,7 @@ export default new Vuex.Store({
|
||||||
}
|
}
|
||||||
if (state.recipes.length) {
|
if (state.recipes.length) {
|
||||||
localRecipesIDs = state.recipes.map((e) => e.id)
|
localRecipesIDs = state.recipes.map((e) => e.id)
|
||||||
partition = recipes.reduce(
|
partition = ao.reduce(
|
||||||
(result, recipe) => {
|
(result, recipe) => {
|
||||||
localRecipesIDs.indexOf(recipe.id) < 0
|
localRecipesIDs.indexOf(recipe.id) < 0
|
||||||
? result[0].push(recipe) // create candidates
|
? result[0].push(recipe) // create candidates
|
||||||
|
@ -710,20 +776,21 @@ export default new Vuex.Store({
|
||||||
)
|
)
|
||||||
if (partition[0].length) createDocuments(partition[0])
|
if (partition[0].length) createDocuments(partition[0])
|
||||||
if (partition[1].length) updateDocuments(partition[1])
|
if (partition[1].length) updateDocuments(partition[1])
|
||||||
} else createDocuments(recipes)
|
} else createDocuments(ao)
|
||||||
state.importSummary.found = recipes.length
|
state.impSum.found = ao.length
|
||||||
state.importSummary.imported = imported
|
state.impSum.imported = imported
|
||||||
state.importSummary.updated = updated
|
state.impSum.updated = updated
|
||||||
},
|
},
|
||||||
addRecipe(state, recipe) {
|
// AddRecipe
|
||||||
let r = JSON.parse(JSON.stringify(recipe))
|
addR(state, o: IRecipe) {
|
||||||
Object.keys(recipe).forEach((e) => {
|
let r = JSON.parse(JSON.stringify(o))
|
||||||
|
Object.keys(o).forEach((e) => {
|
||||||
if (e.match(/tags|ingredients|instructions|combinations|notes/))
|
if (e.match(/tags|ingredients|instructions|combinations|notes/))
|
||||||
r[e] = JSON.stringify(r[e])
|
r[e] = JSON.stringify(r[e])
|
||||||
if (e.match(/favorite|tried/)) r[e] = r[e] ? 1 : 0
|
if (e.match(/favorite|tried/)) r[e] = r[e] ? 1 : 0
|
||||||
})
|
})
|
||||||
const cols = Object.keys(recipe).join(', ')
|
const cols = Object.keys(o).join(', ')
|
||||||
const placeholder = Object.keys(recipe)
|
const placeholder = Object.keys(o)
|
||||||
.fill('?')
|
.fill('?')
|
||||||
.join(', ')
|
.join(', ')
|
||||||
db.execute(
|
db.execute(
|
||||||
|
@ -732,18 +799,19 @@ export default new Vuex.Store({
|
||||||
)
|
)
|
||||||
let i: number
|
let i: number
|
||||||
function exist({ id }, index: number) {
|
function exist({ id }, index: number) {
|
||||||
if (id === recipe.id) {
|
if (id === o.id) {
|
||||||
i = index
|
i = index
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
state.recipes.some(exist)
|
state.recipes.some(exist)
|
||||||
? Object.assign(state.recipes[i], recipe)
|
? Object.assign(state.recipes[i], o)
|
||||||
: state.recipes.push(recipe)
|
: state.recipes.push(o)
|
||||||
},
|
},
|
||||||
deleteRecipes(state, ids) {
|
// DeleteRecipes
|
||||||
ids.forEach((id: string) => {
|
deleteRs(state, a) {
|
||||||
|
a.forEach((id: string) => {
|
||||||
let i = state.recipes.findIndex((e) => e.id === id)
|
let i = state.recipes.findIndex((e) => e.id === id)
|
||||||
getFileAccess().deleteFile(state.recipes[i].image)
|
getFileAccess().deleteFile(state.recipes[i].image)
|
||||||
state.recipes.splice(i, 1)
|
state.recipes.splice(i, 1)
|
||||||
|
@ -760,7 +828,8 @@ export default new Vuex.Store({
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
initListItems(state) {
|
// InitialiseListItems
|
||||||
|
initLIs(state) {
|
||||||
if (!state.cuisines.length) {
|
if (!state.cuisines.length) {
|
||||||
db.select(`SELECT * FROM lists`).then((res) => {
|
db.select(`SELECT * FROM lists`).then((res) => {
|
||||||
if (!res.length) {
|
if (!res.length) {
|
||||||
|
@ -788,14 +857,16 @@ export default new Vuex.Store({
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
importListItems(state, { data, listName }) {
|
// ImportListItems
|
||||||
|
importLIs(state, { data, listName }) {
|
||||||
state[listName] = [...new Set([...state[listName], ...data])]
|
state[listName] = [...new Set([...state[listName], ...data])]
|
||||||
if (listItems[listName].sort) state[listName].sort()
|
if (listItems[listName].sort) state[listName].sort()
|
||||||
db.execute(
|
db.execute(
|
||||||
`UPDATE lists SET ${listName} = '${JSON.stringify(state[listName])}'`
|
`UPDATE lists SET ${listName} = '${JSON.stringify(state[listName])}'`
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
addListItem(state, { item, listName }) {
|
// AddListItem
|
||||||
|
addLI(state, { item, listName }) {
|
||||||
let lowercase = state[listName].map((e: string) => e.toLowerCase())
|
let lowercase = state[listName].map((e: string) => e.toLowerCase())
|
||||||
if (lowercase.indexOf(item.toLowerCase()) == -1) {
|
if (lowercase.indexOf(item.toLowerCase()) == -1) {
|
||||||
state[listName].push(item)
|
state[listName].push(item)
|
||||||
|
@ -808,13 +879,15 @@ export default new Vuex.Store({
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
removeListItem(state, { item, listName }) {
|
// RemoveListItem
|
||||||
|
removeLI(state, { item, listName }) {
|
||||||
state[listName].splice(state[listName].indexOf(item), 1)
|
state[listName].splice(state[listName].indexOf(item), 1)
|
||||||
db.execute(
|
db.execute(
|
||||||
`UPDATE lists SET ${listName} = '${JSON.stringify(state[listName])}'`
|
`UPDATE lists SET ${listName} = '${JSON.stringify(state[listName])}'`
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
resetListItems(state, listName) {
|
// ResetListItems
|
||||||
|
resetLIs(state, listName) {
|
||||||
let defs = listItems[listName].defs
|
let defs = listItems[listName].defs
|
||||||
state[listName] = [...defs]
|
state[listName] = [...defs]
|
||||||
if (listItems[listName].sort)
|
if (listItems[listName].sort)
|
||||||
|
@ -825,9 +898,10 @@ export default new Vuex.Store({
|
||||||
`UPDATE lists SET ${listName} = '${JSON.stringify(state[listName])}'`
|
`UPDATE lists SET ${listName} = '${JSON.stringify(state[listName])}'`
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
initMealPlans(state) {
|
// InitialiseMealPlans
|
||||||
|
initMPs(state) {
|
||||||
if (!state.mealPlans.length) {
|
if (!state.mealPlans.length) {
|
||||||
let c = state.planDeletion
|
let c = state.planDel
|
||||||
let date = new Date()
|
let date = new Date()
|
||||||
let d = new Date()
|
let d = new Date()
|
||||||
d.setHours(0, 0, 0, 0)
|
d.setHours(0, 0, 0, 0)
|
||||||
|
@ -848,9 +922,10 @@ export default new Vuex.Store({
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
importMealPlansFromJSON(state, mealPlans) {
|
// ImportMealPlansFromJSON
|
||||||
|
importMPsJSON(state, ao) {
|
||||||
let updatedMealPlans = []
|
let updatedMealPlans = []
|
||||||
let newMealPlans = mealPlans.filter((e) => {
|
let newMealPlans = ao.filter((e) => {
|
||||||
if (e.hasOwnProperty('eventColor')) {
|
if (e.hasOwnProperty('eventColor')) {
|
||||||
return !state.mealPlans.some((f) => {
|
return !state.mealPlans.some((f) => {
|
||||||
let d = new Date(e.startDate)
|
let d = new Date(e.startDate)
|
||||||
|
@ -930,8 +1005,9 @@ export default new Vuex.Store({
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
importMealPlansFromDB(state, mealPlans) {
|
// ImportMealPlansFromDB
|
||||||
let newMealPlans = mealPlans.filter(
|
importMPsDB(state, ao: IMealPlan[]) {
|
||||||
|
let newMealPlans = ao.filter(
|
||||||
(e) =>
|
(e) =>
|
||||||
!state.mealPlans.some((f) =>
|
!state.mealPlans.some((f) =>
|
||||||
Object.keys(f).every((key) => f[key] == e[key])
|
Object.keys(f).every((key) => f[key] == e[key])
|
||||||
|
@ -945,7 +1021,11 @@ export default new Vuex.Store({
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
addMealPlan(state, { plan, index, inDB }) {
|
// AddMealPlan
|
||||||
|
addMP(
|
||||||
|
state,
|
||||||
|
{ plan, index, inDB }: { plan: IMealPlan; index: number; inDB: number }
|
||||||
|
) {
|
||||||
let mealPlan = {
|
let mealPlan = {
|
||||||
id: plan.id,
|
id: plan.id,
|
||||||
date: plan.date,
|
date: plan.date,
|
||||||
|
@ -968,7 +1048,11 @@ export default new Vuex.Store({
|
||||||
state.mealPlans.splice(index, 0, mealPlan)
|
state.mealPlans.splice(index, 0, mealPlan)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
deleteMealPlan(state, { id, index, inDB }) {
|
// DeleteMealPlan
|
||||||
|
deleteMP(
|
||||||
|
state,
|
||||||
|
{ id, index, inDB }: { id: string; index: number; inDB: number }
|
||||||
|
) {
|
||||||
if (inDB) {
|
if (inDB) {
|
||||||
db.execute(`DELETE FROM mealPlans WHERE id = '${id}'`)
|
db.execute(`DELETE FROM mealPlans WHERE id = '${id}'`)
|
||||||
} else {
|
} else {
|
||||||
|
@ -989,9 +1073,10 @@ export default new Vuex.Store({
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
unSyncCombinations(state, { id, combinations }) {
|
// UnLinkCombinations
|
||||||
|
unLinkCs(state, { id, a }) {
|
||||||
state.recipes.forEach((e, i) => {
|
state.recipes.forEach((e, i) => {
|
||||||
if (combinations.includes(e.id)) {
|
if (a.includes(e.id)) {
|
||||||
state.recipes[i].combinations.splice(e.combinations.indexOf(id), 1)
|
state.recipes[i].combinations.splice(e.combinations.indexOf(id), 1)
|
||||||
db.execute(
|
db.execute(
|
||||||
`UPDATE recipes SET combinations = '${JSON.stringify(
|
`UPDATE recipes SET combinations = '${JSON.stringify(
|
||||||
|
@ -1001,20 +1086,19 @@ export default new Vuex.Store({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
setShake(state, n) {
|
// SetShake
|
||||||
|
setS(state, n: number) {
|
||||||
state.shake = n
|
state.shake = n
|
||||||
setNumber('shake', n)
|
setNumber('shake', n)
|
||||||
},
|
},
|
||||||
setRating(state, { id, rating }) {
|
// SetRating
|
||||||
|
setR(state, { id, rating }) {
|
||||||
let i = state.recipes.findIndex((e) => e.id == id)
|
let i = state.recipes.findIndex((e) => e.id == id)
|
||||||
state.recipes[i].rating = rating
|
state.recipes[i].rating = rating
|
||||||
db.execute(`UPDATE recipes SET rating = ${rating} WHERE id = '${id}'`)
|
db.execute(`UPDATE recipes SET rating = ${rating} WHERE id = '${id}'`)
|
||||||
},
|
},
|
||||||
toggleCart(state, { id }) {
|
// UnLinkBrokenImages
|
||||||
let i = state.recipes.indexOf(state.recipes.filter((e) => e.id === id)[0])
|
unLinkBIs(state) {
|
||||||
state.recipes[i].inBag = !state.recipes[i].inBag
|
|
||||||
},
|
|
||||||
unlinkBrokenImages(state) {
|
|
||||||
state.recipes.forEach((r, i) => {
|
state.recipes.forEach((r, i) => {
|
||||||
if (r.image && !File.exists(r.image)) {
|
if (r.image && !File.exists(r.image)) {
|
||||||
r.image = null
|
r.image = null
|
||||||
|
@ -1023,160 +1107,157 @@ export default new Vuex.Store({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
setCuisine(state, value) {
|
setCuisine(state, s: string) {
|
||||||
state.selCuisine = value
|
state.selCuisine = s
|
||||||
},
|
},
|
||||||
setCategory(state, value) {
|
setCategory(state, s: string) {
|
||||||
state.selCategory = value
|
state.selCategory = s
|
||||||
},
|
},
|
||||||
setTag(state, value) {
|
setTag(state, s: string) {
|
||||||
state.selTag = value
|
state.selTag = s
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
toggleAwakeViewer({ commit }) {
|
toggleAwakeV({ commit }) {
|
||||||
commit('toggleAwakeViewer')
|
commit('toggleAwakeV')
|
||||||
},
|
},
|
||||||
toggleEdgeSwipe({ commit }) {
|
toggleEdgeS({ commit }) {
|
||||||
commit('toggleEdgeSwipe')
|
commit('toggleEdgeS')
|
||||||
},
|
},
|
||||||
setPlanDeletion({ commit }, s) {
|
setPlanDel({ commit }, s: string) {
|
||||||
commit('setPlanDeletion', s)
|
commit('setPlanDel', s)
|
||||||
},
|
},
|
||||||
setPlannerView({ commit }, s) {
|
setPlannerV({ commit }, s: string) {
|
||||||
commit('setPlannerView', s)
|
commit('setPlannerV', s)
|
||||||
},
|
},
|
||||||
setRTL({ commit }) {
|
setRTL({ commit }) {
|
||||||
commit('setRTL')
|
commit('setRTL')
|
||||||
},
|
},
|
||||||
sortActiveTimers({ commit }) {
|
sortATs({ commit }) {
|
||||||
commit('sortActiveTimers')
|
commit('sortATs')
|
||||||
},
|
},
|
||||||
setFGService({ commit }, val) {
|
setFgS({ commit }, n: number) {
|
||||||
commit('setFGService', val)
|
commit('setFgS', n)
|
||||||
},
|
},
|
||||||
addTimerPreset({ commit }, timer) {
|
addTP({ commit }, o) {
|
||||||
commit('addTimerPreset', timer)
|
commit('addTP', o)
|
||||||
},
|
},
|
||||||
deleteTimerPreset({ commit }, timer) {
|
deleteTP({ commit }, o) {
|
||||||
commit('deleteTimerPreset', timer)
|
commit('deleteTP', o)
|
||||||
},
|
},
|
||||||
initTimerPresets({ commit }) {
|
initTPs({ commit }) {
|
||||||
commit('initTimerPresets')
|
commit('initTPs')
|
||||||
},
|
},
|
||||||
importTimerPresets({ commit }, timers) {
|
importTPs({ commit }, ao) {
|
||||||
commit('importTimerPresets', timers)
|
commit('importTPs', ao)
|
||||||
},
|
},
|
||||||
clearTimerInterval({ commit }) {
|
clearATIs({ commit }) {
|
||||||
commit('clearTimerInterval')
|
commit('clearATIs')
|
||||||
},
|
},
|
||||||
addActiveTimer({ commit }, timer) {
|
addAT({ commit }, o) {
|
||||||
commit('addActiveTimer', timer)
|
commit('addAT', o)
|
||||||
},
|
},
|
||||||
updateActiveTimer({ commit }, timer) {
|
updateAT({ commit }, o) {
|
||||||
commit('updateActiveTimer', timer)
|
commit('updateAT', o)
|
||||||
},
|
},
|
||||||
removeActiveTimer({ commit }, i) {
|
removeAT({ commit }, n: number) {
|
||||||
commit('removeActiveTimer', i)
|
commit('removeAT', n)
|
||||||
},
|
},
|
||||||
setTimerDelay({ commit }, n) {
|
setTD({ commit }, n: number) {
|
||||||
commit('setTimerDelay', n)
|
commit('setTD', n)
|
||||||
},
|
},
|
||||||
setTimerSound({ commit }, sound) {
|
setTS({ commit }, s: string) {
|
||||||
commit('setTimerSound', sound)
|
commit('setTS', s)
|
||||||
},
|
},
|
||||||
setTimerVibrate({ commit }, n) {
|
setTV({ commit }, n: number) {
|
||||||
commit('setTimerVibrate', n)
|
commit('setTV', n)
|
||||||
},
|
},
|
||||||
clearImportSummary({ commit }) {
|
clearIS({ commit }) {
|
||||||
commit('clearImportSummary')
|
commit('clearIS')
|
||||||
},
|
},
|
||||||
setFirstDay({ commit }, n) {
|
setFD({ commit }, n: number) {
|
||||||
commit('setFirstDay', n)
|
commit('setFD', n)
|
||||||
},
|
},
|
||||||
setTheme({ commit }, theme) {
|
setT({ commit }, s: string) {
|
||||||
commit('setTheme', theme)
|
commit('setT', s)
|
||||||
},
|
},
|
||||||
clearFilter({ commit }) {
|
clearF({ commit }) {
|
||||||
commit('clearFilter')
|
commit('clearF')
|
||||||
},
|
},
|
||||||
setLayout({ commit }, type) {
|
setL({ commit }, s: string) {
|
||||||
commit('setLayout', type)
|
commit('setL', s)
|
||||||
},
|
},
|
||||||
setSortType({ commit }, sortType) {
|
setST({ commit }, s: string) {
|
||||||
commit('setSortType', sortType)
|
commit('setST', s)
|
||||||
},
|
},
|
||||||
initRecipes({ commit }) {
|
initRs({ commit }) {
|
||||||
commit('initRecipes')
|
commit('initRs')
|
||||||
},
|
},
|
||||||
importRecipesFromJSON({ commit }, recipes) {
|
importRsJSON({ commit }, ao) {
|
||||||
commit('importRecipesFromJSON', recipes)
|
commit('importRsJSON', ao)
|
||||||
},
|
},
|
||||||
importRecipesFromDB({ commit }, recipes) {
|
importRsDB({ commit }, ao) {
|
||||||
commit('importRecipesFromDB', recipes)
|
commit('importRsDB', ao)
|
||||||
},
|
},
|
||||||
addRecipeAction({ commit }, recipe) {
|
addR({ commit }, o) {
|
||||||
commit('addRecipe', recipe)
|
commit('addR', o)
|
||||||
},
|
},
|
||||||
deleteRecipes({ commit }, ids) {
|
deleteRs({ commit }, a) {
|
||||||
commit('deleteRecipes', ids)
|
commit('deleteRs', a)
|
||||||
},
|
},
|
||||||
initListItems({ commit }) {
|
initLIs({ commit }) {
|
||||||
commit('initListItems')
|
commit('initLIs')
|
||||||
},
|
},
|
||||||
importListItems({ commit }, data) {
|
importLIs({ commit }, ao) {
|
||||||
commit('importListItems', data)
|
commit('importLIs', ao)
|
||||||
},
|
},
|
||||||
addListItemAction({ commit }, item) {
|
addLI({ commit }, s: string) {
|
||||||
commit('addListItem', item)
|
commit('addLI', s)
|
||||||
},
|
},
|
||||||
removeListItemAction({ commit }, item) {
|
removeLI({ commit }, s: string) {
|
||||||
commit('removeListItem', item)
|
commit('removeLI', s)
|
||||||
},
|
},
|
||||||
resetListItemsAction({ commit }, listName) {
|
resetLIs({ commit }, s: string) {
|
||||||
commit('resetListItems', listName)
|
commit('resetLIs', s)
|
||||||
},
|
},
|
||||||
initMealPlans({ commit }) {
|
initMPs({ commit }) {
|
||||||
commit('initMealPlans')
|
commit('initMPs')
|
||||||
},
|
},
|
||||||
importMealPlansFromJSON({ commit }, mealPlans) {
|
importMPsJSON({ commit }, ao) {
|
||||||
commit('importMealPlansFromJSON', mealPlans)
|
commit('importMPsJSON', ao)
|
||||||
},
|
},
|
||||||
importMealPlansFromDB({ commit }, mealPlans) {
|
importMPsDB({ commit }, ao) {
|
||||||
commit('importMealPlansFromDB', mealPlans)
|
commit('importMPsDB', ao)
|
||||||
},
|
},
|
||||||
addMealPlanAction({ commit }, mealPlan) {
|
addMP({ commit }, o) {
|
||||||
commit('addMealPlan', mealPlan)
|
commit('addMP', o)
|
||||||
},
|
},
|
||||||
deleteMealPlanAction({ commit }, mealPlan) {
|
deleteMP({ commit }, o) {
|
||||||
commit('deleteMealPlan', mealPlan)
|
commit('deleteMP', o)
|
||||||
},
|
},
|
||||||
toggleStateAction({ commit }, toggledRecipe) {
|
toggleState({ commit }, o) {
|
||||||
commit('toggleState', toggledRecipe)
|
commit('toggleState', o)
|
||||||
},
|
},
|
||||||
unSyncCombinationsAction({ commit }, combinations) {
|
unLinkCs({ commit }, a) {
|
||||||
commit('unSyncCombinations', combinations)
|
commit('unLinkCs', a)
|
||||||
},
|
},
|
||||||
setShake({ commit }, n) {
|
setS({ commit }, n: number) {
|
||||||
commit('setShake', n)
|
commit('setS', n)
|
||||||
},
|
},
|
||||||
setRatingAction({ commit }, rating) {
|
setR({ commit }, n: number) {
|
||||||
commit('setRating', rating)
|
commit('setR', n)
|
||||||
},
|
},
|
||||||
toggleCartAction({ commit }, recipe) {
|
unLinkBIs({ commit }) {
|
||||||
commit('toggleCart', recipe)
|
commit('unLinkBIs')
|
||||||
},
|
},
|
||||||
unlinkBrokenImages({ commit }) {
|
setCuisine({ commit }, s: string) {
|
||||||
commit('unlinkBrokenImages')
|
commit('setCuisine', s)
|
||||||
},
|
},
|
||||||
setCuisine({ commit }, value) {
|
setCategory({ commit }, s: string) {
|
||||||
commit('setCuisine', value)
|
commit('setCategory', s)
|
||||||
},
|
},
|
||||||
setCategory({ commit }, value) {
|
setTag({ commit }, s: string) {
|
||||||
commit('setCategory', value)
|
commit('setTag', s)
|
||||||
},
|
|
||||||
setTag({ commit }, value) {
|
|
||||||
commit('setTag', value)
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue