From 6931d5700593657c15050aaf8a5176d11fa0f5ab Mon Sep 17 00:00:00 2001 From: Paolo Arena Date: Thu, 14 Feb 2019 18:38:23 +0100 Subject: [PATCH] Fix: Todo Multi refresh ... fix some promises problem --- .env.development | 2 +- src-pwa/custom-service-worker.js | 62 ++++++++----- src/App.ts | 33 ++++--- src/components/Header.vue | 12 +-- .../todos/SingleTodo/SingleTodo.scss | 6 +- src/components/todos/SingleTodo/SingleTodo.ts | 10 +-- .../todos/SingleTodo/SingleTodo.vue | 20 ++--- src/components/todos/todo/todo.ts | 88 ++++++++++++++----- src/components/todos/todo/todo.vue | 27 ++++-- src/css/themes/common.variables.styl | 1 + src/model/Todos.ts | 2 +- src/model/other.ts | 1 + src/root/home/home.ts | 18 ++-- src/root/home/home.vue | 8 ++ src/statics/i18n.js | 6 +- src/statics/js/storage.js | 1 + src/store/Api/index.ts | 8 +- src/store/Modules/GlobalStore.ts | 61 +++++++------ src/store/Modules/Todos.ts | 14 +-- src/store/Modules/UserStore.ts | 24 ++--- src/views/login/signin/signin.ts | 11 ++- src/views/login/vreg/vreg.ts | 29 +++--- 22 files changed, 281 insertions(+), 163 deletions(-) diff --git a/.env.development b/.env.development index c1e8448..e032ebc 100644 --- a/.env.development +++ b/.env.development @@ -1,4 +1,4 @@ -APP_VERSION="DEV 0.0.17" +APP_VERSION="DEV 0.0.27" 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 8ab8af3..43ee1de 100644 --- a/src-pwa/custom-service-worker.js +++ b/src-pwa/custom-service-worker.js @@ -6,11 +6,11 @@ // Questo è il swSrc -console.log(' [ VER-0.0.21 ] _---------________------ PAO: this is my custom service worker'); +console.log(' [ VER-0.0.27 ] _---------________------ 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'); importScripts('../statics/js/storage.js'); +importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js'); //++Todo: Replace with local workbox.js let port = 3000; @@ -24,6 +24,9 @@ const cfgenv = { dbversion: 11, } +// console.log('serverweb', cfgenv.serverweb) + + async function writeData(table, data) { // console.log('writeData', table, data); await idbKeyval.setdata(table, data); @@ -54,10 +57,10 @@ async function deleteItemFromData(table, id) { if (!workbox) { let workbox = new self.WorkboxSW(); - // console.log('SW-06 3'); } if (workbox) { + // console.log('WORKBOX PRESENT') // const url = new URL(location.href); // const debug = url.searchParams.has('debug'); const debug = false; @@ -101,11 +104,12 @@ if (workbox) { }) ); + // console.log(' routing.registerRoute function declaration:') workbox.routing.registerRoute( new RegExp(cfgenv.serverweb + '/todos/'), function (args) { - // console.log('registerRoute!') + console.log('registerRoute! ', cfgenv.serverweb + '/todos/') // console.log('DATABODY:', args.event.request.body) let myres = null // return fetch(args.event.request, args.event.headers) @@ -117,8 +121,11 @@ if (workbox) { // console.log('res.status', res.status) if (res.status === 200) { const clonedRes = res.clone(); - clearAllData('todos') - return clonedRes + + return clearAllData('todos') + .then(() => { + return clonedRes + }) } }) .then((clonedRes) => { @@ -126,12 +133,12 @@ if (workbox) { return clonedRes.json(); return null }) - .then(data => { + .then(async 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]) + console.log('***********************+++++++++++++++++++++++++++++++++++++++++++++++++++********** Records TODOS Received from Server [', data.todos.length, 'record]', data.todos) + for (const key in data.todos) { + await writeData('todos', data.todos[key]) } } } @@ -483,21 +490,30 @@ self.addEventListener('push', function (event) { var data = { title: 'New!', content: 'Something new happened!', url: '/' }; - if (event.data) { - data = JSON.parse(event.data.text()); - } + try { - var options = { - body: data.content, - icon: '/statics/icons/android-chrome-192x192.png', - badge: '/statics/icons/android-chrome-192x192.png', - data: { - url: data.url + if (event.data) { + try { + data = JSON.parse(event.data.text()); + } catch (e) { + data = event.data.text(); + } } - }; - event.waitUntil( - self.registration.showNotification(data.title, options) - ); + var options = { + body: data.content, + icon: '/statics/icons/android-chrome-192x192.png', + badge: '/statics/icons/android-chrome-192x192.png', + data: { + url: data.url + } + }; + + event.waitUntil( + self.registration.showNotification(data.title, options) + ); + } catch (e) { + console.log('Error on event push:', e) + } }); diff --git a/src/App.ts b/src/App.ts index bee552c..3ce9f38 100644 --- a/src/App.ts +++ b/src/App.ts @@ -12,7 +12,6 @@ import globalroutines from './globalroutines/index' import { GlobalStore } from './store/Modules' - @Component({ components: { appHeader: Header @@ -25,6 +24,7 @@ export default class App extends Vue { public backgroundColor = 'whitesmoke' public $q + public listaRoutingNoLogin = ['/vreg?', '/offline'] created() { if (process.env.DEV) { @@ -36,16 +36,30 @@ export default class App extends Vue { // console.info(process.env) } - UserStore.actions.autologin_FromLocalStorage() - .then((loadstorage) => { - if (loadstorage) { - globalroutines(this, 'loadapp', '') - // this.$router.replace('/') + // Make autologin only if some routing + + // console.log('window.location.href', window.location.href) + + let chiamaautologin = true + this.listaRoutingNoLogin.forEach(mystr => { + if (window.location.href.includes(mystr)) { + chiamaautologin = false + } + }) + + if (chiamaautologin) { + console.log('CHIAMA autologin_FromLocalStorage') + UserStore.actions.autologin_FromLocalStorage() + .then((loadstorage) => { + if (loadstorage) { + globalroutines(this, 'loadapp', '') + // this.$router.replace('/') // Create Subscription to Push Notification - GlobalStore.actions.createPushSubscription() - } - }) + GlobalStore.actions.createPushSubscription() + } + }) + } // Calling the Server for updates ? // Check the verified_email @@ -53,5 +67,4 @@ export default class App extends Vue { } - } diff --git a/src/components/Header.vue b/src/components/Header.vue index 4f5a7bd..049b2ae 100644 --- a/src/components/Header.vue +++ b/src/components/Header.vue @@ -111,11 +111,11 @@ this.strConn = value - this.$q.notify({ - color : 'primary', - icon: 'wifi', - message: "CAMBIATOO! " + value - }) + // this.$q.notify({ + // color : 'primary', + // icon: 'wifi', + // message: "CAMBIATOO! " + value + // }) } @@ -124,7 +124,7 @@ changeconn_changed(value: string, oldValue: string) { if (value != oldValue) { - console.log('SSSSSSSS: ', value, oldValue) + // console.log('SSSSSSSS: ', value, oldValue) const color = (value === 'online') ? 'positive' : 'warning' diff --git a/src/components/todos/SingleTodo/SingleTodo.scss b/src/components/todos/SingleTodo/SingleTodo.scss index 9ea75a7..4eebdb8 100644 --- a/src/components/todos/SingleTodo/SingleTodo.scss +++ b/src/components/todos/SingleTodo/SingleTodo.scss @@ -78,7 +78,10 @@ $heightitem: 19px; padding: 0px; text-align: center; vertical-align: middle; - display: none; + display: block; + @media screen and (min-width: 600px) { + display: none; + } color: #777; height: 100%; //visibility: hidden; @@ -291,6 +294,7 @@ $heightitem: 19px; } + /* .container { background-color: #ccc; diff --git a/src/components/todos/SingleTodo/SingleTodo.ts b/src/components/todos/SingleTodo/SingleTodo.ts index e3e9048..813ab95 100644 --- a/src/components/todos/SingleTodo/SingleTodo.ts +++ b/src/components/todos/SingleTodo/SingleTodo.ts @@ -266,9 +266,9 @@ export default class SingleTodo extends Vue { */ if (((e.keyCode === 8) || (e.keyCode === 46)) && (this.precDescr === '') && !e.shiftKey) { e.preventDefault() + this.deselectRiga() this.clickMenu(rescodes.MenuAction.DELETE) .then(() => { - this.deselectRiga() this.faiFocus('insertTask', true) return }) @@ -356,13 +356,13 @@ export default class SingleTodo extends Vue { async clickMenu(action) { console.log('click menu: ', action) if (action === rescodes.MenuAction.DELETE) { - return this.askConfirmDelete() + return await this.askConfirmDelete() } else if (action === rescodes.MenuAction.TOGGLE_EXPIRING) { - return this.enableExpiring() + return await this.enableExpiring() } else if (action === rescodes.MenuAction.COMPLETED) { - return this.setCompleted() + return await this.setCompleted() } else if (action === rescodes.MenuAction.PROGRESS_BAR) { - return this.updatedata() + return await this.updatedata() } } diff --git a/src/components/todos/SingleTodo/SingleTodo.vue b/src/components/todos/SingleTodo/SingleTodo.vue index 4531097..68ffee7 100644 --- a/src/components/todos/SingleTodo/SingleTodo.vue +++ b/src/components/todos/SingleTodo/SingleTodo.vue @@ -4,16 +4,6 @@ -
- - - - - - -
+
+ + + + + + +
diff --git a/src/components/todos/todo/todo.ts b/src/components/todos/todo/todo.ts index de67750..b9f12f5 100644 --- a/src/components/todos/todo/todo.ts +++ b/src/components/todos/todo/todo.ts @@ -20,7 +20,7 @@ import VueIdb from 'vue-idb' import globalroutines from '../../../globalroutines/index' import $ from 'jquery' -import Api from "@api" +import Api from '@api' @Component({ @@ -43,7 +43,9 @@ export default class Todo extends Vue { itemDragEnd: any = null selrowid: number = 0 polling = null - mytypetransgroup: string = 'crossfade' + mytypetransgroup: string = 'flip-list' + tmpstrTodos: string = '' + loadDone: boolean = false fieldtochange: String [] = ['descr', 'completed', 'category', 'expiring_at', 'priority', 'id_prev', 'id_next', 'pos', 'enableExpiring', 'progress'] @@ -67,7 +69,7 @@ export default class Todo extends Vue { @Watch('$route.params.category') changecat() { // console.log('changecat') this.mytypetransgroup = 'nessuno' - this.updatetable().then(() => { + this.updatetable(false, '$route.params.category').then(() => { this.mytypetransgroup = 'crossfade' }) } @@ -80,23 +82,31 @@ export default class Todo extends Vue { return Todos.state.reload_fromServer } + set reload_fromServer(value: number) { + Todos.state.reload_fromServer = value + } + @Watch('todos_changed', { immediate: true, deep: true }) - changetodos_changed(value: string, oldValue: string) { + changetodos_changed(value: number, oldValue: number) { // this.$q.notify('Changed...') - console.log('Todos.state.todos_changed CHANGED!', value, oldValue) - this.updatetable(true) + if ((value > 1) && (this.loadDone)) { + // console.log('Todos.state.todos_changed CHANGED!', value, oldValue) + this.updatetable(true, 'todos_changed') + } } @Watch('reload_fromServer', { immediate: true }) - reload_fromServer_changed(value: string, oldValue: string) { - console.log('reload_fromServer_changed!', value, oldValue) - // if (value) { - Todos.actions.dbLoadTodo(false) + reload_fromServer_changed(value: number, oldValue: number) { + if (value > 0) { + // console.log('reload_fromServer_changed!', value, oldValue) + // if (value) { + Todos.actions.dbLoadTodo(false) - Todos.actions.updateArrayInMemory() + Todos.actions.updateArrayInMemory() + } // } } @@ -108,7 +118,37 @@ export default class Todo extends Vue { @Watch('testPao', { immediate: true, deep: true }) changedTestpao(value: string, oldValue: string) { // console.log('testpao CHANGED', value, oldValue) - this.updatetable(true) + // this.updatetable(true, 'testPao') + } + + getArrTodos() { + + let mystr = '' + let mythis = this + + mythis.tmpstrTodos = '' + globalroutines(null, 'readall', 'todos', null) + .then(function (alldata) { + const myrecs = [...alldata] + + myrecs.forEach(rec => { + mystr = mystr + rec.descr + '] [' + }) + + mythis.tmpstrTodos = 'TODOS: ' + mystr + }) + } + + setArrTodos() { + + let mystr = '' + let mythis = this + + mythis.tmpstrTodos = '' + globalroutines(null, 'write', 'todos', this.todos_arr[0]) + .then(function (alldata) { + mythis.getArrTodos() + }) } getCategory() { @@ -283,7 +323,7 @@ export default class Todo extends Vue { // Updated only elements modified await this.updateModifyRecords(true) - this.updatetable() + this.updatetable(false, 'onEnd') } @@ -299,7 +339,7 @@ export default class Todo extends Vue { }) if (update) - await this.updatetable(refresh) + await this.updatetable(refresh, 'updateModifyRecords') } @@ -322,6 +362,7 @@ export default class Todo extends Vue { async load() { + this.todos_arr = [...Todos.state.todos] // Set last category selected @@ -334,7 +375,7 @@ export default class Todo extends Vue { this.setarrPriority() this.clearArr() - await this.updatetable() + await this.updatetable(false, 'load') this.checkUpdate_everytime() @@ -345,6 +386,7 @@ export default class Todo extends Vue { }) */ + this.loadDone = true } // Call to check if need to refresh @@ -356,8 +398,8 @@ export default class Todo extends Vue { initcat() { - var tomorrow = new Date(); - tomorrow.setDate(tomorrow.getDate() + 1); + let tomorrow = new Date(); + tomorrow.setDate(tomorrow.getDate() + 1) const objtodo: ITodo = { @@ -433,7 +475,7 @@ export default class Todo extends Vue { const rismod = await this.modify(lastelem, false) this.saveItemToSyncAndDb(rescodes.DB.TABLE_SYNC_TODOS, 'POST', objtodo, true) - this.updatetable(false) + this.updatetable(false, 'insertTodo') // console.log('ESCO.........') @@ -582,7 +624,7 @@ export default class Todo extends Vue { // Delete item await globalroutines(this, 'delete', 'todos', null, id) .then((ris) => { - mythis.updatetable() + mythis.updatetable(false, 'deleteitem') }).catch((error) => { console.log('err: ', error) }) @@ -603,8 +645,8 @@ export default class Todo extends Vue { return itemnew.pos !== itemold.pos } - async updatetable(refresh: boolean = false) { - console.log('updatetable') + async updatetable(refresh: boolean = false, strpos = '') { + console.log('updatetable', strpos) this.prevRecords = [...this.todos_arr] @@ -808,7 +850,7 @@ export default class Todo extends Vue { // console.log('SET MODIFIED FALSE') if (update) - this.updatetable(false) + this.updatetable(false, 'modify') }) }) @@ -829,7 +871,7 @@ export default class Todo extends Vue { } clicktest2() { - this.updatetable(false) + this.updatetable(false, 'clicktest') console.log('Todos.state.todos', Todos.state.todos) } diff --git a/src/components/todos/todo/todo.vue b/src/components/todos/todo/todo.vue index 1e61910..0eedb26 100644 --- a/src/components/todos/todo/todo.vue +++ b/src/components/todos/todo/todo.vue @@ -12,7 +12,7 @@
- +
@@ -35,15 +35,24 @@ :after="[{icon: 'arrow_forward', content: true, handler () {}}]" v-on:keyup.enter="insertTodo"/> - - - + -
- - - -
+ + + + + + + + + + + + + + + +
diff --git a/src/css/themes/common.variables.styl b/src/css/themes/common.variables.styl index 4d659aa..6b8b26a 100644 --- a/src/css/themes/common.variables.styl +++ b/src/css/themes/common.variables.styl @@ -23,3 +23,4 @@ $positive = #21BA45 $negative = #DB2828 $info = #31CCEC $warning = #F2C037 + diff --git a/src/model/Todos.ts b/src/model/Todos.ts index f62482b..0634125 100644 --- a/src/model/Todos.ts +++ b/src/model/Todos.ts @@ -22,7 +22,7 @@ export interface ITodosState { networkDataReceived: boolean todos: ITodo[] todos_changed: number - reload_fromServer: boolean + reload_fromServer: number testpao: String insidePending: boolean } diff --git a/src/model/other.ts b/src/model/other.ts index dc9e839..6086868 100644 --- a/src/model/other.ts +++ b/src/model/other.ts @@ -1,5 +1,6 @@ export interface IToken { access: string + // browser: string token: string data_login: Date } diff --git a/src/root/home/home.ts b/src/root/home/home.ts index 0851073..8f62da5 100644 --- a/src/root/home/home.ts +++ b/src/root/home/home.ts @@ -59,7 +59,8 @@ export default class Home extends Vue { window.addEventListener('beforeinstallprompt', function (event) { // console.log('******************************** beforeinstallprompt fired') event.preventDefault() - console.log('§§§§§§§§§§§§§§§§§§§§ IMPOSTA DEFERRED PROMPT !!!!!!!!!!!!!!!!! ') + // console.log('§§§§§§§§§§§§§§§§§§§§ IMPOSTA DEFERRED PROMPT !!!!!!!!!!!!!!!!! ') + // #Todo++ IMPOSTA DEFERRED PROMPT return false }) @@ -69,6 +70,10 @@ export default class Home extends Vue { return Notification.permission } + NotServiceWorker () { + return (!('serviceWorker' in navigator)) + } + displayConfirmNotification() { let options = null if ('serviceWorker' in navigator) { @@ -88,10 +93,12 @@ export default class Home extends Vue { ] } - navigator.serviceWorker.ready - .then(function (swreg) { - swreg.showNotification('Successfully subscribed!', options) - }) + if ('serviceWorker' in navigator) { + navigator.serviceWorker.ready + .then(function (swreg) { + swreg.showNotification('Successfully subscribed!', options) + }) + } } } @@ -168,7 +175,6 @@ export default class Home extends Vue { } - test_fetch() { fetch('https:/httpbin.org/post', { method: 'POST', diff --git a/src/root/home/home.vue b/src/root/home/home.vue index 1aa581b..7813d58 100644 --- a/src/root/home/home.vue +++ b/src/root/home/home.vue @@ -5,6 +5,8 @@ + +
@@ -16,6 +18,12 @@ :label="$t('notification.titlegranted')" helper="Stato Notifiche"> + +
diff --git a/src/statics/i18n.js b/src/statics/i18n.js index 8f08e32..e10e65c 100644 --- a/src/statics/i18n.js +++ b/src/statics/i18n.js @@ -17,7 +17,7 @@ const messages = { msg: { hello: 'Buongiorno', myAppName: 'FreePlanet', - myDescriz: 'La prima App Libera' + myDescriz: '' }, pages: { home: 'Principale', @@ -143,7 +143,7 @@ const messages = { msg: { hello: 'Buenos Días', myAppName: 'FreePlanet', - myDescriz: 'La primera App Libera' + myDescriz: '' }, pages: { home: 'Principal', @@ -269,7 +269,7 @@ const messages = { msg: { hello: 'Hello!', myAppName: 'FreePlanet', - myDescriz: 'The first Free app' + myDescriz: '' }, pages: { home: 'Dashboard One', diff --git a/src/statics/js/storage.js b/src/statics/js/storage.js index f9b3841..88d097f 100644 --- a/src/statics/js/storage.js +++ b/src/statics/js/storage.js @@ -1,5 +1,6 @@ let idbKeyval = (() => { let db; + // console.log('idbKeyval...') function getDB() { if (!db) { diff --git a/src/store/Api/index.ts b/src/store/Api/index.ts index f495e52..0274374 100644 --- a/src/store/Api/index.ts +++ b/src/store/Api/index.ts @@ -155,7 +155,7 @@ export namespace ApiTool { let lettoqualcosa = false // console.log('A1) INIZIO.............................................................') - globalroutines(null, 'readall', table, null) + return globalroutines(null, 'readall', table, null) .then(function (alldata) { const myrecs = [...alldata] // console.log('----------------------- LEGGO QUALCOSA ') @@ -178,11 +178,11 @@ export namespace ApiTool { body: JSON.stringify(rec) }) .then(() => { - globalroutines(null, 'delete', table, null, rec._id) lettoqualcosa = true + return globalroutines(null, 'delete', table, null, rec._id) }) .then(() => { - globalroutines(null, 'delete', 'swmsg', null, mystrparam) + return globalroutines(null, 'delete', 'swmsg', null, mystrparam) }) .catch(function (err) { if (err.message === 'Failed to fetch') { @@ -206,8 +206,8 @@ export namespace ApiTool { .then((errorfromserver) => { // console.log('¨¨¨¨¨¨¨¨¨¨¨¨¨¨ errorfromserver:', errorfromserver) const mystate = errorfromserver ? 'offline' : 'online' - globalroutines(null, 'write', 'config', { _id: 2, stateconn: mystate }) GlobalStore.mutations.setStateConnection(mystate) + return globalroutines(null, 'write', 'config', { _id: 2, stateconn: mystate }) }) // console.log(' [Alternative] A2) ?????????????????????????? ESCO DAL LOOP !!!!!!!!!') diff --git a/src/store/Modules/GlobalStore.ts b/src/store/Modules/GlobalStore.ts index 3dbdc93..6c5aaa6 100644 --- a/src/store/Modules/GlobalStore.ts +++ b/src/store/Modules/GlobalStore.ts @@ -123,10 +123,10 @@ namespace Actions { function createPushSubscription(context) { // If Already subscribed, don't send to the Server DB - if (state.wasAlreadySubOnDb) { - // console.log('wasAlreadySubOnDb!') - return - } + // if (state.wasAlreadySubOnDb) { + // // console.log('wasAlreadySubOnDb!') + // return + // } if (!('serviceWorker' in navigator)) { return @@ -141,7 +141,7 @@ namespace Actions { let reg const mykey = process.env.PUBLICKEY_PUSH const mystate = state - navigator.serviceWorker.ready + return navigator.serviceWorker.ready .then(function (swreg) { reg = swreg return swreg.pushManager.getSubscription() @@ -149,11 +149,13 @@ namespace Actions { .then(function (subscription) { mystate.wasAlreadySubscribed = !(subscription === null) - if (mystate.wasAlreadySubOnDb) { - // console.log('User is already SAVED Subscribe on DB!') - return null + if (mystate.wasAlreadySubscribed) { + console.log('User is already SAVED Subscribe on DB!') + // return null + return subscription } else { // Create a new subscription + console.log('Create a new subscription') let convertedVapidPublicKey = urlBase64ToUint8Array(mykey) return reg.pushManager.subscribe({ userVisibleOnly: true, @@ -165,7 +167,7 @@ namespace Actions { saveNewSubscriptionToServer(context, newSub) }) .catch(function (err) { - console.log(err) + console.log('ERR createPushSubscription:', err) }) } @@ -178,11 +180,16 @@ namespace Actions { console.log('saveSubscriptionToServer: ', newSub) // console.log('context', context) - const options = { - title: translate('notification.title_subscribed'), - content: translate('notification.subscribed'), - openUrl: '/' - } + let options = null + + // If is not already stored in DB, then show the message to the user. + // if (!state.wasAlreadySubscribed) { + options = { + title: translate('notification.title_subscribed'), + content: translate('notification.subscribed'), + openUrl: '/' + } + // } let myres = { options: { ...options }, @@ -252,20 +259,22 @@ namespace Actions { globalroutines(null, 'clearalldata', table, null) }) - // REMOVE ALL SUBSCRIPTION - console.log('REMOVE ALL SUBSCRIPTION...') - await navigator.serviceWorker.ready.then(function (reg) { - console.log('... Ready') - reg.pushManager.getSubscription().then(function (subscription) { - console.log(' Found Subscription...') - subscription.unsubscribe().then(function (successful) { - // You've successfully unsubscribed - console.log('You\'ve successfully unsubscribed') - }).catch(function (e) { - // Unsubscription failed + if ('serviceWorker' in navigator) { + // REMOVE ALL SUBSCRIPTION + console.log('REMOVE ALL SUBSCRIPTION...') + await navigator.serviceWorker.ready.then(function (reg) { + console.log('... Ready') + reg.pushManager.getSubscription().then(function (subscription) { + console.log(' Found Subscription...') + subscription.unsubscribe().then(function (successful) { + // You've successfully unsubscribed + console.log('You\'ve successfully unsubscribed') + }).catch(function (e) { + // Unsubscription failed + }) }) }) - }) + } await deleteSubscriptionToServer(context) diff --git a/src/store/Modules/Todos.ts b/src/store/Modules/Todos.ts index 8e79f88..fd466bc 100644 --- a/src/store/Modules/Todos.ts +++ b/src/store/Modules/Todos.ts @@ -14,7 +14,7 @@ const state: ITodosState = { networkDataReceived: false, todos: [], todos_changed: 1, - reload_fromServer: false, + reload_fromServer: 0, testpao: 'Test', insidePending: false } @@ -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 = { @@ -78,10 +78,10 @@ namespace Actions { let count = await checkPendingMsg(null) if (count > 0) { - return navigator.serviceWorker.ready + return await navigator.serviceWorker.ready .then(function (sw) { - globalroutines(null, 'readall', 'swmsg') + return globalroutines(null, 'readall', 'swmsg') .then(function (arr_recmsg) { // let recclone = [...arr_recmsg] if (arr_recmsg.length > 0) { @@ -119,11 +119,11 @@ namespace Actions { .then(ris => { if (ris) { console.log('risPending = ', ris) - const result = sendSwMsgIfAvailable() + return sendSwMsgIfAvailable() .then(something => { if (something) { // Refresh data - waitAndRefreshData(context) + return waitAndRefreshData(context) } }) } @@ -204,7 +204,7 @@ namespace Actions { Todos.mutations.setTodos_changed() } - console.log('********** res', res, 'state.todos', state.todos, 'checkPending', checkPending) + console.log('********** res', 'state.todos', state.todos, 'checkPending', checkPending) // After Login will store into the indexedDb... diff --git a/src/store/Modules/UserStore.ts b/src/store/Modules/UserStore.ts index 636d794..8930196 100644 --- a/src/store/Modules/UserStore.ts +++ b/src/store/Modules/UserStore.ts @@ -89,7 +89,7 @@ namespace Mutations { state.verified_email = data.verified_email state.category = data.categorySel resetArrToken(state.tokens) - state.tokens.push({ access: 'auth ' + navigator.userAgent, token: state.x_auth_token, date_login: new Date() }) + state.tokens.push({ access: 'auth', token: state.x_auth_token, date_login: new Date() }) // console.log('state.tokens', state.tokens) } @@ -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', token: data.x_auth_token, data_login: new Date() }) } function setServerCode(state: IUserState, num: number) { @@ -135,7 +135,7 @@ namespace Mutations { // Take only the others access (from others Browser) return arrtokens.filter((token: IToken) => { - return token.access !== 'auth ' + navigator.userAgent + return token.access !== 'auth' }) } @@ -368,14 +368,16 @@ namespace Actions { let sub = null - sub = await navigator.serviceWorker.ready - .then(function (swreg) { - const sub = swreg.pushManager.getSubscription() - return sub - }) - .catch(e => { - sub = null - }) + if ('serviceWorker' in navigator) { + sub = await navigator.serviceWorker.ready + .then(function (swreg) { + const sub = swreg.pushManager.getSubscription() + return sub + }) + .catch(e => { + sub = null + }) + } const options = { title: translate('notification.title_subscribed'), diff --git a/src/views/login/signin/signin.ts b/src/views/login/signin/signin.ts index 0ef5e6b..c85632e 100644 --- a/src/views/login/signin/signin.ts +++ b/src/views/login/signin/signin.ts @@ -148,9 +148,16 @@ export default class Signin extends Vue { .then((riscode) => { if (riscode === rescodes.OK) { GlobalStore.actions.createPushSubscription() + .then(ris => { + }) + .catch(e => { + console.log('ERROR = ' + e) + }) + .then(() => { + this.checkErrors(riscode) + this.$q.loading.hide() + }) } - this.checkErrors(riscode) - this.$q.loading.hide() }) .catch(error => { console.log('ERROR = ' + error) diff --git a/src/views/login/vreg/vreg.ts b/src/views/login/vreg/vreg.ts index 6578ff1..ab836e8 100644 --- a/src/views/login/vreg/vreg.ts +++ b/src/views/login/vreg/vreg.ts @@ -8,9 +8,7 @@ import { serv_constants } from '../../../store/Modules/serv_constants' import './vreg.css' import { ILinkReg } from '../../../model/other' -@Component({ - -}) +@Component({}) export default class Vreg extends Vue { public risultato: string = '---' public riscode: number = 0 @@ -43,20 +41,21 @@ export default class Vreg extends Vue { let param: ILinkReg param = { idlink: this.$route.query.idlink.toString() } console.log('idlink = ', param) - UserStore.actions.vreg(param).then((ris) => { - this.riscode = ris.code - this.risultato = ris.msg - console.log('RIS = ') - console.log(ris) + return UserStore.actions.vreg(param) + .then((ris) => { + this.riscode = ris.code + this.risultato = ris.msg + console.log('RIS = ') + console.log(ris) - if (this.verificatook) { - setTimeout(() => { - this.$router.replace('/signin') - }, 3000) - } + if (this.verificatook) { + setTimeout(() => { + this.$router.replace('/signin') + }, 3000) + } - }).catch((err) => { - console.log('ERR = ' + err) + }).catch((err) => { + console.log('ERR = ' + err) }) } }