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:
@@ -19,22 +19,35 @@ import * as Types from "@src/store/Api/ApiTypes"
|
||||
// const algoliaApi = new AlgoliaSearch()
|
||||
export namespace ApiTool {
|
||||
export async function post(path: string, payload?: any) {
|
||||
GlobalStore.state.connData.downloading_server = 1
|
||||
GlobalStore.state.connData.uploading_server = 1
|
||||
return await Request('post', path, payload)
|
||||
}
|
||||
|
||||
export async function postFormData(path: string, payload?: any) {
|
||||
GlobalStore.state.connData.uploading_server = 1
|
||||
GlobalStore.state.connData.downloading_server = 1
|
||||
return await Request('postFormData', path, payload)
|
||||
}
|
||||
|
||||
export async function get(path: string, payload?: any) {
|
||||
GlobalStore.state.connData.downloading_server = 1
|
||||
GlobalStore.state.connData.uploading_server = 0
|
||||
return await Request('get', path, payload)
|
||||
}
|
||||
|
||||
export async function put(path: string, payload?: any) {
|
||||
GlobalStore.state.connData.uploading_server = 1
|
||||
return await Request('put', path, payload)
|
||||
}
|
||||
|
||||
export async function patch(path: string, payload?: any) {
|
||||
GlobalStore.state.connData.uploading_server = 1
|
||||
return await Request('patch', path, payload)
|
||||
}
|
||||
|
||||
export async function Delete(path: string, payload: any) {
|
||||
GlobalStore.state.connData.uploading_server = 1
|
||||
return await Request('delete', path, payload)
|
||||
}
|
||||
|
||||
@@ -53,10 +66,21 @@ export namespace ApiTool {
|
||||
UserStore.mutations.setResStatus(0)
|
||||
return await new Promise(function (resolve, reject) {
|
||||
|
||||
|
||||
return sendRequest(url, method, mydata)
|
||||
.then(res => {
|
||||
// console.log('res', res)
|
||||
|
||||
setTimeout(function () {
|
||||
if (method === 'get')
|
||||
GlobalStore.state.connData.downloading_server = 0
|
||||
else {
|
||||
GlobalStore.state.connData.uploading_server = 0
|
||||
GlobalStore.state.connData.downloading_server = 0
|
||||
}
|
||||
}, 1000)
|
||||
|
||||
|
||||
UserStore.mutations.setResStatus(res.status)
|
||||
if (res.status === serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN) {
|
||||
// Forbidden
|
||||
@@ -71,6 +95,15 @@ export namespace ApiTool {
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
setTimeout(function () {
|
||||
if (method === 'get')
|
||||
GlobalStore.state.connData.downloading_server = -1
|
||||
else {
|
||||
GlobalStore.state.connData.uploading_server = -1
|
||||
GlobalStore.state.connData.downloading_server = -1
|
||||
}
|
||||
}, 1000)
|
||||
|
||||
console.log('error', error)
|
||||
return reject(error)
|
||||
})
|
||||
@@ -92,10 +125,10 @@ export namespace ApiTool {
|
||||
if (cmd === 'sync-todos') {
|
||||
// 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)
|
||||
// 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
|
||||
@@ -108,21 +141,23 @@ export namespace ApiTool {
|
||||
|
||||
const promises = myrecs.map(rec => {
|
||||
// console.log('syncing', table, '', rec.descr)
|
||||
let link = String(process.env.MONGODB_HOST) + '/todos'
|
||||
// let link = String(process.env.MONGODB_HOST) + '/todos'
|
||||
let link = '/todos'
|
||||
|
||||
if (method !== 'POST')
|
||||
link += '/' + rec._id
|
||||
|
||||
// console.log(' [Alternative] ++++++++++++++++++ SYNCING !!!! ', rec.descr, table, 'FETCH: ', method, link, 'data:')
|
||||
console.log(' [Alternative] ++++++++++++++++++ SYNCING !!!! ', rec.descr, table, 'FETCH: ', method, link, 'data:')
|
||||
|
||||
// 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)
|
||||
})
|
||||
return SendReq(link, method, rec)
|
||||
// return fetch(link, {
|
||||
// method: method,
|
||||
// headers: headers,
|
||||
// cache: 'no-cache',
|
||||
// mode: 'cors', // 'no-cors',
|
||||
// body: JSON.stringify(rec)
|
||||
// })
|
||||
.then(() => {
|
||||
lettoqualcosa = true
|
||||
return globalroutines(null, 'delete', table, null, rec._id)
|
||||
|
||||
Reference in New Issue
Block a user