- fix: Date problems... (it was a bad "copy" function, the object date was not valid...
- fix: error fetch on loading... (offline appeared)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
APP_VERSION="DEV 0.0.13"
|
APP_VERSION="DEV 0.0.17"
|
||||||
SERVICE_WORKER_FILE='service-worker.js'
|
SERVICE_WORKER_FILE='service-worker.js'
|
||||||
APP_ID='1'
|
APP_ID='1'
|
||||||
APP_URL='https://freeplanet.app'
|
APP_URL='https://freeplanet.app'
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
// Questo è il swSrc
|
// Questo è il swSrc
|
||||||
|
|
||||||
console.log(' [ VER-0.0.12 ] _---------________-----------_________------------__________________________ PAO: this is my custom service worker');
|
console.log(' [ VER-0.0.17 ] _---------________-----------_________------------__________________________ PAO: this is my custom service worker');
|
||||||
|
|
||||||
importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js'); //++Todo: Replace with local workbox.js
|
importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js'); //++Todo: Replace with local workbox.js
|
||||||
importScripts('../statics/js/idb.js');
|
importScripts('../statics/js/idb.js');
|
||||||
@@ -20,12 +20,6 @@ const cfgenv = {
|
|||||||
dbversion: 11,
|
dbversion: 11,
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log('SW-06 2');
|
|
||||||
|
|
||||||
// console.log('SERVERWEB=', cfgenv.serverweb)
|
|
||||||
|
|
||||||
// console.log('serverweb', cfgenv.serverweb)
|
|
||||||
|
|
||||||
async function writeData(table, data) {
|
async function writeData(table, data) {
|
||||||
// console.log('writeData', table, data);
|
// console.log('writeData', table, data);
|
||||||
await idbKeyval.setdata(table, data);
|
await idbKeyval.setdata(table, data);
|
||||||
@@ -108,30 +102,43 @@ if (workbox) {
|
|||||||
new RegExp(cfgenv.serverweb + '/todos/'),
|
new RegExp(cfgenv.serverweb + '/todos/'),
|
||||||
function (args) {
|
function (args) {
|
||||||
// console.log('registerRoute!')
|
// console.log('registerRoute!')
|
||||||
|
// console.log('DATABODY:', args.event.request.body)
|
||||||
|
let myres = null
|
||||||
return fetch(args.event.request, args.event.headers)
|
return fetch(args.event.request, args.event.headers)
|
||||||
.then(function (res) {
|
.then(function (res) {
|
||||||
console.log('1° ******* [[[ SERVICE-WORKER ]]] registerRoute fetch: -> ', args.event.headers)
|
myres = res
|
||||||
|
console.log('1° ******* [[[ SERVICE-WORKER ]]] registerRoute fetch: -> ', args.event.request, res)
|
||||||
// LOAD FROM SERVER , AND SAVE INTO INDEXEDDB
|
// LOAD FROM SERVER , AND SAVE INTO INDEXEDDB
|
||||||
console.log('res.status', res.status)
|
console.log('res.status', res.status)
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
const clonedRes = res.clone();
|
const clonedRes = res.clone();
|
||||||
return clearAllData('todos')
|
clearAllData('todos')
|
||||||
.then(function () {
|
return clonedRes
|
||||||
return clonedRes.json();
|
}
|
||||||
})
|
})
|
||||||
.then(function (data) {
|
.then((clonedRes) => {
|
||||||
|
if (clonedRes !== null)
|
||||||
|
return clonedRes.json();
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
if (data) {
|
||||||
if (data.todos) {
|
if (data.todos) {
|
||||||
console.log('Records TODOS Received from Server [', data.todos.length, 'record]', data.todos)
|
console.log('Records TODOS Received from Server [', data.todos.length, 'record]', data.todos)
|
||||||
for (let key in data.todos) {
|
for (let key in data.todos) {
|
||||||
writeData('todos', data.todos[key])
|
writeData('todos', data.todos[key])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return res
|
|
||||||
})
|
})
|
||||||
}
|
.then(() => {
|
||||||
);
|
return myres
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log('ERROR registerRoute FETCH:', err)
|
||||||
|
return myres
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
workbox.routing.registerRoute(
|
workbox.routing.registerRoute(
|
||||||
@@ -199,18 +206,18 @@ if (workbox) {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// workbox.routing.registerRoute(
|
// workbox.routing.registerRoute(
|
||||||
// new RegExp(/^http/),
|
// new RegExp(/^http/),
|
||||||
// workbox.strategies.networkFirst({
|
// workbox.strategies.networkFirst({
|
||||||
// cacheName: 'all-stuff',
|
// cacheName: 'all-stuff',
|
||||||
// plugins: [
|
// plugins: [
|
||||||
// new workbox.expiration.Plugin({
|
// new workbox.expiration.Plugin({
|
||||||
// maxAgeSeconds: 10 * 24 * 60 * 60,
|
// maxAgeSeconds: 10 * 24 * 60 * 60,
|
||||||
// // Only cache 10 requests.
|
// // Only cache 10 requests.
|
||||||
// }),
|
// }),
|
||||||
// ]
|
// ]
|
||||||
// })
|
// })
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
|
||||||
workbox.routing.registerRoute(
|
workbox.routing.registerRoute(
|
||||||
@@ -227,13 +234,23 @@ if ('serviceWorker' in navigator) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.addEventListener('fetch', (event) => {
|
self.addEventListener('fetch', function (event) {
|
||||||
if (event.request.url === '/') {
|
event.respondWith(
|
||||||
const staleWhileRevalidate = new workbox.strategies.StaleWhileRevalidate();
|
fetch(event.request, event.headers)
|
||||||
event.respondWith(staleWhileRevalidate.handle({ event }));
|
.catch(err => {
|
||||||
}
|
console.log('_______________________ ERRORE FETCH SW: ', event.request, err)
|
||||||
|
return caches.match(event.request);
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// self.addEventListener('fetch', (event) => {
|
||||||
|
// if (event.request.url === '/') {
|
||||||
|
// const staleWhileRevalidate = new workbox.strategies.StaleWhileRevalidate();
|
||||||
|
// event.respondWith(staleWhileRevalidate.handle({ event }));
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
// self.addEventListener('fetch', function (event) {
|
// self.addEventListener('fetch', function (event) {
|
||||||
// console.log('[Service Worker] Fetching something ....', event);
|
// console.log('[Service Worker] Fetching something ....', event);
|
||||||
// console.log('event.request.cache=', event.request.cache)
|
// console.log('event.request.cache=', event.request.cache)
|
||||||
@@ -295,6 +312,8 @@ self.addEventListener('sync', function (event) {
|
|||||||
|
|
||||||
console.log('++++++++++++++++++ SYNCING !!!! ', rec.descr, table, 'FETCH: ', method, link, 'data:')
|
console.log('++++++++++++++++++ SYNCING !!!! ', rec.descr, table, 'FETCH: ', method, link, 'data:')
|
||||||
|
|
||||||
|
console.log('DATATOSAVE:', JSON.stringify(rec))
|
||||||
|
|
||||||
// Insert/Delete/Update table to the server
|
// Insert/Delete/Update table to the server
|
||||||
fetch(link, {
|
fetch(link, {
|
||||||
method: method,
|
method: method,
|
||||||
@@ -302,14 +321,15 @@ self.addEventListener('sync', function (event) {
|
|||||||
mode: 'cors', // 'no-cors',
|
mode: 'cors', // 'no-cors',
|
||||||
body: JSON.stringify(rec)
|
body: JSON.stringify(rec)
|
||||||
})
|
})
|
||||||
.then(resData => deleteItemFromData(table, rec._id))
|
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('DELETE: ', mystrparam)
|
console.log('DELETE SWMSG: ', mystrparam)
|
||||||
deleteItemFromData('swmsg', mystrparam)
|
deleteItemFromData('swmsg', mystrparam)
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
|
console.log('DELETE : ', table, mystrparam)
|
||||||
|
deleteItemFromData(table, rec._id)
|
||||||
console.log('!!!!!!!!!!!!!!! Error while sending data', err);
|
console.log('!!!!!!!!!!!!!!! Error while sending data', err);
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -69,6 +69,11 @@ export default class SingleTodo extends Vue {
|
|||||||
this.updateClasses()
|
this.updateClasses()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dateToYYYYMMDD(date) {
|
||||||
|
// may have timezone caveats https://stackoverflow.com/a/29774197/1850609
|
||||||
|
return date && date.toISOString().split('T')[0]
|
||||||
|
}
|
||||||
|
|
||||||
isTodo() {
|
isTodo() {
|
||||||
return this.isTodoByElem(this.itemtodo)
|
return this.isTodoByElem(this.itemtodo)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,9 +49,13 @@
|
|||||||
<div v-if="itemtodo.enableExpiring">
|
<div v-if="itemtodo.enableExpiring">
|
||||||
<div :class="classExpiring">
|
<div :class="classExpiring">
|
||||||
<q-datetime
|
<q-datetime
|
||||||
|
type="date"
|
||||||
:class="classExpiringEx"
|
:class="classExpiringEx"
|
||||||
v-model="itemtodo.expiring_at"
|
v-model="itemtodo.expiring_at"
|
||||||
class="myexpired">
|
class="myexpired"
|
||||||
|
format="DD/MM/YY"
|
||||||
|
@change="val => { model = val }" >
|
||||||
|
|
||||||
</q-datetime>
|
</q-datetime>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -350,24 +350,11 @@ export default class Todo extends Vue {
|
|||||||
}, 10000)
|
}, 10000)
|
||||||
}
|
}
|
||||||
|
|
||||||
copy(o) {
|
|
||||||
let output, v, key
|
|
||||||
output = Array.isArray(o) ? [] : {}
|
|
||||||
for (key in o) {
|
|
||||||
v = o[key]
|
|
||||||
output[key] = (typeof v === 'object') ? this.copy(v) : v
|
|
||||||
}
|
|
||||||
return output
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
initcat() {
|
initcat() {
|
||||||
|
|
||||||
|
var tomorrow = new Date();
|
||||||
|
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||||
|
|
||||||
let mydatenow = new Date().getDate()
|
|
||||||
let mydateexp = new Date().getDate() + 10
|
|
||||||
|
|
||||||
// console.log('User:' + UserStore.state.userId)
|
|
||||||
|
|
||||||
const objtodo: ITodo = {
|
const objtodo: ITodo = {
|
||||||
// _id: new Date().toISOString(), // Create NEW
|
// _id: new Date().toISOString(), // Create NEW
|
||||||
@@ -376,11 +363,11 @@ export default class Todo extends Vue {
|
|||||||
descr: '',
|
descr: '',
|
||||||
priority: rescodes.Todos.PRIORITY_NORMAL,
|
priority: rescodes.Todos.PRIORITY_NORMAL,
|
||||||
completed: false,
|
completed: false,
|
||||||
created_at: mydatenow,
|
created_at: new Date(),
|
||||||
modify_at: mydatenow,
|
modify_at: new Date(),
|
||||||
completed_at: 0,
|
completed_at: new Date(),
|
||||||
category: '',
|
category: '',
|
||||||
expiring_at: mydateexp,
|
expiring_at: tomorrow,
|
||||||
enableExpiring: false,
|
enableExpiring: false,
|
||||||
id_prev: '',
|
id_prev: '',
|
||||||
id_next: '',
|
id_next: '',
|
||||||
@@ -388,7 +375,8 @@ export default class Todo extends Vue {
|
|||||||
modified: false,
|
modified: false,
|
||||||
progress: 0
|
progress: 0
|
||||||
}
|
}
|
||||||
return this.copy(objtodo)
|
// return this.copy(objtodo)
|
||||||
|
return objtodo
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -417,8 +405,6 @@ export default class Todo extends Vue {
|
|||||||
|
|
||||||
const objtodo = this.initcat()
|
const objtodo = this.initcat()
|
||||||
|
|
||||||
console.log('insertTodo ', UserStore.state.userId)
|
|
||||||
|
|
||||||
objtodo.descr = this.todo
|
objtodo.descr = this.todo
|
||||||
objtodo.category = this.getCategory()
|
objtodo.category = this.getCategory()
|
||||||
const lastelem: ITodo = this.getLastList()
|
const lastelem: ITodo = this.getLastList()
|
||||||
@@ -766,7 +752,7 @@ export default class Todo extends Vue {
|
|||||||
|
|
||||||
modifyField(recOut, recIn, field) {
|
modifyField(recOut, recIn, field) {
|
||||||
if (recOut[field] !== recIn[field]) {
|
if (recOut[field] !== recIn[field]) {
|
||||||
// console.log('*************** CAMPO ', field, 'MODIFICATO!', recOut[field], recIn[field])
|
// console.log('*************** CAMPO ', field, 'MODIFICATO!', recOut[field])
|
||||||
recOut.modified = true
|
recOut.modified = true
|
||||||
recOut[field] = recIn[field]
|
recOut[field] = recIn[field]
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
export let idbKeyval = (() => {
|
export let idbKeyval = (() => {
|
||||||
let db;
|
let db;
|
||||||
|
const fieldsData = ['completed_at', 'created_at', 'expiring_at', 'modify_at']
|
||||||
|
|
||||||
function getDB() {
|
function getDB() {
|
||||||
if (!db) {
|
if (!db) {
|
||||||
@@ -29,7 +30,7 @@ export let idbKeyval = (() => {
|
|||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function withStore(type, table, callback, ) {
|
async function withStore(type, table, callback,) {
|
||||||
const db = await getDB();
|
const db = await getDB();
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const transaction = db.transaction(table, type);
|
const transaction = db.transaction(table, type);
|
||||||
@@ -47,14 +48,18 @@ export let idbKeyval = (() => {
|
|||||||
});
|
});
|
||||||
return req.result;
|
return req.result;
|
||||||
},
|
},
|
||||||
|
jsonCopy(src) {
|
||||||
|
return JSON.parse(JSON.stringify(src));
|
||||||
|
},
|
||||||
|
|
||||||
async getdata(table, key) {
|
async getdata(table, key) {
|
||||||
let req;
|
let req;
|
||||||
|
|
||||||
await withStore('readonly', table, store => {
|
await withStore('readonly', table, store => {
|
||||||
console.log('store', store, 'key', key)
|
// console.log('store', store, 'key', key)
|
||||||
req = store.get(key);
|
req = store.get(key);
|
||||||
});
|
});
|
||||||
// console.log('RISFINALE!', req.result)
|
|
||||||
return req.result;
|
return req.result;
|
||||||
},
|
},
|
||||||
async getalldata(table) {
|
async getalldata(table) {
|
||||||
@@ -80,7 +85,6 @@ export let idbKeyval = (() => {
|
|||||||
},
|
},
|
||||||
async setdata(table, value) {
|
async setdata(table, value) {
|
||||||
let req;
|
let req;
|
||||||
// console.log('setdata', table, value)
|
|
||||||
|
|
||||||
await withStore('readwrite', table, store => {
|
await withStore('readwrite', table, store => {
|
||||||
req = store.put(value);
|
req = store.put(value);
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ export interface ITodo {
|
|||||||
descr?: string,
|
descr?: string,
|
||||||
priority: number,
|
priority: number,
|
||||||
completed: boolean,
|
completed: boolean,
|
||||||
created_at: any,
|
created_at: Date,
|
||||||
modify_at: any,
|
modify_at: Date,
|
||||||
completed_at: any,
|
completed_at: Date,
|
||||||
expiring_at: any,
|
expiring_at: Date,
|
||||||
enableExpiring?: boolean,
|
enableExpiring?: boolean,
|
||||||
id_prev?: string,
|
id_prev?: string,
|
||||||
id_next?: string,
|
id_next?: string,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export interface IToken {
|
export interface IToken {
|
||||||
access: string
|
access: string
|
||||||
token: string
|
token: string
|
||||||
|
data_login: Date
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -47,14 +47,28 @@ let idbKeyval = (() => {
|
|||||||
});
|
});
|
||||||
return req.result;
|
return req.result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// jsonCopy(src) {
|
||||||
|
// return JSON.parse(JSON.stringify(src));
|
||||||
|
// },
|
||||||
|
|
||||||
|
// contains(a, b) {
|
||||||
|
// // array matches
|
||||||
|
// if (Array.isArray(b)) {
|
||||||
|
// return b.some(x => a.indexOf(x) > -1);
|
||||||
|
// }
|
||||||
|
// // string match
|
||||||
|
// return a.indexOf(b) > -1;
|
||||||
|
// },
|
||||||
|
|
||||||
async getdata(table, key) {
|
async getdata(table, key) {
|
||||||
let req;
|
let req;
|
||||||
|
|
||||||
await withStore('readonly', table, store => {
|
await withStore('readonly', table, store => {
|
||||||
console.log('store', store, 'key', key)
|
// console.log('store', store, 'key', key)
|
||||||
req = store.get(key);
|
req = store.get(key);
|
||||||
});
|
});
|
||||||
// console.log('RISFINALE!', req.result)
|
|
||||||
return req.result;
|
return req.result;
|
||||||
},
|
},
|
||||||
async getalldata(table) {
|
async getalldata(table) {
|
||||||
@@ -73,7 +87,7 @@ let idbKeyval = (() => {
|
|||||||
},
|
},
|
||||||
async setdata(table, value) {
|
async setdata(table, value) {
|
||||||
let req;
|
let req;
|
||||||
console.log('setdata', table, value)
|
// console.log('setdata', table, value)
|
||||||
|
|
||||||
await withStore('readwrite', table, store => {
|
await withStore('readwrite', table, store => {
|
||||||
req = store.put(value);
|
req = store.put(value);
|
||||||
|
|||||||
@@ -31,9 +31,12 @@ async function sendRequest(url: string, lang: string, mytok: string, method: str
|
|||||||
method: method,
|
method: method,
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
body: JSON.stringify(mydata),
|
|
||||||
headers: authHeader
|
headers: authHeader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mydata !== null)
|
||||||
|
configInit.body = JSON.stringify(mydata)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const request: Promise<Response> = fetch(url, configInit)
|
const request: Promise<Response> = fetch(url, configInit)
|
||||||
|
|||||||
@@ -107,8 +107,10 @@ export namespace ApiTool {
|
|||||||
return resolve({ res, body })
|
return resolve({ res, body })
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
UserStore.mutations.setServerCode(rescodes.ERR_GENERICO)
|
return resolve({ res, body: {} })
|
||||||
return reject({ code: rescodes.ERR_GENERICO, status: res.status })
|
// Array not found...
|
||||||
|
// UserStore.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||||
|
// return reject({ code: rescodes.ERR_GENERICO, status: res.status })
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -278,6 +278,8 @@ namespace Actions {
|
|||||||
|
|
||||||
const token = UserStore.state.idToken
|
const token = UserStore.state.idToken
|
||||||
|
|
||||||
|
console.log('TODO TO SAVE: ', itemtodo)
|
||||||
|
|
||||||
let res = await Api.SendReq(call, UserStore.state.lang, token, method, itemtodo)
|
let res = await Api.SendReq(call, UserStore.state.lang, token, method, itemtodo)
|
||||||
.then(({ res, newItem }) => {
|
.then(({ res, newItem }) => {
|
||||||
console.log('dbInsertSaveTodo RIS =', newItem)
|
console.log('dbInsertSaveTodo RIS =', newItem)
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ namespace Mutations {
|
|||||||
state.category = data.categorySel
|
state.category = data.categorySel
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
state.tokens = [
|
state.tokens = [
|
||||||
{ access: 'auth', token: data.idToken }
|
{ access: 'auth ' + navigator.userAgent, token: data.idToken, date_login: new Date() }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ namespace Mutations {
|
|||||||
if (!state.tokens) {
|
if (!state.tokens) {
|
||||||
state.tokens = []
|
state.tokens = []
|
||||||
}
|
}
|
||||||
state.tokens.push({ access: 'auth', token: data.idToken })
|
state.tokens.push({ access: 'auth ' + navigator.userAgent, token: data.idToken, data_login: new Date() })
|
||||||
}
|
}
|
||||||
|
|
||||||
function setServerCode(state: IUserState, num: number) {
|
function setServerCode(state: IUserState, num: number) {
|
||||||
@@ -143,6 +143,7 @@ namespace Mutations {
|
|||||||
if (state.servercode !== rescodes.ERR_SERVERFETCH) {
|
if (state.servercode !== rescodes.ERR_SERVERFETCH) {
|
||||||
state.servercode = err
|
state.servercode = err
|
||||||
}
|
}
|
||||||
|
console.log('Err catch: (servercode:', err, ')')
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMsgError(state: IUserState, err: number) {
|
function getMsgError(state: IUserState, err: number) {
|
||||||
|
|||||||
Reference in New Issue
Block a user