Fix: Todo Multi refresh ...

fix some promises problem
This commit is contained in:
Paolo Arena
2019-02-14 18:38:23 +01:00
parent e8d2d49829
commit 6931d57005
22 changed files with 281 additions and 163 deletions

View File

@@ -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'

View File

@@ -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)
}
});

View File

@@ -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 {
}
}

View File

@@ -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'

View File

@@ -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;

View File

@@ -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()
}
}

View File

@@ -4,16 +4,6 @@
<SubMenus :menuPopupTodo="menuPopupTodo" :itemtodo="itemtodo" @clickMenu="clickMenu" @setPriority="setPriority"></SubMenus>
</q-context-menu>
<div v-if="isTodo()" class="flex-item pos-item" @mouseup.left="mouseUp" @mousedown="clickRiga">
<q-btn flat
class="pos-item-popover"
icon="menu" >
<q-popover self="top right">
<SubMenus :menuPopupTodo="menuPopupTodo" :itemtodo="itemtodo" @clickMenu="clickMenu" @setPriority="setPriority"></SubMenus>
</q-popover>
</q-btn>
</div>
<div v-if="isTodo()" class="flex-item completed-item">
<q-btn push flat
@@ -59,6 +49,16 @@
</q-datetime>
</div>
</div>
<div v-if="isTodo()" class="flex-item pos-item" @mouseup.left="mouseUp" @mousedown="clickRiga">
<q-btn flat
class="pos-item-popover"
icon="menu" >
<q-popover self="top right">
<SubMenus :menuPopupTodo="menuPopupTodo" :itemtodo="itemtodo" @clickMenu="clickMenu" @setPriority="setPriority"></SubMenus>
</q-popover>
</q-btn>
</div>
<!--<div class="flex-item btn-item">-->
<!--{{itemtodo.expiring_at}}-->
<!--</div>-->

View File

@@ -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)
}

View File

@@ -12,7 +12,7 @@
<div class="drag">
<draggable v-model="todos_arr" :options="{draggable:'.myitemdrag'}"
@start="onStart" @end="onEnd" class="dragArea">
<transition-group :name="mytypetransgroup" >
<transition-group :name="mytypetransgroup">
<div :id="getmyid(mytodo._id)" :key="mytodo._id" v-for="mytodo in todos_arr" class="myitemdrag">
<div v-if="(prior !== mytodo.priority) && !mytodo.completed" :class="getTitlePriority(mytodo.priority)">
@@ -35,15 +35,24 @@
:after="[{icon: 'arrow_forward', content: true, handler () {}}]"
v-on:keyup.enter="insertTodo"/>
<q-input v-model="testPao" float-label="testPao"/>
<q-input v-model="todos_changed" float-label="todos_changed"/>
<q-input v-model="reload_fromServer" float-label="reload_fromServer"/>
<!--{{ tmpstrTodos }}-->
<div class="flex-item btn-item">
<!--<q-btn class="mybtn" round color="" icon="lock" @click="clicktest()"></q-btn>-->
<!--<q-btn class="mybtn" round color="" icon="person" @click="clicktest2()"></q-btn>-->
<q-btn class="mybtn" round color="" icon="list" @click="checkUpdate()"></q-btn>
</div>
<!--<div class="flex-item btn-item">-->
<!--<q-btn class="mybtn" round color="" icon="lock" @click="getArrTodos">Get Todo</q-btn>-->
<!--<q-btn class="mybtn" round color="" icon="person" @click="setArrTodos">Set Todo</q-btn>-->
<!--<q-btn class="mybtn" round color="" icon="list" @click="reload_fromServer++">Reload</q-btn>-->
<!--</div>-->
<!--<q-input v-model="testPao" float-label="testPao"/>-->
<!--<q-input v-model="todos_changed" float-label="todos_changed"/>-->
<!--<q-input v-model="reload_fromServer" float-label="reload_fromServer"/>-->
<!--<div class="flex-item btn-item">-->
<!--&lt;!&ndash;<q-btn class="mybtn" round color="" icon="lock" @click="clicktest()"></q-btn>&ndash;&gt;-->
<!--&lt;!&ndash;<q-btn class="mybtn" round color="" icon="person" @click="clicktest2()"></q-btn>&ndash;&gt;-->
<!--<q-btn class="mybtn" round color="" icon="list" @click="checkUpdate()"></q-btn>-->
<!--</div>-->
</div>
</q-page>

View File

@@ -23,3 +23,4 @@ $positive = #21BA45
$negative = #DB2828
$info = #31CCEC
$warning = #F2C037

View File

@@ -22,7 +22,7 @@ export interface ITodosState {
networkDataReceived: boolean
todos: ITodo[]
todos_changed: number
reload_fromServer: boolean
reload_fromServer: number
testpao: String
insidePending: boolean
}

View File

@@ -1,5 +1,6 @@
export interface IToken {
access: string
// browser: string
token: string
data_login: Date
}

View File

@@ -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',

View File

@@ -5,6 +5,8 @@
<q-btn v-if="getPermission() !== 'granted'" class="enable-notifications" color="primary" rounded size="lg" icon="notifications" @click="askfornotification" :label="$t('notification.ask')"/>
<q-btn v-if="getPermission() === 'granted'" class="enable-notifications" color="primary" rounded size="lg" icon="notifications" @click="showNotificationExample" label="Send Notification"/>
<!--<q-btn v-if="getPermission() === 'granted'" class="enable-notifications" color="secondary" rounded size="lg" icon="notifications" @click="createPushSubscription" label="Create Push Subscription !"/>-->
<br>
<div>
<q-chip square color="secondary">
@@ -16,6 +18,12 @@
:label="$t('notification.titlegranted')"
helper="Stato Notifiche">
</q-field>
<q-field
v-if="NotServiceWorker()"
icon="notifications"
label="Service Worker not present"
>
</q-field>
</div>
</q-page>

View File

@@ -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',

View File

@@ -1,5 +1,6 @@
let idbKeyval = (() => {
let db;
// console.log('idbKeyval...')
function getDB() {
if (!db) {

View File

@@ -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 !!!!!!!!!')

View File

@@ -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)

View File

@@ -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...

View File

@@ -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'),

View File

@@ -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)

View File

@@ -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)
})
}
}