2019-12-04 02:04:54 +01:00
|
|
|
import { ICfgServer, IConfig, IGlobalState, IListRoutes, IMenuList, ISettings, StateConnection } from 'model'
|
2018-11-17 21:07:07 +01:00
|
|
|
import { storeBuilder } from './Store/Store'
|
|
|
|
|
|
2019-02-05 18:17:36 +01:00
|
|
|
import Vue from 'vue'
|
|
|
|
|
|
2019-02-06 18:47:54 +01:00
|
|
|
import translate from './../../globalroutines/util'
|
|
|
|
|
|
2019-02-05 18:17:36 +01:00
|
|
|
import urlBase64ToUint8Array from '../../js/utility'
|
|
|
|
|
|
2019-02-22 10:23:00 +01:00
|
|
|
import Api from '@api'
|
2019-03-04 17:28:29 +01:00
|
|
|
import * as Types from '@src/store/Api/ApiTypes'
|
2019-03-13 01:53:53 +01:00
|
|
|
import { costanti } from '@src/store/Modules/costanti'
|
|
|
|
|
import { tools } from '@src/store/Modules/tools'
|
2019-07-12 14:09:44 +02:00
|
|
|
import { toolsext } from '@src/store/Modules/toolsext'
|
2019-03-22 15:32:32 +01:00
|
|
|
import * as ApiTables from '@src/store/Modules/ApiTables'
|
2019-10-26 02:21:14 +02:00
|
|
|
import { CalendarStore, GlobalStore, MessageStore, Projects, Todos, UserStore } from '@store'
|
2019-03-13 01:53:53 +01:00
|
|
|
import messages from '../../statics/i18n'
|
|
|
|
|
import globalroutines from './../../globalroutines/index'
|
2019-05-02 16:58:36 +02:00
|
|
|
|
2019-05-03 20:31:47 +02:00
|
|
|
import { cfgrouter } from '../../router/route-config'
|
2019-10-11 21:40:47 +02:00
|
|
|
import { static_data } from '@src/db/static_data'
|
2019-10-20 22:44:18 +02:00
|
|
|
import { IDataPass, IParamsQuery } from '@src/model/GlobalStore'
|
2019-10-15 20:40:23 +02:00
|
|
|
import { serv_constants } from '@src/store/Modules/serv_constants'
|
|
|
|
|
import { IUserState } from '@src/model'
|
2019-10-20 22:44:18 +02:00
|
|
|
import { Calendar } from 'element-ui'
|
2019-10-28 16:00:37 +01:00
|
|
|
import { fieldsTable } from '@src/store/Modules/fieldsTable'
|
2019-12-07 00:20:55 +01:00
|
|
|
import router from '@router'
|
2019-10-10 16:53:33 +02:00
|
|
|
// import { static_data } from '@src/db/static_data'
|
2019-02-09 18:04:49 +01:00
|
|
|
|
2019-02-12 12:06:01 +01:00
|
|
|
let stateConnDefault = 'online'
|
|
|
|
|
|
|
|
|
|
getstateConnSaved()
|
2019-03-13 01:53:53 +01:00
|
|
|
.then((conn) => {
|
2019-02-12 12:06:01 +01:00
|
|
|
stateConnDefault = conn
|
|
|
|
|
})
|
2018-11-15 19:48:37 +01:00
|
|
|
|
|
|
|
|
const state: IGlobalState = {
|
2019-11-04 20:29:35 +01:00
|
|
|
finishLoading: false,
|
2018-11-15 19:48:37 +01:00
|
|
|
conta: 0,
|
2019-02-13 18:48:30 +01:00
|
|
|
wasAlreadySubscribed: false,
|
|
|
|
|
wasAlreadySubOnDb: false,
|
2018-11-15 19:48:37 +01:00
|
|
|
isLoginPage: false,
|
|
|
|
|
layoutNeeded: true,
|
|
|
|
|
mobileMode: false,
|
|
|
|
|
menuCollapse: true,
|
2019-01-02 18:01:36 +01:00
|
|
|
leftDrawerOpen: true,
|
2019-10-20 01:22:38 +02:00
|
|
|
RightDrawerOpen: false,
|
2019-02-12 12:06:01 +01:00
|
|
|
stateConnection: stateConnDefault,
|
2019-02-22 10:23:00 +01:00
|
|
|
networkDataReceived: false,
|
|
|
|
|
cfgServer: [],
|
2019-02-27 02:58:41 +01:00
|
|
|
testp1: { contatore: 0, mioarray: [] },
|
2019-01-30 01:05:31 +01:00
|
|
|
category: 'personal',
|
2019-01-29 23:13:28 +01:00
|
|
|
posts: [],
|
2019-03-13 01:53:53 +01:00
|
|
|
menulinks: {},
|
2019-01-29 23:13:28 +01:00
|
|
|
listatodo: [
|
2019-04-02 00:18:01 +02:00
|
|
|
{ nametranslate: 'personal', description: 'personal' },
|
|
|
|
|
{ nametranslate: 'work', description: 'work' },
|
|
|
|
|
{ nametranslate: 'shopping', description: 'shopping' }
|
2019-02-22 10:23:00 +01:00
|
|
|
],
|
|
|
|
|
connData: {
|
|
|
|
|
uploading_server: 0,
|
|
|
|
|
uploading_indexeddb: 0,
|
|
|
|
|
downloading_server: 0,
|
|
|
|
|
downloading_indexeddb: 0
|
2019-03-04 17:28:29 +01:00
|
|
|
},
|
2019-04-29 01:01:31 +02:00
|
|
|
arrConfig: [],
|
|
|
|
|
lastaction: {
|
|
|
|
|
table: '',
|
|
|
|
|
type: 0,
|
|
|
|
|
_id: 0
|
2019-11-04 20:29:35 +01:00
|
|
|
},
|
2019-12-04 02:04:54 +01:00
|
|
|
serv_settings: [],
|
|
|
|
|
templemail: [],
|
|
|
|
|
opzemail: [],
|
2019-11-12 21:33:18 +01:00
|
|
|
settings: [],
|
2019-11-15 00:32:39 +01:00
|
|
|
disciplines: [],
|
2020-01-03 01:53:19 +01:00
|
|
|
paymenttypes: [],
|
2019-11-21 00:19:42 +01:00
|
|
|
autoplaydisc: 8000,
|
|
|
|
|
newstosent: [],
|
2019-12-27 12:43:42 +01:00
|
|
|
gallery: [],
|
2019-12-07 00:20:55 +01:00
|
|
|
mailinglist: [],
|
2020-01-21 01:38:28 +01:00
|
|
|
mypage: [],
|
2020-05-10 21:06:42 +02:00
|
|
|
calzoom: []
|
2019-03-04 17:28:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getConfig(id) {
|
|
|
|
|
return await globalroutines(null, 'read', 'config', null, id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getstateConnSaved() {
|
|
|
|
|
const config = await getConfig(costanti.CONFIG_ID_CFG)
|
2019-03-14 21:09:41 +01:00
|
|
|
// console.log('config', config)
|
2019-03-05 23:44:48 +01:00
|
|
|
if (config) {
|
|
|
|
|
if (config.length > 1) {
|
|
|
|
|
const cfgstateconn = config[1]
|
|
|
|
|
return cfgstateconn.stateconn
|
|
|
|
|
} else {
|
|
|
|
|
return 'online'
|
|
|
|
|
}
|
2019-03-04 17:28:29 +01:00
|
|
|
} else {
|
2019-03-05 23:44:48 +01:00
|
|
|
return 'offline'
|
2019-02-22 10:23:00 +01:00
|
|
|
}
|
2018-11-15 19:48:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const b = storeBuilder.module<IGlobalState>('GlobalModule', state)
|
|
|
|
|
|
|
|
|
|
// Getters
|
|
|
|
|
namespace Getters {
|
|
|
|
|
|
2019-03-13 01:53:53 +01:00
|
|
|
const conta = b.read((state) => state.conta, 'conta')
|
|
|
|
|
const listatodo = b.read((state) => state.listatodo, 'listatodo')
|
|
|
|
|
const category = b.read((state) => state.category, 'category')
|
2018-12-22 18:42:00 +01:00
|
|
|
|
2019-03-13 01:53:53 +01:00
|
|
|
const testpao1_getter_contatore = b.read((state) => (param1) => state.testp1.contatore + 100 + param1, 'testpao1_getter_contatore')
|
|
|
|
|
const testpao1_getter_array = b.read((state) => (param1) => state.testp1.mioarray.filter((item) => item).map((item) => item.valore), 'testpao1_getter_array')
|
2019-03-04 17:28:29 +01:00
|
|
|
|
2019-03-13 01:53:53 +01:00
|
|
|
const getConfigbyId = b.read((state) => (id) => state.arrConfig.find((item) => item._id === id), 'getConfigbyId')
|
|
|
|
|
const getConfigStringbyId = b.read((state) => (params) => {
|
|
|
|
|
const config = state.arrConfig.find((item) => item._id === params.id)
|
2019-03-04 17:28:29 +01:00
|
|
|
if (config) {
|
|
|
|
|
return config.value
|
|
|
|
|
} else {
|
2019-03-05 23:44:48 +01:00
|
|
|
return params.default
|
2019-03-04 17:28:29 +01:00
|
|
|
}
|
|
|
|
|
}, 'getConfigStringbyId')
|
|
|
|
|
|
2019-03-13 01:53:53 +01:00
|
|
|
const showtype = b.read((state) => {
|
2019-03-04 17:28:29 +01:00
|
|
|
// const config = state.arrConfig.find(item => item._id === cat + costanti.CONFIG_ID_SHOW_TYPE_TODOS)
|
2019-03-13 01:53:53 +01:00
|
|
|
const config = state.arrConfig.find((item) => item._id === costanti.CONFIG_ID_SHOW_TYPE_TODOS)
|
|
|
|
|
if (config) {
|
2019-03-04 17:28:29 +01:00
|
|
|
return config.value
|
2019-03-13 01:53:53 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2019-03-04 17:28:29 +01:00
|
|
|
return ''
|
2019-03-13 01:53:53 +01:00
|
|
|
}
|
2019-03-04 17:28:29 +01:00
|
|
|
|
|
|
|
|
}, 'showtype')
|
2019-02-27 02:58:41 +01:00
|
|
|
|
2019-12-07 00:20:55 +01:00
|
|
|
const getPage = b.read((mystate: IGlobalState) => (path) => {
|
|
|
|
|
// const config = state.arrConfig.find(item => item._id === cat + costanti.CONFIG_ID_SHOW_TYPE_TODOS)
|
|
|
|
|
return mystate.mypage.find((page) => (`/` + page.path) === path)
|
|
|
|
|
|
|
|
|
|
}, 'getPage')
|
|
|
|
|
|
2020-05-10 21:06:42 +02:00
|
|
|
const getmenu = b.read((mystate: IGlobalState) => {
|
2019-05-03 20:31:47 +02:00
|
|
|
// console.log('getmenu', cfgrouter.getmenu())
|
2019-03-31 14:27:27 +02:00
|
|
|
|
2020-05-10 21:06:42 +02:00
|
|
|
mystate.menulinks = {
|
2019-03-31 14:27:27 +02:00
|
|
|
Dashboard: {
|
2019-05-02 16:58:36 +02:00
|
|
|
routes: cfgrouter.getmenu(),
|
2019-03-31 14:27:27 +02:00
|
|
|
show: true
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-22 18:49:38 +01:00
|
|
|
|
2020-05-10 21:06:42 +02:00
|
|
|
return mystate.menulinks
|
2019-03-13 01:53:53 +01:00
|
|
|
|
2019-04-25 00:30:13 +02:00
|
|
|
// console.log('state.menulinks', state.menulinks)
|
2019-04-03 02:48:05 +02:00
|
|
|
|
2019-03-13 01:53:53 +01:00
|
|
|
}, 'getmenu')
|
2019-02-27 02:58:41 +01:00
|
|
|
|
2019-04-11 17:40:41 +02:00
|
|
|
const t = b.read((state) => (params) => {
|
|
|
|
|
const msg = params.split('.')
|
2019-07-12 14:09:44 +02:00
|
|
|
const lang = toolsext.getLocale()
|
2019-04-11 17:40:41 +02:00
|
|
|
|
|
|
|
|
const stringa = messages[lang]
|
|
|
|
|
|
|
|
|
|
let ris = stringa
|
|
|
|
|
msg.forEach((param) => {
|
|
|
|
|
ris = ris[param]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return ris
|
|
|
|
|
}, 't')
|
|
|
|
|
|
2019-11-04 20:29:35 +01:00
|
|
|
const getListByTable = b.read((state) => (table) => {
|
|
|
|
|
if (table === tools.TABEVENTS)
|
|
|
|
|
return CalendarStore.state.eventlist
|
|
|
|
|
else if (table === 'operators')
|
|
|
|
|
return CalendarStore.state.operators
|
|
|
|
|
else if (table === 'wheres')
|
|
|
|
|
return CalendarStore.state.wheres
|
|
|
|
|
else if (table === 'contribtype')
|
|
|
|
|
return CalendarStore.state.contribtype
|
2019-11-12 21:33:18 +01:00
|
|
|
else if (table === 'disciplines')
|
|
|
|
|
return GlobalStore.state.disciplines
|
2019-11-21 00:19:42 +01:00
|
|
|
else if (table === tools.TABNEWSLETTER)
|
|
|
|
|
return GlobalStore.state.newstosent
|
2019-12-27 12:43:42 +01:00
|
|
|
else if (table === tools.TABGALLERY)
|
|
|
|
|
return GlobalStore.state.gallery
|
2019-12-04 02:04:54 +01:00
|
|
|
else if (table === tools.TABTEMPLEMAIL)
|
|
|
|
|
return GlobalStore.state.templemail
|
|
|
|
|
else if (table === tools.TABOPZEMAIL)
|
|
|
|
|
return GlobalStore.state.opzemail
|
2019-11-21 00:19:42 +01:00
|
|
|
else if (table === tools.TABMAILINGLIST)
|
|
|
|
|
return GlobalStore.state.mailinglist
|
2019-12-07 00:20:55 +01:00
|
|
|
else if (table === tools.TABMYPAGE)
|
|
|
|
|
return GlobalStore.state.mypage
|
2020-01-21 01:38:28 +01:00
|
|
|
else if (table === tools.TABCALZOOM)
|
|
|
|
|
return GlobalStore.state.calzoom
|
2020-01-03 01:53:19 +01:00
|
|
|
else if (table === 'paymenttypes')
|
|
|
|
|
return GlobalStore.state.paymenttypes
|
2019-11-04 20:29:35 +01:00
|
|
|
else if (table === 'bookings')
|
|
|
|
|
return CalendarStore.state.bookedevent
|
|
|
|
|
else if (table === 'users')
|
|
|
|
|
return UserStore.state.usersList
|
|
|
|
|
else if (table === 'sendmsgs')
|
|
|
|
|
return MessageStore.state.last_msgs
|
|
|
|
|
else if (table === 'settings')
|
|
|
|
|
return UserStore.state.settings
|
|
|
|
|
else
|
|
|
|
|
return null
|
|
|
|
|
|
|
|
|
|
}, 'getListByTable')
|
|
|
|
|
|
2019-12-04 02:04:54 +01:00
|
|
|
const getrecSettingsByKey = b.read((mystate: IGlobalState) => (key, serv): ISettings => {
|
|
|
|
|
if (serv)
|
|
|
|
|
return mystate.serv_settings.find((rec) => rec.key === key)
|
|
|
|
|
else
|
|
|
|
|
return mystate.settings.find((rec) => rec.key === key)
|
|
|
|
|
}, 'getrecSettingsByKey')
|
|
|
|
|
|
|
|
|
|
const getValueSettingsByKey = b.read((mystate: IGlobalState) => (key, serv): any => {
|
|
|
|
|
|
|
|
|
|
const myrec = getters.getrecSettingsByKey(key, serv)
|
|
|
|
|
|
2019-11-04 20:29:35 +01:00
|
|
|
if (!!myrec) {
|
|
|
|
|
if (myrec.type === tools.FieldType.date)
|
|
|
|
|
return myrec.value_date
|
2019-12-04 02:04:54 +01:00
|
|
|
else if (myrec.type === tools.FieldType.number)
|
2019-11-04 20:29:35 +01:00
|
|
|
return myrec.value_num
|
2019-12-04 02:04:54 +01:00
|
|
|
else if (myrec.type === tools.FieldType.boolean)
|
|
|
|
|
return myrec.value_bool
|
2019-11-04 20:29:35 +01:00
|
|
|
else
|
|
|
|
|
return myrec.value_str
|
|
|
|
|
} else {
|
|
|
|
|
return ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, 'getValueSettingsByKey')
|
|
|
|
|
|
2019-12-04 18:21:17 +01:00
|
|
|
const gettemplemailbyId = b.read((mystate: IGlobalState) => (templid): string => {
|
|
|
|
|
const myrec = mystate.templemail.find((rec) => rec._id === templid)
|
|
|
|
|
return (!!myrec) ? myrec.subject : ''
|
|
|
|
|
}, 'gettemplemailbyId')
|
|
|
|
|
|
2018-11-15 19:48:37 +01:00
|
|
|
export const getters = {
|
2019-02-27 02:58:41 +01:00
|
|
|
get testpao1_getter_contatore() {
|
|
|
|
|
return testpao1_getter_contatore()
|
|
|
|
|
},
|
|
|
|
|
get testpao1_getter_array() {
|
|
|
|
|
return testpao1_getter_array()
|
|
|
|
|
},
|
2018-12-22 18:42:00 +01:00
|
|
|
get conta() {
|
|
|
|
|
return conta()
|
2019-01-29 23:13:28 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
get listaTodo() {
|
|
|
|
|
return listatodo()
|
2019-01-30 01:05:31 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
get category() {
|
|
|
|
|
return category()
|
2019-02-12 12:06:01 +01:00
|
|
|
},
|
|
|
|
|
|
2019-03-04 17:28:29 +01:00
|
|
|
get getConfigbyId() {
|
|
|
|
|
return getConfigbyId()
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
get getConfigStringbyId() {
|
|
|
|
|
return getConfigStringbyId()
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
get showtype() {
|
|
|
|
|
return showtype()
|
|
|
|
|
},
|
|
|
|
|
|
2019-03-13 01:53:53 +01:00
|
|
|
get getmenu() {
|
|
|
|
|
return getmenu()
|
|
|
|
|
},
|
|
|
|
|
|
2019-11-04 20:29:35 +01:00
|
|
|
get getListByTable() {
|
|
|
|
|
return getListByTable()
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
get getValueSettingsByKey() {
|
|
|
|
|
return getValueSettingsByKey()
|
|
|
|
|
},
|
|
|
|
|
|
2019-12-04 02:04:54 +01:00
|
|
|
get getrecSettingsByKey() {
|
|
|
|
|
return getrecSettingsByKey()
|
|
|
|
|
},
|
|
|
|
|
|
2019-12-04 18:21:17 +01:00
|
|
|
get gettemplemailbyId() {
|
|
|
|
|
return gettemplemailbyId()
|
|
|
|
|
},
|
|
|
|
|
|
2019-12-07 00:20:55 +01:00
|
|
|
get getPage() {
|
|
|
|
|
return getPage()
|
|
|
|
|
},
|
|
|
|
|
|
2019-04-11 17:40:41 +02:00
|
|
|
get t() {
|
|
|
|
|
return t()
|
|
|
|
|
},
|
|
|
|
|
|
2019-02-12 12:06:01 +01:00
|
|
|
get isOnline() {
|
2019-04-02 00:18:01 +02:00
|
|
|
// console.log('*********************** isOnline')
|
2019-02-12 12:06:01 +01:00
|
|
|
return state.stateConnection === 'online'
|
2019-02-22 10:23:00 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
get isNewVersionAvailable() {
|
2019-03-14 21:09:41 +01:00
|
|
|
// console.log('state.cfgServer', state.cfgServer)
|
2020-05-10 21:06:42 +02:00
|
|
|
const serversrec = state.cfgServer.find((x) => (x.chiave === tools.SERVKEY_VERS) && (x.idapp === process.env.APP_ID))
|
2019-03-14 21:09:41 +01:00
|
|
|
// console.log('Record ', serversrec)
|
2019-02-22 10:23:00 +01:00
|
|
|
if (serversrec) {
|
|
|
|
|
console.log('Vers Server ', serversrec.valore, 'Vers locale:', process.env.APP_VERSION)
|
|
|
|
|
return serversrec.valore !== process.env.APP_VERSION
|
2019-03-13 01:53:53 +01:00
|
|
|
} else {
|
2019-02-22 10:23:00 +01:00
|
|
|
return false
|
2019-03-13 01:53:53 +01:00
|
|
|
}
|
2018-12-22 18:42:00 +01:00
|
|
|
}
|
2018-11-15 19:48:37 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace Mutations {
|
2019-02-27 02:58:41 +01:00
|
|
|
function setPaoArray(state: IGlobalState, miorec: ICfgServer) {
|
|
|
|
|
state.testp1.mioarray[state.testp1.mioarray.length - 1] = miorec
|
|
|
|
|
|
|
|
|
|
tools.notifyarraychanged(state.testp1.mioarray)
|
|
|
|
|
console.log('last elem = ', state.testp1.mioarray[state.testp1.mioarray.length - 1])
|
|
|
|
|
}
|
2019-03-04 17:28:29 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
function NewArray(state: IGlobalState, newarr: ICfgServer[]) {
|
|
|
|
|
state.testp1.mioarray = newarr
|
|
|
|
|
}
|
2019-03-04 17:28:29 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
function setPaoArray_Delete(state: IGlobalState) {
|
|
|
|
|
state.testp1.mioarray.pop()
|
|
|
|
|
}
|
2018-11-15 19:48:37 +01:00
|
|
|
|
|
|
|
|
function setConta(state: IGlobalState, num: number) {
|
|
|
|
|
state.conta = num
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-02 18:01:36 +01:00
|
|
|
function setleftDrawerOpen(state: IGlobalState, bool: boolean) {
|
|
|
|
|
state.leftDrawerOpen = bool
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-30 01:05:31 +01:00
|
|
|
function setCategorySel(state: IGlobalState, cat: string) {
|
|
|
|
|
state.category = cat
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-09 18:04:49 +01:00
|
|
|
function setStateConnection(state: IGlobalState, stateconn: StateConnection) {
|
|
|
|
|
if (state.stateConnection !== stateconn) {
|
|
|
|
|
console.log('INTERNET ', stateconn)
|
|
|
|
|
state.stateConnection = stateconn
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-30 01:05:31 +01:00
|
|
|
|
2019-03-04 17:28:29 +01:00
|
|
|
function saveConfig(state: IGlobalState, data: IConfig) {
|
|
|
|
|
let dataout
|
|
|
|
|
// this.$set(dataout, data.value, {'value': 'default value'})
|
|
|
|
|
return globalroutines(null, 'write', 'config', { _id: data._id, value: data.value })
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-13 18:48:30 +01:00
|
|
|
function SetwasAlreadySubOnDb(state: IGlobalState, subscrib: boolean) {
|
|
|
|
|
state.wasAlreadySubOnDb = subscrib
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 17:28:29 +01:00
|
|
|
function setShowType(state: IGlobalState, showtype: number) {
|
2019-03-05 23:44:48 +01:00
|
|
|
console.log('setShowType', showtype)
|
2019-03-04 17:28:29 +01:00
|
|
|
const config = Getters.getters.getConfigbyId(costanti.CONFIG_ID_SHOW_TYPE_TODOS)
|
2019-03-05 23:44:48 +01:00
|
|
|
console.log('config', config)
|
2019-03-04 17:28:29 +01:00
|
|
|
if (config) {
|
|
|
|
|
config.value = String(showtype)
|
2019-03-22 18:49:38 +01:00
|
|
|
Todos.state.showtype = parseInt(config.value, 10)
|
2019-03-05 23:44:48 +01:00
|
|
|
} else {
|
|
|
|
|
Todos.state.showtype = showtype
|
2019-03-04 17:28:29 +01:00
|
|
|
}
|
2019-03-05 23:44:48 +01:00
|
|
|
console.log('Todos.state.showtype', Todos.state.showtype)
|
|
|
|
|
GlobalStore.mutations.saveConfig({ _id: costanti.CONFIG_ID_SHOW_TYPE_TODOS, value: String(showtype) })
|
|
|
|
|
|
2019-03-04 17:28:29 +01:00
|
|
|
}
|
|
|
|
|
|
2019-10-20 22:44:18 +02:00
|
|
|
function UpdateValuesInMemory(mystate: IGlobalState, mydata: IDataPass) {
|
|
|
|
|
|
|
|
|
|
const id = mydata.id
|
|
|
|
|
const table = mydata.table
|
|
|
|
|
|
|
|
|
|
try {
|
2019-11-04 20:29:35 +01:00
|
|
|
const mylist = Getters.getters.getListByTable(table)
|
2019-10-28 16:00:37 +01:00
|
|
|
const mykey = fieldsTable.getKeyByTable(table)
|
2019-10-20 22:44:18 +02:00
|
|
|
|
2019-11-05 23:53:18 +01:00
|
|
|
if (!!mylist) {
|
|
|
|
|
const myrec = mylist.find((event) => event[mykey] === id)
|
|
|
|
|
// console.log('myrec', myrec)
|
|
|
|
|
if (myrec) {
|
|
|
|
|
for (const [key, value] of Object.entries(mydata.fieldsvalue)) {
|
2020-01-03 01:53:19 +01:00
|
|
|
// console.log('key', value, myrec[key])
|
2019-11-05 23:53:18 +01:00
|
|
|
myrec[key] = value
|
|
|
|
|
}
|
2019-10-20 22:44:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-04 02:04:54 +01:00
|
|
|
function setValueSettingsByKey(mystate: IGlobalState, { key, value, serv }) {
|
|
|
|
|
// Update the Server
|
|
|
|
|
|
|
|
|
|
// Update in Memory
|
|
|
|
|
let myrec = null
|
|
|
|
|
if (serv)
|
|
|
|
|
myrec = mystate.serv_settings.find((rec) => rec.key === key)
|
|
|
|
|
else
|
|
|
|
|
myrec = mystate.settings.find((rec) => rec.key === key)
|
|
|
|
|
|
|
|
|
|
if (!!myrec) {
|
|
|
|
|
if (myrec.type === tools.FieldType.date)
|
|
|
|
|
myrec.value_date = value
|
|
|
|
|
else if (myrec.type === tools.FieldType.number)
|
|
|
|
|
myrec.value_num = value
|
|
|
|
|
else if (myrec.type === tools.FieldType.boolean)
|
|
|
|
|
myrec.value_bool = value
|
|
|
|
|
else
|
|
|
|
|
myrec.value_str = value
|
|
|
|
|
|
|
|
|
|
console.log('setValueSettingsByKey value', value, 'myrec', myrec)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 19:48:37 +01:00
|
|
|
export const mutations = {
|
2019-01-02 18:01:36 +01:00
|
|
|
setConta: b.commit(setConta),
|
2019-01-30 01:05:31 +01:00
|
|
|
setleftDrawerOpen: b.commit(setleftDrawerOpen),
|
2019-02-09 18:04:49 +01:00
|
|
|
setCategorySel: b.commit(setCategorySel),
|
2019-02-13 18:48:30 +01:00
|
|
|
setStateConnection: b.commit(setStateConnection),
|
2019-02-27 02:58:41 +01:00
|
|
|
SetwasAlreadySubOnDb: b.commit(SetwasAlreadySubOnDb),
|
2019-03-04 17:28:29 +01:00
|
|
|
saveConfig: b.commit(saveConfig),
|
2019-02-27 02:58:41 +01:00
|
|
|
setPaoArray: b.commit(setPaoArray),
|
|
|
|
|
setPaoArray_Delete: b.commit(setPaoArray_Delete),
|
2019-03-04 17:28:29 +01:00
|
|
|
NewArray: b.commit(NewArray),
|
2019-10-20 22:44:18 +02:00
|
|
|
setShowType: b.commit(setShowType),
|
2019-12-04 02:04:54 +01:00
|
|
|
UpdateValuesInMemory: b.commit(UpdateValuesInMemory),
|
|
|
|
|
setValueSettingsByKey: b.commit(setValueSettingsByKey)
|
2018-11-15 19:48:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace Actions {
|
2018-11-17 20:32:28 +01:00
|
|
|
async function setConta(context, num: number) {
|
2018-11-15 19:48:37 +01:00
|
|
|
Mutations.mutations.setConta(num)
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-05 18:17:36 +01:00
|
|
|
function createPushSubscription(context) {
|
2019-02-13 18:48:30 +01:00
|
|
|
|
|
|
|
|
// If Already subscribed, don't send to the Server DB
|
2019-02-14 18:38:23 +01:00
|
|
|
// if (state.wasAlreadySubOnDb) {
|
|
|
|
|
// // console.log('wasAlreadySubOnDb!')
|
|
|
|
|
// return
|
|
|
|
|
// }
|
2019-02-13 18:48:30 +01:00
|
|
|
|
2019-10-11 21:40:47 +02:00
|
|
|
if (!static_data.functionality.PWA)
|
|
|
|
|
return
|
|
|
|
|
|
2019-02-05 18:17:36 +01:00
|
|
|
if (!('serviceWorker' in navigator)) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-12 12:06:01 +01:00
|
|
|
if (!('PushManager' in window)) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-21 00:19:42 +01:00
|
|
|
console.log('createPushSubscription')
|
2019-02-05 18:17:36 +01:00
|
|
|
|
|
|
|
|
let reg
|
|
|
|
|
const mykey = process.env.PUBLICKEY_PUSH
|
|
|
|
|
const mystate = state
|
2019-02-14 18:38:23 +01:00
|
|
|
return navigator.serviceWorker.ready
|
2019-04-29 02:47:53 +02:00
|
|
|
.then((swreg) => {
|
2019-02-05 18:17:36 +01:00
|
|
|
reg = swreg
|
|
|
|
|
return swreg.pushManager.getSubscription()
|
|
|
|
|
})
|
2019-04-29 02:47:53 +02:00
|
|
|
.then((subscription) => {
|
2020-05-10 21:06:42 +02:00
|
|
|
console.log('subscription = ', subscription)
|
|
|
|
|
|
2019-02-13 18:48:30 +01:00
|
|
|
mystate.wasAlreadySubscribed = !(subscription === null)
|
2019-02-05 18:17:36 +01:00
|
|
|
|
2019-02-14 18:38:23 +01:00
|
|
|
if (mystate.wasAlreadySubscribed) {
|
2019-02-27 02:58:41 +01:00
|
|
|
// console.log('User is already SAVED Subscribe on DB!')
|
2019-02-14 18:38:23 +01:00
|
|
|
// return null
|
|
|
|
|
return subscription
|
2019-02-05 18:17:36 +01:00
|
|
|
} else {
|
|
|
|
|
// Create a new subscription
|
2019-02-14 18:38:23 +01:00
|
|
|
console.log('Create a new subscription')
|
2019-03-13 01:53:53 +01:00
|
|
|
const convertedVapidPublicKey = urlBase64ToUint8Array(mykey)
|
2019-02-05 18:17:36 +01:00
|
|
|
return reg.pushManager.subscribe({
|
|
|
|
|
userVisibleOnly: true,
|
|
|
|
|
applicationServerKey: convertedVapidPublicKey
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
2019-04-29 02:47:53 +02:00
|
|
|
.then((newSub) => {
|
2019-02-13 18:48:30 +01:00
|
|
|
saveNewSubscriptionToServer(context, newSub)
|
2019-02-05 18:17:36 +01:00
|
|
|
})
|
2019-04-29 02:47:53 +02:00
|
|
|
.catch((err) => {
|
2019-02-14 18:38:23 +01:00
|
|
|
console.log('ERR createPushSubscription:', err)
|
2019-02-05 18:17:36 +01:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calling the Server to Save in the MongoDB the Subscriber
|
|
|
|
|
function saveNewSubscriptionToServer(context, newSub) {
|
2020-04-10 13:03:19 +02:00
|
|
|
|
2019-02-13 18:48:30 +01:00
|
|
|
// If already subscribed, exit
|
2020-05-10 21:06:42 +02:00
|
|
|
// if (true) {
|
|
|
|
|
// return
|
|
|
|
|
// }
|
2019-10-10 16:53:33 +02:00
|
|
|
|
2019-03-13 01:53:53 +01:00
|
|
|
if (!newSub) {
|
2019-02-13 18:48:30 +01:00
|
|
|
return
|
2019-03-13 01:53:53 +01:00
|
|
|
}
|
2019-02-13 18:48:30 +01:00
|
|
|
|
2019-10-10 16:53:33 +02:00
|
|
|
if (UserStore.getters.isUserInvalid) {
|
2019-09-12 16:19:23 +02:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
// console.log('saveSubscriptionToServer: ', newSub)
|
2019-02-13 18:48:30 +01:00
|
|
|
// console.log('context', context)
|
2019-02-05 18:17:36 +01:00
|
|
|
|
2020-05-10 21:06:42 +02:00
|
|
|
console.log('saveNewSubscriptionToServer')
|
|
|
|
|
|
2019-02-14 18:38:23 +01:00
|
|
|
let options = null
|
2020-05-10 21:06:42 +02:00
|
|
|
let notreg = false
|
|
|
|
|
|
|
|
|
|
if (UserStore.getters.isTokenInvalid) {
|
|
|
|
|
notreg = true
|
|
|
|
|
}
|
2019-02-14 18:38:23 +01:00
|
|
|
|
|
|
|
|
// If is not already stored in DB, then show the message to the user.
|
2020-05-10 21:06:42 +02:00
|
|
|
if (!state.wasAlreadySubscribed || notreg) {
|
2019-02-14 18:38:23 +01:00
|
|
|
options = {
|
2020-05-10 21:06:42 +02:00
|
|
|
title: tools.translate('notification.title_subscribed', [{strin: 'sitename', strout: translate('ws.sitename')}]),
|
2019-02-14 18:38:23 +01:00
|
|
|
content: translate('notification.subscribed'),
|
|
|
|
|
openUrl: '/'
|
|
|
|
|
}
|
2019-02-14 19:01:32 +01:00
|
|
|
}
|
2019-02-05 18:17:36 +01:00
|
|
|
|
2019-03-13 01:53:53 +01:00
|
|
|
const myres = {
|
2019-02-14 19:01:32 +01:00
|
|
|
options,
|
2019-02-06 18:47:54 +01:00
|
|
|
subs: newSub,
|
|
|
|
|
others: {
|
2019-10-25 19:07:56 +02:00
|
|
|
userId: UserStore.state.my._id,
|
|
|
|
|
access: UserStore.state.my.tokens[0].access
|
2019-02-22 10:23:00 +01:00
|
|
|
}
|
2019-02-05 18:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-19 02:33:02 +01:00
|
|
|
return Api.SendReq('/subscribe', 'POST', myres)
|
2019-03-13 01:53:53 +01:00
|
|
|
.then((res) => {
|
2019-02-13 18:48:30 +01:00
|
|
|
state.wasAlreadySubscribed = true
|
|
|
|
|
state.wasAlreadySubOnDb = true
|
2019-02-05 18:17:36 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
localStorage.setItem(tools.localStorage.wasAlreadySubOnDb, String(state.wasAlreadySubOnDb))
|
2019-02-13 18:48:30 +01:00
|
|
|
})
|
2019-03-13 01:53:53 +01:00
|
|
|
.catch((e) => {
|
2019-02-13 18:48:30 +01:00
|
|
|
console.log('Error during Subscription!', e)
|
|
|
|
|
})
|
2019-02-05 18:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-12 12:06:01 +01:00
|
|
|
async function deleteSubscriptionToServer(context) {
|
|
|
|
|
console.log('DeleteSubscriptionToServer: ')
|
|
|
|
|
|
2019-03-15 02:01:03 +01:00
|
|
|
return Api.SendReq('/subscribe/del', 'DELETE', null)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
|
|
|
|
|
})
|
2019-02-12 12:06:01 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-05 18:17:36 +01:00
|
|
|
function prova(context) {
|
|
|
|
|
// console.log('prova')
|
2019-02-27 02:58:41 +01:00
|
|
|
// state.testp1.mioarray[state.testp1.mioarray.length - 1].valore = 'VALMODIF';
|
2019-02-05 18:17:36 +01:00
|
|
|
|
|
|
|
|
// let msg = t('notification.title_subscribed')
|
|
|
|
|
|
|
|
|
|
// console.log('msg', msg)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-12 12:06:01 +01:00
|
|
|
async function clearDataAfterLogout(context) {
|
|
|
|
|
console.log('clearDataAfterLogout')
|
2019-02-09 18:04:49 +01:00
|
|
|
|
|
|
|
|
// Clear all data from the IndexedDB
|
2019-03-28 12:58:34 +01:00
|
|
|
for (const table of ApiTables.allTables()) {
|
2019-02-20 19:17:29 +01:00
|
|
|
await globalroutines(null, 'clearalldata', table, null)
|
|
|
|
|
}
|
2019-02-09 18:04:49 +01:00
|
|
|
|
2019-10-11 21:40:47 +02:00
|
|
|
if (static_data.functionality.PWA) {
|
|
|
|
|
if ('serviceWorker' in navigator) {
|
|
|
|
|
// REMOVE ALL SUBSCRIPTION
|
|
|
|
|
console.log('REMOVE ALL SUBSCRIPTION...')
|
|
|
|
|
await navigator.serviceWorker.ready.then((reg) => {
|
|
|
|
|
console.log('... Ready')
|
|
|
|
|
reg.pushManager.getSubscription().then((subscription) => {
|
|
|
|
|
console.log(' Found Subscription...')
|
|
|
|
|
if (subscription) {
|
|
|
|
|
subscription.unsubscribe().then((successful) => {
|
|
|
|
|
// You've successfully unsubscribed
|
|
|
|
|
console.log('You\'ve successfully unsubscribed')
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
// Unsubscription failed
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
2019-02-12 12:06:01 +01:00
|
|
|
})
|
2019-10-11 21:40:47 +02:00
|
|
|
}
|
2019-02-14 18:38:23 +01:00
|
|
|
}
|
2019-02-12 12:06:01 +01:00
|
|
|
|
|
|
|
|
await deleteSubscriptionToServer(context)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function clearDataAfterLoginOnlyIfActiveConnection(context) {
|
|
|
|
|
|
2019-02-09 18:04:49 +01:00
|
|
|
}
|
2019-02-05 18:17:36 +01:00
|
|
|
|
2019-02-12 12:06:01 +01:00
|
|
|
async function loadAfterLogin(context) {
|
2020-01-20 01:50:21 +01:00
|
|
|
console.log('loadAfterLogin')
|
2019-02-12 12:06:01 +01:00
|
|
|
actions.clearDataAfterLoginOnlyIfActiveConnection()
|
2019-03-04 17:28:29 +01:00
|
|
|
|
2020-01-20 01:50:21 +01:00
|
|
|
let isok = false
|
|
|
|
|
|
|
|
|
|
if (!await Actions.actions.loadSite()) {
|
|
|
|
|
this.$router.push('/signin')
|
|
|
|
|
} else {
|
|
|
|
|
isok = true
|
|
|
|
|
}
|
2019-10-23 23:47:12 +02:00
|
|
|
|
2019-03-04 17:28:29 +01:00
|
|
|
state.arrConfig = await globalroutines(null, 'readall', 'config', null)
|
2020-01-20 01:50:21 +01:00
|
|
|
|
|
|
|
|
return isok
|
2019-02-05 18:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-22 10:23:00 +01:00
|
|
|
async function saveCfgServerKey(context, dataval: ICfgServer) {
|
|
|
|
|
console.log('saveCfgServerKey dataval', dataval)
|
|
|
|
|
|
2019-03-13 01:53:53 +01:00
|
|
|
const ris = await Api.SendReq('/admin/updateval', 'POST', { pairval: dataval })
|
|
|
|
|
.then((res) => {
|
2019-02-22 10:23:00 +01:00
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function checkUpdates(context) {
|
|
|
|
|
console.log('checkUpdates')
|
|
|
|
|
|
2019-10-25 19:07:56 +02:00
|
|
|
// if (UserStore.state.my._id === '')
|
2019-02-22 10:23:00 +01:00
|
|
|
// return false // Login not made
|
|
|
|
|
|
|
|
|
|
state.networkDataReceived = false
|
|
|
|
|
|
2019-03-13 01:53:53 +01:00
|
|
|
const ris = await Api.SendReq('/checkupdates', 'GET', null)
|
|
|
|
|
.then((res) => {
|
2019-02-22 10:23:00 +01:00
|
|
|
state.networkDataReceived = true
|
|
|
|
|
|
2019-10-13 20:46:09 +02:00
|
|
|
// console.log('******* checkUpdates RES :', res.data.cfgServer)
|
2019-02-22 10:23:00 +01:00
|
|
|
if (res.data.cfgServer) {
|
|
|
|
|
state.cfgServer = [...res.data.cfgServer]
|
2019-10-13 20:46:09 +02:00
|
|
|
// console.log('res.data.cfgServer', res.data.cfgServer)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// console.log('res.data.userslist', res.data.usersList)
|
|
|
|
|
if (res.data.usersList) {
|
|
|
|
|
UserStore.mutations.setusersList(res.data.usersList)
|
2019-02-22 10:23:00 +01:00
|
|
|
}
|
|
|
|
|
|
2019-10-26 02:21:14 +02:00
|
|
|
if (res.data.last_msgs) {
|
|
|
|
|
MessageStore.state.last_msgs = [...res.data.last_msgs]
|
2019-10-24 23:30:18 +02:00
|
|
|
}
|
|
|
|
|
|
2019-10-26 02:21:14 +02:00
|
|
|
// console.log('MessageStore.state.last_msgs', MessageStore.state.last_msgs)
|
2019-10-24 23:30:18 +02:00
|
|
|
|
2019-02-22 10:23:00 +01:00
|
|
|
// console.log('********** res', 'state.todos', state.todos, 'checkPending', checkPending)
|
|
|
|
|
// After Login will store into the indexedDb...
|
|
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
})
|
2019-03-13 01:53:53 +01:00
|
|
|
.catch((error) => {
|
2019-02-22 10:23:00 +01:00
|
|
|
console.log('error checkUpdates', error)
|
|
|
|
|
UserStore.mutations.setErrorCatch(error)
|
|
|
|
|
return error
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
2019-02-05 18:17:36 +01:00
|
|
|
|
2020-05-10 21:06:42 +02:00
|
|
|
async function sendPushNotif(context, { params }) {
|
|
|
|
|
|
|
|
|
|
return await Api.SendReq('/push/send', 'POST', { params })
|
|
|
|
|
.then((res) => {
|
|
|
|
|
// console.table(res)
|
|
|
|
|
return res.data
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.log('error sendPushNotif', error)
|
|
|
|
|
return null
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-14 20:32:15 +02:00
|
|
|
async function loadTable(context, params: IParamsQuery) {
|
2019-10-20 01:22:38 +02:00
|
|
|
// console.log('loadTable', params)
|
2019-10-14 20:32:15 +02:00
|
|
|
|
|
|
|
|
return await Api.SendReq('/gettable', 'POST', params)
|
|
|
|
|
.then((res) => {
|
2019-10-20 01:22:38 +02:00
|
|
|
// console.table(res)
|
|
|
|
|
return res.data
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.log('error loadTable', error)
|
|
|
|
|
UserStore.mutations.setErrorCatch(error)
|
|
|
|
|
return null
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function saveTable(context, mydata: object) {
|
|
|
|
|
// console.log('saveTable', mydata)
|
|
|
|
|
|
|
|
|
|
return await Api.SendReq('/settable', 'POST', mydata)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
// console.table(res)
|
2019-10-14 20:32:15 +02:00
|
|
|
return res.data
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
2019-10-20 01:22:38 +02:00
|
|
|
console.log('error saveTable', error)
|
2019-10-14 20:32:15 +02:00
|
|
|
UserStore.mutations.setErrorCatch(error)
|
|
|
|
|
return null
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-20 22:44:18 +02:00
|
|
|
async function saveFieldValue(context, mydata: IDataPass) {
|
2019-12-28 14:30:51 +01:00
|
|
|
// console.log('saveFieldValue', mydata)
|
2019-10-15 20:40:23 +02:00
|
|
|
|
|
|
|
|
return await Api.SendReq(`/chval`, 'PATCH', { data: mydata })
|
|
|
|
|
.then((res) => {
|
2019-10-20 22:44:18 +02:00
|
|
|
if (res) {
|
|
|
|
|
Mutations.mutations.UpdateValuesInMemory(mydata)
|
2019-10-15 20:40:23 +02:00
|
|
|
return (res.data.code === serv_constants.RIS_CODE_OK)
|
2019-10-20 22:44:18 +02:00
|
|
|
} else
|
2019-10-15 20:40:23 +02:00
|
|
|
return false
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
return false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-10 21:06:42 +02:00
|
|
|
async function callFunz(context, { mydata }) {
|
|
|
|
|
// console.log('saveFieldValue', mydata)
|
|
|
|
|
|
|
|
|
|
return await Api.SendReq(`/callfunz`, 'PATCH', { data: mydata })
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (res) {
|
|
|
|
|
return (res.data.code === serv_constants.RIS_CODE_OK)
|
|
|
|
|
} else
|
|
|
|
|
return false
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
return false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-15 20:40:23 +02:00
|
|
|
async function DeleteRec(context, { table, id }) {
|
2019-10-24 23:30:18 +02:00
|
|
|
console.log('DeleteRec', table, id)
|
2019-10-15 20:40:23 +02:00
|
|
|
|
|
|
|
|
return await Api.SendReq('/delrec/' + table + '/' + id, 'DELETE', null)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (res.status === 200) {
|
|
|
|
|
if (res.data.code === serv_constants.RIS_CODE_OK) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.error(error)
|
|
|
|
|
return false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-27 20:36:18 +01:00
|
|
|
async function DeleteFile(context, { filename }) {
|
|
|
|
|
console.log('DeleteFile', filename)
|
|
|
|
|
|
|
|
|
|
return await Api.SendReq('/delfile', 'DELETE', {filename})
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (res.status === 200) {
|
|
|
|
|
if (res.data.code === serv_constants.RIS_CODE_OK) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.error(error)
|
|
|
|
|
return false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-20 22:44:18 +02:00
|
|
|
async function DuplicateRec(context, { table, id }) {
|
|
|
|
|
console.log('DuplicateRec', id)
|
|
|
|
|
|
|
|
|
|
return await Api.SendReq('/duprec/' + table + '/' + id, 'POST', null)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (res.status === 200) {
|
|
|
|
|
if (res.data.code === serv_constants.RIS_CODE_OK) {
|
|
|
|
|
return res.data.record
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.error(error)
|
|
|
|
|
return null
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-25 09:26:08 +01:00
|
|
|
async function InviaMsgADonatori(context, { msgobj, navemediatore, tipomsg }) {
|
2020-03-10 21:42:30 +01:00
|
|
|
console.log('InviaMsgADonatori', msgobj)
|
|
|
|
|
|
|
|
|
|
const mydata = {
|
|
|
|
|
idapp: process.env.APP_ID,
|
|
|
|
|
msgextra: msgobj.msgextra,
|
|
|
|
|
msgpar1: msgobj.msgpar1,
|
2020-03-25 09:26:08 +01:00
|
|
|
username: msgobj.username,
|
2020-04-07 14:33:56 +02:00
|
|
|
username_mitt: msgobj.username_mitt,
|
2020-03-25 09:26:08 +01:00
|
|
|
tipomsg,
|
2020-03-10 21:42:30 +01:00
|
|
|
inviareale: msgobj.inviareale,
|
|
|
|
|
navemediatore
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await Api.SendReq('/dashboard/msgnave', 'POST', mydata)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (res.status === 200) {
|
|
|
|
|
if (res.data.code === serv_constants.RIS_CODE_OK) {
|
|
|
|
|
return res.data.ris
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.error(error)
|
|
|
|
|
return null
|
|
|
|
|
})
|
|
|
|
|
}
|
2020-03-21 10:33:10 +01:00
|
|
|
async function GetArrNavi(context) {
|
|
|
|
|
console.log('GetArrNavi')
|
|
|
|
|
|
|
|
|
|
const mydata = {
|
|
|
|
|
idapp: process.env.APP_ID
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await Api.SendReq('/dashboard/getnavi', 'POST', mydata)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (res.status === 200) {
|
|
|
|
|
if (res.data.code === serv_constants.RIS_CODE_OK) {
|
|
|
|
|
return res.data.ris
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.error(error)
|
|
|
|
|
return null
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-07 14:33:56 +02:00
|
|
|
async function GetNave(context, { riga, col, riga1don, col1don, ind_order }) {
|
|
|
|
|
// console.log('GetNave')
|
|
|
|
|
|
|
|
|
|
const mydata = {
|
|
|
|
|
idapp: process.env.APP_ID,
|
|
|
|
|
riga,
|
|
|
|
|
col,
|
|
|
|
|
riga1don,
|
|
|
|
|
col1don,
|
|
|
|
|
ind_order
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await Api.SendReq('/dashboard/getnave', 'POST', mydata)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (res.status === 200) {
|
|
|
|
|
if (res.data.code === serv_constants.RIS_CODE_OK) {
|
|
|
|
|
return res.data.ris
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.error(error)
|
|
|
|
|
return null
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-31 20:34:49 +02:00
|
|
|
async function GetData(context, { data }) {
|
|
|
|
|
console.log('GetData')
|
|
|
|
|
|
|
|
|
|
const mydata = {
|
|
|
|
|
idapp: process.env.APP_ID,
|
|
|
|
|
data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await Api.SendReq('/dashboard/getdata', 'POST', mydata)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (res.status === 200) {
|
|
|
|
|
if (res.data.code === serv_constants.RIS_CODE_OK) {
|
|
|
|
|
return res.data.ris
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.error(error)
|
|
|
|
|
return null
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 22:43:54 +02:00
|
|
|
async function GetArrDoniNavi(context, { ricalcola, showall }) {
|
2020-03-21 10:33:10 +01:00
|
|
|
console.log('GetArrDoniNavi')
|
|
|
|
|
|
|
|
|
|
const mydata = {
|
2020-03-25 18:28:39 +01:00
|
|
|
idapp: process.env.APP_ID,
|
2020-05-11 22:43:54 +02:00
|
|
|
ricalcola,
|
|
|
|
|
showall
|
2020-03-21 10:33:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await Api.SendReq('/dashboard/getdoninavi', 'POST', mydata)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (res.status === 200) {
|
|
|
|
|
if (res.data.code === serv_constants.RIS_CODE_OK) {
|
|
|
|
|
return res.data.ris
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.error(error)
|
|
|
|
|
return null
|
|
|
|
|
})
|
|
|
|
|
}
|
2020-03-10 21:42:30 +01:00
|
|
|
|
2019-10-23 23:47:12 +02:00
|
|
|
async function loadSite(context) {
|
|
|
|
|
// console.log('CalendarStore: loadAfterLogin')
|
|
|
|
|
// Load local data
|
|
|
|
|
const showall = UserStore.state.isAdmin || UserStore.state.isManager ? '1' : '0'
|
|
|
|
|
|
2019-10-25 19:07:56 +02:00
|
|
|
const myuserid = (UserStore.state.my._id) ? UserStore.state.my._id : '0'
|
2019-10-23 23:47:12 +02:00
|
|
|
|
2019-11-08 23:43:00 +01:00
|
|
|
CalendarStore.state.editable = false
|
|
|
|
|
|
2019-11-04 20:29:35 +01:00
|
|
|
return await Api.SendReq('/loadsite/' + myuserid + '/' + process.env.APP_ID + '/' + showall, 'GET', null)
|
2019-10-23 23:47:12 +02:00
|
|
|
.then((res) => {
|
2020-01-13 23:53:27 +01:00
|
|
|
// console.log('____________________________ res', res)
|
2020-01-03 22:03:59 +01:00
|
|
|
if (res.status === 200) {
|
|
|
|
|
CalendarStore.state.bookedevent = (res.data.bookedevent) ? res.data.bookedevent : []
|
|
|
|
|
CalendarStore.state.eventlist = (res.data.eventlist) ? res.data.eventlist : []
|
|
|
|
|
CalendarStore.state.operators = (res.data.operators) ? res.data.operators : []
|
|
|
|
|
CalendarStore.state.wheres = (res.data.wheres) ? res.data.wheres : []
|
|
|
|
|
CalendarStore.state.contribtype = (res.data.contribtype) ? res.data.contribtype : []
|
|
|
|
|
GlobalStore.state.settings = (res.data.settings) ? [...res.data.settings] : []
|
|
|
|
|
GlobalStore.state.disciplines = (res.data.disciplines) ? [...res.data.disciplines] : []
|
|
|
|
|
GlobalStore.state.paymenttypes = (res.data.paymenttypes) ? [...res.data.paymenttypes] : []
|
|
|
|
|
GlobalStore.state.gallery = (res.data.gallery) ? [...res.data.gallery] : []
|
2020-01-21 01:38:28 +01:00
|
|
|
GlobalStore.state.calzoom = (res.data.calzoom) ? [...res.data.calzoom] : []
|
2020-01-03 22:03:59 +01:00
|
|
|
|
|
|
|
|
if (showall) {
|
|
|
|
|
GlobalStore.state.newstosent = (res.data.newstosent) ? [...res.data.newstosent] : []
|
|
|
|
|
GlobalStore.state.mailinglist = (res.data.mailinglist) ? [...res.data.mailinglist] : []
|
|
|
|
|
GlobalStore.state.mypage = (res.data.mypage) ? [...res.data.mypage] : []
|
|
|
|
|
}
|
2019-11-21 00:19:42 +01:00
|
|
|
|
2020-01-27 15:09:11 +01:00
|
|
|
// console.log('res.data.myuser', res.data.myuser)
|
2020-01-03 22:03:59 +01:00
|
|
|
if (res.data.myuser) {
|
|
|
|
|
UserStore.mutations.authUser(res.data.myuser)
|
2019-12-29 01:54:00 +01:00
|
|
|
|
2020-01-03 22:03:59 +01:00
|
|
|
UserStore.mutations.updateLocalStorage(res.data.myuser)
|
2020-01-20 01:50:21 +01:00
|
|
|
} else {
|
|
|
|
|
// User not exist !!
|
|
|
|
|
|
2020-01-03 22:03:59 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-20 01:50:21 +01:00
|
|
|
const islogged = localStorage.getItem(tools.localStorage.username)
|
|
|
|
|
console.log('islogged', islogged)
|
2019-12-29 01:54:00 +01:00
|
|
|
|
2020-04-07 14:33:56 +02:00
|
|
|
CalendarStore.state.editable = UserStore.state.isAdmin || UserStore.state.isManager || UserStore.state.isTutor
|
2020-01-20 01:50:21 +01:00
|
|
|
if (res.data.myuser === null) {
|
|
|
|
|
if (islogged) {
|
|
|
|
|
// Fai Logout
|
|
|
|
|
console.log('Fai Logout', 'islogged', islogged)
|
|
|
|
|
UserStore.actions.logout()
|
|
|
|
|
GlobalStore.state.RightDrawerOpen = true
|
|
|
|
|
return false
|
|
|
|
|
}
|
2020-01-03 22:03:59 +01:00
|
|
|
}
|
2020-01-20 01:50:21 +01:00
|
|
|
|
2020-01-03 22:03:59 +01:00
|
|
|
}
|
2019-11-08 23:43:00 +01:00
|
|
|
|
2020-01-20 01:50:21 +01:00
|
|
|
return true
|
|
|
|
|
|
2019-10-23 23:47:12 +02:00
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.log('error dbLoad', error)
|
|
|
|
|
// UserStore.mutations.setErrorCatch(error)
|
|
|
|
|
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, tools.ERR_GENERICO, error)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-04 02:04:54 +01:00
|
|
|
async function sendEmailTest(context, { previewonly }) {
|
2019-11-21 00:19:42 +01:00
|
|
|
const usertosend = {
|
2019-12-04 02:04:54 +01:00
|
|
|
locale: tools.getLocale(),
|
|
|
|
|
previewonly
|
2019-11-21 00:19:42 +01:00
|
|
|
}
|
|
|
|
|
console.log(usertosend)
|
|
|
|
|
|
2019-12-04 02:04:54 +01:00
|
|
|
return await Api.SendReq('/news/testemail', 'POST', usertosend)
|
2019-11-21 00:19:42 +01:00
|
|
|
.then((res) => {
|
|
|
|
|
return res
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-31 20:34:49 +02:00
|
|
|
function isMyLang(rec) {
|
|
|
|
|
if (!rec.lang)
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
|
|
return (rec.lang === tools.getLocale(false) || tools.getLocale() === '')
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-07 00:20:55 +01:00
|
|
|
async function addDynamicPages(context) {
|
|
|
|
|
|
|
|
|
|
const arrpagesroute: IListRoutes[] = []
|
|
|
|
|
for (const page of state.mypage) {
|
2019-12-28 02:17:07 +01:00
|
|
|
if (page.active) {
|
2020-03-31 20:34:49 +02:00
|
|
|
// console.log('page', page.lang)
|
|
|
|
|
if (isMyLang(page)) {
|
|
|
|
|
// console.log('page', page.lang, 'OK')
|
|
|
|
|
arrpagesroute.push({
|
|
|
|
|
active: true,
|
|
|
|
|
order: page.order,
|
|
|
|
|
lang: page.lang,
|
|
|
|
|
path: '/' + page.path,
|
|
|
|
|
name: undefined,
|
|
|
|
|
text: page.title,
|
|
|
|
|
materialIcon: page.icon,
|
|
|
|
|
component: () => import('@/root/mypage/mypage.vue'),
|
|
|
|
|
inmenu: page.inmenu,
|
|
|
|
|
infooter: page.infooter,
|
|
|
|
|
onlyif_logged: page.onlyif_logged,
|
|
|
|
|
level_child: page.l_child,
|
|
|
|
|
level_parent: page.l_par,
|
|
|
|
|
})
|
|
|
|
|
}
|
2019-12-28 02:17:07 +01:00
|
|
|
}
|
2019-12-07 00:20:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const last = {
|
2019-12-28 14:30:51 +01:00
|
|
|
active: true,
|
2019-12-31 00:44:43 +01:00
|
|
|
order: 10000,
|
2019-12-07 00:20:55 +01:00
|
|
|
path: '*',
|
|
|
|
|
materialIcon: 'fas fa-calendar-plus',
|
|
|
|
|
name: 'otherpages.error404def',
|
|
|
|
|
component: () => import('@/root/My404page/My404page.vue'),
|
|
|
|
|
inmenu: false,
|
|
|
|
|
infooter: false
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-10 21:06:42 +02:00
|
|
|
const sito_offline = {
|
|
|
|
|
active: true,
|
|
|
|
|
order: 20,
|
|
|
|
|
path: '/sito_offline',
|
|
|
|
|
materialIcon: 'home',
|
|
|
|
|
name: 'otherpages.sito_offline',
|
|
|
|
|
component: () => import('@/rootgen/sito_offline/sito_offline.vue'),
|
|
|
|
|
inmenu: true,
|
|
|
|
|
infooter: true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!tools.sito_online(false)) {
|
|
|
|
|
static_data.routes = [sito_offline, last]
|
|
|
|
|
} else {
|
|
|
|
|
static_data.routes = [...static_data.baseroutes, ...arrpagesroute, last]
|
|
|
|
|
}
|
2019-12-31 00:44:43 +01:00
|
|
|
|
|
|
|
|
// Sort array
|
|
|
|
|
static_data.routes = static_data.routes.sort((a, b) => a.order - b.order)
|
2019-12-07 00:20:55 +01:00
|
|
|
|
2020-05-10 21:06:42 +02:00
|
|
|
if (tools.sito_online(false)) {
|
|
|
|
|
router.addRoutes([...arrpagesroute, last])
|
|
|
|
|
} else {
|
|
|
|
|
router.addRoutes([sito_offline, last])
|
|
|
|
|
this.$router.replace('/sito_offline')
|
|
|
|
|
}
|
2019-12-07 00:20:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function sendFile(context, formdata) {
|
|
|
|
|
try {
|
|
|
|
|
const { data } = await Api.postFormData('/upload', formdata)
|
|
|
|
|
console.log(data)
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log('Error sendFile: ', e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 19:48:37 +01:00
|
|
|
export const actions = {
|
2019-02-05 18:17:36 +01:00
|
|
|
setConta: b.dispatch(setConta),
|
|
|
|
|
createPushSubscription: b.dispatch(createPushSubscription),
|
|
|
|
|
loadAfterLogin: b.dispatch(loadAfterLogin),
|
2019-10-23 23:47:12 +02:00
|
|
|
loadSite: b.dispatch(loadSite),
|
2019-02-09 18:04:49 +01:00
|
|
|
clearDataAfterLogout: b.dispatch(clearDataAfterLogout),
|
2019-02-12 12:06:01 +01:00
|
|
|
clearDataAfterLoginOnlyIfActiveConnection: b.dispatch(clearDataAfterLoginOnlyIfActiveConnection),
|
2019-02-22 10:23:00 +01:00
|
|
|
prova: b.dispatch(prova),
|
|
|
|
|
saveCfgServerKey: b.dispatch(saveCfgServerKey),
|
2019-10-14 20:32:15 +02:00
|
|
|
checkUpdates: b.dispatch(checkUpdates),
|
2019-10-15 20:40:23 +02:00
|
|
|
saveFieldValue: b.dispatch(saveFieldValue),
|
2020-05-10 21:06:42 +02:00
|
|
|
callFunz: b.dispatch(callFunz),
|
|
|
|
|
sendPushNotif: b.dispatch(sendPushNotif),
|
2019-10-15 20:40:23 +02:00
|
|
|
loadTable: b.dispatch(loadTable),
|
2019-10-20 01:22:38 +02:00
|
|
|
saveTable: b.dispatch(saveTable),
|
2019-10-20 22:44:18 +02:00
|
|
|
DeleteRec: b.dispatch(DeleteRec),
|
2019-12-27 20:36:18 +01:00
|
|
|
DeleteFile: b.dispatch(DeleteFile),
|
2019-11-21 00:19:42 +01:00
|
|
|
sendEmailTest: b.dispatch(sendEmailTest),
|
2019-12-07 00:20:55 +01:00
|
|
|
DuplicateRec: b.dispatch(DuplicateRec),
|
2020-03-10 21:42:30 +01:00
|
|
|
InviaMsgADonatori: b.dispatch(InviaMsgADonatori),
|
2020-03-21 10:33:10 +01:00
|
|
|
GetArrNavi: b.dispatch(GetArrNavi),
|
2020-04-07 14:33:56 +02:00
|
|
|
GetNave: b.dispatch(GetNave),
|
2020-03-21 10:33:10 +01:00
|
|
|
GetArrDoniNavi: b.dispatch(GetArrDoniNavi),
|
2020-03-31 20:34:49 +02:00
|
|
|
GetData: b.dispatch(GetData),
|
2019-12-07 00:20:55 +01:00
|
|
|
addDynamicPages: b.dispatch(addDynamicPages)
|
2018-11-15 19:48:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-22 23:30:02 +01:00
|
|
|
const stateGetter = b.state()
|
|
|
|
|
|
2018-11-15 19:48:37 +01:00
|
|
|
// Module
|
|
|
|
|
const GlobalModule = {
|
2018-12-26 21:02:16 +01:00
|
|
|
get state() {
|
|
|
|
|
return stateGetter()
|
|
|
|
|
},
|
2019-03-13 01:53:53 +01:00
|
|
|
actions: Actions.actions,
|
2018-11-15 19:48:37 +01:00
|
|
|
getters: Getters.getters,
|
2019-03-13 01:53:53 +01:00
|
|
|
mutations: Mutations.mutations
|
2018-11-15 19:48:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default GlobalModule
|