diff --git a/.env.development b/.env.development
index ad2fa59..c1e8448 100644
--- a/.env.development
+++ b/.env.development
@@ -1,4 +1,4 @@
-APP_VERSION="DEV 0.0.13"
+APP_VERSION="DEV 0.0.17"
SERVICE_WORKER_FILE='service-worker.js'
APP_ID='1'
APP_URL='https://freeplanet.app'
diff --git a/src-pwa/custom-service-worker.js b/src-pwa/custom-service-worker.js
index 4118dca..b296be7 100644
--- a/src-pwa/custom-service-worker.js
+++ b/src-pwa/custom-service-worker.js
@@ -6,7 +6,7 @@
// 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('../statics/js/idb.js');
@@ -20,12 +20,6 @@ const cfgenv = {
dbversion: 11,
}
-// console.log('SW-06 2');
-
-// console.log('SERVERWEB=', cfgenv.serverweb)
-
-// console.log('serverweb', cfgenv.serverweb)
-
async function writeData(table, data) {
// console.log('writeData', table, data);
await idbKeyval.setdata(table, data);
@@ -108,30 +102,43 @@ if (workbox) {
new RegExp(cfgenv.serverweb + '/todos/'),
function (args) {
// console.log('registerRoute!')
+ // console.log('DATABODY:', args.event.request.body)
+ let myres = null
return fetch(args.event.request, args.event.headers)
.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
console.log('res.status', res.status)
if (res.status === 200) {
const clonedRes = res.clone();
- return clearAllData('todos')
- .then(function () {
- return clonedRes.json();
- })
- .then(function (data) {
- if (data.todos) {
- console.log('Records TODOS Received from Server [', data.todos.length, 'record]', data.todos)
- for (let key in data.todos) {
- writeData('todos', data.todos[key])
- }
- }
- });
+ clearAllData('todos')
+ return clonedRes
}
- return res
})
- }
- );
+ .then((clonedRes) => {
+ if (clonedRes !== null)
+ return clonedRes.json();
+ return null
+ })
+ .then(data => {
+ if (data) {
+ if (data.todos) {
+ console.log('Records TODOS Received from Server [', data.todos.length, 'record]', data.todos)
+ for (let key in data.todos) {
+ writeData('todos', data.todos[key])
+ }
+ }
+ }
+ })
+ .then(() => {
+ return myres
+ })
+ .catch(err => {
+ console.log('ERROR registerRoute FETCH:', err)
+ return myres
+ })
+ })
workbox.routing.registerRoute(
@@ -199,18 +206,18 @@ if (workbox) {
})
);
- // workbox.routing.registerRoute(
- // new RegExp(/^http/),
- // workbox.strategies.networkFirst({
- // cacheName: 'all-stuff',
- // plugins: [
- // new workbox.expiration.Plugin({
- // maxAgeSeconds: 10 * 24 * 60 * 60,
- // // Only cache 10 requests.
- // }),
- // ]
- // })
- // );
+// workbox.routing.registerRoute(
+// new RegExp(/^http/),
+// workbox.strategies.networkFirst({
+// cacheName: 'all-stuff',
+// plugins: [
+// new workbox.expiration.Plugin({
+// maxAgeSeconds: 10 * 24 * 60 * 60,
+// // Only cache 10 requests.
+// }),
+// ]
+// })
+// );
workbox.routing.registerRoute(
@@ -227,13 +234,23 @@ if ('serviceWorker' in navigator) {
}
-self.addEventListener('fetch', (event) => {
- if (event.request.url === '/') {
- const staleWhileRevalidate = new workbox.strategies.StaleWhileRevalidate();
- event.respondWith(staleWhileRevalidate.handle({ event }));
- }
+self.addEventListener('fetch', function (event) {
+ event.respondWith(
+ fetch(event.request, event.headers)
+ .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) {
// console.log('[Service Worker] Fetching something ....', event);
// 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('DATATOSAVE:', JSON.stringify(rec))
+
// Insert/Delete/Update table to the server
fetch(link, {
method: method,
@@ -302,14 +321,15 @@ self.addEventListener('sync', function (event) {
mode: 'cors', // 'no-cors',
body: JSON.stringify(rec)
})
- .then(resData => deleteItemFromData(table, rec._id))
.then(() => {
- console.log('DELETE: ', mystrparam)
+ console.log('DELETE SWMSG: ', mystrparam)
deleteItemFromData('swmsg', mystrparam)
})
.catch(function (err) {
+ console.log('DELETE : ', table, mystrparam)
+ deleteItemFromData(table, rec._id)
console.log('!!!!!!!!!!!!!!! Error while sending data', err);
- });
+ })
}
}
})
diff --git a/src/components/todos/SingleTodo/SingleTodo.ts b/src/components/todos/SingleTodo/SingleTodo.ts
index 84d6b48..8d7ead8 100644
--- a/src/components/todos/SingleTodo/SingleTodo.ts
+++ b/src/components/todos/SingleTodo/SingleTodo.ts
@@ -69,6 +69,11 @@ export default class SingleTodo extends Vue {
this.updateClasses()
}
+ dateToYYYYMMDD(date) {
+ // may have timezone caveats https://stackoverflow.com/a/29774197/1850609
+ return date && date.toISOString().split('T')[0]
+ }
+
isTodo() {
return this.isTodoByElem(this.itemtodo)
}
diff --git a/src/components/todos/SingleTodo/SingleTodo.vue b/src/components/todos/SingleTodo/SingleTodo.vue
index 1c33fb7..8be08c9 100644
--- a/src/components/todos/SingleTodo/SingleTodo.vue
+++ b/src/components/todos/SingleTodo/SingleTodo.vue
@@ -49,9 +49,13 @@
+ class="myexpired"
+ format="DD/MM/YY"
+ @change="val => { model = val }" >
+
diff --git a/src/components/todos/todo/todo.ts b/src/components/todos/todo/todo.ts
index 0f09fe7..8d7b184 100644
--- a/src/components/todos/todo/todo.ts
+++ b/src/components/todos/todo/todo.ts
@@ -350,24 +350,11 @@ export default class Todo extends Vue {
}, 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() {
+ 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 = {
// _id: new Date().toISOString(), // Create NEW
@@ -376,11 +363,11 @@ export default class Todo extends Vue {
descr: '',
priority: rescodes.Todos.PRIORITY_NORMAL,
completed: false,
- created_at: mydatenow,
- modify_at: mydatenow,
- completed_at: 0,
+ created_at: new Date(),
+ modify_at: new Date(),
+ completed_at: new Date(),
category: '',
- expiring_at: mydateexp,
+ expiring_at: tomorrow,
enableExpiring: false,
id_prev: '',
id_next: '',
@@ -388,7 +375,8 @@ export default class Todo extends Vue {
modified: false,
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()
- console.log('insertTodo ', UserStore.state.userId)
-
objtodo.descr = this.todo
objtodo.category = this.getCategory()
const lastelem: ITodo = this.getLastList()
@@ -766,7 +752,7 @@ export default class Todo extends Vue {
modifyField(recOut, 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[field] = recIn[field]
return true
diff --git a/src/js/storage.js b/src/js/storage.js
index c27daf1..ead047a 100644
--- a/src/js/storage.js
+++ b/src/js/storage.js
@@ -1,5 +1,6 @@
export let idbKeyval = (() => {
let db;
+ const fieldsData = ['completed_at', 'created_at', 'expiring_at', 'modify_at']
function getDB() {
if (!db) {
@@ -29,7 +30,7 @@ export let idbKeyval = (() => {
return db;
}
- async function withStore(type, table, callback, ) {
+ async function withStore(type, table, callback,) {
const db = await getDB();
return new Promise((resolve, reject) => {
const transaction = db.transaction(table, type);
@@ -47,14 +48,18 @@ export let idbKeyval = (() => {
});
return req.result;
},
+ jsonCopy(src) {
+ return JSON.parse(JSON.stringify(src));
+ },
+
async getdata(table, key) {
let req;
await withStore('readonly', table, store => {
- console.log('store', store, 'key', key)
+ // console.log('store', store, 'key', key)
req = store.get(key);
});
- // console.log('RISFINALE!', req.result)
+
return req.result;
},
async getalldata(table) {
@@ -80,9 +85,8 @@ export let idbKeyval = (() => {
},
async setdata(table, value) {
let req;
- // console.log('setdata', table, value)
- await withStore('readwrite', table, store => {
+ await withStore('readwrite', table, store => {
req = store.put(value);
});
return req.result;
diff --git a/src/model/Todos.ts b/src/model/Todos.ts
index 0243a45..f62482b 100644
--- a/src/model/Todos.ts
+++ b/src/model/Todos.ts
@@ -5,10 +5,10 @@ export interface ITodo {
descr?: string,
priority: number,
completed: boolean,
- created_at: any,
- modify_at: any,
- completed_at: any,
- expiring_at: any,
+ created_at: Date,
+ modify_at: Date,
+ completed_at: Date,
+ expiring_at: Date,
enableExpiring?: boolean,
id_prev?: string,
id_next?: string,
diff --git a/src/model/other.ts b/src/model/other.ts
index e40635d..c7c5a3c 100644
--- a/src/model/other.ts
+++ b/src/model/other.ts
@@ -1,6 +1,7 @@
export interface IToken {
access: string
token: string
+ data_login: Date
}
diff --git a/src/statics/js/storage.js b/src/statics/js/storage.js
index c8b2316..505a0aa 100644
--- a/src/statics/js/storage.js
+++ b/src/statics/js/storage.js
@@ -47,14 +47,28 @@ let idbKeyval = (() => {
});
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) {
let req;
await withStore('readonly', table, store => {
- console.log('store', store, 'key', key)
+ // console.log('store', store, 'key', key)
req = store.get(key);
});
- // console.log('RISFINALE!', req.result)
+
return req.result;
},
async getalldata(table) {
@@ -73,7 +87,7 @@ let idbKeyval = (() => {
},
async setdata(table, value) {
let req;
- console.log('setdata', table, value)
+ // console.log('setdata', table, value)
await withStore('readwrite', table, store => {
req = store.put(value);
diff --git a/src/store/Api/Inst-Pao.ts b/src/store/Api/Inst-Pao.ts
index c66bebc..1fd4da2 100644
--- a/src/store/Api/Inst-Pao.ts
+++ b/src/store/Api/Inst-Pao.ts
@@ -31,9 +31,12 @@ async function sendRequest(url: string, lang: string, mytok: string, method: str
method: method,
cache: 'no-cache',
mode: 'cors',
- body: JSON.stringify(mydata),
headers: authHeader
}
+
+ if (mydata !== null)
+ configInit.body = JSON.stringify(mydata)
+
}
const request: Promise = fetch(url, configInit)
diff --git a/src/store/Api/index.ts b/src/store/Api/index.ts
index a0114d4..6c1f9fe 100644
--- a/src/store/Api/index.ts
+++ b/src/store/Api/index.ts
@@ -107,8 +107,10 @@ export namespace ApiTool {
return resolve({ res, body })
})
.catch(e => {
- UserStore.mutations.setServerCode(rescodes.ERR_GENERICO)
- return reject({ code: rescodes.ERR_GENERICO, status: res.status })
+ return resolve({ res, body: {} })
+ // Array not found...
+ // UserStore.mutations.setServerCode(rescodes.ERR_GENERICO)
+ // return reject({ code: rescodes.ERR_GENERICO, status: res.status })
})
})
diff --git a/src/store/Modules/Todos.ts b/src/store/Modules/Todos.ts
index d84f2b9..e15ed32 100644
--- a/src/store/Modules/Todos.ts
+++ b/src/store/Modules/Todos.ts
@@ -278,6 +278,8 @@ namespace Actions {
const token = UserStore.state.idToken
+ console.log('TODO TO SAVE: ', itemtodo)
+
let res = await Api.SendReq(call, UserStore.state.lang, token, method, itemtodo)
.then(({ res, newItem }) => {
console.log('dbInsertSaveTodo RIS =', newItem)
diff --git a/src/store/Modules/UserStore.ts b/src/store/Modules/UserStore.ts
index 4725410..892e6b6 100644
--- a/src/store/Modules/UserStore.ts
+++ b/src/store/Modules/UserStore.ts
@@ -92,7 +92,7 @@ namespace Mutations {
state.category = data.categorySel
// @ts-ignore
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) {
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) {
@@ -143,6 +143,7 @@ namespace Mutations {
if (state.servercode !== rescodes.ERR_SERVERFETCH) {
state.servercode = err
}
+ console.log('Err catch: (servercode:', err, ')')
}
function getMsgError(state: IUserState, err: number) {