Show Button, when Upgrade Version is available ! (check from the server, the version number

- for debug: added led button to see when is calling the server and the IndexedDb.
This commit is contained in:
Paolo Arena
2019-02-22 10:23:00 +01:00
parent 1623a5c35d
commit 0e98ac1eaa
41 changed files with 1411 additions and 992 deletions

View File

@@ -1,4 +1,4 @@
import { IGlobalState, StateConnection } from 'model'
import { ICfgServer, IGlobalState, StateConnection } from 'model'
import { storeBuilder } from './Store/Store'
import Vue from 'vue'
@@ -8,10 +8,10 @@ import translate from './../../globalroutines/util'
import urlBase64ToUint8Array from '../../js/utility'
import messages from '../../statics/i18n'
import { GlobalStore, UserStore } from '@store'
import { GlobalStore, Todos, UserStore } from '@store'
import globalroutines from './../../globalroutines/index'
import Api from "@api"
import { rescodes } from "@src/store/Modules/rescodes"
import Api from '@api'
import { rescodes } from '@src/store/Modules/rescodes'
const allTables = ['todos', 'sync_todos', 'sync_todos_patch', 'delete_todos', 'config', 'swmsg']
const allTablesAfterLogin = ['todos', 'sync_todos', 'sync_todos_patch', 'delete_todos', 'config', 'swmsg']
@@ -42,13 +42,21 @@ const state: IGlobalState = {
menuCollapse: true,
leftDrawerOpen: true,
stateConnection: stateConnDefault,
networkDataReceived: false,
cfgServer: [],
category: 'personal',
posts: [],
listatodo: [
{ namecat: 'personal', description: 'personal' },
{ namecat: 'work', description: 'work' },
{ namecat: 'shopping', description: 'shopping' }
]
],
connData: {
uploading_server: 0,
uploading_indexeddb: 0,
downloading_server: 0,
downloading_indexeddb: 0
}
}
@@ -75,7 +83,19 @@ namespace Getters {
},
get isOnline() {
console.log('*********************** isOnline')
return state.stateConnection === 'online'
},
get isNewVersionAvailable() {
console.log('state.cfgServer', state.cfgServer)
const serversrec = state.cfgServer.find(x => x.chiave === rescodes.SERVKEY_VERS)
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
}
}
}
@@ -197,7 +217,7 @@ namespace Actions {
others: {
userId: UserStore.state.userId,
access: UserStore.state.tokens[0].access
},
}
}
return Api.SendReq('/subscribe', 'POST', myres)
@@ -253,7 +273,7 @@ namespace Actions {
console.log('clearDataAfterLogout')
// Clear all data from the IndexedDB
for (const table of allTables){
for (const table of allTables) {
await globalroutines(null, 'clearalldata', table, null)
}
@@ -295,6 +315,47 @@ namespace Actions {
actions.clearDataAfterLoginOnlyIfActiveConnection()
}
async function saveCfgServerKey(context, dataval: ICfgServer) {
console.log('saveCfgServerKey dataval', dataval)
let ris = await Api.SendReq('/admin/updateval', 'POST', {pairval: dataval})
.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)
// Todos.mutations.setTodos_changed()
}
// 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
})
}
export const actions = {
setConta: b.dispatch(setConta),
@@ -302,7 +363,9 @@ namespace Actions {
loadAfterLogin: b.dispatch(loadAfterLogin),
clearDataAfterLogout: b.dispatch(clearDataAfterLogout),
clearDataAfterLoginOnlyIfActiveConnection: b.dispatch(clearDataAfterLoginOnlyIfActiveConnection),
prova: b.dispatch(prova)
prova: b.dispatch(prova),
saveCfgServerKey: b.dispatch(saveCfgServerKey),
checkUpdates: b.dispatch(checkUpdates)
}
}

View File

