2019-03-04 17:28:29 +01:00
|
|
|
import { ICfgServer, IConfig, IGlobalState, StateConnection } from 'model'
|
2018-11-17 21:07:07 +01:00
|
|
|
import { storeBuilder } from './Store/Store'
|
|
|
|
|
|
2019-02-05 18:17:36 +01:00
|
|
|
import Vue from 'vue'
|
|
|
|
|
|
2019-02-06 18:47:54 +01:00
|
|
|
import translate from './../../globalroutines/util'
|
|
|
|
|
|
2019-02-05 18:17:36 +01:00
|
|
|
import urlBase64ToUint8Array from '../../js/utility'
|
|
|
|
|
|
2019-03-05 23:44:48 +01:00
|
|
|
import messages from '../../statics/i18n'
|
2019-02-22 10:23:00 +01:00
|
|
|
import { GlobalStore, Todos, UserStore } from '@store'
|
2019-02-09 18:04:49 +01:00
|
|
|
import globalroutines from './../../globalroutines/index'
|
2019-02-22 10:23:00 +01:00
|
|
|
import Api from '@api'
|
2019-02-27 02:58:41 +01:00
|
|
|
import { tools } from '@src/store/Modules/tools'
|
2019-03-04 17:28:29 +01:00
|
|
|
import { costanti } from '@src/store/Modules/costanti'
|
|
|
|
|
import * as Types from '@src/store/Api/ApiTypes'
|
2019-02-09 18:04:49 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
const allTables = ['todos', 'categories', 'sync_todos', 'sync_todos_patch', 'delete_todos', 'config', 'swmsg']
|
|
|
|
|
const allTablesAfterLogin = ['todos', 'categories', 'sync_todos', 'sync_todos_patch', 'delete_todos', 'config', 'swmsg']
|
2019-02-12 12:06:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
let stateConnDefault = 'online'
|
|
|
|
|
|
|
|
|
|
getstateConnSaved()
|
|
|
|
|
.then(conn => {
|
|
|
|
|
stateConnDefault = conn
|
|
|
|
|
})
|
2018-11-15 19:48:37 +01:00
|
|
|
|
|
|
|
|
const state: IGlobalState = {
|
|
|
|
|
conta: 0,
|
2019-02-13 18:48:30 +01:00
|
|
|
wasAlreadySubscribed: false,
|
|
|
|
|
wasAlreadySubOnDb: false,
|
2018-11-15 19:48:37 +01:00
|
|
|
isLoginPage: false,
|
|
|
|
|
layoutNeeded: true,
|
|
|
|
|
mobileMode: false,
|
|
|
|
|
menuCollapse: true,
|
2019-01-02 18:01:36 +01:00
|
|
|
leftDrawerOpen: true,
|
2019-02-12 12:06:01 +01:00
|
|
|
stateConnection: stateConnDefault,
|
2019-02-22 10:23:00 +01:00
|
|
|
networkDataReceived: false,
|
|
|
|
|
cfgServer: [],
|
2019-02-27 02:58:41 +01:00
|
|
|
testp1: { contatore: 0, mioarray: [] },
|
2019-01-30 01:05:31 +01:00
|
|
|
category: 'personal',
|
2019-01-29 23:13:28 +01:00
|
|
|
posts: [],
|
|
|
|
|
listatodo: [
|
2019-02-12 12:06:01 +01:00
|
|
|
{ namecat: 'personal', description: 'personal' },
|
|
|
|
|
{ namecat: 'work', description: 'work' },
|
|
|
|
|
{ namecat: 'shopping', description: 'shopping' }
|
2019-02-22 10:23:00 +01:00
|
|
|
],
|
|
|
|
|
connData: {
|
|
|
|
|
uploading_server: 0,
|
|
|
|
|
uploading_indexeddb: 0,
|
|
|
|
|
downloading_server: 0,
|
|
|
|
|
downloading_indexeddb: 0
|
2019-03-04 17:28:29 +01:00
|
|
|
},
|
|
|
|
|
arrConfig: []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getConfig(id) {
|
|
|
|
|
return await globalroutines(null, 'read', 'config', null, id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getstateConnSaved() {
|
|
|
|
|
const config = await getConfig(costanti.CONFIG_ID_CFG)
|
|
|
|
|
console.log('config', config)
|
2019-03-05 23:44:48 +01:00
|
|
|
if (config) {
|
|
|
|
|
if (config.length > 1) {
|
|
|
|
|
const cfgstateconn = config[1]
|
|
|
|
|
return cfgstateconn.stateconn
|
|
|
|
|
} else {
|
|
|
|
|
return 'online'
|
|
|
|
|
}
|
2019-03-04 17:28:29 +01:00
|
|
|
} else {
|
2019-03-05 23:44:48 +01:00
|
|
|
return 'offline'
|
2019-02-22 10:23:00 +01:00
|
|
|
}
|
2018-11-15 19:48:37 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-12 12:06:01 +01:00
|
|
|
|
2018-11-15 19:48:37 +01:00
|
|
|
const b = storeBuilder.module<IGlobalState>('GlobalModule', state)
|
|
|
|
|
|
|
|
|
|
// Getters
|
|
|
|
|
namespace Getters {
|
|
|
|
|
|
2018-12-26 21:02:16 +01:00
|
|
|
const conta = b.read(state => state.conta, 'conta')
|
2019-01-29 23:13:28 +01:00
|
|
|
const listatodo = b.read(state => state.listatodo, 'listatodo')
|
2019-01-30 01:05:31 +01:00
|
|
|
const category = b.read(state => state.category, 'category')
|
2018-12-22 18:42:00 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
const testpao1_getter_contatore = b.read(state => param1 => state.testp1.contatore + 100 + param1, 'testpao1_getter_contatore')
|
2019-03-04 17:28:29 +01:00
|
|
|
const testpao1_getter_array = b.read(state => param1 => state.testp1.mioarray.filter(item => item).map(item => item.valore), 'testpao1_getter_array')
|
|
|
|
|
|
|
|
|
|
const getConfigbyId = b.read(state => id => state.arrConfig.find(item => item._id === id), 'getConfigbyId')
|
2019-03-05 23:44:48 +01:00
|
|
|
const getConfigStringbyId = b.read(state => params => {
|
|
|
|
|
const config = state.arrConfig.find(item => item._id === params.id)
|
2019-03-04 17:28:29 +01:00
|
|
|
if (config) {
|
|
|
|
|
return config.value
|
|
|
|
|
} else {
|
2019-03-05 23:44:48 +01:00
|
|
|
return params.default
|
2019-03-04 17:28:29 +01:00
|
|
|
}
|
|
|
|
|
}, 'getConfigStringbyId')
|
|
|
|
|
|
|
|
|
|
const showtype = b.read(state => {
|
|
|
|
|
// const config = state.arrConfig.find(item => item._id === cat + costanti.CONFIG_ID_SHOW_TYPE_TODOS)
|
|
|
|
|
const config = state.arrConfig.find(item => item._id === costanti.CONFIG_ID_SHOW_TYPE_TODOS)
|
|
|
|
|
if (config)
|
|
|
|
|
return config.value
|
|
|
|
|
else
|
|
|
|
|
return ''
|
|
|
|
|
|
|
|
|
|
}, 'showtype')
|
2019-02-27 02:58:41 +01:00
|
|
|
|
|
|
|
|
|
2018-11-15 19:48:37 +01:00
|
|
|
export const getters = {
|
2019-02-27 02:58:41 +01:00
|
|
|
get testpao1_getter_contatore() {
|
|
|
|
|
return testpao1_getter_contatore()
|
|
|
|
|
},
|
|
|
|
|
get testpao1_getter_array() {
|
|
|
|
|
return testpao1_getter_array()
|
|
|
|
|
},
|
2018-12-22 18:42:00 +01:00
|
|
|
get conta() {
|
|
|
|
|
return conta()
|
2019-01-29 23:13:28 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
get listaTodo() {
|
|
|
|
|
return listatodo()
|
2019-01-30 01:05:31 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
get category() {
|
|
|
|
|
return category()
|
2019-02-12 12:06:01 +01:00
|
|
|
},
|
|
|
|
|
|
2019-03-04 17:28:29 +01:00
|
|
|
get getConfigbyId() {
|
|
|
|
|
return getConfigbyId()
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
get getConfigStringbyId() {
|
|
|
|
|
return getConfigStringbyId()
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
get showtype() {
|
|
|
|
|
return showtype()
|
|
|
|
|
},
|
|
|
|
|
|
2019-02-12 12:06:01 +01:00
|
|
|
get isOnline() {
|
2019-02-22 10:23:00 +01:00
|
|
|
console.log('*********************** isOnline')
|
2019-02-12 12:06:01 +01:00
|
|
|
return state.stateConnection === 'online'
|
2019-02-22 10:23:00 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
get isNewVersionAvailable() {
|
|
|
|
|
console.log('state.cfgServer', state.cfgServer)
|
2019-02-27 02:58:41 +01:00
|
|
|
const serversrec = state.cfgServer.find(x => x.chiave === tools.SERVKEY_VERS)
|
2019-02-22 10:23:00 +01:00
|
|
|
console.log('Record ', serversrec)
|
|
|
|
|
if (serversrec) {
|
|
|
|
|
console.log('Vers Server ', serversrec.valore, 'Vers locale:', process.env.APP_VERSION)
|
|
|
|
|
return serversrec.valore !== process.env.APP_VERSION
|
|
|
|
|
} else
|
|
|
|
|
return false
|
2018-12-22 18:42:00 +01:00
|
|
|
}
|
2018-11-15 19:48:37 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace Mutations {
|
2019-02-27 02:58:41 +01:00
|
|
|
function setPaoArray(state: IGlobalState, miorec: ICfgServer) {
|
|
|
|
|
state.testp1.mioarray[state.testp1.mioarray.length - 1] = miorec
|
|
|
|
|
|
|
|
|
|
tools.notifyarraychanged(state.testp1.mioarray)
|
|
|
|
|
console.log('last elem = ', state.testp1.mioarray[state.testp1.mioarray.length - 1])
|
|
|
|
|
}
|
2019-03-04 17:28:29 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
function NewArray(state: IGlobalState, newarr: ICfgServer[]) {
|
|
|
|
|
state.testp1.mioarray = newarr
|
|
|
|
|
}
|
2019-03-04 17:28:29 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
function setPaoArray_Delete(state: IGlobalState) {
|
|
|
|
|
state.testp1.mioarray.pop()
|
|
|
|
|
}
|
2018-11-15 19:48:37 +01:00
|
|
|
|
|
|
|
|
function setConta(state: IGlobalState, num: number) {
|
|
|
|
|
state.conta = num
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-02 18:01:36 +01:00
|
|
|
function setleftDrawerOpen(state: IGlobalState, bool: boolean) {
|
|
|
|
|
state.leftDrawerOpen = bool
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-30 01:05:31 +01:00
|
|
|
function setCategorySel(state: IGlobalState, cat: string) {
|
|
|
|
|
state.category = cat
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-09 18:04:49 +01:00
|
|
|
function setStateConnection(state: IGlobalState, stateconn: StateConnection) {
|
|
|
|
|
if (state.stateConnection !== stateconn) {
|
|
|
|
|
console.log('INTERNET ', stateconn)
|
|
|
|
|
state.stateConnection = stateconn
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-30 01:05:31 +01:00
|
|
|
|
2019-03-04 17:28:29 +01:00
|
|
|
function saveConfig(state: IGlobalState, data: IConfig) {
|
|
|
|
|
let dataout
|
|
|
|
|
// this.$set(dataout, data.value, {'value': 'default value'})
|
|
|
|
|
return globalroutines(null, 'write', 'config', { _id: data._id, value: data.value })
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-13 18:48:30 +01:00
|
|
|
function SetwasAlreadySubOnDb(state: IGlobalState, subscrib: boolean) {
|
|
|
|
|
state.wasAlreadySubOnDb = subscrib
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 17:28:29 +01:00
|
|
|
function setShowType(state: IGlobalState, showtype: number) {
|
2019-03-05 23:44:48 +01:00
|
|
|
console.log('setShowType', showtype)
|
2019-03-04 17:28:29 +01:00
|
|
|
const config = Getters.getters.getConfigbyId(costanti.CONFIG_ID_SHOW_TYPE_TODOS)
|
2019-03-05 23:44:48 +01:00
|
|
|
console.log('config', config)
|
2019-03-04 17:28:29 +01:00
|
|
|
if (config) {
|
|
|
|
|
config.value = String(showtype)
|
|
|
|
|
Todos.state.showtype = parseInt(config.value)
|
2019-03-05 23:44:48 +01:00
|
|
|
} else {
|
|
|
|
|
Todos.state.showtype = showtype
|
2019-03-04 17:28:29 +01:00
|
|
|
}
|
2019-03-05 23:44:48 +01:00
|
|
|
console.log('Todos.state.showtype', Todos.state.showtype)
|
|
|
|
|
GlobalStore.mutations.saveConfig({ _id: costanti.CONFIG_ID_SHOW_TYPE_TODOS, value: String(showtype) })
|
|
|
|
|
|
2019-03-04 17:28:29 +01:00
|
|
|
}
|
|
|
|
|
|
2018-11-15 19:48:37 +01:00
|
|
|
export const mutations = {
|
2019-01-02 18:01:36 +01:00
|
|
|
setConta: b.commit(setConta),
|
2019-01-30 01:05:31 +01:00
|
|
|
setleftDrawerOpen: b.commit(setleftDrawerOpen),
|
2019-02-09 18:04:49 +01:00
|
|
|
setCategorySel: b.commit(setCategorySel),
|
2019-02-13 18:48:30 +01:00
|
|
|
setStateConnection: b.commit(setStateConnection),
|
2019-02-27 02:58:41 +01:00
|
|
|
SetwasAlreadySubOnDb: b.commit(SetwasAlreadySubOnDb),
|
2019-03-04 17:28:29 +01:00
|
|
|
saveConfig: b.commit(saveConfig),
|
2019-02-27 02:58:41 +01:00
|
|
|
setPaoArray: b.commit(setPaoArray),
|
|
|
|
|
setPaoArray_Delete: b.commit(setPaoArray_Delete),
|
2019-03-04 17:28:29 +01:00
|
|
|
NewArray: b.commit(NewArray),
|
|
|
|
|
setShowType: b.commit(setShowType)
|
2018-11-15 19:48:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace Actions {
|
2018-11-17 20:32:28 +01:00
|
|
|
async function setConta(context, num: number) {
|
2018-11-15 19:48:37 +01:00
|
|
|
Mutations.mutations.setConta(num)
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-05 18:17:36 +01:00
|
|
|
function createPushSubscription(context) {
|
2019-02-13 18:48:30 +01:00
|
|
|
|
|
|
|
|
// If Already subscribed, don't send to the Server DB
|
2019-02-14 18:38:23 +01:00
|
|
|
// if (state.wasAlreadySubOnDb) {
|
|
|
|
|
// // console.log('wasAlreadySubOnDb!')
|
|
|
|
|
// return
|
|
|
|
|
// }
|
2019-02-13 18:48:30 +01:00
|
|
|
|
2019-02-05 18:17:36 +01:00
|
|
|
if (!('serviceWorker' in navigator)) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-12 12:06:01 +01:00
|
|
|
if (!('PushManager' in window)) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 18:48:07 +01:00
|
|
|
// console.log('createPushSubscription')
|
2019-02-05 18:17:36 +01:00
|
|
|
|
|
|
|
|
let reg
|
|
|
|
|
const mykey = process.env.PUBLICKEY_PUSH
|
|
|
|
|
const mystate = state
|
2019-02-14 18:38:23 +01:00
|
|
|
return navigator.serviceWorker.ready
|
2019-02-05 18:17:36 +01:00
|
|
|
.then(function (swreg) {
|
|
|
|
|
reg = swreg
|
|
|
|
|
return swreg.pushManager.getSubscription()
|
|
|
|
|
})
|
|
|
|
|
.then(function (subscription) {
|
2019-02-13 18:48:30 +01:00
|
|
|
mystate.wasAlreadySubscribed = !(subscription === null)
|
2019-02-05 18:17:36 +01:00
|
|
|
|
2019-02-14 18:38:23 +01:00
|
|
|
if (mystate.wasAlreadySubscribed) {
|
2019-02-27 02:58:41 +01:00
|
|
|
// console.log('User is already SAVED Subscribe on DB!')
|
2019-02-14 18:38:23 +01:00
|
|
|
// return null
|
|
|
|
|
return subscription
|
2019-02-05 18:17:36 +01:00
|
|
|
} else {
|
|
|
|
|
// Create a new subscription
|
2019-02-14 18:38:23 +01:00
|
|
|
console.log('Create a new subscription')
|
2019-02-05 18:17:36 +01:00
|
|
|
let convertedVapidPublicKey = urlBase64ToUint8Array(mykey)
|
|
|
|
|
return reg.pushManager.subscribe({
|
|
|
|
|
userVisibleOnly: true,
|
|
|
|
|
applicationServerKey: convertedVapidPublicKey
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.then(function (newSub) {
|
2019-02-13 18:48:30 +01:00
|
|
|
saveNewSubscriptionToServer(context, newSub)
|
2019-02-05 18:17:36 +01:00
|
|
|
})
|
|
|
|
|
.catch(function (err) {
|
2019-02-14 18:38:23 +01:00
|
|
|
console.log('ERR createPushSubscription:', err)
|
2019-02-05 18:17:36 +01:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calling the Server to Save in the MongoDB the Subscriber
|
|
|
|
|
function saveNewSubscriptionToServer(context, newSub) {
|
2019-02-13 18:48:30 +01:00
|
|
|
// If already subscribed, exit
|
|
|
|
|
if (!newSub)
|
|
|
|
|
return
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
// console.log('saveSubscriptionToServer: ', newSub)
|
2019-02-13 18:48:30 +01:00
|
|
|
// console.log('context', context)
|
2019-02-05 18:17:36 +01:00
|
|
|
|
2019-02-14 18:38:23 +01:00
|
|
|
let options = null
|
|
|
|
|
|
|
|
|
|
// If is not already stored in DB, then show the message to the user.
|
2019-02-14 19:01:32 +01:00
|
|
|
if (!state.wasAlreadySubscribed) {
|
2019-02-14 18:38:23 +01:00
|
|
|
options = {
|
|
|
|
|
title: translate('notification.title_subscribed'),
|
|
|
|
|
content: translate('notification.subscribed'),
|
|
|
|
|
openUrl: '/'
|
|
|
|
|
}
|
2019-02-14 19:01:32 +01:00
|
|
|
}
|
2019-02-05 18:17:36 +01:00
|
|
|
|
|
|
|
|
let myres = {
|
2019-02-14 19:01:32 +01:00
|
|
|
options,
|
2019-02-06 18:47:54 +01:00
|
|
|
subs: newSub,
|
|
|
|
|
others: {
|
2019-02-12 12:06:01 +01:00
|
|
|
userId: UserStore.state.userId,
|
|
|
|
|
access: UserStore.state.tokens[0].access
|
2019-02-22 10:23:00 +01:00
|
|
|
}
|
2019-02-05 18:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-19 02:33:02 +01:00
|
|
|
return Api.SendReq('/subscribe', 'POST', myres)
|
|
|
|
|
.then(res => {
|
2019-02-13 18:48:30 +01:00
|
|
|
state.wasAlreadySubscribed = true
|
|
|
|
|
state.wasAlreadySubOnDb = true
|
2019-02-05 18:17:36 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
localStorage.setItem(tools.localStorage.wasAlreadySubOnDb, String(state.wasAlreadySubOnDb))
|
2019-02-13 18:48:30 +01:00
|
|
|
})
|
|
|
|
|
.catch(e => {
|
|
|
|
|
console.log('Error during Subscription!', e)
|
|
|
|
|
})
|
2019-02-05 18:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-12 12:06:01 +01:00
|
|
|
async function deleteSubscriptionToServer(context) {
|
|
|
|
|
console.log('DeleteSubscriptionToServer: ')
|
|
|
|
|
|
|
|
|
|
return await fetch(process.env.MONGODB_HOST + '/subscribe/del', {
|
|
|
|
|
method: 'DELETE',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json',
|
|
|
|
|
'x-auth': UserStore.state.x_auth_token
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-05 18:17:36 +01:00
|
|
|
function t(params) {
|
|
|
|
|
let msg = params.split('.')
|
|
|
|
|
let lang = UserStore.state.lang
|
|
|
|
|
|
|
|
|
|
let stringa = messages[lang]
|
|
|
|
|
|
|
|
|
|
let ris = stringa
|
|
|
|
|
msg.forEach(param => {
|
|
|
|
|
ris = ris[param]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return ris
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function prova(context) {
|
|
|
|
|
// console.log('prova')
|
2019-02-27 02:58:41 +01:00
|
|
|
// state.testp1.mioarray[state.testp1.mioarray.length - 1].valore = 'VALMODIF';
|
2019-02-05 18:17:36 +01:00
|
|
|
|
|
|
|
|
// let msg = t('notification.title_subscribed')
|
|
|
|
|
|
|
|
|
|
// console.log('msg', msg)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-12 12:06:01 +01:00
|
|
|
async function clearDataAfterLogout(context) {
|
|
|
|
|
console.log('clearDataAfterLogout')
|
2019-02-09 18:04:49 +01:00
|
|
|
|
|
|
|
|
// Clear all data from the IndexedDB
|
2019-02-22 10:23:00 +01:00
|
|
|
for (const table of allTables) {
|
2019-02-20 19:17:29 +01:00
|
|
|
await globalroutines(null, 'clearalldata', table, null)
|
|
|
|
|
}
|
2019-02-09 18:04:49 +01:00
|
|
|
|
2019-02-14 18:38:23 +01:00
|
|
|
if ('serviceWorker' in navigator) {
|
|
|
|
|
// REMOVE ALL SUBSCRIPTION
|
|
|
|
|
console.log('REMOVE ALL SUBSCRIPTION...')
|
|
|
|
|
await navigator.serviceWorker.ready.then(function (reg) {
|
|
|
|
|
console.log('... Ready')
|
|
|
|
|
reg.pushManager.getSubscription().then(function (subscription) {
|
|
|
|
|
console.log(' Found Subscription...')
|
|
|
|
|
subscription.unsubscribe().then(function (successful) {
|
|
|
|
|
// You've successfully unsubscribed
|
|
|
|
|
console.log('You\'ve successfully unsubscribed')
|
|
|
|
|
}).catch(function (e) {
|
|
|
|
|
// Unsubscription failed
|
|
|
|
|
})
|
2019-02-12 12:06:01 +01:00
|
|
|
})
|
|
|
|
|
})
|
2019-02-14 18:38:23 +01:00
|
|
|
}
|
2019-02-12 12:06:01 +01:00
|
|
|
|
|
|
|
|
await deleteSubscriptionToServer(context)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function clearDataAfterLoginOnlyIfActiveConnection(context) {
|
|
|
|
|
|
|
|
|
|
// if (Getters.getters.isOnline) {
|
|
|
|
|
// console.log('clearDataAfterLoginOnlyIfActiveConnection')
|
|
|
|
|
// // Clear all data from the IndexedDB
|
|
|
|
|
// allTablesAfterLogin.forEach(table => {
|
|
|
|
|
// globalroutines(null, 'clearalldata', table, null)
|
|
|
|
|
// })
|
|
|
|
|
// }
|
|
|
|
|
|
2019-02-09 18:04:49 +01:00
|
|
|
}
|
2019-02-05 18:17:36 +01:00
|
|
|
|
2019-02-12 12:06:01 +01:00
|
|
|
|
|
|
|
|
async function loadAfterLogin(context) {
|
2019-03-04 17:28:29 +01:00
|
|
|
console.log('loadAfterLogin')
|
2019-02-12 12:06:01 +01:00
|
|
|
actions.clearDataAfterLoginOnlyIfActiveConnection()
|
2019-03-04 17:28:29 +01:00
|
|
|
|
|
|
|
|
state.arrConfig = await globalroutines(null, 'readall', 'config', null)
|
2019-02-05 18:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-22 10:23:00 +01:00
|
|
|
async function saveCfgServerKey(context, dataval: ICfgServer) {
|
|
|
|
|
console.log('saveCfgServerKey dataval', dataval)
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
let ris = await Api.SendReq('/admin/updateval', 'POST', { pairval: dataval })
|
2019-02-22 10:23:00 +01:00
|
|
|
.then(res => {
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function checkUpdates(context) {
|
|
|
|
|
console.log('checkUpdates')
|
|
|
|
|
|
|
|
|
|
// if (UserStore.state.userId === '')
|
|
|
|
|
// return false // Login not made
|
|
|
|
|
|
|
|
|
|
state.networkDataReceived = false
|
|
|
|
|
|
|
|
|
|
let ris = await Api.SendReq('/checkupdates', 'GET', null)
|
|
|
|
|
.then(res => {
|
|
|
|
|
state.networkDataReceived = true
|
|
|
|
|
|
|
|
|
|
console.log('******* checkUpdates RES :', res.data.cfgServer)
|
|
|
|
|
if (res.data.cfgServer) {
|
|
|
|
|
state.cfgServer = [...res.data.cfgServer]
|
|
|
|
|
console.log('res.data.cfgServer', res.data.cfgServer)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// console.log('********** res', 'state.todos', state.todos, 'checkPending', checkPending)
|
|
|
|
|
// After Login will store into the indexedDb...
|
|
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
console.log('error checkUpdates', error)
|
|
|
|
|
UserStore.mutations.setErrorCatch(error)
|
|
|
|
|
return error
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
2019-02-05 18:17:36 +01:00
|
|
|
|
2018-11-15 19:48:37 +01:00
|
|
|
export const actions = {
|
2019-02-05 18:17:36 +01:00
|
|
|
setConta: b.dispatch(setConta),
|
|
|
|
|
createPushSubscription: b.dispatch(createPushSubscription),
|
|
|
|
|
loadAfterLogin: b.dispatch(loadAfterLogin),
|
2019-02-09 18:04:49 +01:00
|
|
|
clearDataAfterLogout: b.dispatch(clearDataAfterLogout),
|
2019-02-12 12:06:01 +01:00
|
|
|
clearDataAfterLoginOnlyIfActiveConnection: b.dispatch(clearDataAfterLoginOnlyIfActiveConnection),
|
2019-02-22 10:23:00 +01:00
|
|
|
prova: b.dispatch(prova),
|
|
|
|
|
saveCfgServerKey: b.dispatch(saveCfgServerKey),
|
|
|
|
|
checkUpdates: b.dispatch(checkUpdates)
|
2018-11-15 19:48:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-22 23:30:02 +01:00
|
|
|
const stateGetter = b.state()
|
|
|
|
|
|
2018-11-15 19:48:37 +01:00
|
|
|
// Module
|
|
|
|
|
const GlobalModule = {
|
2018-12-26 21:02:16 +01:00
|
|
|
get state() {
|
|
|
|
|
return stateGetter()
|
|
|
|
|
},
|
2018-11-15 19:48:37 +01:00
|
|
|
getters: Getters.getters,
|
|
|
|
|
mutations: Mutations.mutations,
|
|
|
|
|
actions: Actions.actions
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default GlobalModule
|