++ If press DELETE or BACKSPACE and is blank description, delete the Todos.
- fix: if offline, doesn't save to cache?? if I refresh page, the data disappear - ++ field to the percent progress - fix: Refreshing 2 times the array todos.. because there is a filter
This commit is contained in:
@@ -9,7 +9,7 @@ async function sendRequest(url: string, lang: string, mytok: string, method: str
|
||||
authHeader.append('Accept', 'application/json')
|
||||
if (url !== process.env.MONGODB_HOST + '/users/login') {
|
||||
authHeader.append('x-auth', mytok)
|
||||
console.log('TOK PASSATO ALLA FETCH:', mytok)
|
||||
// console.log('TOK PASSATO ALLA FETCH:', mytok)
|
||||
}
|
||||
// authHeader.append('accept-language', lang)
|
||||
|
||||
|
||||
@@ -55,11 +55,11 @@ export namespace ApiTool {
|
||||
|
||||
return sendRequest(url, UserStore.state.lang, UserStore.state.x_auth_token, method, mydata)
|
||||
.then(resreceived => {
|
||||
console.log('resreceived', resreceived)
|
||||
// console.log('resreceived', resreceived)
|
||||
ricevuto = true
|
||||
let res = resreceived.clone()
|
||||
if (process.env.DEV) {
|
||||
console.log('SendReq RES [', res.status, ']', res)
|
||||
// console.log('SendReq RES [', res.status, ']', res)
|
||||
}
|
||||
|
||||
UserStore.mutations.setResStatus(res.status)
|
||||
@@ -143,66 +143,73 @@ export namespace ApiTool {
|
||||
// let lang = multiparams[3]
|
||||
|
||||
if (cmd === 'sync-todos') {
|
||||
console.log('[Alternative] Syncing', cmd, table, method)
|
||||
// console.log('[Alternative] Syncing', cmd, table, method)
|
||||
|
||||
const headers = new Headers()
|
||||
headers.append('content-Type', 'application/json')
|
||||
headers.append('Accept', 'application/json')
|
||||
headers.append('x-auth', token)
|
||||
|
||||
let errorfromserver = false
|
||||
let lettoqualcosa = false
|
||||
|
||||
// console.log('A1) INIZIO.............................................................')
|
||||
await globalroutines(null, 'readall', table, null)
|
||||
globalroutines(null, 'readall', table, null)
|
||||
.then(function (alldata) {
|
||||
const myrecs = [...alldata]
|
||||
// console.log('----------------------- LEGGO QUALCOSA ')
|
||||
if (myrecs) {
|
||||
for (let rec of myrecs) {
|
||||
// console.log('syncing', table, '', rec.descr)
|
||||
let link = process.env.MONGODB_HOST + '/todos'
|
||||
const myrecs = [...alldata]
|
||||
// console.log('----------------------- LEGGO QUALCOSA ')
|
||||
|
||||
if (method !== 'POST')
|
||||
link += '/' + rec._id
|
||||
const promises = myrecs.map(rec => {
|
||||
// console.log('syncing', table, '', rec.descr)
|
||||
let link = process.env.MONGODB_HOST + '/todos'
|
||||
|
||||
console.log(' [Alternative] ++++++++++++++++++ SYNCING !!!! ', rec.descr, table, 'FETCH: ', method, link, 'data:')
|
||||
if (method !== 'POST')
|
||||
link += '/' + rec._id
|
||||
|
||||
let lettoqualcosa = false
|
||||
// console.log(' [Alternative] ++++++++++++++++++ SYNCING !!!! ', rec.descr, table, 'FETCH: ', method, link, 'data:')
|
||||
|
||||
// Insert/Delete/Update table to the server
|
||||
fetch(link, {
|
||||
method: method,
|
||||
headers: headers,
|
||||
cache: 'no-cache',
|
||||
mode: 'cors', // 'no-cors',
|
||||
body: JSON.stringify(rec)
|
||||
}).then(resData => {
|
||||
lettoqualcosa = true
|
||||
// Insert/Delete/Update table to the server
|
||||
return fetch(link, {
|
||||
method: method,
|
||||
headers: headers,
|
||||
cache: 'no-cache',
|
||||
mode: 'cors', // 'no-cors',
|
||||
body: JSON.stringify(rec)
|
||||
})
|
||||
.then(() => {
|
||||
globalroutines(null, 'delete', table, null, rec._id)
|
||||
lettoqualcosa = true
|
||||
})
|
||||
.then(() => {
|
||||
globalroutines(null, 'delete', 'swmsg', null, mystrparam)
|
||||
})
|
||||
.catch(function (err) {
|
||||
if (err.message === 'Failed to fetch') {
|
||||
errorfromserver = true
|
||||
}
|
||||
// console.log(' [Alternative] !!!!!!!!!!!!!!! Error while sending data', err, errorfromserver, 'lettoqualcosa', lettoqualcosa)
|
||||
})
|
||||
})
|
||||
|
||||
return globalroutines(null, 'delete', 'swmsg', null, mystrparam)
|
||||
}).then(() => globalroutines(null, 'delete', table, null, rec._id))
|
||||
.then((ris) => {
|
||||
return globalroutines(null, 'write', 'config', { _id: 2, stateconn: 'online' })
|
||||
})
|
||||
.then(() => {
|
||||
// console.log('Clear', 'swmsg', method)
|
||||
GlobalStore.mutations.setStateConnection(lettoqualcosa ? 'online' : 'offline')
|
||||
})
|
||||
.catch(function (err) {
|
||||
if (err.message === 'Failed to fetch') {
|
||||
// console.log('config WRITE OFFLINE')
|
||||
globalroutines(null, 'write', 'config', { _id: 2, stateconn: 'offline' })
|
||||
}
|
||||
console.log(' [Alternative] !!!!!!!!!!!!!!! Error while sending data', err)
|
||||
GlobalStore.mutations.setStateConnection(lettoqualcosa ? 'online' : 'offline')
|
||||
})
|
||||
// CALL ALL THE PROMISES
|
||||
return Promise.all(promises).then(() => {
|
||||
return (errorfromserver && !lettoqualcosa)
|
||||
}).catch(err => {
|
||||
return (errorfromserver && !lettoqualcosa)
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
).catch(e => {
|
||||
console.log('ERROR:', e)
|
||||
}).catch(e => {
|
||||
// console.log('ERROR:', e)
|
||||
return (errorfromserver && !lettoqualcosa)
|
||||
})
|
||||
.then((errorfromserver) => {
|
||||
// console.log('¨¨¨¨¨¨¨¨¨¨¨¨¨¨ errorfromserver:', errorfromserver)
|
||||
const mystate = errorfromserver ? 'offline' : 'online'
|
||||
globalroutines(null, 'write', 'config', { _id: 2, stateconn: mystate })
|
||||
GlobalStore.mutations.setStateConnection(mystate)
|
||||
})
|
||||
|
||||
console.log(' [Alternative] A2) ?????????????????????????? ESCO DAL LOOP !!!!!!!!! err=')
|
||||
// console.log(' [Alternative] A2) ?????????????????????????? ESCO DAL LOOP !!!!!!!!!')
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace Actions {
|
||||
mystate.isSubscribed = !(subscription === null)
|
||||
|
||||
if (mystate.isSubscribed) {
|
||||
console.log('User is already Subscribed!')
|
||||
// console.log('User is already Subscribed!')
|
||||
} else {
|
||||
// Create a new subscription
|
||||
let convertedVapidPublicKey = urlBase64ToUint8Array(mykey)
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Mutations {
|
||||
function setTodos_changed(state: ITodosState) {
|
||||
state.todos_changed++
|
||||
mutations.setTestpao('Cambiato : ' + String(state.todos_changed))
|
||||
console.log('******************************* state.todos_changed', state.todos_changed)
|
||||
console.log('******* state.todos_changed', state.todos_changed)
|
||||
}
|
||||
|
||||
export const mutations = {
|
||||
@@ -195,16 +195,16 @@ namespace Actions {
|
||||
state.networkDataReceived = false
|
||||
|
||||
let ris = await Api.SendReq(call, 'GET', null)
|
||||
.then(({ resData, body, status }) => {
|
||||
.then(({ res, body, status }) => {
|
||||
state.networkDataReceived = true
|
||||
|
||||
// console.log('******* UPDATE TODOS.STATE.TODOS !:', resData.todos)
|
||||
// console.log('******* UPDATE TODOS.STATE.TODOS !:', res.todos)
|
||||
if (body.todos) {
|
||||
state.todos = [...body.todos]
|
||||
Todos.mutations.setTodos_changed()
|
||||
}
|
||||
|
||||
console.log('********** resData', resData, 'state.todos', state.todos, 'checkPending', checkPending)
|
||||
console.log('********** res', res, 'state.todos', state.todos, 'checkPending', checkPending)
|
||||
|
||||
// After Login will store into the indexedDb...
|
||||
|
||||
@@ -216,8 +216,8 @@ namespace Actions {
|
||||
return { status }
|
||||
})
|
||||
|
||||
console.log('ris : ', ris)
|
||||
console.log('ris STATUS: ', ris.status)
|
||||
// console.log('ris : ', ris)
|
||||
// console.log('ris STATUS: ', ris.status)
|
||||
|
||||
if (!Todos.state.networkDataReceived) {
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace Mutations {
|
||||
if (!state.tokens) {
|
||||
state.tokens = []
|
||||
}
|
||||
state.tokens.push({ access: 'auth ' + navigator.userAgent, token: data.x_auth_token, data_login: new Date() })
|
||||
state.tokens.push({ access: 'auth ' + navigator.userAgent, token: data.x_auth_token, data_login: new Date() })
|
||||
}
|
||||
|
||||
function setServerCode(state: IUserState, num: number) {
|
||||
@@ -227,7 +227,7 @@ namespace Actions {
|
||||
})
|
||||
.catch((error) => {
|
||||
UserStore.mutations.setErrorCatch(error)
|
||||
return UserStore.getters.getServerCode
|
||||
return { code: UserStore.getters.getServerCode, msg: error }
|
||||
})
|
||||
|
||||
}
|
||||
@@ -366,7 +366,7 @@ namespace Actions {
|
||||
|
||||
console.log('MYLANG = ' + state.lang)
|
||||
|
||||
await navigator.serviceWorker.ready
|
||||
return await navigator.serviceWorker.ready
|
||||
.then(function (swreg) {
|
||||
const sub = swreg.pushManager.getSubscription()
|
||||
return sub
|
||||
@@ -408,7 +408,26 @@ namespace Actions {
|
||||
|
||||
Mutations.mutations.setServerCode(myres.status)
|
||||
|
||||
if (myres.status === 200) {
|
||||
if (myres.status !== 200) {
|
||||
return Promise.reject(rescodes.ERR_GENERICO)
|
||||
}
|
||||
return { res, body }
|
||||
|
||||
}).then(({ res, body }) => {
|
||||
|
||||
if (myres.status === serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN) {
|
||||
if (process.env.DEV) {
|
||||
console.log('CODE = ' + body.code)
|
||||
}
|
||||
return body.code
|
||||
} else if (res.status !== 200) {
|
||||
if (process.env.DEV) {
|
||||
console.log('CODE = ' + body.code)
|
||||
}
|
||||
return body.code
|
||||
}
|
||||
|
||||
if (res.status === 200) {
|
||||
let myuser: IUserState = body.usertosend
|
||||
if (myuser) {
|
||||
let userId = myuser.userId
|
||||
@@ -436,24 +455,19 @@ namespace Actions {
|
||||
localStorage.setItem(rescodes.localStorage.isLogged, String(true))
|
||||
localStorage.setItem(rescodes.localStorage.verified_email, String(verified_email))
|
||||
|
||||
setGlobal(true)
|
||||
}
|
||||
}
|
||||
|
||||
// dispatch('storeUser', authData);
|
||||
// dispatch('setLogoutTimer', myres.data.expiresIn);
|
||||
return rescodes.OK
|
||||
} else {
|
||||
return rescodes.ERR_GENERICO
|
||||
}
|
||||
} else if (myres.status === serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN) {
|
||||
if (process.env.DEV) {
|
||||
console.log('CODE = ' + body.code)
|
||||
}
|
||||
return body.code
|
||||
return rescodes.OK
|
||||
|
||||
}).then(code => {
|
||||
if (code === rescodes.OK) {
|
||||
return setGlobal(true)
|
||||
.then(() => {
|
||||
return code
|
||||
})
|
||||
} else {
|
||||
if (process.env.DEV) {
|
||||
console.log('CODE = ' + body.code)
|
||||
}
|
||||
return body.code
|
||||
return code
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -507,7 +521,6 @@ namespace Actions {
|
||||
GlobalStore.mutations.setCategorySel(localStorage.getItem(rescodes.localStorage.categorySel))
|
||||
|
||||
|
||||
|
||||
await GlobalStore.actions.loadAfterLogin()
|
||||
.then(() => {
|
||||
Todos.actions.dbLoadTodo(true)
|
||||
|
||||
Reference in New Issue
Block a user