@@ -11,7 +11,6 @@ import { serv_constants } from '@src/store/Modules/serv_constants'
const state: ITodosState = {
visuOnlyUncompleted: false,
networkDataReceived: false,
todos: [],
todos_changed: 1,
reload_fromServer: 0,
@@ -162,14 +161,15 @@ namespace Actions {
})
}
async function waitAndcheckPendingMsg(context) {
await aspettansec(1000)
// await aspettansec(1000)
return await checkPendingMsg(context)
.then(ris => {
if (ris) {
console.log('risPending = ', ris)
// console.log('risPending = ', ris)
return sendSwMsgIfAvailable()
.then(something => {
if (something) {
@@ -184,7 +184,7 @@ namespace Actions {
}
async function waitAndRefreshData(context) {
await aspettansec(3000)
// await aspettansec(3000)
return await dbLoadTodo(context, false)
}
@@ -214,7 +214,7 @@ namespace Actions {
return globalroutines(null, 'count', 'swmsg')
.then(function (count) {
if (count > 0) {
console.log('count = ', count)
// console.log('count = ', count)
return resolve(true)
} else {
return resolve(false)
@@ -234,11 +234,11 @@ namespace Actions {
if (UserStore.state.userId === '')
return false // Login not made
state.networkDataReceived = false
GlobalStore.state.networkDataReceived = false
let ris = await Api.SendReq('/todos/' + UserStore.state.userId, 'GET', null)
.then(res => {
state.networkDataReceived = true
GlobalStore.state.networkDataReceived = true
// console.log('******* UPDATE TODOS.STATE.TODOS !:', res.todos)
if (res.data.todos) {
@@ -260,7 +260,7 @@ namespace Actions {
// console.log('ris : ', ris)
// console.log('ris STATUS: ', ris.status)
if (!Todos.state.networkDataReceived) {
if (!GlobalStore.state.networkDataReceived) {
if (ris.status === serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN) {
consolelogpao('UNAUTHORIZING... TOKEN EXPIRED... !! ')
@@ -379,7 +379,7 @@ namespace Actions {
updatefromIndexedDbToStateTodo: b.dispatch(updatefromIndexedDbToStateTodo),
getTodosByCategory: b.dispatch(getTodosByCategory),
checkPendingMsg: b.dispatch(checkPendingMsg),
waitAndcheckPendingMsg: b.dispatch(waitAndcheckPendingMsg)
waitAndcheckPendingMsg: b.dispatch(waitAndcheckPendingMsg),
}
}

View File

@@ -10,7 +10,7 @@ import { GlobalStore, UserStore, Todos } from '@store'
import globalroutines from './../../globalroutines/index'
import translate from './../../globalroutines/util'
import * as Types from "@src/store/Api/ApiTypes"
import * as Types from '@src/store/Api/ApiTypes'
const bcrypt = require('bcryptjs')
@@ -27,7 +27,8 @@ const state: IUserState = {
verified_email: false,
categorySel: 'personal',
servercode: 0,
x_auth_token: ''
x_auth_token: '',
isAdmin: false
}
@@ -84,13 +85,23 @@ namespace Getters {
namespace Mutations {
function authUser(state, data: IUserState) {
function authUser(state: IUserState, data: IUserState ) {
state.userId = data.userId
state.username = data.username
state.verified_email = data.verified_email
state.category = data.categorySel
if (data.verified_email)
state.verified_email = data.verified_email
if (data.categorySel)
state.categorySel = data.categorySel // ??
resetArrToken(state.tokens)
state.tokens.push({ access: 'auth', token: state.x_auth_token, date_login: new Date() })
state.tokens.push({ access: 'auth', token: state.x_auth_token, data_login: new Date() })
// ++Todo: Settings Users Admin
if (state.username === 'paoloar77')
state.isAdmin = true
// console.log('state.tokens', state.tokens)
}
@@ -501,6 +512,7 @@ namespace Actions {
GlobalStore.mutations.setleftDrawerOpen(localStorage.getItem(rescodes.localStorage.leftDrawerOpen) === 'true')
GlobalStore.mutations.setCategorySel(localStorage.getItem(rescodes.localStorage.categorySel))
GlobalStore.actions.checkUpdates()
await GlobalStore.actions.loadAfterLogin()
.then(() => {

View File

@@ -11,6 +11,8 @@ export const rescodes = {
LIST_END: '10000000',
LIST_START: '0',
SERVKEY_VERS: 'vers',
localStorage: {
verified_email: 'vf',
wasAlreadySubOnDb: 'sb',