2019-03-13 01:53:53 +01:00
|
|
|
import Api from '@api'
|
2019-02-27 02:58:41 +01:00
|
|
|
import { ITodo } from '@src/model'
|
2019-03-21 20:43:15 +01:00
|
|
|
import { GlobalStore, Todos, UserStore } from '@store'
|
2019-03-13 01:53:53 +01:00
|
|
|
import globalroutines from './../../globalroutines/index'
|
|
|
|
|
import { costanti } from './costanti'
|
2019-03-14 21:09:41 +01:00
|
|
|
import Quasar from 'quasar'
|
2019-02-27 02:58:41 +01:00
|
|
|
|
2019-03-13 13:40:17 +01:00
|
|
|
export interface INotify {
|
|
|
|
|
color?: string | 'primary'
|
|
|
|
|
textColor?: string
|
|
|
|
|
icon?: string | ''
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
export const tools = {
|
2019-03-21 20:43:15 +01:00
|
|
|
allTables: ['todos', 'categories', 'sync_post_todos', 'sync_patch_todos', 'delete_todos', 'config', 'swmsg'],
|
2019-02-06 18:47:54 +01:00
|
|
|
EMPTY: 0,
|
2018-11-17 20:32:28 +01:00
|
|
|
CALLING: 10,
|
|
|
|
|
OK: 20,
|
|
|
|
|
ERR_GENERICO: -1,
|
2019-02-06 18:47:54 +01:00
|
|
|
ERR_SERVERFETCH: -2,
|
|
|
|
|
ERR_AUTHENTICATION: -5,
|
2018-11-17 20:32:28 +01:00
|
|
|
DUPLICATE_EMAIL_ID: 11000,
|
2019-01-05 20:11:41 +01:00
|
|
|
DUPLICATE_USERNAME_ID: 11100,
|
|
|
|
|
|
2019-03-14 21:09:41 +01:00
|
|
|
arrLangUsed: ['enUs', 'it', 'es'],
|
|
|
|
|
|
2019-02-02 20:13:06 +01:00
|
|
|
LIST_END: '10000000',
|
|
|
|
|
LIST_START: '0',
|
2019-01-27 19:09:48 +01:00
|
|
|
|
2019-02-22 10:23:00 +01:00
|
|
|
SERVKEY_VERS: 'vers',
|
|
|
|
|
|
2019-01-05 20:11:41 +01:00
|
|
|
localStorage: {
|
2019-02-09 18:04:49 +01:00
|
|
|
verified_email: 'vf',
|
2019-02-13 18:48:30 +01:00
|
|
|
wasAlreadySubOnDb: 'sb',
|
2019-01-30 01:05:31 +01:00
|
|
|
categorySel: 'cs',
|
2019-01-05 20:11:41 +01:00
|
|
|
isLogged: 'ilog',
|
|
|
|
|
expirationDate: 'expdate',
|
|
|
|
|
leftDrawerOpen: 'ldo',
|
|
|
|
|
userId: 'uid',
|
|
|
|
|
token: 'tk',
|
2019-02-16 02:01:17 +01:00
|
|
|
username: 'uname',
|
2019-02-20 11:53:56 +01:00
|
|
|
lang: 'lg'
|
2019-01-14 22:40:30 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
Todos: {
|
2019-01-27 19:09:48 +01:00
|
|
|
PRIORITY_HIGH: 2,
|
|
|
|
|
PRIORITY_NORMAL: 1,
|
|
|
|
|
PRIORITY_LOW: 0
|
|
|
|
|
},
|
|
|
|
|
|
2019-02-02 20:13:06 +01:00
|
|
|
DB: {
|
2019-03-21 20:43:15 +01:00
|
|
|
CMD_SYNC: 'sync-',
|
|
|
|
|
CMD_SYNC_NEW: 'sync-new-',
|
|
|
|
|
CMD_DELETE: 'sync-delete-',
|
|
|
|
|
TABLE_SYNC_POST: 'sync_post_',
|
|
|
|
|
TABLE_SYNC_PATCH: 'sync_patch_',
|
|
|
|
|
TABLE_DELETE: 'delete_'
|
2019-02-02 20:13:06 +01:00
|
|
|
},
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
MenuAction: {
|
2019-01-28 03:13:04 +01:00
|
|
|
DELETE: 100,
|
2019-01-28 13:31:41 +01:00
|
|
|
TOGGLE_EXPIRING: 101,
|
2019-01-29 00:48:04 +01:00
|
|
|
COMPLETED: 110,
|
2019-01-29 23:13:28 +01:00
|
|
|
PROGRESS_BAR: 120,
|
2019-03-04 17:28:29 +01:00
|
|
|
PRIORITY: 130,
|
2019-03-13 01:53:53 +01:00
|
|
|
SHOW_TASK: 150
|
2019-01-14 22:40:30 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
selectPriority: {
|
2019-03-13 01:53:53 +01:00
|
|
|
it: [
|
2019-01-14 22:40:30 +01:00
|
|
|
{
|
2019-01-16 02:26:43 +01:00
|
|
|
id: 1,
|
2019-01-14 22:40:30 +01:00
|
|
|
label: 'Alta',
|
2019-01-27 19:09:48 +01:00
|
|
|
value: 2,
|
2019-01-16 02:26:43 +01:00
|
|
|
icon: 'expand_less'
|
2019-01-14 22:40:30 +01:00
|
|
|
},
|
|
|
|
|
{
|
2019-01-16 02:26:43 +01:00
|
|
|
id: 2,
|
2019-01-14 22:40:30 +01:00
|
|
|
label: 'Normale',
|
2019-01-27 19:09:48 +01:00
|
|
|
value: 1,
|
2019-01-16 02:26:43 +01:00
|
|
|
icon: 'remove'
|
2019-01-14 22:40:30 +01:00
|
|
|
},
|
|
|
|
|
{
|
2019-01-16 02:26:43 +01:00
|
|
|
id: 3,
|
2019-01-14 22:40:30 +01:00
|
|
|
label: 'Bassa',
|
2019-01-27 19:09:48 +01:00
|
|
|
value: 0,
|
2019-01-16 02:26:43 +01:00
|
|
|
icon: 'expand_more'
|
2019-01-14 22:40:30 +01:00
|
|
|
}],
|
2019-03-13 01:53:53 +01:00
|
|
|
es: [
|
2019-02-16 02:01:17 +01:00
|
|
|
{
|
|
|
|
|
id: 1,
|
|
|
|
|
label: 'Alta',
|
|
|
|
|
value: 2,
|
|
|
|
|
icon: 'expand_less'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 2,
|
|
|
|
|
label: 'Normal',
|
|
|
|
|
value: 1,
|
|
|
|
|
icon: 'remove'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 3,
|
|
|
|
|
label: 'Baja',
|
|
|
|
|
value: 0,
|
|
|
|
|
icon: 'expand_more'
|
|
|
|
|
}],
|
2019-03-13 01:53:53 +01:00
|
|
|
enUs: [
|
2019-02-16 02:01:17 +01:00
|
|
|
{
|
|
|
|
|
id: 1,
|
|
|
|
|
label: 'High',
|
|
|
|
|
value: 2,
|
|
|
|
|
icon: 'expand_less'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 2,
|
|
|
|
|
label: 'Normal',
|
|
|
|
|
value: 1,
|
|
|
|
|
icon: 'remove'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 3,
|
|
|
|
|
label: 'Low',
|
|
|
|
|
value: 0,
|
|
|
|
|
icon: 'expand_more'
|
|
|
|
|
}],
|
2019-03-13 01:53:53 +01:00
|
|
|
de: [
|
2019-01-14 22:40:30 +01:00
|
|
|
{
|
2019-01-16 02:26:43 +01:00
|
|
|
id: 1,
|
2019-01-14 22:40:30 +01:00
|
|
|
label: 'High',
|
2019-01-27 19:09:48 +01:00
|
|
|
value: 2,
|
2019-01-16 02:26:43 +01:00
|
|
|
icon: 'expand_less'
|
2019-01-14 22:40:30 +01:00
|
|
|
},
|
|
|
|
|
{
|
2019-01-16 02:26:43 +01:00
|
|
|
id: 2,
|
2019-01-14 22:40:30 +01:00
|
|
|
label: 'Normal',
|
2019-01-27 19:09:48 +01:00
|
|
|
value: 1,
|
2019-01-16 02:26:43 +01:00
|
|
|
icon: 'remove'
|
2019-01-14 22:40:30 +01:00
|
|
|
},
|
|
|
|
|
{
|
2019-01-16 02:26:43 +01:00
|
|
|
id: 3,
|
2019-01-14 22:40:30 +01:00
|
|
|
label: 'Low',
|
2019-01-27 19:09:48 +01:00
|
|
|
value: 0,
|
2019-01-16 02:26:43 +01:00
|
|
|
icon: 'expand_more'
|
2019-01-14 22:40:30 +01:00
|
|
|
}]
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
},
|
|
|
|
|
|
2019-02-15 01:25:44 +01:00
|
|
|
INDEX_MENU_DELETE: 4,
|
2019-01-29 03:12:18 +01:00
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
menuPopupTodo: {
|
2019-03-13 01:53:53 +01:00
|
|
|
it: [
|
2019-01-27 19:09:48 +01:00
|
|
|
{
|
2019-01-29 23:13:28 +01:00
|
|
|
id: 10,
|
|
|
|
|
label: '',
|
2019-01-29 00:48:04 +01:00
|
|
|
value: 120, // PROGRESS_BAR
|
2019-01-29 23:13:28 +01:00
|
|
|
icon: 'rowing',
|
2019-01-29 00:48:04 +01:00
|
|
|
checked: true
|
|
|
|
|
},
|
|
|
|
|
{
|
2019-01-29 23:13:28 +01:00
|
|
|
id: 20,
|
|
|
|
|
label: 'Imposta Priorità',
|
|
|
|
|
value: 130, // PRIORITY
|
|
|
|
|
icon: 'rowing',
|
|
|
|
|
checked: false
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 30,
|
2019-01-28 13:31:41 +01:00
|
|
|
label: 'Completato',
|
|
|
|
|
value: 110, // COMPLETED
|
|
|
|
|
icon: 'check_circle',
|
|
|
|
|
checked: true
|
2019-01-27 19:09:48 +01:00
|
|
|
},
|
|
|
|
|
{
|
2019-01-29 23:13:28 +01:00
|
|
|
id: 40,
|
2019-01-28 03:13:04 +01:00
|
|
|
label: 'Imposta Scadenza',
|
|
|
|
|
value: 101, // TOGGLE_EXPIRING
|
2019-01-28 13:31:41 +01:00
|
|
|
icon: 'date_range',
|
|
|
|
|
checked: true
|
|
|
|
|
},
|
|
|
|
|
{
|
2019-01-29 23:13:28 +01:00
|
|
|
id: 50,
|
2019-02-02 20:13:06 +01:00
|
|
|
label: 'Elimina',
|
2019-01-28 13:31:41 +01:00
|
|
|
value: 100, // DELETE
|
|
|
|
|
icon: 'delete',
|
|
|
|
|
checked: false
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
2019-02-27 02:58:41 +01:00
|
|
|
],
|
2019-03-13 01:53:53 +01:00
|
|
|
es: [
|
2019-02-16 02:01:17 +01:00
|
|
|
{
|
|
|
|
|
id: 10,
|
|
|
|
|
label: '',
|
|
|
|
|
value: 120, // PROGRESS_BAR
|
|
|
|
|
icon: 'rowing',
|
|
|
|
|
checked: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 20,
|
|
|
|
|
label: 'Establecer Prioridad',
|
|
|
|
|
value: 130, // PRIORITY
|
|
|
|
|
icon: 'rowing',
|
|
|
|
|
checked: false
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 30,
|
|
|
|
|
label: 'Completado',
|
|
|
|
|
value: 110, // COMPLETED
|
|
|
|
|
icon: 'check_circle',
|
|
|
|
|
checked: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 40,
|
|
|
|
|
label: 'Establecer expiración',
|
|
|
|
|
value: 101, // TOGGLE_EXPIRING
|
|
|
|
|
icon: 'date_range',
|
|
|
|
|
checked: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 50,
|
|
|
|
|
label: 'Borrar',
|
|
|
|
|
value: 100, // DELETE
|
|
|
|
|
icon: 'delete',
|
|
|
|
|
checked: false
|
|
|
|
|
}
|
|
|
|
|
],
|
2019-03-13 01:53:53 +01:00
|
|
|
enUs: [
|
2019-01-27 19:09:48 +01:00
|
|
|
{
|
2019-01-29 23:13:28 +01:00
|
|
|
id: 10,
|
|
|
|
|
label: '',
|
2019-01-29 00:48:04 +01:00
|
|
|
value: 120, // PROGRESS_BAR
|
|
|
|
|
icon: 'check_circle',
|
|
|
|
|
checked: true
|
|
|
|
|
},
|
|
|
|
|
{
|
2019-01-29 23:13:28 +01:00
|
|
|
id: 20,
|
|
|
|
|
label: 'Set Priority',
|
|
|
|
|
value: 130, // PRIORITY
|
|
|
|
|
icon: 'high_priority',
|
|
|
|
|
checked: false
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 30,
|
2019-01-28 13:31:41 +01:00
|
|
|
label: 'Completed',
|
|
|
|
|
value: 110, // COMPLETED
|
|
|
|
|
icon: 'check_circle',
|
|
|
|
|
checked: true
|
2019-01-27 19:09:48 +01:00
|
|
|
},
|
|
|
|
|
{
|
2019-01-29 23:13:28 +01:00
|
|
|
id: 40,
|
2019-01-28 03:13:04 +01:00
|
|
|
label: 'Set Expiring',
|
|
|
|
|
value: 101, // TOGGLE_EXPIRING
|
2019-01-28 13:31:41 +01:00
|
|
|
icon: 'date_range',
|
|
|
|
|
checked: true
|
|
|
|
|
},
|
|
|
|
|
{
|
2019-01-29 23:13:28 +01:00
|
|
|
id: 50,
|
2019-01-28 13:31:41 +01:00
|
|
|
label: 'Delete',
|
|
|
|
|
value: 100, // DELETE
|
|
|
|
|
icon: 'trash',
|
|
|
|
|
checked: false
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
2019-02-27 02:58:41 +01:00
|
|
|
]
|
2019-02-03 03:44:25 +01:00
|
|
|
},
|
|
|
|
|
|
2019-03-04 17:28:29 +01:00
|
|
|
menuPopupConfigTodo: {
|
2019-03-13 01:53:53 +01:00
|
|
|
it: [
|
2019-03-04 17:28:29 +01:00
|
|
|
{
|
|
|
|
|
id: 10,
|
|
|
|
|
label: 'Mostra Task',
|
|
|
|
|
value: 150, // SHOW_TASK
|
2019-03-13 01:53:53 +01:00
|
|
|
icon: 'rowing'
|
|
|
|
|
}
|
2019-03-04 17:28:29 +01:00
|
|
|
],
|
2019-03-13 01:53:53 +01:00
|
|
|
es: [
|
2019-03-04 17:28:29 +01:00
|
|
|
{
|
|
|
|
|
id: 10,
|
|
|
|
|
label: 'Mostrar Tareas',
|
|
|
|
|
value: 150,
|
2019-03-13 01:53:53 +01:00
|
|
|
icon: 'rowing'
|
|
|
|
|
}
|
2019-03-04 17:28:29 +01:00
|
|
|
],
|
2019-03-13 01:53:53 +01:00
|
|
|
enUs: [
|
2019-03-04 17:28:29 +01:00
|
|
|
{
|
|
|
|
|
id: 10,
|
|
|
|
|
label: 'Show Task',
|
|
|
|
|
value: 150,
|
2019-03-13 01:53:53 +01:00
|
|
|
icon: 'rowing'
|
|
|
|
|
}
|
2019-03-04 17:28:29 +01:00
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
listOptionShowTask: {
|
2019-03-13 01:53:53 +01:00
|
|
|
it: [
|
2019-03-04 17:28:29 +01:00
|
|
|
{
|
|
|
|
|
id: 10,
|
|
|
|
|
label: 'Mostra gli ultimi N completati',
|
|
|
|
|
value: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED,
|
|
|
|
|
icon: 'rowing',
|
|
|
|
|
checked: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 20,
|
|
|
|
|
label: 'Compiti da Completare',
|
|
|
|
|
value: costanti.ShowTypeTask.SHOW_ONLY_TOCOMPLETE,
|
|
|
|
|
icon: 'rowing',
|
|
|
|
|
checked: false
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 30,
|
|
|
|
|
label: 'Tutti i compiti',
|
|
|
|
|
value: costanti.ShowTypeTask.SHOW_ALL,
|
|
|
|
|
icon: 'check_circle',
|
|
|
|
|
checked: true
|
|
|
|
|
}
|
|
|
|
|
],
|
2019-03-13 01:53:53 +01:00
|
|
|
es: [
|
2019-03-04 17:28:29 +01:00
|
|
|
{
|
|
|
|
|
id: 10,
|
|
|
|
|
label: 'Mostrar los ultimos N completados',
|
|
|
|
|
value: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED,
|
|
|
|
|
icon: 'rowing',
|
|
|
|
|
checked: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 20,
|
|
|
|
|
label: 'Tareas para completar',
|
|
|
|
|
value: costanti.ShowTypeTask.SHOW_ONLY_TOCOMPLETE,
|
|
|
|
|
icon: 'rowing',
|
|
|
|
|
checked: false
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 30,
|
|
|
|
|
label: 'Todos las Tareas',
|
|
|
|
|
value: costanti.ShowTypeTask.SHOW_ALL,
|
|
|
|
|
icon: 'check_circle',
|
|
|
|
|
checked: true
|
|
|
|
|
}
|
|
|
|
|
],
|
2019-03-13 01:53:53 +01:00
|
|
|
enUs: [
|
2019-03-04 17:28:29 +01:00
|
|
|
{
|
|
|
|
|
id: 10,
|
|
|
|
|
label: 'Show last N Completed',
|
|
|
|
|
value: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED,
|
|
|
|
|
icon: 'rowing',
|
|
|
|
|
checked: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 20,
|
|
|
|
|
label: 'Task to complete',
|
|
|
|
|
value: costanti.ShowTypeTask.SHOW_ONLY_TOCOMPLETE,
|
|
|
|
|
icon: 'rowing',
|
|
|
|
|
checked: false
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 30,
|
|
|
|
|
label: 'All Tasks',
|
|
|
|
|
value: costanti.ShowTypeTask.SHOW_ALL,
|
|
|
|
|
icon: 'check_circle',
|
|
|
|
|
checked: true
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
|
2019-02-15 01:25:44 +01:00
|
|
|
jsonCopy(src) {
|
|
|
|
|
return JSON.parse(JSON.stringify(src))
|
2019-02-20 11:53:56 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getItemLS(item) {
|
|
|
|
|
let ris = localStorage.getItem(item)
|
2019-03-13 01:53:53 +01:00
|
|
|
if ((ris == null) || (ris === '') || (ris === 'null')) {
|
2019-02-20 11:53:56 +01:00
|
|
|
ris = ''
|
2019-03-13 01:53:53 +01:00
|
|
|
}
|
2019-02-20 11:53:56 +01:00
|
|
|
|
|
|
|
|
return ris
|
2019-02-27 02:58:41 +01:00
|
|
|
},
|
2019-02-15 01:25:44 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
notifyarraychanged(array) {
|
2019-03-13 01:53:53 +01:00
|
|
|
if (array.length > 0) {
|
2019-02-27 02:58:41 +01:00
|
|
|
array.splice(array.length - 1, 1, array[array.length - 1])
|
2019-03-13 01:53:53 +01:00
|
|
|
}
|
2019-02-27 02:58:41 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
existArr(x) {
|
|
|
|
|
return x = (typeof x !== 'undefined' && x instanceof Array) ? x : []
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
json2array(json) {
|
2019-03-13 01:53:53 +01:00
|
|
|
const result = []
|
|
|
|
|
const keys = Object.keys(json)
|
2019-03-21 20:43:15 +01:00
|
|
|
keys.forEach((key) => {
|
2019-02-27 02:58:41 +01:00
|
|
|
result.push(json[key])
|
|
|
|
|
})
|
|
|
|
|
return result
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async cmdToSyncAndDb(cmd, table, method, item: ITodo, id, msg: String) {
|
|
|
|
|
// Send to Server to Sync
|
|
|
|
|
|
2019-03-21 20:43:15 +01:00
|
|
|
// console.log('cmdToSyncAndDb', cmd, table, method, item.descr, id, msg)
|
2019-02-27 02:58:41 +01:00
|
|
|
|
|
|
|
|
let cmdSw = cmd
|
2019-03-21 20:43:15 +01:00
|
|
|
if ((cmd === tools.DB.CMD_SYNC_NEW) || (cmd === tools.DB.CMD_DELETE)) {
|
|
|
|
|
cmdSw = tools.DB.CMD_SYNC
|
2019-02-27 02:58:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ('serviceWorker' in navigator) {
|
|
|
|
|
return await navigator.serviceWorker.ready
|
2019-03-21 20:43:15 +01:00
|
|
|
.then((sw) => {
|
2019-02-27 02:58:41 +01:00
|
|
|
// console.log('---------------------- navigator.serviceWorker.ready')
|
|
|
|
|
|
|
|
|
|
return globalroutines(null, 'write', table, item, id)
|
2019-03-21 20:43:15 +01:00
|
|
|
.then((id) => {
|
2019-02-27 02:58:41 +01:00
|
|
|
// console.log('id', id)
|
|
|
|
|
const sep = '|'
|
|
|
|
|
|
2019-03-13 01:53:53 +01:00
|
|
|
const multiparams = cmdSw + sep + table + sep + method + sep + UserStore.state.x_auth_token + sep + UserStore.state.lang
|
|
|
|
|
const mymsgkey = {
|
2019-02-27 02:58:41 +01:00
|
|
|
_id: multiparams,
|
|
|
|
|
value: multiparams
|
|
|
|
|
}
|
|
|
|
|
return globalroutines(null, 'write', 'swmsg', mymsgkey, multiparams)
|
2019-03-13 01:53:53 +01:00
|
|
|
.then((ris) => {
|
2019-02-27 02:58:41 +01:00
|
|
|
// if ('SyncManager' in window) {
|
|
|
|
|
// console.log(' SENDING... sw.sync.register', multiparams)
|
|
|
|
|
// return sw.sync.register(multiparams)
|
|
|
|
|
// } else {
|
|
|
|
|
// #Todo ++ Alternative 2 to SyncManager
|
|
|
|
|
return Api.syncAlternative(multiparams)
|
|
|
|
|
// }
|
|
|
|
|
})
|
2019-03-21 20:43:15 +01:00
|
|
|
.then(() => {
|
2019-02-27 02:58:41 +01:00
|
|
|
let data = null
|
|
|
|
|
if (msg !== '') {
|
|
|
|
|
data = { message: msg, position: 'bottom', timeout: 3000 }
|
|
|
|
|
}
|
|
|
|
|
return data
|
|
|
|
|
})
|
2019-03-21 20:43:15 +01:00
|
|
|
.catch((err) => {
|
2019-02-27 02:58:41 +01:00
|
|
|
console.error('Errore in globalroutines', table, err)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
2019-03-13 13:40:17 +01:00
|
|
|
},
|
2019-02-27 02:58:41 +01:00
|
|
|
|
2019-03-21 20:43:15 +01:00
|
|
|
async dbInsertSave(call, item, method) {
|
|
|
|
|
|
|
|
|
|
let ret = true
|
|
|
|
|
if (!('serviceWorker' in navigator)) {
|
|
|
|
|
|
|
|
|
|
console.log('dbInsertSave', item, method)
|
|
|
|
|
|
|
|
|
|
if (UserStore.state.userId === '') {
|
|
|
|
|
return false
|
|
|
|
|
} // Login not made
|
|
|
|
|
|
|
|
|
|
call = '/' + call
|
|
|
|
|
if (method !== 'POST') {
|
|
|
|
|
call += '/' + item._id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('SAVE: ', item)
|
|
|
|
|
|
|
|
|
|
ret = await Api.SendReq(call, method, item)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
console.log('dbInsertSave ', call, 'to the Server', res.data)
|
|
|
|
|
|
|
|
|
|
return (res.status === 200)
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
UserStore.mutations.setErrorCatch(error)
|
|
|
|
|
return false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async dbdeleteItem(call, item) {
|
|
|
|
|
|
|
|
|
|
if (!('serviceWorker' in navigator)) {
|
|
|
|
|
// console.log('dbdeleteItem', item)
|
|
|
|
|
if (UserStore.state.userId === '') {
|
|
|
|
|
return false
|
|
|
|
|
} // Login not made
|
|
|
|
|
|
|
|
|
|
call = '/' + call
|
|
|
|
|
|
|
|
|
|
const res = await Api.SendReq(call + item._id, 'DELETE', item)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
console.log('dbdeleteItem to the Server')
|
|
|
|
|
return res
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
UserStore.mutations.setErrorCatch(error)
|
|
|
|
|
return UserStore.getters.getServerCode
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async cmdToSyncAndDbTable(cmd, nametab: string, table, method, item: ITodo, id, msg: String) {
|
|
|
|
|
// Send to Server to Sync
|
|
|
|
|
|
|
|
|
|
console.log('cmdToSyncAndDb', cmd, table, method, item.descr, id, msg)
|
|
|
|
|
|
|
|
|
|
const risdata = await tools.cmdToSyncAndDb(cmd, table, method, item, id, msg)
|
|
|
|
|
|
|
|
|
|
if (cmd === tools.DB.CMD_SYNC_NEW) {
|
|
|
|
|
if ((method === 'POST') || (method === 'PATCH')) {
|
|
|
|
|
await tools.dbInsertSave(nametab, item, method)
|
|
|
|
|
}
|
|
|
|
|
} else if (cmd === tools.DB.CMD_DELETE) {
|
|
|
|
|
await tools.dbdeleteItem(nametab, item)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return risdata
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
deleteItemToSyncAndDb(nametab: string, item, id) {
|
|
|
|
|
tools.cmdToSyncAndDbTable(tools.DB.CMD_DELETE, nametab, tools.DB.TABLE_DELETE + nametab, 'DELETE', item, id, '')
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async saveItemToSyncAndDb(nametab: string, method, item) {
|
|
|
|
|
let table = ''
|
|
|
|
|
if (method === 'POST')
|
|
|
|
|
table = tools.DB.TABLE_SYNC_POST
|
|
|
|
|
else if (method === 'PATCH')
|
|
|
|
|
table = tools.DB.TABLE_SYNC_PATCH
|
|
|
|
|
|
|
|
|
|
return await tools.cmdToSyncAndDbTable(tools.DB.CMD_SYNC_NEW, nametab, table + nametab, method, item, 0, '')
|
|
|
|
|
},
|
|
|
|
|
|
2019-03-14 21:09:41 +01:00
|
|
|
showNotif(q: any, msg, data?: INotify | null) {
|
2019-03-13 13:40:17 +01:00
|
|
|
let myicon = data ? data.icon : 'ion-add'
|
2019-03-21 20:43:15 +01:00
|
|
|
if (!myicon) {
|
2019-03-13 13:40:17 +01:00
|
|
|
myicon = 'ion-add'
|
2019-03-21 20:43:15 +01:00
|
|
|
}
|
2019-03-13 13:40:17 +01:00
|
|
|
let mycolor = data ? data.color : 'primary'
|
2019-03-21 20:43:15 +01:00
|
|
|
if (!mycolor) {
|
2019-03-13 13:40:17 +01:00
|
|
|
mycolor = 'primary'
|
2019-03-21 20:43:15 +01:00
|
|
|
}
|
2019-03-13 13:40:17 +01:00
|
|
|
q.notify({
|
|
|
|
|
message: msg,
|
|
|
|
|
icon: myicon,
|
|
|
|
|
classes: 'my-notif-class',
|
|
|
|
|
color: mycolor,
|
|
|
|
|
timeout: 3000
|
|
|
|
|
})
|
2019-03-14 21:09:41 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
checkLangPassed(mylang) {
|
|
|
|
|
|
|
|
|
|
const mybrowserLang = Quasar.lang.isoName
|
|
|
|
|
|
|
|
|
|
if (mylang !== '') {
|
|
|
|
|
if ((mylang.toLowerCase() === 'enus') || (mylang.toLowerCase() === 'en-us')) {
|
|
|
|
|
mylang = 'enUs'
|
|
|
|
|
}
|
|
|
|
|
if ((mylang.toLowerCase() === 'es') || (mylang.toLowerCase() === 'es-es') || (mylang.toLowerCase() === 'eses')) {
|
|
|
|
|
mylang = 'es'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(tools.arrLangUsed.includes(mylang))) {
|
|
|
|
|
console.log('non incluso ', mylang)
|
|
|
|
|
mylang = tools.arrLangUsed[0]
|
|
|
|
|
|
|
|
|
|
// Metti Inglese come default
|
|
|
|
|
UserStore.mutations.setlang(mylang)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mylang) {
|
|
|
|
|
mylang = process.env.LANG_DEFAULT
|
|
|
|
|
}
|
|
|
|
|
console.log('mylang calc : ', mylang)
|
|
|
|
|
|
|
|
|
|
return mylang
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getimglogo() {
|
|
|
|
|
return 'statics/images/' + process.env.LOGO_REG
|
2019-03-21 20:43:15 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
consolelogpao(strlog, strlog2 = '', strlog3 = '') {
|
|
|
|
|
globalroutines(null, 'log', strlog + ' ' + strlog2 + ' ' + strlog3, null)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async checkPendingMsg() {
|
|
|
|
|
// console.log('checkPendingMsg')
|
|
|
|
|
|
|
|
|
|
const config = await globalroutines(null, 'read', 'config', null, '1')
|
|
|
|
|
// console.log('config', config)
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (config) {
|
|
|
|
|
if (!!config[1].stateconn) {
|
|
|
|
|
// console.log('config.stateconn', config[1].stateconn)
|
|
|
|
|
|
|
|
|
|
if (config[1].stateconn !== GlobalStore.state.stateConnection) {
|
|
|
|
|
GlobalStore.mutations.setStateConnection(config[1].stateconn)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
// Check if there is something
|
|
|
|
|
return globalroutines(null, 'count', 'swmsg')
|
|
|
|
|
.then((count) => {
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
// console.log('count = ', count)
|
|
|
|
|
return resolve(true)
|
|
|
|
|
} else {
|
|
|
|
|
return resolve(false)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
|
|
|
|
return reject()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// If something in the call of Service Worker went wrong (Network or Server Down), then retry !
|
|
|
|
|
async sendSwMsgIfAvailable() {
|
|
|
|
|
let something = false
|
|
|
|
|
|
|
|
|
|
if ('serviceWorker' in navigator) {
|
|
|
|
|
console.log(' -------- sendSwMsgIfAvailable')
|
|
|
|
|
|
|
|
|
|
const count = await tools.checkPendingMsg()
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
return await navigator.serviceWorker.ready
|
|
|
|
|
.then((sw) => {
|
|
|
|
|
|
|
|
|
|
return globalroutines(null, 'readall', 'swmsg')
|
|
|
|
|
.then((arr_recmsg) => {
|
|
|
|
|
if (arr_recmsg.length > 0) {
|
|
|
|
|
|
|
|
|
|
// console.log('---------------------- 2) navigator (2) .serviceWorker.ready')
|
|
|
|
|
let promiseChain = Promise.resolve()
|
|
|
|
|
|
|
|
|
|
for (const rec of arr_recmsg) {
|
|
|
|
|
// console.log(' .... sw.sync.register ( ', rec._id)
|
|
|
|
|
// if ('SyncManager' in window) {
|
|
|
|
|
// sw.sync.register(rec._id)
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
|
|
// #Alternative to SyncManager
|
|
|
|
|
promiseChain = promiseChain.then(() => {
|
|
|
|
|
return Api.syncAlternative(rec._id)
|
|
|
|
|
.then(() => {
|
|
|
|
|
something = true
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
return promiseChain
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
resolve(something)
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async waitAndRefreshData() {
|
|
|
|
|
return await Todos.actions.dbLoadTodo({ checkPending: false })
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async waitAndcheckPendingMsg() {
|
|
|
|
|
|
|
|
|
|
// await aspettansec(1000)
|
|
|
|
|
|
|
|
|
|
return await tools.checkPendingMsg()
|
|
|
|
|
.then((ris) => {
|
|
|
|
|
if (ris) {
|
|
|
|
|
// console.log('risPending = ', ris)
|
|
|
|
|
return tools.sendSwMsgIfAvailable()
|
|
|
|
|
.then((something) => {
|
|
|
|
|
if (something) {
|
|
|
|
|
if (process.env.DEBUG === '1') {
|
|
|
|
|
console.log('something')
|
|
|
|
|
}
|
|
|
|
|
// Refresh data
|
|
|
|
|
return tools.waitAndRefreshData()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async updatefromIndexedDbToStateTodo(nametab) {
|
|
|
|
|
await globalroutines(null, 'updatefromIndexedDbToStateTodo', nametab, null)
|
|
|
|
|
.then(() => {
|
|
|
|
|
console.log('updatefromIndexedDbToStateTodo! ')
|
|
|
|
|
return true
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
isLoggedToSystem() {
|
|
|
|
|
const tok = tools.getItemLS(tools.localStorage.token)
|
|
|
|
|
return !!tok
|
2019-02-27 02:58:41 +01:00
|
|
|
}
|
2019-02-15 01:25:44 +01:00
|
|
|
|
2019-03-21 20:43:15 +01:00
|
|
|
|
2018-11-17 20:32:28 +01:00
|
|
|
}
|