Cleaning Code, moving functions...

This commit is contained in:
Paolo Arena
2019-03-22 18:49:38 +01:00
parent dd695a7ce5
commit 4d32467eb1
10 changed files with 49 additions and 99 deletions

View File

@@ -9,12 +9,6 @@ export const allTables = ['todos', 'categories', 'sync_post_todos', 'sync_patch_
export const LIST_START = '0'
export const Priority = {
PRIORITY_HIGH: 2,
PRIORITY_NORMAL: 1,
PRIORITY_LOW: 0
}
export const DB = {
CMD_SYNC: 'sync-',
CMD_SYNC_NEW: 'sync-new-',
@@ -24,7 +18,7 @@ export const DB = {
TABLE_DELETE: 'delete_'
}
export async function dbInsertSave(call, item, method) {
async function dbInsertSave(call, item, method) {
let ret = true
if (!('serviceWorker' in navigator)) {
@@ -57,7 +51,7 @@ export async function dbInsertSave(call, item, method) {
return ret
}
export async function dbDeleteItem(call, item) {
async function dbDeleteItem(call, item) {
if (!('serviceWorker' in navigator)) {
// console.log('dbdeleteItem', item)
@@ -81,7 +75,7 @@ export async function dbDeleteItem(call, item) {
}
}
export async function Sync_Execute(cmd, table, method, item: ITodo, id, msg: String) {
async function Sync_Execute(cmd, table, method, item: ITodo, id, msg: String) {
// Send to Server to Sync
// console.log('Sync_Execute', cmd, table, method, item.descr, id, msg)
@@ -131,7 +125,7 @@ export async function Sync_Execute(cmd, table, method, item: ITodo, id, msg: Str
}
}
export async function Sync_ExecuteCmd(cmd, nametab: string, table, method, item: ITodo, id, msg: String) {
async function Sync_ExecuteCmd(cmd, nametab: string, table, method, item: ITodo, id, msg: String) {
// Send to Server to Sync
console.log('Sync_Execute', cmd, table, method, item.descr, id, msg)
@@ -187,7 +181,7 @@ export async function aftercalling(ris, checkPending: boolean, nametabindex: str
}
}
export async function checkPendingMsg() {
async function checkPendingMsg() {
// console.log('checkPendingMsg')
const config = await globalroutines(null, 'read', 'config', null, '1')
@@ -226,7 +220,7 @@ export async function checkPendingMsg() {
}
// If something in the call of Service Worker went wrong (Network or Server Down), then retry !
export async function sendSwMsgIfAvailable() {
async function sendSwMsgIfAvailable() {
let something = false
if ('serviceWorker' in navigator) {
@@ -273,7 +267,7 @@ export async function sendSwMsgIfAvailable() {
})
}
export async function waitAndRefreshData() {
async function waitAndRefreshData() {
return await Todos.actions.dbLoadTodo({ checkPending: false })
}
@@ -299,7 +293,7 @@ export async function waitAndcheckPendingMsg() {
})
}
export async function updatefromIndexedDbToStateTodo(nametab) {
async function updatefromIndexedDbToStateTodo(nametab) {
await globalroutines(null, 'updatefromIndexedDbToStateTodo', nametab, null)
.then(() => {
console.log('updatefromIndexedDbToStateTodo! ')
@@ -340,7 +334,7 @@ sendMessageToSW(recdata, method) {
}
*/
export function setmodifiedIfchanged(recOut, recIn, field) {
function setmodifiedIfchanged(recOut, recIn, field) {
if (String(recOut[field]) !== String(recIn[field])) {
// console.log('*************** CAMPO ', field, 'MODIFICATO!', recOut[field], recIn[field])
recOut.modified = true
@@ -407,8 +401,3 @@ export function table_DeleteRecord(nametable, myobjtrov, id) {
Sync_DeleteItem(nametable, myobjtrov, id)
}
export function isLoggedToSystem() {
const tok = tools.getItemLS(tools.localStorage.token)
return !!tok
}

View File

@@ -122,7 +122,6 @@ namespace Getters {
})
if (UserStore.state.isAdmin) {
state.menulinks = {
Dashboard: {
@@ -175,6 +174,8 @@ namespace Getters {
}
}
console.log('___ return getMenu ', state.menulinks)
return state.menulinks
}, 'getmenu')
@@ -284,7 +285,7 @@ namespace Mutations {
console.log('config', config)
if (config) {
config.value = String(showtype)
Todos.state.showtype = parseInt(config.value)
Todos.state.showtype = parseInt(config.value, 10)
} else {
Todos.state.showtype = showtype
}

View File

@@ -103,10 +103,10 @@ function getLastFirstElemPriority(cat: string, priority: number, atfirst: boolea
if (trovato) {
return myarr.length - 1
} else {
if (priority === tools.Todos.PRIORITY_LOW) {
if (priority === tools.Priority.PRIORITY_LOW) {
return myarr.length - 1
}
else if (priority === tools.Todos.PRIORITY_HIGH) {
else if (priority === tools.Priority.PRIORITY_HIGH) {
return 0
}
}
@@ -150,7 +150,7 @@ function initcat() {
_id: objectId(),
userId: UserStore.state.userId,
descr: '',
priority: tools.Todos.PRIORITY_NORMAL,
priority: tools.Priority.PRIORITY_NORMAL,
completed: false,
created_at: new Date(),
modify_at: new Date(),

View File

@@ -36,7 +36,7 @@ export const tools = {
lang: 'lg'
},
Todos: {
Priority: {
PRIORITY_HIGH: 2,
PRIORITY_NORMAL: 1,
PRIORITY_LOW: 0
@@ -442,10 +442,27 @@ export const tools = {
})
},
dragula_option($service, dragname) {
$service.options(dragname,
{
moves(el, source, handle, sibling) {
return !el.classList.contains('donotdrag') // elements are always draggable by default
},
accepts(el, target, source, sibling) {
return true // elements can be dropped in any of the `containers` by default
},
invalid(el, handle) {
return el.classList.contains('donotdrag') // don't prevent any drags from initiating by default
},
direction: 'vertical'
})
},
isLoggedToSystem() {
const tok = tools.getItemLS(tools.localStorage.token)
return !!tok
}
// _.cloneDeep( Per clonare un oggetto
}