Notification with Service Workers now is working!
When a Notification arrives, it save into the IndexDb, then in Vue.js call a polling to check in the db if there is a different record count. If is different then call a get to update the notification.
This commit is contained in:
@@ -26,4 +26,5 @@ TELEGRAM_SUPPORT=""
|
|||||||
PROJECT_ID_MAIN="5cc0a13fe5c9d156728f400a"
|
PROJECT_ID_MAIN="5cc0a13fe5c9d156728f400a"
|
||||||
TEST_CELL=""
|
TEST_CELL=""
|
||||||
ISTEST=1
|
ISTEST=1
|
||||||
|
INLOCALE=1
|
||||||
BAK_MONGODB_HOST="http://192.168.0.200:3000"
|
BAK_MONGODB_HOST="http://192.168.0.200:3000"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const OtherTables = ['categories', 'config', 'swmsg']
|
const OtherTables = ['categories', 'config', 'swmsg', 'notifications']
|
||||||
const MainTables = ['todos', 'projects']
|
const MainTables = ['todos', 'projects']
|
||||||
const allMethod = ['sync_post_', 'sync_patch_', 'delete_']
|
const allMethod = ['sync_post_', 'sync_patch_', 'delete_']
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ let idbKeyval = (() => {
|
|||||||
if (!db) {
|
if (!db) {
|
||||||
// console.log('CREO DB STORAGE JS !')
|
// console.log('CREO DB STORAGE JS !')
|
||||||
db = new Promise((resolve, reject) => {
|
db = new Promise((resolve, reject) => {
|
||||||
const openreq = indexedDB.open('mydb3', 11);
|
const openreq = indexedDB.open('mydb3', 13);
|
||||||
|
|
||||||
openreq.onerror = () => {
|
openreq.onerror = () => {
|
||||||
reject(openreq.error);
|
reject(openreq.error);
|
||||||
@@ -84,12 +84,19 @@ let idbKeyval = (() => {
|
|||||||
async getdata(table, key) {
|
async getdata(table, key) {
|
||||||
let req;
|
let req;
|
||||||
|
|
||||||
|
console.log('getdata', table, key)
|
||||||
|
|
||||||
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(' req', req)
|
||||||
});
|
});
|
||||||
|
|
||||||
return req.result;
|
if (req) {
|
||||||
|
return req.result;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async getalldata(table) {
|
async getalldata(table) {
|
||||||
let req;
|
let req;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import { CacheableResponsePlugin } from 'workbox-cacheable-response'
|
|||||||
import { ExpirationPlugin } from 'workbox-expiration'
|
import { ExpirationPlugin } from 'workbox-expiration'
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
' [ VER-0.1.2b ] _---------________------ PAO: this is my custom service worker')
|
' [ VER-0.3.23b ] _---------________------ PAO: this is my custom service worker')
|
||||||
|
|
||||||
importScripts('js/idb.js')
|
importScripts('js/idb.js')
|
||||||
importScripts('js/storage.js')
|
importScripts('js/storage.js')
|
||||||
@@ -24,6 +24,8 @@ importScripts('js/storage.js')
|
|||||||
|
|
||||||
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.4/workbox-sw.js');
|
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.4/workbox-sw.js');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js');
|
// importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js');
|
||||||
|
|
||||||
// importScripts('./ChabokSDKWorker.js', 'https://storage.googleapis.com/workbox-cdn/releases/5.0.0/workbox-sw.js');
|
// importScripts('./ChabokSDKWorker.js', 'https://storage.googleapis.com/workbox-cdn/releases/5.0.0/workbox-sw.js');
|
||||||
@@ -43,7 +45,7 @@ const cfgenv = {
|
|||||||
// 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,152 +352,155 @@ if ('serviceWorker' in navigator) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// self.addEventListener('fetch', (event) => {
|
self.addEventListener('fetch', (event) => {
|
||||||
// if (event.request.url === '/') {
|
if (event.request.url === '/') {
|
||||||
// const StaleWhileRevalidate = new StaleWhileRevalidate();
|
const StaleWhileRevalidate = new StaleWhileRevalidate();
|
||||||
// event.respondWith(StaleWhileRevalidate.handle({ event }));
|
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)
|
||||||
// if (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin') {
|
if (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin') {
|
||||||
// console.log('SAME ORIGIN!', event);
|
console.log('SAME ORIGIN!', event);
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
// event.respondWith(caches.match(event.request));
|
event.respondWith(caches.match(event.request));
|
||||||
// });
|
});
|
||||||
//
|
|
||||||
|
|
||||||
// const syncStore = {}
|
|
||||||
// self.addEventListener('message', event => {
|
|
||||||
// if (event.data.type === 'sync') {
|
|
||||||
// // get a unique id to save the data
|
|
||||||
// const id = uuid()
|
|
||||||
// syncStore[id] = event.data
|
|
||||||
// // register a sync and pass the id as tag for it to get the data
|
|
||||||
// self.registration.sync.register(id)
|
|
||||||
// }
|
|
||||||
// console.log(event.data)
|
|
||||||
// })
|
|
||||||
|
|
||||||
// addEventListener('fetch', event => {
|
const syncStore = {}
|
||||||
// // Prevent the default, and handle the request ourselves.
|
self.addEventListener('message', event => {
|
||||||
// event.respondWith(async function() {
|
if (event.data.type === 'sync') {
|
||||||
// // Try to get the response from a cache.
|
console.log('addEventListener - message')
|
||||||
// const cachedResponse = await caches.match(event.request);
|
// get a unique id to save the data
|
||||||
// // Return it if we found one.
|
const id = uuid()
|
||||||
// if (cachedResponse && (event.request.cache !== 'no-cache'))
|
syncStore[id] = event.data
|
||||||
// return cachedResponse;
|
// register a sync and pass the id as tag for it to get the data
|
||||||
//
|
self.registration.sync.register(id)
|
||||||
// // If we didn't find a match in the cache, use the network.
|
console.log('self.registration.sync.register(id)')
|
||||||
// return fetch(event.request);
|
}
|
||||||
// }());
|
console.log(event.data)
|
||||||
// });
|
})
|
||||||
|
|
||||||
// self.addEventListener('fetch', function (event) {
|
addEventListener('fetch', event => {
|
||||||
// event.respondWith(
|
// Prevent the default, and handle the request ourselves.
|
||||||
// caches.match(event.request).then(function (response) {
|
event.respondWith(async function() {
|
||||||
// return response ||
|
// Try to get the response from a cache.
|
||||||
// fetch(event.request, event.headers)
|
const cachedResponse = await caches.match(event.request);
|
||||||
// .catch(err => {
|
// Return it if we found one.
|
||||||
// console.log('_______________________ ERRORE FETCH SW: ', event.request, err)
|
if (cachedResponse && (event.request.cache !== 'no-cache'))
|
||||||
// writeData('config', { _id: 2, stateconn: 'offline' })
|
return cachedResponse;
|
||||||
// return caches.match(event.request);
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
// );
|
|
||||||
// });
|
|
||||||
|
|
||||||
// self.addEventListener('fetch', function (event) {
|
// If we didn't find a match in the cache, use the network.
|
||||||
// event.respondWith(
|
return fetch(event.request);
|
||||||
// fetch(event.request, event.headers)
|
}());
|
||||||
// .catch(err => {
|
});
|
||||||
// console.log('_______________________ ERRORE FETCH SW: ', event.request, err)
|
|
||||||
// writeData('config', {_id: 2, stateconn: 'offline'})
|
|
||||||
// return caches.match(event.request);
|
|
||||||
// })
|
|
||||||
// );
|
|
||||||
// });
|
|
||||||
|
|
||||||
// self.addEventListener('sync', function (event) {
|
self.addEventListener('fetch', function (event) {
|
||||||
// console.log('[Service Worker V5] Background syncing', event.tag);
|
event.respondWith(
|
||||||
//
|
caches.match(event.request).then(function (response) {
|
||||||
// let mystrparam = event.tag
|
return response ||
|
||||||
// let multiparams = mystrparam.split('|')
|
fetch(event.request, event.headers)
|
||||||
// if (multiparams) {
|
.catch(err => {
|
||||||
// if (multiparams.length > 3) {
|
console.log('_______________________ ERRORE FETCH SW: ', event.request, err)
|
||||||
// let cmd = multiparams[0]
|
writeData('config', { _id: 2, stateconn: 'offline' })
|
||||||
// let table = multiparams[1]
|
return caches.match(event.request);
|
||||||
// let method = multiparams[2]
|
})
|
||||||
// let token = multiparams[3]
|
})
|
||||||
// // let lang = multiparams[3]
|
);
|
||||||
//
|
});
|
||||||
// if (cmd === 'sync-todos') {
|
|
||||||
// console.log('[Service Worker] Syncing', cmd, table, method);
|
self.addEventListener('fetch', function (event) {
|
||||||
//
|
event.respondWith(
|
||||||
// const headers = new Headers()
|
fetch(event.request, event.headers)
|
||||||
// headers.append('content-Type', 'application/json')
|
.catch(err => {
|
||||||
// headers.append('Accept', 'application/json')
|
console.log('_______________________ ERRORE FETCH SW: ', event.request, err)
|
||||||
// headers.append('x-auth', token)
|
writeData('config', {_id: 2, stateconn: 'offline'})
|
||||||
//
|
return caches.match(event.request);
|
||||||
//
|
})
|
||||||
// // console.log('A1) INIZIO.............................................................');
|
);
|
||||||
//
|
});
|
||||||
// event.waitUntil(
|
|
||||||
// readAllData(table)
|
self.addEventListener('sync', function (event) {
|
||||||
// .then(function (alldata) {
|
console.log('[Service Worker V5] Background syncing', event);
|
||||||
// const myrecs = [...alldata]
|
console.log('event:', event);
|
||||||
// console.log('----------------------- LEGGO QUALCOSA DAL WAITUNTIL ')
|
|
||||||
// let errorfromserver = false
|
let mystrparam = event.tag
|
||||||
// if (myrecs) {
|
let multiparams = mystrparam.split('|')
|
||||||
// for (let rec of myrecs) {
|
if (multiparams) {
|
||||||
// //console.log('syncing', table, '', rec.descr)
|
if (multiparams.length > 3) {
|
||||||
// let link = cfgenv.serverweb + '/todos'
|
let cmd = multiparams[0]
|
||||||
//
|
let table = multiparams[1]
|
||||||
// if (method !== 'POST')
|
let method = multiparams[2]
|
||||||
// link += '/' + rec._id
|
let token = multiparams[3]
|
||||||
//
|
// let lang = multiparams[3]
|
||||||
// console.log('++++++++++++++++++ SYNCING !!!! ', rec.descr, table, 'FETCH: ', method, link, 'data:')
|
|
||||||
//
|
if (cmd === 'sync-todos') {
|
||||||
// // console.log('DATATOSAVE:', JSON.stringify(rec))
|
console.log('[Service Worker] Syncing', cmd, table, method);
|
||||||
//
|
|
||||||
// // Insert/Delete/Update table to the server
|
const headers = new Headers()
|
||||||
// fetch(link, {
|
headers.append('content-Type', 'application/json')
|
||||||
// method: method,
|
headers.append('Accept', 'application/json')
|
||||||
// headers: headers,
|
headers.append('x-auth', token)
|
||||||
// cache: 'no-cache',
|
|
||||||
// mode: 'cors', // 'no-cors',
|
|
||||||
// body: JSON.stringify(rec)
|
// console.log('A1) INIZIO.............................................................');
|
||||||
// })
|
|
||||||
// .then(() => {
|
event.waitUntil(
|
||||||
// deleteItemFromData(table, rec._id)
|
readAllData(table)
|
||||||
// })
|
.then(function (alldata) {
|
||||||
// .then(() => {
|
const myrecs = [...alldata]
|
||||||
// deleteItemFromData('swmsg', mystrparam)
|
console.log('----------------------- LEGGO QUALCOSA DAL WAITUNTIL ')
|
||||||
// })
|
let errorfromserver = false
|
||||||
// .catch(function (err) {
|
if (myrecs) {
|
||||||
// console.log('!!!!!!!!!!!!!!! Error while sending data', err, err.message);
|
for (let rec of myrecs) {
|
||||||
// if (err.message === 'Failed to fetch') {
|
//console.log('syncing', table, '', rec.descr)
|
||||||
// errorfromserver = true
|
let link = cfgenv.serverweb + '/todos'
|
||||||
// }
|
|
||||||
// })
|
if (method !== 'POST')
|
||||||
// }
|
link += '/' + rec._id
|
||||||
// return errorfromserver
|
|
||||||
// }
|
console.log('++++++++++++++++++ SYNCING !!!! ', rec.descr, table, 'FETCH: ', method, link, 'data:')
|
||||||
// })
|
|
||||||
// .then((errorfromserver) => {
|
// console.log('DATATOSAVE:', JSON.stringify(rec))
|
||||||
// const mystate = !errorfromserver ? 'online' : 'offline'
|
|
||||||
// writeData('config', { _id: 2, stateconn: mystate })
|
// Insert/Delete/Update table to the server
|
||||||
// })
|
fetch(link, {
|
||||||
// );
|
method: method,
|
||||||
// // console.log('A2) ?????????????????????????? ESCO DAL LOOP !!!!!!!!! err=')
|
headers: headers,
|
||||||
// }
|
cache: 'no-cache',
|
||||||
// }
|
mode: 'cors', // 'no-cors',
|
||||||
// }
|
body: JSON.stringify(rec)
|
||||||
// })
|
})
|
||||||
// ;
|
.then(() => {
|
||||||
|
deleteItemFromData(table, rec._id)
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
deleteItemFromData('swmsg', mystrparam)
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
console.log('!!!!!!!!!!!!!!! Error while sending data', err, err.message);
|
||||||
|
if (err.message === 'Failed to fetch') {
|
||||||
|
errorfromserver = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return errorfromserver
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then((errorfromserver) => {
|
||||||
|
const mystate = !errorfromserver ? 'online' : 'offline'
|
||||||
|
writeData('config', { _id: 2, stateconn: mystate })
|
||||||
|
})
|
||||||
|
);
|
||||||
|
// console.log('A2) ?????????????????????????? ESCO DAL LOOP !!!!!!!!! err=')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
@@ -565,28 +570,62 @@ self.addEventListener('push', (event) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
let isobj = false
|
||||||
if (event.data) {
|
if (event.data) {
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(event.data.text())
|
data = JSON.parse(event.data.text())
|
||||||
|
isobj = true
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
data = event.data.text()
|
data = event.data.text()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const options = {
|
console.log('event.data', data)
|
||||||
body: data.content,
|
|
||||||
icon: '/images/android-chrome-192x192.png',
|
let options = {}
|
||||||
badge: '/images/android-chrome-192x192.png',
|
|
||||||
data: {
|
let myid = '0'
|
||||||
url: data.url,
|
|
||||||
},
|
if (isobj) {
|
||||||
tag: 'received',
|
if (data.id) {
|
||||||
renitify: true, // vibrate also with others messages.
|
myid = data.id
|
||||||
|
}
|
||||||
|
|
||||||
|
options = {
|
||||||
|
body: data.content,
|
||||||
|
icon: data.icon ? data.icon : '/images/android-chrome-192x192.png',
|
||||||
|
badge: data.badge ? data.badge : '/images/android-chrome-192x192.png',
|
||||||
|
data: {
|
||||||
|
url: data.url,
|
||||||
|
},
|
||||||
|
tag: data.tag,
|
||||||
|
renitify: true, // vibrate also with others messages.
|
||||||
|
}
|
||||||
|
|
||||||
|
event.waitUntil(
|
||||||
|
self.registration.showNotification(data.title ? data.title : data.content, options),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
let text = data;
|
||||||
|
options = {
|
||||||
|
body: text,
|
||||||
|
icon: '/images/android-chrome-192x192.png',
|
||||||
|
badge: '/images/android-chrome-192x192.png',
|
||||||
|
data: {
|
||||||
|
url: '/',
|
||||||
|
},
|
||||||
|
tag: 'notif',
|
||||||
|
renitify: true, // vibrate also with others messages.
|
||||||
|
}
|
||||||
|
|
||||||
|
event.waitUntil(
|
||||||
|
self.registration.showNotification('', options),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
event.waitUntil(
|
self.registration.sync.register(myid)
|
||||||
self.registration.showNotification(data.title, options),
|
writeData('notifications', { _id: myid, tag: options.tag })
|
||||||
)
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('Error on event push:', e)
|
console.log('Error on event push:', e)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export const shared_consts = {
|
|||||||
FILTER_ASK_ZOOM_VISTO: 32768,
|
FILTER_ASK_ZOOM_VISTO: 32768,
|
||||||
FILTER_HOURS_MYLIST: 65536,
|
FILTER_HOURS_MYLIST: 65536,
|
||||||
FILTER_HOURS_ALL: 131072,
|
FILTER_HOURS_ALL: 131072,
|
||||||
FILTER_MISSING_PAYMENT: 262144,
|
FILTER_REPORTED: 262144,
|
||||||
FILTER_TO_MAKE_MEMBERSHIP_CARD: 524288,
|
FILTER_TO_MAKE_MEMBERSHIP_CARD: 524288,
|
||||||
FILTER_MEMBERSHIP_CARD_OK: 1048576,
|
FILTER_MEMBERSHIP_CARD_OK: 1048576,
|
||||||
FILTER_USER_NO_VERIFIED_APORTADOR: 2097152,
|
FILTER_USER_NO_VERIFIED_APORTADOR: 2097152,
|
||||||
|
|||||||
@@ -78,14 +78,6 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getenv(myvar: any) {
|
|
||||||
try {
|
|
||||||
return process.env[myvar]
|
|
||||||
} catch (e) {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getPermission() {
|
function getPermission() {
|
||||||
return Notification.permission
|
return Notification.permission
|
||||||
}
|
}
|
||||||
@@ -123,7 +115,6 @@ export default defineComponent({
|
|||||||
appname,
|
appname,
|
||||||
meta,
|
meta,
|
||||||
mystilecard,
|
mystilecard,
|
||||||
getenv,
|
|
||||||
getPermission,
|
getPermission,
|
||||||
NotServiceWorker,
|
NotServiceWorker,
|
||||||
PagLogin,
|
PagLogin,
|
||||||
|
|||||||
@@ -131,10 +131,6 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getenv(myvar: any) {
|
|
||||||
return process.env[myvar]
|
|
||||||
}
|
|
||||||
|
|
||||||
function initprompt() {
|
function initprompt() {
|
||||||
window.addEventListener('beforeinstallprompt', function (event) {
|
window.addEventListener('beforeinstallprompt', function (event) {
|
||||||
// console.log('******************************** beforeinstallprompt fired')
|
// console.log('******************************** beforeinstallprompt fired')
|
||||||
@@ -232,7 +228,6 @@ export default defineComponent({
|
|||||||
getappname,
|
getappname,
|
||||||
appname,
|
appname,
|
||||||
mystilecard,
|
mystilecard,
|
||||||
getenv,
|
|
||||||
getPermission,
|
getPermission,
|
||||||
NotServiceWorker,
|
NotServiceWorker,
|
||||||
PagLogin,
|
PagLogin,
|
||||||
|
|||||||
@@ -78,14 +78,6 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getenv(myvar: any) {
|
|
||||||
try {
|
|
||||||
return process.env[myvar]
|
|
||||||
} catch (e) {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getPermission() {
|
function getPermission() {
|
||||||
return Notification.permission
|
return Notification.permission
|
||||||
}
|
}
|
||||||
@@ -123,7 +115,6 @@ export default defineComponent({
|
|||||||
appname,
|
appname,
|
||||||
meta,
|
meta,
|
||||||
mystilecard,
|
mystilecard,
|
||||||
getenv,
|
|
||||||
getPermission,
|
getPermission,
|
||||||
NotServiceWorker,
|
NotServiceWorker,
|
||||||
PagLogin,
|
PagLogin,
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
// import { useGlobalStore } from '@store/globalStore'
|
// import { useGlobalStore } from '@store/globalStore'
|
||||||
// import indexdb from './indexdb'
|
|
||||||
|
|
||||||
import indexdb from './indexdb'
|
import indexdb from './indexdb'
|
||||||
|
|
||||||
import { idbKeyval as storage } from '@src/js/storage'
|
import { idbKeyval as storage } from '@src/js/storage'
|
||||||
|
|
||||||
export default async (cmd: string, table: string, data: any = null, id = '') => {
|
export default async (cmd: string, table: string, data: any = null, id: any = '') => {
|
||||||
// const globalStore = useGlobalStore()
|
// const globalStore = useGlobalStore()
|
||||||
|
|
||||||
// const descr = data !== null ? data.descr : ''
|
// const descr = data !== null ? data.descr : ''
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ import { useUserStore } from '@store/UserStore'
|
|||||||
import { useGlobalStore } from '@store/globalStore'
|
import { useGlobalStore } from '@store/globalStore'
|
||||||
import { idbKeyval as storage } from '../js/storage.js'
|
import { idbKeyval as storage } from '../js/storage.js'
|
||||||
|
|
||||||
function writeConfigIndexDb(context: any, data: any) {
|
function writeConfigIndexDb(data: any) {
|
||||||
// console.log('writeConfigIndexDb', data)
|
// console.log('writeConfigIndexDb', data)
|
||||||
|
|
||||||
storage.setdata('config', data)
|
storage.setdata('config', data)
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveConfigIndexDb(context: any) {
|
function saveConfigIndexDb() {
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
|
|
||||||
const data: ICfgData = {
|
const data: ICfgData = {
|
||||||
@@ -22,10 +22,10 @@ function saveConfigIndexDb(context: any) {
|
|||||||
userId: userStore.my._id,
|
userId: userStore.my._id,
|
||||||
}
|
}
|
||||||
|
|
||||||
writeConfigIndexDb('config', data)
|
writeConfigIndexDb(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function readfromIndexDbToState(context: any, table: string) {
|
async function readfromIndexDbToState(table: string) {
|
||||||
console.log('*** readfromIndexDbToState ***', table)
|
console.log('*** readfromIndexDbToState ***', table)
|
||||||
|
|
||||||
return storage.getalldata(table)
|
return storage.getalldata(table)
|
||||||
@@ -79,13 +79,13 @@ function consolelogpao(str: string, str2 = '', str3 = '') {
|
|||||||
// Todos.mutations.setTestpao(str + str2 + str3)
|
// Todos.mutations.setTestpao(str + str2 + str3)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async (context: any, cmd: string, table: string, datakey: any = null, id = '') => {
|
export default async (cmd: string, table: string, datakey: any = null, id: any = '') => {
|
||||||
const globalStore = useGlobalStore()
|
const globalStore = useGlobalStore()
|
||||||
try {
|
try {
|
||||||
// console.log('TABLE', table, 'cmd', cmd)
|
// console.log('TABLE', table, 'cmd', cmd)
|
||||||
if (cmd === 'loadapp') {
|
if (cmd === 'loadapp') {
|
||||||
// ****** LOAD APP AL CARICAMENTO ! *******
|
// ****** LOAD APP AL CARICAMENTO ! *******
|
||||||
return saveConfigIndexDb(context)
|
return saveConfigIndexDb()
|
||||||
}
|
}
|
||||||
if (cmd === 'write') {
|
if (cmd === 'write') {
|
||||||
if (globalStore) {
|
if (globalStore) {
|
||||||
@@ -94,7 +94,7 @@ export default async (context: any, cmd: string, table: string, datakey: any = n
|
|||||||
return await storage.setdata(table, datakey)
|
return await storage.setdata(table, datakey)
|
||||||
}
|
}
|
||||||
if (cmd === 'updatefromIndexedDbToState') {
|
if (cmd === 'updatefromIndexedDbToState') {
|
||||||
return await readfromIndexDbToState(context, table)
|
return await readfromIndexDbToState(table)
|
||||||
}
|
}
|
||||||
if (cmd === 'readall') {
|
if (cmd === 'readall') {
|
||||||
if (globalStore) {
|
if (globalStore) {
|
||||||
@@ -104,7 +104,9 @@ export default async (context: any, cmd: string, table: string, datakey: any = n
|
|||||||
return await storage.getalldata(table)
|
return await storage.getalldata(table)
|
||||||
}
|
}
|
||||||
if (cmd === 'count') {
|
if (cmd === 'count') {
|
||||||
return await storage.count(table)
|
let contatore = await storage.count(table)
|
||||||
|
// console.log('COUNT:', table, contatore)
|
||||||
|
return contatore
|
||||||
}
|
}
|
||||||
if (cmd === 'read') {
|
if (cmd === 'read') {
|
||||||
if (globalStore) {
|
if (globalStore) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export let idbKeyval = (() => {
|
|||||||
// console.log('CREO DB STORAGE JS !')
|
// console.log('CREO DB STORAGE JS !')
|
||||||
db = new Promise((resolve, reject) => {
|
db = new Promise((resolve, reject) => {
|
||||||
// console.log('open mydb3')
|
// console.log('open mydb3')
|
||||||
const openreq = indexedDB.open('mydb3', 12);
|
const openreq = indexedDB.open('mydb3', 13);
|
||||||
|
|
||||||
openreq.onerror = () => {
|
openreq.onerror = () => {
|
||||||
reject(openreq.error);
|
reject(openreq.error);
|
||||||
@@ -50,7 +50,7 @@ export let idbKeyval = (() => {
|
|||||||
return {
|
return {
|
||||||
async get(key) {
|
async get(key) {
|
||||||
let req;
|
let req;
|
||||||
withStore('readonly', 'keyval', store => {
|
await withStore('readonly', 'keyval', store => {
|
||||||
req = store.get(key);
|
req = store.get(key);
|
||||||
});
|
});
|
||||||
return req.result;
|
return req.result;
|
||||||
@@ -62,30 +62,49 @@ export let idbKeyval = (() => {
|
|||||||
async getdata(table, key) {
|
async getdata(table, key) {
|
||||||
let req;
|
let req;
|
||||||
|
|
||||||
withStore('readonly', table, store => {
|
|
||||||
|
await withStore('readonly', table, store => {
|
||||||
// console.log('getdata', table, key)
|
// console.log('getdata', table, key)
|
||||||
req = store.get(key);
|
req = store.get(key);
|
||||||
|
// console.log(' req', req)
|
||||||
});
|
});
|
||||||
|
|
||||||
return req.result;
|
if (req) {
|
||||||
|
console.log('getdata', table, key, req.result)
|
||||||
|
return req.result;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async getalldata(table) {
|
async getalldata(table) {
|
||||||
let req;
|
let req;
|
||||||
withStore('readonly', table, store => {
|
await withStore('readonly', table, store => {
|
||||||
req = store.getAll();
|
req = store.getAll();
|
||||||
|
console.log(' req', req)
|
||||||
});
|
});
|
||||||
return req.result;
|
if (req) {
|
||||||
|
return req.result;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async count(table) {
|
async count(table) {
|
||||||
let req;
|
let req;
|
||||||
withStore('readonly', table, store => {
|
await withStore('readonly', table, store => {
|
||||||
req = store.count();
|
req = store.count();
|
||||||
});
|
});
|
||||||
return req.result;
|
|
||||||
|
// console.log('req', req)
|
||||||
|
if (req) {
|
||||||
|
// console.log('COUNT:', table, req.result)
|
||||||
|
return req.result;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async set(key, value) {
|
async set(key, value) {
|
||||||
let req;
|
let req;
|
||||||
withStore('readwrite', 'keyval', store => {
|
await withStore('readwrite', 'keyval', store => {
|
||||||
req = store.put(value, key);
|
req = store.put(value, key);
|
||||||
});
|
});
|
||||||
return req.result;
|
return req.result;
|
||||||
@@ -94,7 +113,7 @@ export let idbKeyval = (() => {
|
|||||||
let req;
|
let req;
|
||||||
|
|
||||||
// console.log('setdata', table, value)
|
// console.log('setdata', table, value)
|
||||||
withStore('readwrite', table, store => {
|
await withStore('readwrite', table, store => {
|
||||||
req = store.put(value);
|
req = store.put(value);
|
||||||
});
|
});
|
||||||
return req.result;
|
return req.result;
|
||||||
@@ -121,6 +140,7 @@ export let idbKeyval = (() => {
|
|||||||
// iOS add-to-homescreen is missing IDB, or at least it used to.
|
// iOS add-to-homescreen is missing IDB, or at least it used to.
|
||||||
// I haven't tested this in a while.
|
// I haven't tested this in a while.
|
||||||
if (!self.indexedDB) {
|
if (!self.indexedDB) {
|
||||||
|
console.log('NO indexedDB')
|
||||||
idbKeyval = {
|
idbKeyval = {
|
||||||
get: key => Promise.resolve(localStorage.getItem(key)),
|
get: key => Promise.resolve(localStorage.getItem(key)),
|
||||||
set: (key, val) => Promise.resolve(localStorage.setItem(key, val)),
|
set: (key, val) => Promise.resolve(localStorage.setItem(key, val)),
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import { shared_consts } from '@/common/shared_vuejs'
|
|||||||
import { useI18n } from '@/boot/i18n'
|
import { useI18n } from '@/boot/i18n'
|
||||||
import { useQuasar } from 'quasar'
|
import { useQuasar } from 'quasar'
|
||||||
import { costanti } from '@costanti'
|
import { costanti } from '@costanti'
|
||||||
|
import { waitAndcheckPendingNotif } from '../../../store/Modules/ApiTables'
|
||||||
|
|
||||||
const namespace = 'notifModule'
|
const namespace = 'notifModule'
|
||||||
|
|
||||||
@@ -50,6 +51,9 @@ export default defineComponent({
|
|||||||
const userId = ref('')
|
const userId = ref('')
|
||||||
const open = ref(false)
|
const open = ref(false)
|
||||||
|
|
||||||
|
const polling = ref(<any> null)
|
||||||
|
const eseguipolling = ref(true)
|
||||||
|
|
||||||
const notifsel = ref(<INotif>{
|
const notifsel = ref(<INotif>{
|
||||||
dest: '',
|
dest: '',
|
||||||
datenotif: new Date()
|
datenotif: new Date()
|
||||||
@@ -61,6 +65,30 @@ export default defineComponent({
|
|||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
function checkIfArrivedSomeNotif() {
|
||||||
|
waitAndcheckPendingNotif()
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkifpolling() {
|
||||||
|
console.log('checkifpolling')
|
||||||
|
if (eseguipolling.value) {
|
||||||
|
if (!polling.value) {
|
||||||
|
console.log('esegui POLLING....')
|
||||||
|
polling.value = setInterval(() => {
|
||||||
|
checkIfArrivedSomeNotif()
|
||||||
|
}, 3000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function beforeDestroy() {
|
||||||
|
console.log('beforeDestroy')
|
||||||
|
if (polling.value)
|
||||||
|
clearInterval(polling.value)
|
||||||
|
}
|
||||||
|
|
||||||
watch(() => usernotifs.value, async (to: any, from: any) => {
|
watch(() => usernotifs.value, async (to: any, from: any) => {
|
||||||
|
|
||||||
if (usernotifs.value) {
|
if (usernotifs.value) {
|
||||||
@@ -152,6 +180,7 @@ export default defineComponent({
|
|||||||
async function mounted() {
|
async function mounted() {
|
||||||
myuser.value = userStore.my
|
myuser.value = userStore.my
|
||||||
await refreshdata(userStore.my.username)
|
await refreshdata(userStore.my.username)
|
||||||
|
checkifpolling()
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(mounted)
|
onMounted(mounted)
|
||||||
@@ -177,7 +206,6 @@ export default defineComponent({
|
|||||||
notifStore,
|
notifStore,
|
||||||
show_all,
|
show_all,
|
||||||
t,
|
t,
|
||||||
$q,
|
|
||||||
username,
|
username,
|
||||||
userStore,
|
userStore,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export interface IMessage {
|
|||||||
read?: boolean
|
read?: boolean
|
||||||
deleted?: boolean
|
deleted?: boolean
|
||||||
status?: StatusMessage
|
status?: StatusMessage
|
||||||
options?: number
|
typesend?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface INotif {
|
export interface INotif {
|
||||||
@@ -120,4 +120,5 @@ export interface INotifState {
|
|||||||
last_notifs: INotif[]
|
last_notifs: INotif[]
|
||||||
show_all: boolean
|
show_all: boolean
|
||||||
updateNotification: boolean
|
updateNotification: boolean
|
||||||
|
countNotif: number
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
<CMyPage img="" :title="$t('otherpages.admin.userpanel')" keywords="" :description="$t('otherpages.admin.userpanel')">
|
<CMyPage img="" :title="$t('otherpages.admin.userpanel')" keywords="" :description="$t('otherpages.admin.userpanel')">
|
||||||
|
|
||||||
<q-btn color="green" label="Esporta Lista Email" @click="exportListaEmail"></q-btn>
|
<q-btn color="green" label="Esporta Lista Email" @click="exportListaEmail"></q-btn>
|
||||||
<div class="q-ma-sm row bordo_stondato" style="min-width: 300px; ">
|
<br>
|
||||||
|
|
||||||
|
<div v-if="myuser.username" class="q-ma-sm row bordo_stondato" style="min-width: 300px; ">
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<q-select rounded outlined v-model="notifdirtype" :options="listnotiftype" label="Tipo" emit-value map-options>
|
<q-select rounded outlined v-model="notifdirtype" :options="listnotiftype" label="Tipo" emit-value map-options>
|
||||||
@@ -65,7 +67,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="!!myuser && search">
|
<div v-if="myuser.username">
|
||||||
username cercato: <em>"{{ search }}"</em><br>
|
username cercato: <em>"{{ search }}"</em><br>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ export default defineComponent({
|
|||||||
label: 'Non hanno l\'Invitante',
|
label: 'Non hanno l\'Invitante',
|
||||||
value: shared_consts.FILTER_USER_NO_INVITANTE
|
value: shared_consts.FILTER_USER_NO_INVITANTE
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Segnalati',
|
||||||
|
value: shared_consts.FILTER_REPORTED
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'No Approv. Invitante',
|
label: 'No Approv. Invitante',
|
||||||
value: shared_consts.FILTER_USER_NO_VERIFIED_APORTADOR
|
value: shared_consts.FILTER_USER_NO_VERIFIED_APORTADOR
|
||||||
|
|||||||
@@ -415,6 +415,9 @@ const msg_it = {
|
|||||||
verified_by_aportador: 'Verificato',
|
verified_by_aportador: 'Verificato',
|
||||||
notAsk_ToVerify: 'No Verif. Reg',
|
notAsk_ToVerify: 'No Verif. Reg',
|
||||||
trust_modified: 'Fiducia Modificata',
|
trust_modified: 'Fiducia Modificata',
|
||||||
|
reported: 'Segnalato',
|
||||||
|
username_who_reported: 'Segnal da',
|
||||||
|
date_reported: 'Data Segnal.',
|
||||||
blocked: 'Bloccato',
|
blocked: 'Bloccato',
|
||||||
username_who_block: 'Bloccato da',
|
username_who_block: 'Bloccato da',
|
||||||
username_regala_invitato: 'Username del Destinatario del regalo',
|
username_regala_invitato: 'Username del Destinatario del regalo',
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { Api } from '@api'
|
|||||||
import * as Types from '@src/store/Api/ApiTypes'
|
import * as Types from '@src/store/Api/ApiTypes'
|
||||||
|
|
||||||
async function sendRequest(url: string, method: string, mydata: any) {
|
async function sendRequest(url: string, method: string, mydata: any) {
|
||||||
if (!process.env.DEBUG) console.log('sendRequest', method, url)
|
if (process.env.DEBUG) console.log('sendRequest', method, url)
|
||||||
|
|
||||||
let request
|
let request
|
||||||
if (method === 'GET') request = Api.get(url, mydata)
|
if (method === 'GET') request = Api.get(url, mydata)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { useUserStore } from '@store/UserStore'
|
|||||||
import { tools } from '@src/store/Modules/tools'
|
import { tools } from '@src/store/Modules/tools'
|
||||||
import * as Types from './ApiTypes'
|
import * as Types from './ApiTypes'
|
||||||
|
|
||||||
export let API_URL = process.env.MONGODB_HOST
|
export let API_URL = ''
|
||||||
export const axiosInstance: AxiosInstance = axios.create({
|
export const axiosInstance: AxiosInstance = axios.create({
|
||||||
baseURL: API_URL,
|
baseURL: API_URL,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -18,14 +18,14 @@ export const axiosInstance: AxiosInstance = axios.create({
|
|||||||
axiosInstance.interceptors.response.use(
|
axiosInstance.interceptors.response.use(
|
||||||
|
|
||||||
(response) => {
|
(response) => {
|
||||||
if (process.env.DEBUG === '1') console.log(response)
|
if (process.env.DEBUGGING === '1') console.log(response)
|
||||||
return response
|
return response
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
const globalStore = useGlobalStore()
|
const globalStore = useGlobalStore()
|
||||||
// console.log('error', error)
|
// console.log('error', error)
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
if (process.env.DEBUG === '1') console.log('Status = ', error.response.status)
|
if (process.env.DEBUGGING === '1') console.log('Status = ', error.response.status)
|
||||||
console.log('Request Error: ', error.response)
|
console.log('Request Error: ', error.response)
|
||||||
if (error.response.status !== 0) {
|
if (error.response.status !== 0) {
|
||||||
globalStore.setStateConnection('online')
|
globalStore.setStateConnection('online')
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ export const Api = {
|
|||||||
idapp: process.env.APP_ID,
|
idapp: process.env.APP_ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('INIZIO - SendReq', url)
|
// console.log('INIZIO - SendReq', url)
|
||||||
// console.log('mydata', mydata)
|
// console.log('mydata', mydata)
|
||||||
|
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
@@ -145,7 +145,7 @@ export const Api = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async syncAlternative(mystrparam: string) {
|
async syncAlternative(mystrparam: string) {
|
||||||
// console.log('[ALTERNATIVE Background syncing', mystrparam)
|
console.log('[ALTERNATIVE Background syncing', mystrparam)
|
||||||
|
|
||||||
const multiparams = mystrparam.split('|')
|
const multiparams = mystrparam.split('|')
|
||||||
if (multiparams) {
|
if (multiparams) {
|
||||||
|
|||||||
@@ -106,8 +106,8 @@ export const useMessageStore = defineStore('MessageStore', {
|
|||||||
data.datemsg = tools.getDateNow()
|
data.datemsg = tools.getDateNow()
|
||||||
data.status = StatusMessage.WaitingToSend
|
data.status = StatusMessage.WaitingToSend
|
||||||
// Options
|
// Options
|
||||||
data.options = tools.SetBit(data.options, shared_consts.MessageOptions.Notify_ByEmail)
|
data.typesend = tools.SetBit(data.typesend, shared_consts.MessageOptions.Notify_ByEmail)
|
||||||
data.options = tools.SetBit(data.options, shared_consts.MessageOptions.Notify_ByPushNotification)
|
data.typesend = tools.SetBit(data.typesend, shared_consts.MessageOptions.Notify_ByPushNotification)
|
||||||
|
|
||||||
// console.log('DOPO:')
|
// console.log('DOPO:')
|
||||||
// console.table(data)
|
// console.table(data)
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ import { useGlobalStore } from '@store/globalStore'
|
|||||||
import globalroutines from '../../globalroutines/index'
|
import globalroutines from '../../globalroutines/index'
|
||||||
import { useProjectStore } from '@store/Projects'
|
import { useProjectStore } from '@store/Projects'
|
||||||
import { useTodoStore } from '@store/Todos'
|
import { useTodoStore } from '@store/Todos'
|
||||||
|
import { useNotifStore } from '@store/NotifStore'
|
||||||
|
|
||||||
export function getLinkByTableName(nametable: string) {
|
export function getLinkByTableName(nametable: string) {
|
||||||
if (nametable === 'todos') {
|
if (nametable === 'todos') {
|
||||||
return 'todos'
|
return 'todos'
|
||||||
}
|
} else if (nametable === 'projects') {
|
||||||
if (nametable === 'projects') {
|
|
||||||
return 'projects'
|
return 'projects'
|
||||||
}
|
}
|
||||||
return ''
|
return ''
|
||||||
@@ -34,13 +34,13 @@ export const DB = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function allTables() {
|
export function allTables() {
|
||||||
/* const myarr = OtherTables
|
const myarr = OtherTables
|
||||||
for (const tab of costanti.MainTables) {
|
for (const tab of MainTables) {
|
||||||
for (const method of costanti.allMethod) {
|
for (const method of allMethod) {
|
||||||
myarr.push(method + tab)
|
myarr.push(method + tab)
|
||||||
}
|
}
|
||||||
} */
|
}
|
||||||
return costanti.OtherTables
|
return myarr
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updatefromIndexedDbToState(nametab: string) {
|
async function updatefromIndexedDbToState(nametab: string) {
|
||||||
@@ -52,7 +52,7 @@ async function updatefromIndexedDbToState(nametab: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function checkPendingMsg() {
|
async function checkPendingMsg() {
|
||||||
// console.log('checkPendingMsg')
|
console.log('checkPendingMsg')
|
||||||
const globalStore = useGlobalStore()
|
const globalStore = useGlobalStore()
|
||||||
|
|
||||||
const config = await globalroutines('read', 'config', null, '1')
|
const config = await globalroutines('read', 'config', null, '1')
|
||||||
@@ -82,8 +82,26 @@ async function checkPendingMsg() {
|
|||||||
}).catch(() => reject()))
|
}).catch(() => reject()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function checkPendingNotif() {
|
||||||
|
|
||||||
|
const notifStore = useNotifStore()
|
||||||
|
|
||||||
|
const howmanybefore = notifStore.countNotif
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
|
return new Promise((resolve, reject) => globalroutines('count', 'notifications')
|
||||||
|
.then((count) => {
|
||||||
|
if (count !== howmanybefore) {
|
||||||
|
notifStore.setCountNotifs(count)
|
||||||
|
return resolve(true)
|
||||||
|
}
|
||||||
|
return resolve(false)
|
||||||
|
}).catch(() => reject()))
|
||||||
|
}
|
||||||
|
|
||||||
function useServiceWorker() {
|
function useServiceWorker() {
|
||||||
return false // return 'serviceWorker' in navigator
|
return 'serviceWorker' in navigator
|
||||||
|
// return false //
|
||||||
}
|
}
|
||||||
|
|
||||||
// If something in the call of Service Worker went wrong (Network or Server Down), then retry !
|
// If something in the call of Service Worker went wrong (Network or Server Down), then retry !
|
||||||
@@ -99,7 +117,7 @@ async function sendSwMsgIfAvailable() {
|
|||||||
.then(() => globalroutines('readall', 'swmsg')
|
.then(() => globalroutines('readall', 'swmsg')
|
||||||
.then((arr_recmsg) => {
|
.then((arr_recmsg) => {
|
||||||
if (arr_recmsg.length > 0) {
|
if (arr_recmsg.length > 0) {
|
||||||
// console.log('---------------------- 2) navigator (2) .serviceWorker.ready')
|
console.log('---------------------- 2) navigator (2) .serviceWorker.ready')
|
||||||
let promiseChain = Promise.resolve()
|
let promiseChain = Promise.resolve()
|
||||||
|
|
||||||
for (const rec of arr_recmsg) {
|
for (const rec of arr_recmsg) {
|
||||||
@@ -130,6 +148,14 @@ export async function waitAndRefreshData() {
|
|||||||
return await todos.dbLoad({ checkPending: false })
|
return await todos.dbLoad({ checkPending: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function waitAndRefreshNotif() {
|
||||||
|
|
||||||
|
const notifStore = useNotifStore()
|
||||||
|
|
||||||
|
notifStore.updateNotification = true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function waitAndcheckPendingMsg() {
|
export async function waitAndcheckPendingMsg() {
|
||||||
// await aspettansec(1000)
|
// await aspettansec(1000)
|
||||||
const globalStore = useGlobalStore()
|
const globalStore = useGlobalStore()
|
||||||
@@ -157,6 +183,21 @@ export async function waitAndcheckPendingMsg() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function waitAndcheckPendingNotif() {
|
||||||
|
// await aspettansec(1000)
|
||||||
|
const globalStore = useGlobalStore()
|
||||||
|
|
||||||
|
return checkPendingNotif()
|
||||||
|
.then((ris) => {
|
||||||
|
if (ris) {
|
||||||
|
if (globalStore.isOnline()) { // If is Offline, then check
|
||||||
|
return waitAndRefreshNotif()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async function dbInsertSave(call: string, item: any, method: string) {
|
async function dbInsertSave(call: string, item: any, method: string) {
|
||||||
let ret = true
|
let ret = true
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ export const costanti = {
|
|||||||
|
|
||||||
MAX_PHASES: 5,
|
MAX_PHASES: 5,
|
||||||
|
|
||||||
OtherTables: ['config', 'swmsg'],
|
OtherTables: ['config', 'swmsg', 'notifications'],
|
||||||
// export const MainTables = ['todos', 'projects']
|
// export const MainTables = ['todos', 'projects']
|
||||||
MainTables: [],
|
MainTables: [],
|
||||||
allMethod: ['sync_post_', 'sync_patch_', 'delete_', 'hide_'],
|
allMethod: ['sync_post_', 'sync_patch_', 'delete_', 'hide_'],
|
||||||
|
|||||||
@@ -2156,8 +2156,8 @@ export const colTableUsersISP = [
|
|||||||
AddCol({ name: 'username_who_block', label_trans: 'reg.username_who_block' }),
|
AddCol({ name: 'username_who_block', label_trans: 'reg.username_who_block' }),
|
||||||
AddCol({ name: 'date_blocked', label_trans: 'reg.date_blocked', fieldtype: costanti.FieldType.date }),
|
AddCol({ name: 'date_blocked', label_trans: 'reg.date_blocked', fieldtype: costanti.FieldType.date }),
|
||||||
AddCol({ name: 'reported', label_trans: 'reg.reported', fieldtype: costanti.FieldType.boolean }),
|
AddCol({ name: 'reported', label_trans: 'reg.reported', fieldtype: costanti.FieldType.boolean }),
|
||||||
AddCol({ name: 'username_who_reported', label_trans: 'reg.username_who_reported' }),
|
AddCol({ name: 'username_who_report', label_trans: 'reg.username_who_reported' }),
|
||||||
AddCol({ name: 'date_reported', label_trans: 'reg.date_reported', fieldtype: costanti.FieldType.date }),
|
AddCol({ name: 'date_report', label_trans: 'reg.date_reported', fieldtype: costanti.FieldType.date }),
|
||||||
AddCol({
|
AddCol({
|
||||||
name: 'profile.resplist',
|
name: 'profile.resplist',
|
||||||
field: 'profile',
|
field: 'profile',
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ export const tools = {
|
|||||||
TABBED_HOME: 't-home',
|
TABBED_HOME: 't-home',
|
||||||
TABBED_NAVE: 't-nave',
|
TABBED_NAVE: 't-nave',
|
||||||
|
|
||||||
|
|
||||||
FILTER_ALL: 0,
|
FILTER_ALL: 0,
|
||||||
FILTER_MYREC: 1,
|
FILTER_MYREC: 1,
|
||||||
FILTER_MYFOLLOW: 2,
|
FILTER_MYFOLLOW: 2,
|
||||||
@@ -5627,6 +5628,14 @@ export const tools = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getEnv(name: string) {
|
||||||
|
const config: any = {
|
||||||
|
// @ts-ignore
|
||||||
|
VUE_APP_BACKEND_API_URL: window?.appConfig?.VUE_APP_BACKEND_API_URL || process.env.VUE_APP_BACKEND_API_URL
|
||||||
|
}
|
||||||
|
|
||||||
|
return config[name];
|
||||||
|
},
|
||||||
|
|
||||||
// getLocale() {
|
// getLocale() {
|
||||||
// if (navigator.languages && navigator.languages.length > 0) {
|
// if (navigator.languages && navigator.languages.length > 0) {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ export const useNotifStore = defineStore('NotifStore', {
|
|||||||
last_notifs: [],
|
last_notifs: [],
|
||||||
show_all: true,
|
show_all: true,
|
||||||
updateNotification: false,
|
updateNotification: false,
|
||||||
|
countNotif: 0,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getters: {
|
getters: {
|
||||||
@@ -32,11 +33,17 @@ export const useNotifStore = defineStore('NotifStore', {
|
|||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
|
||||||
|
updateArrNotif() {
|
||||||
|
this.setBadgeIconApp()
|
||||||
|
},
|
||||||
|
|
||||||
setNotif(notif: INotif) {
|
setNotif(notif: INotif) {
|
||||||
console.log('setNotif', notif)
|
console.log('setNotif', notif)
|
||||||
if (notif) {
|
if (notif) {
|
||||||
this.last_notifs = [notif, ...this.last_notifs]
|
this.last_notifs = [notif, ...this.last_notifs]
|
||||||
}
|
}
|
||||||
|
this.updateArrNotif()
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setAsRead(idnotif: string) {
|
setAsRead(idnotif: string) {
|
||||||
@@ -44,6 +51,18 @@ export const useNotifStore = defineStore('NotifStore', {
|
|||||||
if (rec) {
|
if (rec) {
|
||||||
rec.read = true
|
rec.read = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.updateArrNotif()
|
||||||
|
},
|
||||||
|
|
||||||
|
async setBadgeIconApp(){
|
||||||
|
// Get our dummy count and update it,
|
||||||
|
// just to give more context for this demo.
|
||||||
|
const countNow = this.getnumNotifUnread()
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
await navigator.setAppBadge(countNow)
|
||||||
|
.catch((error: any) => { /* ... */ });
|
||||||
},
|
},
|
||||||
|
|
||||||
setAllRead(username: string) {
|
setAllRead(username: string) {
|
||||||
@@ -55,6 +74,7 @@ export const useNotifStore = defineStore('NotifStore', {
|
|||||||
rec.read = true
|
rec.read = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.updateArrNotif()
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@@ -71,6 +91,7 @@ export const useNotifStore = defineStore('NotifStore', {
|
|||||||
this.last_notifs = this.last_notifs.filter((rec) => rec._id !== id)
|
this.last_notifs = this.last_notifs.filter((rec) => rec._id !== id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.updateArrNotif()
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
@@ -85,6 +106,7 @@ export const useNotifStore = defineStore('NotifStore', {
|
|||||||
// console.log('res', res)
|
// console.log('res', res)
|
||||||
if (res) {
|
if (res) {
|
||||||
this.last_notifs = []
|
this.last_notifs = []
|
||||||
|
this.updateArrNotif()
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
@@ -110,6 +132,7 @@ export const useNotifStore = defineStore('NotifStore', {
|
|||||||
} else {
|
} else {
|
||||||
this.last_notifs = []
|
this.last_notifs = []
|
||||||
}
|
}
|
||||||
|
this.updateArrNotif()
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@@ -157,5 +180,10 @@ export const useNotifStore = defineStore('NotifStore', {
|
|||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setCountNotifs(num: number) {
|
||||||
|
this.countNotif = num
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import { shared_consts } from '@/common/shared_vuejs'
|
|||||||
import { costanti } from '@costanti'
|
import { costanti } from '@costanti'
|
||||||
import { IMyGroup } from '@model/UserStore'
|
import { IMyGroup } from '@model/UserStore'
|
||||||
|
|
||||||
|
import globalroutines from '../globalroutines/index'
|
||||||
|
|
||||||
export const DefaultUser: IUserFields = {
|
export const DefaultUser: IUserFields = {
|
||||||
_id: '',
|
_id: '',
|
||||||
email: '',
|
email: '',
|
||||||
@@ -955,6 +957,7 @@ export const useUserStore = defineStore('UserStore', {
|
|||||||
|
|
||||||
return await this.setGlobal($router, isLogged)
|
return await this.setGlobal($router, isLogged)
|
||||||
.then((loadstorage: any) => {
|
.then((loadstorage: any) => {
|
||||||
|
console.log('RISULT setGlobal:', loadstorage)
|
||||||
if (loadstorage) {
|
if (loadstorage) {
|
||||||
|
|
||||||
if ($q.screen.gt.sm) {
|
if ($q.screen.gt.sm) {
|
||||||
@@ -969,7 +972,7 @@ export const useUserStore = defineStore('UserStore', {
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|
||||||
//++Todo PWA: globalroutines('loadapp', '')
|
globalroutines('loadapp', '')
|
||||||
|
|
||||||
// Create Subscription to Push Notification
|
// Create Subscription to Push Notification
|
||||||
globalStore.createPushSubscription()
|
globalStore.createPushSubscription()
|
||||||
|
|||||||
@@ -564,6 +564,7 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
|||||||
|
|
||||||
async createPushSubscription() {
|
async createPushSubscription() {
|
||||||
|
|
||||||
|
// console.log('ENTER TO createPushSubscription')
|
||||||
// If Already subscribed, don't send to the Server DB
|
// If Already subscribed, don't send to the Server DB
|
||||||
// if (state.wasAlreadySubOnDb) {
|
// if (state.wasAlreadySubOnDb) {
|
||||||
// // console.log('wasAlreadySubOnDb!')
|
// // console.log('wasAlreadySubOnDb!')
|
||||||
@@ -574,10 +575,12 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
|||||||
return
|
return
|
||||||
|
|
||||||
if (!('serviceWorker' in navigator)) {
|
if (!('serviceWorker' in navigator)) {
|
||||||
|
console.log('serviceWorker not present !')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!('PushManager' in window)) {
|
if (!('PushManager' in window)) {
|
||||||
|
console.log('PushManager not present !')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1657,12 +1660,23 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
|||||||
|
|
||||||
getServerHost() {
|
getServerHost() {
|
||||||
|
|
||||||
if (this.serverHost) {
|
let myserv = ''
|
||||||
return this.serverHost
|
myserv = window.location.host
|
||||||
} else {
|
|
||||||
return process.env.MONGODB_HOST
|
if (process.env.DEBUGGING) {
|
||||||
|
myserv = 'http://192.168.1.54:3000'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!myserv) {
|
||||||
|
if (this.serverHost) {
|
||||||
|
myserv = this.serverHost
|
||||||
|
} else {
|
||||||
|
myserv = process.env.MONGODB_HOST!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return myserv
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="myuser.reported">
|
<div v-if="myuser.reported">
|
||||||
<CTitleBanner title="L'utente è stato Segnalato per comportamento non idoneo." bgcolor="bg-red" clcolor="text-white">
|
<CTitleBanner title="⚠️ L'utente è stato Segnalato per comportamento non idoneo." bgcolor="bg-red" clcolor="text-white">
|
||||||
</CTitleBanner>
|
</CTitleBanner>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user