Notifications
Settings Notifications User Panel
This commit is contained in:
@@ -1749,6 +1749,7 @@ export const tools = {
|
||||
if (elem.meta && elem.meta.requiresAuth) {
|
||||
visu = visu && this.isLoggedToSystem()
|
||||
}
|
||||
// console.log('MENU visu', elem.path, visu)
|
||||
return visu
|
||||
},
|
||||
|
||||
@@ -4003,7 +4004,7 @@ export const tools = {
|
||||
let ris = true
|
||||
const online = this.getValDb('SITO_ONLINE', false, true)
|
||||
ris = userStore.isAdmin && !pertutti ? true : online
|
||||
// console.log('isadmin', userStore.isAdmin)
|
||||
console.log('sito_online', ris)
|
||||
return ris
|
||||
},
|
||||
|
||||
@@ -5537,7 +5538,7 @@ export const tools = {
|
||||
},
|
||||
|
||||
getvalueAll(myval: string | Date) {
|
||||
const mydate = new Date(myval);
|
||||
const mydate = new Date(myval)
|
||||
if (mydate instanceof Date && !isNaN(mydate.valueOf())) {
|
||||
return this.getstrDateTime(mydate)
|
||||
} else {
|
||||
@@ -5556,6 +5557,30 @@ export const tools = {
|
||||
}
|
||||
},
|
||||
|
||||
timeAgo(input: any) {
|
||||
const date = (input instanceof Date) ? input : new Date(input)
|
||||
const formatter = new Intl.RelativeTimeFormat(toolsext.getLocale() || 'it')
|
||||
const ranges: any = {
|
||||
years: 3600 * 24 * 365,
|
||||
months: 3600 * 24 * 30,
|
||||
weeks: 3600 * 24 * 7,
|
||||
days: 3600 * 24,
|
||||
hours: 3600,
|
||||
minutes: 60,
|
||||
seconds: 1
|
||||
}
|
||||
const secondsElapsed = (date.getTime() - Date.now()) / 1000
|
||||
let key: any
|
||||
for (key in ranges) {
|
||||
if (ranges[key] < Math.abs(secondsElapsed)) {
|
||||
// @ts-ignore
|
||||
const delta = secondsElapsed / ranges[key]
|
||||
// @ts-ignore
|
||||
return formatter.format(Math.round(delta), key)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// getLocale() {
|
||||
// if (navigator.languages && navigator.languages.length > 0) {
|
||||
|
||||
@@ -63,6 +63,7 @@ export const toolsext = {
|
||||
TABMYGROUPS: 'mygroups',
|
||||
TABSKILLS: 'skills',
|
||||
TABSECTORS: 'sectors',
|
||||
TABSECTORGOODS: 'sectorgoods',
|
||||
TABREGIONS: 'regions',
|
||||
TABCITIES: 'cities',
|
||||
TABPROVINCE: 'provinces',
|
||||
|
||||
@@ -18,7 +18,7 @@ export const useNotifStore = defineStore('NotifStore', {
|
||||
getters: {
|
||||
|
||||
getlasts_notifs: (mystate: INotifState) => (): INotif[] => {
|
||||
const ctrec = (mystate.last_notifs) ? mystate.last_notifs.slice(0, 5).filter((rec) => mystate.show_all ? true : !rec.read) : []
|
||||
const ctrec = (mystate.last_notifs) ? mystate.last_notifs.slice(0, 10).filter((rec) => mystate.show_all ? true : !rec.read) : []
|
||||
// const ctrec = (mystate.notifs) ? mystate.notifs.slice().reverse().slice(0, 5) : []
|
||||
return (ctrec)
|
||||
|
||||
@@ -33,7 +33,7 @@ export const useNotifStore = defineStore('NotifStore', {
|
||||
actions: {
|
||||
|
||||
setNotif(notif: INotif) {
|
||||
// console.log('arrnotif', arrnotif)
|
||||
console.log('setNotif', notif)
|
||||
if (notif) {
|
||||
this.last_notifs = [notif, ...this.last_notifs]
|
||||
}
|
||||
@@ -61,15 +61,42 @@ export const useNotifStore = defineStore('NotifStore', {
|
||||
console.error(error)
|
||||
return false
|
||||
})
|
||||
},
|
||||
|
||||
deleteRec(username: string, id: string) {
|
||||
return Api.SendReq(`/sendnotif/del/${username}/${id}/${process.env.APP_ID}`, 'GET', null)
|
||||
.then((res) => {
|
||||
// console.log('res', res)
|
||||
if (res) {
|
||||
this.last_notifs = this.last_notifs.filter((rec) => rec._id !== id)
|
||||
}
|
||||
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
return false
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
deleteRec(id: string) {
|
||||
deleteAll(username: string, id: string) {
|
||||
return Api.SendReq(`/sendnotif/delall/${username}/${process.env.APP_ID}`, 'GET', null)
|
||||
.then((res) => {
|
||||
// console.log('res', res)
|
||||
if (res) {
|
||||
this.last_notifs = []
|
||||
}
|
||||
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
return false
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
deactivateRec(id: string) {
|
||||
|
||||
return ''
|
||||
},
|
||||
|
||||
async updateNotifDataFromServer({ username, lastdataread }: {username: string, lastdataread: Date}) {
|
||||
@@ -94,14 +121,17 @@ export const useNotifStore = defineStore('NotifStore', {
|
||||
async SendNotifEvent(notif: INotif) {
|
||||
console.log('SendNotifEvent', notif)
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
|
||||
const data: INotif = { ...NotifDefault, ...notif }
|
||||
|
||||
data.idapp = process.env.APP_ID
|
||||
data.type = notif.type
|
||||
data.typedir = notif.typedir
|
||||
data.typeid = notif.typeid
|
||||
data.sender = notif.sender
|
||||
data.dest = notif.dest
|
||||
data.descr = notif.descr
|
||||
data.link = notif.link
|
||||
data.datenotif = tools.getDateNow()
|
||||
data.read = false
|
||||
|
||||
@@ -110,10 +140,12 @@ export const useNotifStore = defineStore('NotifStore', {
|
||||
|
||||
return Api.SendReq('/sendnotif', 'POST', data)
|
||||
.then((res) => {
|
||||
// console.log('res', res)
|
||||
console.log('res', res)
|
||||
if (res.status === 200) {
|
||||
if (res.data.code === serv_constants.RIS_CODE_OK) {
|
||||
this.setNotif(res.data)
|
||||
if (res.data.code === serv_constants.RIS_CODE_OK && res.data.record) {
|
||||
if (res.data.record.dest === userStore.my.username) {
|
||||
this.setNotif(res.data.record)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,11 @@ export const DefaultUser: IUserFields = {
|
||||
asked_friends: [],
|
||||
asked_groups: [],
|
||||
notifs: [],
|
||||
notif_idCities: [],
|
||||
notif_provinces: [],
|
||||
notif_regions: [],
|
||||
notif_sectors: [],
|
||||
notif_sector_goods: [],
|
||||
},
|
||||
cart: {
|
||||
userId: '',
|
||||
@@ -101,6 +106,11 @@ export const DefaultProfile: IUserProfile = {
|
||||
asked_friends: [],
|
||||
asked_groups: [],
|
||||
notifs: [],
|
||||
notif_idCities: [],
|
||||
notif_provinces: [],
|
||||
notif_regions: [],
|
||||
notif_sectors: [],
|
||||
notif_sector_goods: [],
|
||||
}
|
||||
|
||||
export const useUserStore = defineStore('UserStore', {
|
||||
|
||||
@@ -338,13 +338,14 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
},
|
||||
|
||||
addDynamicPages($router: Router | null) {
|
||||
// console.log('this.mypage', this.mypage)
|
||||
// console.log('addDynamicPages')
|
||||
const arrpagesroute: IListRoutes[] = []
|
||||
|
||||
for (const page of this.mypage) {
|
||||
if (page.active) {
|
||||
// console.log('page', page.lang)
|
||||
if (this.isMyLang(page)) {
|
||||
// console.log('page.active', page.title)
|
||||
// console.log('page', page.title, 'OK')
|
||||
arrpagesroute.push({
|
||||
active: true,
|
||||
@@ -416,17 +417,21 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
|
||||
if ($router) {
|
||||
if (tools.sito_online(false)) {
|
||||
// console.log('SITO ONLINE', arrpagesroute)
|
||||
arrpagesroute.forEach(function (route: any) {
|
||||
$router.addRoute(route)
|
||||
})
|
||||
|
||||
$router.addRoute(last)
|
||||
} else {
|
||||
// console.log('SITO OFFLINE')
|
||||
$router.addRoute(sito_offline)
|
||||
$router.addRoute(last)
|
||||
$router.replace('/sito_offline')
|
||||
}
|
||||
|
||||
// console.log('getRoutes', $router.getRoutes())
|
||||
|
||||
const mypathsel = $router.currentRoute.value.fullPath
|
||||
if (mypathsel !== '/') {
|
||||
// console.log('mypathsel', mypathsel)
|
||||
@@ -898,6 +903,7 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
if (res) {
|
||||
const index = this.mypage.findIndex((rec) => rec.path === path)
|
||||
if (index >= 0) {
|
||||
console.log('load page', path, '...')
|
||||
this.mypage[index] = res.data.mypage
|
||||
}
|
||||
return res.data.mypage
|
||||
@@ -1360,8 +1366,9 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
if (showall) {
|
||||
this.newstosent = (res.data.newstosent) ? [...res.data.newstosent] : []
|
||||
this.mailinglist = (res.data.mailinglist) ? [...res.data.mailinglist] : []
|
||||
this.mypage = (res.data.mypage) ? [...res.data.mypage] : []
|
||||
}
|
||||
this.mypage = (res.data.mypage) ? [...res.data.mypage] : []
|
||||
console.log('this.mypage', this.mypage)
|
||||
|
||||
let isLogged = false
|
||||
|
||||
@@ -1592,7 +1599,7 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
else if (table === toolsext.TABLOCACCOM) myarr = shared_consts.LocationAccom
|
||||
else if (table === toolsext.TABPREF) myarr = shared_consts.Preferences
|
||||
else if (table === 'usernotifs') myarr = shared_consts.UsersNotif_Adv_List
|
||||
else if (table === 'typenotifs') myarr = shared_consts.typeNotifs
|
||||
else if (table === 'typenotifs') myarr = shared_consts.TypeNotifs_Arr
|
||||
else myarr = this.getListByTable(table)
|
||||
|
||||
if (costanti.TABLES_ARRAY.includes(table)) {
|
||||
|
||||
Reference in New Issue
Block a user