First Committ
This commit is contained in:
492
src/store/Modules/ApiTables.ts
Executable file
492
src/store/Modules/ApiTables.ts
Executable file
@@ -0,0 +1,492 @@
|
||||
import Api from '@api'
|
||||
import { ITodo } from '@src/model'
|
||||
import { tools } from '@src/store/Modules/tools'
|
||||
import { toolsext } from '@src/store/Modules/toolsext'
|
||||
import { useUserStore } from '@store/UserStore'
|
||||
import { serv_constants } from '@store/Modules/serv_constants'
|
||||
import { costanti } from '@store/Modules/costanti'
|
||||
import { useGlobalStore } from '@store/globalStore'
|
||||
import globalroutines from '../../globalroutines/index'
|
||||
|
||||
export function getLinkByTableName(nametable: string) {
|
||||
if (nametable === 'todos') {
|
||||
return 'todos'
|
||||
}
|
||||
if (nametable === 'projects') {
|
||||
return 'projects'
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
export const DB = {
|
||||
CMD_SYNC: 'sync',
|
||||
CMD_SYNC_NEW: 'sync-new',
|
||||
CMD_DELETE: 'sync-delete',
|
||||
CMD_HIDE: 'sync-hide',
|
||||
TABLE_SYNC_POST: 'sync_post_',
|
||||
TABLE_SYNC_PATCH: 'sync_patch_',
|
||||
TABLE_DELETE: 'delete_',
|
||||
TABLE_HIDE: 'hide_',
|
||||
}
|
||||
|
||||
export function allTables() {
|
||||
/* const myarr = OtherTables
|
||||
for (const tab of costanti.MainTables) {
|
||||
for (const method of costanti.allMethod) {
|
||||
myarr.push(method + tab)
|
||||
}
|
||||
} */
|
||||
return costanti.OtherTables
|
||||
}
|
||||
|
||||
async function updatefromIndexedDbToState(nametab: string) {
|
||||
await globalroutines(null, 'updatefromIndexedDbToState', nametab, null)
|
||||
.then(() => {
|
||||
console.log('updatefromIndexedDbToState! ')
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
async function checkPendingMsg() {
|
||||
// console.log('checkPendingMsg')
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
const config = await globalroutines(null, 'read', 'config', null, '1')
|
||||
// console.log('config', config)
|
||||
|
||||
try {
|
||||
if (config) {
|
||||
if (config[1].stateconn) {
|
||||
console.log('config.stateconn', config[1].stateconn)
|
||||
|
||||
if (config[1].stateconn !== globalStore.stateConnection) {
|
||||
globalStore.setStateConnection(config[1].stateconn)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// ...
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => globalroutines(null, 'count', 'swmsg')
|
||||
.then((count) => {
|
||||
if (count > 0) {
|
||||
return resolve(true)
|
||||
}
|
||||
return resolve(false)
|
||||
}).catch(() => reject()))
|
||||
}
|
||||
|
||||
function useServiceWorker() {
|
||||
return false // return 'serviceWorker' in navigator
|
||||
}
|
||||
|
||||
// If something in the call of Service Worker went wrong (Network or Server Down), then retry !
|
||||
async function sendSwMsgIfAvailable() {
|
||||
let something = false
|
||||
|
||||
if (useServiceWorker()) {
|
||||
console.log(' -------- sendSwMsgIfAvailable')
|
||||
|
||||
const count = await checkPendingMsg()
|
||||
if (count) {
|
||||
return navigator.serviceWorker.ready
|
||||
.then(() => globalroutines(null, 'readall', 'swmsg')
|
||||
.then((arr_recmsg) => {
|
||||
if (arr_recmsg.length > 0) {
|
||||
// console.log('---------------------- 2) navigator (2) .serviceWorker.ready')
|
||||
let promiseChain = Promise.resolve()
|
||||
|
||||
for (const rec of arr_recmsg) {
|
||||
// #Alternative to SyncManager
|
||||
promiseChain = promiseChain.then(() => Api.syncAlternative(rec._id)
|
||||
.then(() => {
|
||||
//++Todo conv: something = true
|
||||
}))
|
||||
}
|
||||
return promiseChain
|
||||
}
|
||||
return null
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(something)
|
||||
})
|
||||
}
|
||||
|
||||
export async function waitAndRefreshData() {
|
||||
// ++Todo: conv
|
||||
/* await Projects.actions.dbLoad({ checkPending: false, onlyiffirsttime: false })
|
||||
return await Todos.actions.dbLoad({ checkPending: false })
|
||||
*/
|
||||
return null
|
||||
}
|
||||
|
||||
export async function waitAndcheckPendingMsg() {
|
||||
// await aspettansec(1000)
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
return checkPendingMsg()
|
||||
.then((ris) => {
|
||||
if (ris) {
|
||||
if (!globalStore.isOnline()) { // If is Offline, then check
|
||||
|
||||
}
|
||||
|
||||
return sendSwMsgIfAvailable()
|
||||
.then((something) => {
|
||||
if (something) {
|
||||
if (process.env.DEBUG === '1') {
|
||||
console.log('something')
|
||||
}
|
||||
// Refresh data
|
||||
return waitAndRefreshData()
|
||||
}
|
||||
return null
|
||||
})
|
||||
}
|
||||
return null
|
||||
})
|
||||
}
|
||||
|
||||
async function dbInsertSave(call: string, item: any, method: string) {
|
||||
let ret = true
|
||||
const userStore = useUserStore()
|
||||
if (!useServiceWorker()) {
|
||||
console.log('dbInsertSave', item, method)
|
||||
|
||||
if (userStore.isUserInvalid) {
|
||||
return false
|
||||
} // Login not made
|
||||
|
||||
call = `/${call}`
|
||||
if (method !== 'POST') {
|
||||
call += `/${item._id}`
|
||||
}
|
||||
|
||||
console.log('SAVE: ', item)
|
||||
|
||||
ret = await Api.SendReq(call, method, item)
|
||||
.then((res: any) => {
|
||||
console.log('dbInsertSave ', call, 'to the Server', res.data)
|
||||
|
||||
return (res.status === 200)
|
||||
})
|
||||
.catch((error: any) => {
|
||||
userStore.setErrorCatch(error)
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
async function dbDeleteItem(call: string, item: any) {
|
||||
let res = true
|
||||
const userStore = useUserStore()
|
||||
if (!useServiceWorker()) {
|
||||
// console.log('dbdeleteItem', item)
|
||||
if (userStore.isUserInvalid) {
|
||||
return false
|
||||
} // Login not made
|
||||
|
||||
call = `/${call}`
|
||||
|
||||
res = await Api.SendReq(`${call}/${item._id}`, 'DELETE', null)
|
||||
.then((myres: any) => {
|
||||
console.log('dbdeleteItem to the Server')
|
||||
// tools.showPositiveNotif(this.$q, 'Riga cancellata')
|
||||
return myres
|
||||
})
|
||||
.catch((error: any) => {
|
||||
userStore.setErrorCatch(error)
|
||||
return userStore.getServerCode
|
||||
})
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
async function dbHideItem(call: string, item: any) {
|
||||
const userStore = useUserStore()
|
||||
|
||||
if (!useServiceWorker()) {
|
||||
// console.log('dbdeleteItem', item)
|
||||
if (userStore.isUserInvalid) {
|
||||
return false
|
||||
} // Login not made
|
||||
|
||||
item = {
|
||||
...item,
|
||||
hide: true,
|
||||
}
|
||||
|
||||
console.log('dbHideItem', item)
|
||||
|
||||
call = `/${call}`
|
||||
|
||||
return Api.SendReq(`${call + item._id}/true`, 'DELETE', null)
|
||||
.then((myres: any) => {
|
||||
console.log('dbHideItem to the Server')
|
||||
return myres
|
||||
})
|
||||
.catch((error: any) => {
|
||||
userStore.setErrorCatch(error)
|
||||
return userStore.getServerCode
|
||||
})
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
async function Sync_Execute(cmd: string, tablesync: string, nametab: string, method: string, item: ITodo, id: string, msg: string) {
|
||||
// Send to Server to Sync
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
console.log('Sync_Execute', cmd, tablesync, nametab, method, id, msg)
|
||||
if (nametab === 'todos') {
|
||||
console.log(' TODO: ', item.descr)
|
||||
}
|
||||
|
||||
let cmdSw = cmd
|
||||
if ((cmd === DB.CMD_SYNC_NEW) || (cmd === DB.CMD_DELETE) || (cmd === DB.CMD_HIDE)) {
|
||||
cmdSw = DB.CMD_SYNC
|
||||
}
|
||||
|
||||
// console.log('cmdSw', cmdSw)
|
||||
|
||||
// if ('serviceWorker' in navigator) {
|
||||
// console.log('serviceWorker PRESENTE')
|
||||
// } else {
|
||||
// console.log('serviceWorker NON PRESENTE !')
|
||||
// }
|
||||
// console.log('---------------------- navigator.serviceWorker.ready')
|
||||
|
||||
if (useServiceWorker()) {
|
||||
return navigator.serviceWorker.ready
|
||||
.then((sw) => {
|
||||
globalroutines(null, 'write', tablesync, item, id)
|
||||
.then((ris) => {
|
||||
console.log('ris write:', ris)
|
||||
const sep = '|'
|
||||
|
||||
const multiparams = cmdSw + sep + tablesync + sep + nametab + sep + method + sep + userStore.x_auth_token + sep + toolsext.getLocale()
|
||||
const mymsgkey = {
|
||||
_id: multiparams,
|
||||
value: multiparams,
|
||||
}
|
||||
/* console.log('*** swmsg')
|
||||
// if ('SyncManager' in window) {
|
||||
// console.log(' SENDING... sw.sync.register', multiparams)
|
||||
// return sw.sync.register(multiparams)
|
||||
// } else {
|
||||
*/
|
||||
return globalroutines(null, 'write', 'swmsg', mymsgkey, multiparams)
|
||||
.then((ris2) => Api.syncAlternative(multiparams))
|
||||
.then(() => {
|
||||
let data = null
|
||||
if (msg !== '') {
|
||||
data = { message: msg, position: 'bottom', timeout: 3000 }
|
||||
}
|
||||
return data
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Errore in globalroutines', tablesync, nametab, err)
|
||||
})
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Errore catch in globalroutines write', tablesync, nametab, err)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function Sync_ExecuteCmd(cmd: string, nametab: string, method: string, item: ITodo, id: string, msg: string) {
|
||||
// Send to Server to Sync
|
||||
|
||||
let tablesync = ''
|
||||
if (method === 'POST') {
|
||||
tablesync = DB.TABLE_SYNC_POST + nametab
|
||||
} else if (method === 'PATCH') {
|
||||
tablesync = DB.TABLE_SYNC_PATCH + nametab
|
||||
} else if (method === 'DELETE') {
|
||||
tablesync = DB.TABLE_DELETE + nametab
|
||||
} else if (method === 'HIDE') {
|
||||
tablesync = DB.TABLE_HIDE + nametab
|
||||
}
|
||||
|
||||
const risdata = await Sync_Execute(cmd, tablesync, nametab, method, item, id, msg)
|
||||
|
||||
let ris = false
|
||||
if (cmd === DB.CMD_SYNC_NEW) {
|
||||
if ((method === 'POST') || (method === 'PATCH')) {
|
||||
ris = await dbInsertSave(nametab, item, method)
|
||||
}
|
||||
} else if (cmd === DB.CMD_DELETE) {
|
||||
ris = await dbDeleteItem(nametab, item)
|
||||
} else if (cmd === DB.CMD_HIDE) {
|
||||
ris = await dbHideItem(nametab, item)
|
||||
}
|
||||
|
||||
return ris
|
||||
}
|
||||
|
||||
export async function Sync_SaveItem(nametab: string, method: string, item: any) {
|
||||
return Sync_ExecuteCmd(DB.CMD_SYNC_NEW, nametab, method, item, '0', '')
|
||||
}
|
||||
|
||||
export function Sync_DeleteItem(nametab: string, item: any, id: string) {
|
||||
Sync_ExecuteCmd(DB.CMD_DELETE, nametab, 'DELETE', item, id, '')
|
||||
}
|
||||
|
||||
export function Sync_HideItem(nametab: string, item: any, id: string) {
|
||||
Sync_ExecuteCmd(DB.CMD_HIDE, nametab, 'HIDE', item, id, '')
|
||||
}
|
||||
|
||||
export async function aftercalling(ris: any, checkPending: boolean, nametabindex: string) {
|
||||
const userStore = useUserStore()
|
||||
if (ris.status !== 200) {
|
||||
if (process.env.DEBUG === '1') {
|
||||
console.log('ris.status', ris.status)
|
||||
}
|
||||
if (ris.status === serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN) {
|
||||
tools.consolelogpao('UNAUTHORIZING... TOKEN EXPIRED... !! ')
|
||||
} else {
|
||||
tools.consolelogpao('NETWORK UNREACHABLE ! (Error in fetch)', userStore.getServerCode, ris.status)
|
||||
}
|
||||
if (useServiceWorker()) {
|
||||
// Read all data from IndexedDB Store into Memory
|
||||
await updatefromIndexedDbToState(nametabindex)
|
||||
}
|
||||
} else if (ris.status === tools.OK && checkPending) {
|
||||
waitAndcheckPendingMsg()
|
||||
}
|
||||
}
|
||||
|
||||
export function removeitemfromarray(myarray: any, ind: any) {
|
||||
// console.log('PRIMA todos', todos)
|
||||
// Delete Item in to Array
|
||||
if (ind >= 0) {
|
||||
myarray.splice(ind, 1)
|
||||
}
|
||||
// console.log('DOPO todos', todos, 'ind', ind)
|
||||
}
|
||||
|
||||
/*
|
||||
export async functionfunction testfunc() {
|
||||
while (true) {
|
||||
tools.consolelogpao('testfunc')
|
||||
// console.log('Todos.todos_changed:', Todos.todos_changed)
|
||||
await tools.aspettansec(5000)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
sendMessageToSW(recdata, method) {
|
||||
|
||||
navigator.serviceWorker.controller.postMessage({
|
||||
type: 'sync',
|
||||
recdata,
|
||||
method,
|
||||
cmd: 'sync-new-todos',
|
||||
token: userStore.idToken,
|
||||
lang: userStore.lang
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
||||
function setmodifiedIfchanged(recOut: any, recIn: any, field: string) {
|
||||
if (String(recOut[field]) !== String(recIn[field])) {
|
||||
console.log('*************** CAMPO ', field, 'MODIFICATO!', recOut[field], recIn[field])
|
||||
recOut.modified = true
|
||||
recOut[field] = recIn[field]
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
export async function table_ModifyRecord(nametable: string, myitem: any, listFieldsToChange: any, field: string) {
|
||||
// console.log('table_ModifyRecord ... ', nametable)
|
||||
if (myitem === null) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
|
||||
console.log('--> table_ModifyRecord', nametable, myitem)
|
||||
|
||||
if ((field === 'status') && (nametable === 'todos') && (myitem.status === tools.Status.COMPLETED)) {
|
||||
myitem.completed_at = tools.getDateNow()
|
||||
}
|
||||
|
||||
const myobjsaved = tools.jsonCopy(myitem)
|
||||
|
||||
let miorec: any = null
|
||||
if (useServiceWorker()) {
|
||||
// get record from IndexedDb
|
||||
miorec = await globalroutines(null, 'read', nametable, null, myobjsaved._id)
|
||||
if (miorec === undefined) {
|
||||
console.log('~~~~~~~~~~~~~~~~~~~~ !!!!!!!!!!!!!!!!!! Record not Found !!!!!! id=', myobjsaved._id)
|
||||
|
||||
// Prova cmq a salvarlo sul server
|
||||
return Sync_SaveItem(nametable, 'PATCH', miorec)
|
||||
}
|
||||
listFieldsToChange.forEach((myfield: any) => {
|
||||
setmodifiedIfchanged(miorec, myobjsaved, myfield)
|
||||
})
|
||||
} else {
|
||||
miorec = myitem
|
||||
miorec.modified = true
|
||||
}
|
||||
|
||||
console.log(' ... 4 ')
|
||||
|
||||
if (miorec.modified) {
|
||||
console.log(` ${nametable} MODIFICATO! `, miorec.descr, miorec.pos, 'SALVALO SULLA IndexedDB')
|
||||
miorec.modify_at = tools.getDateNow()
|
||||
miorec.modified = false
|
||||
|
||||
// 1) Permit to Update the Views
|
||||
tools.notifyarraychanged(miorec)
|
||||
|
||||
if (useServiceWorker()) {
|
||||
// 2) Modify on IndexedDb
|
||||
console.log('// 2) Modify on IndexedDb', miorec)
|
||||
return globalroutines(null, 'write', nametable, miorec)
|
||||
.then((ris) => Sync_SaveItem(nametable, 'PATCH', miorec)) // 3) Modify on the Server (call)
|
||||
}
|
||||
return Sync_SaveItem(nametable, 'PATCH', miorec)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export function table_DeleteRecord(nametable: string, myobjtrov: any, id: any) {
|
||||
const mymodule: any = tools.getModulesByTable(nametable)
|
||||
|
||||
// 1) Delete from the Todos Array
|
||||
mymodule.deletemyitem(myobjtrov)
|
||||
|
||||
// 2) Delete from the IndexedDb
|
||||
globalroutines(null, 'delete', nametable, null, id)
|
||||
|
||||
// 3) Delete from the Server (call)
|
||||
Sync_DeleteItem(nametable, myobjtrov, id)
|
||||
}
|
||||
|
||||
export function table_HideRecord(nametable: string, myobjtrov: any, id: any) {
|
||||
const mymodule: any = tools.getModulesByTable(nametable)
|
||||
|
||||
// 1) Delete from the Todos Array
|
||||
mymodule.deletemyitem(myobjtrov)
|
||||
|
||||
// 2) Delete from the IndexedDb
|
||||
globalroutines(null, 'delete', nametable, null, id)
|
||||
|
||||
// 3) Hide from the Server (call)
|
||||
Sync_DeleteItem(nametable, myobjtrov, id)
|
||||
}
|
||||
79
src/store/Modules/ProgressBar.ts
Executable file
79
src/store/Modules/ProgressBar.ts
Executable file
@@ -0,0 +1,79 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
import { nextTick } from 'vue'
|
||||
|
||||
const css = require('@css')
|
||||
|
||||
let TIMER: any = null
|
||||
let TIMEOUT: any = null
|
||||
let CUT: any = null
|
||||
|
||||
export const useProgressBar = defineStore('ProgressBar', {
|
||||
state: () => ({
|
||||
percent: 0,
|
||||
show: false,
|
||||
canSuccess: true,
|
||||
duration: 3000,
|
||||
height: '2px',
|
||||
color: css.mainStyle,
|
||||
failedColor: css.red1,
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
start(): void {
|
||||
if (!this.show) {
|
||||
clearTimeout(TIMEOUT)
|
||||
this.show = true
|
||||
this.canSuccess = true
|
||||
if (TIMER) {
|
||||
clearInterval(TIMER)
|
||||
this.percent = 0
|
||||
}
|
||||
CUT = 20000 / Math.floor(this.duration)
|
||||
TIMER = setInterval(() => {
|
||||
this.increase(CUT * Math.random())
|
||||
if (this.percent > 80) {
|
||||
this.pause()
|
||||
}
|
||||
}, 200)
|
||||
}
|
||||
},
|
||||
set(num: number): void {
|
||||
this.show = true
|
||||
this.canSuccess = true
|
||||
this.percent = Math.floor(num)
|
||||
},
|
||||
increase(num: number) {
|
||||
this.percent += Math.floor(num)
|
||||
},
|
||||
decrease(num: number) {
|
||||
this.percent -= Math.floor(num)
|
||||
},
|
||||
finish(): void {
|
||||
this.percent = 100
|
||||
this.hide()
|
||||
},
|
||||
pause() {
|
||||
clearInterval(TIMER)
|
||||
},
|
||||
hide() {
|
||||
clearInterval(TIMER)
|
||||
TIMER = null
|
||||
TIMEOUT = setTimeout(() => {
|
||||
this.show = false
|
||||
this.percent = 0
|
||||
nextTick(() => {
|
||||
setTimeout(() => {
|
||||
this.percent = 0
|
||||
}, 200)
|
||||
})
|
||||
}, 500)
|
||||
},
|
||||
|
||||
fail() {
|
||||
this.canSuccess = false
|
||||
this.finish()
|
||||
},
|
||||
|
||||
},
|
||||
})
|
||||
59
src/store/Modules/costanti.ts
Executable file
59
src/store/Modules/costanti.ts
Executable file
@@ -0,0 +1,59 @@
|
||||
export const costanti = {
|
||||
ShowTypeTask: {
|
||||
SHOW_LAST_N_COMPLETED: 200,
|
||||
SHOW_ONLY_TOCOMPLETE: 201,
|
||||
SHOW_ALL: 202,
|
||||
},
|
||||
CONFIG_ID_CFG: '1',
|
||||
CONFIG_ID_STATE_CONN: '2',
|
||||
CONFIG_ID_SHOW_TYPE_TODOS: '3',
|
||||
|
||||
FuncDialog: {
|
||||
CANCEL_BOOKING: 1,
|
||||
},
|
||||
|
||||
DRAGULA: false,
|
||||
|
||||
TABEVENTS: 'myevents',
|
||||
|
||||
NOFIELD: 'nofield',
|
||||
|
||||
MAX_PHASES: 5,
|
||||
|
||||
OtherTables: ['config', 'swmsg'],
|
||||
// export const MainTables = ['todos', 'projects']
|
||||
MainTables: [],
|
||||
allMethod: ['sync_post_', 'sync_patch_', 'delete_', 'hide_'],
|
||||
|
||||
FieldType: {
|
||||
boolean: 1,
|
||||
date: 2,
|
||||
string: 4,
|
||||
binary: 8,
|
||||
html: 16,
|
||||
select: 32,
|
||||
number: 64,
|
||||
typeinrec: 128,
|
||||
multiselect: 256,
|
||||
password: 512,
|
||||
listimages: 1024,
|
||||
exact: 2048,
|
||||
image: 3000,
|
||||
nationality: 4096,
|
||||
intcode: 5000,
|
||||
multioption: 6000,
|
||||
onlydate: 7000,
|
||||
hours: 8000,
|
||||
},
|
||||
FieldTypeArr: [
|
||||
{ label: 'Boolean', value: 1 },
|
||||
{ label: 'Date', value: 2 },
|
||||
{ label: 'String', value: 4 },
|
||||
{ label: 'Binary', value: 8 },
|
||||
{ label: 'Html', value: 16 },
|
||||
{ label: 'Select', value: 32 },
|
||||
{ label: 'Number', value: 64 },
|
||||
],
|
||||
|
||||
|
||||
}
|
||||
1310
src/store/Modules/fieldsTable.ts
Executable file
1310
src/store/Modules/fieldsTable.ts
Executable file
File diff suppressed because it is too large
Load Diff
180
src/store/Modules/lists.ts
Executable file
180
src/store/Modules/lists.ts
Executable file
@@ -0,0 +1,180 @@
|
||||
export const lists = {
|
||||
MenuAction: {
|
||||
CUT: 71,
|
||||
PASTE: 72,
|
||||
DELETE: 100,
|
||||
TOGGLE_EXPIRING: 101,
|
||||
COMPLETED: 110,
|
||||
PROGRESS_BAR: 120,
|
||||
PRIORITY: 130,
|
||||
SHOW_TASK: 150,
|
||||
SHOW_POSIZ: 155,
|
||||
EDIT: 160,
|
||||
ADD_PROJECT: 200,
|
||||
THEME: 210,
|
||||
THEMEBG: 211,
|
||||
|
||||
DELETE_RECTABLE: 300,
|
||||
DUPLICATE_RECTABLE: 310,
|
||||
DELETE_EVENT: 320,
|
||||
DELETE_EXTRALIST: 330,
|
||||
DELETE_USERLIST: 335,
|
||||
REGALA_INVITATO: 340,
|
||||
REGALA_INVITANTE: 342,
|
||||
SOSTITUISCI: 345,
|
||||
INVIA_MSG_A_DONATORI: 350,
|
||||
INVIA_MSG_A_FLOTTA: 352,
|
||||
INVIA_MSG_A_SINGOLO: 355,
|
||||
DONO_INVIATO: 360,
|
||||
DONO_RICEVUTO: 370,
|
||||
AGGIUNGI_NUOVO_IMBARCO: 380,
|
||||
CANCELLA_IMBARCO: 385,
|
||||
DAMMI_PRIMO_UTENTE_LIBERO: 390,
|
||||
|
||||
CAN_EDIT_TABLE: 400,
|
||||
SHOW_PREV_REC: 401,
|
||||
ZOOM_GIA_PARTECIPATO: 510,
|
||||
},
|
||||
|
||||
selectTheme: [
|
||||
{
|
||||
id: 1,
|
||||
label: 'Theme 1',
|
||||
value: 'red',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
label: 'Theme 2',
|
||||
value: 'pink',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
label: 'Theme 3',
|
||||
value: 'purple',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
label: 'Theme 4',
|
||||
value: 'deep-purple',
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
label: 'Theme 5',
|
||||
value: 'indigo',
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
label: 'Theme 6',
|
||||
value: 'blue',
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
label: 'Theme 7',
|
||||
value: 'green',
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
label: 'Theme 8',
|
||||
value: 'orange',
|
||||
},
|
||||
{
|
||||
id: 9,
|
||||
label: 'Theme 9',
|
||||
value: 'brown',
|
||||
},
|
||||
{
|
||||
id: 10,
|
||||
label: 'Theme 10',
|
||||
value: 'black',
|
||||
},
|
||||
{
|
||||
id: 11,
|
||||
label: 'Theme 11',
|
||||
value: 'white',
|
||||
},
|
||||
],
|
||||
|
||||
selectPriority: {
|
||||
it: [
|
||||
{
|
||||
id: 1,
|
||||
label: 'Alta',
|
||||
value: 2,
|
||||
icon: 'expand_less',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
label: 'Normale',
|
||||
value: 1,
|
||||
icon: 'remove',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
label: 'Bassa',
|
||||
value: 0,
|
||||
icon: 'expand_more',
|
||||
}],
|
||||
es:
|
||||
[
|
||||
{
|
||||
id: 1,
|
||||
label: 'Alta',
|
||||
value: 2,
|
||||
icon: 'expand_less',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
label: 'Normal',
|
||||
value: 1,
|
||||
icon: 'remove',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
label: 'Baja',
|
||||
value: 0,
|
||||
icon: 'expand_more',
|
||||
}],
|
||||
enUs:
|
||||
[
|
||||
{
|
||||
id: 1,
|
||||
label: 'High',
|
||||
value: 2,
|
||||
icon: 'expand_less',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
label: 'Normal',
|
||||
value: 1,
|
||||
icon: 'remove',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
label: 'Low',
|
||||
value: 0,
|
||||
icon: 'expand_more',
|
||||
}],
|
||||
de:
|
||||
[
|
||||
{
|
||||
id: 1,
|
||||
label: 'High',
|
||||
value: 2,
|
||||
icon: 'expand_less',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
label: 'Normal',
|
||||
value: 1,
|
||||
icon: 'remove',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
label: 'Low',
|
||||
value: 0,
|
||||
icon: 'expand_more',
|
||||
}],
|
||||
|
||||
},
|
||||
|
||||
}
|
||||
39
src/store/Modules/serv_constants.ts
Executable file
39
src/store/Modules/serv_constants.ts
Executable file
@@ -0,0 +1,39 @@
|
||||
export const serv_constants = {
|
||||
RIS_CODE_TODO_CREATING_NOTMYUSER: -1001,
|
||||
RIS_CODE_NOT_MY_USERNAME: -1010,
|
||||
|
||||
RIS_CODE_ERR: -99,
|
||||
RIS_CODE_EMAIL_ALREADY_VERIFIED: -5,
|
||||
RIS_CODE_EMAIL_VERIFIED: 1,
|
||||
|
||||
RIS_CODE_USER_NOT_THIS_APORTADOR: -75,
|
||||
RIS_CODE_USER_EXTRALIST_NOTFOUND: -70,
|
||||
RIS_CODE_USERNAME_ALREADY_EXIST: -60,
|
||||
RIS_CODE_USERNAME_NOT_VALID: -65,
|
||||
RIS_CODE_EMAIL_ALREADY_EXIST: -50,
|
||||
RIS_CODE_USER_ALREADY_EXIST: -48,
|
||||
RIS_CODE_EMAIL_NOT_EXIST: -45,
|
||||
RIS_CODE_EMAIL_NOT_SENT: -40,
|
||||
RIS_CODE_ERR_UNAUTHORIZED: -30,
|
||||
|
||||
RIS_CODE_LOGIN_ERR_GENERIC: -20,
|
||||
RIS_CODE_LOGIN_ERR: -10,
|
||||
RIS_CODE_LOGIN_ERR_SUBACCOUNT: -8,
|
||||
|
||||
RIS_CODE_OK: 1,
|
||||
RIS_CODE_LOGIN_OK: 1,
|
||||
RIS_ISCRIZIONE_OK: 5,
|
||||
RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN: 403,
|
||||
|
||||
RIS_CODE_TOKEN_RESETPASSWORD_NOT_FOUND: -23,
|
||||
|
||||
RIS_SUBSCRIBED_OK: 1,
|
||||
RIS_SUBSCRIBED_ALREADYEXIST: 2,
|
||||
RIS_SUBSCRIBED_ERR: -1,
|
||||
RIS_SUBSCRIBED_STR: 'subscribed',
|
||||
|
||||
RIS_UNSUBSCRIBED_OK: 5,
|
||||
RIS_UNSUBSCRIBED_STR: 'unsubscribed',
|
||||
RIS_UNSUBSCRIBED_NOT_EXIST: -5,
|
||||
|
||||
}
|
||||
1734
src/store/Modules/tools.ts
Normal file
1734
src/store/Modules/tools.ts
Normal file
File diff suppressed because it is too large
Load Diff
256
src/store/Modules/toolsext.ts
Executable file
256
src/store/Modules/toolsext.ts
Executable file
@@ -0,0 +1,256 @@
|
||||
import { date, useQuasar } from 'quasar'
|
||||
import { useUserStore } from '@store/UserStore'
|
||||
// import { useGlobalStore } from '@store/globalStore'
|
||||
import { static_data } from '../../db/static_data'
|
||||
|
||||
export const func_tools = {
|
||||
getLocale(vero ?: boolean): string {
|
||||
const userStore = useUserStore()
|
||||
if (userStore) {
|
||||
return userStore.lang
|
||||
}
|
||||
if (!vero) return process.env.LANG_DEFAULT ? process.env.LANG_DEFAULT : 'it'
|
||||
return ''
|
||||
},
|
||||
|
||||
getDateStr(mydate: any) {
|
||||
const DateFormatter = new Intl.DateTimeFormat(func_tools.getLocale() || void 0, {
|
||||
weekday: 'short',
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
// timeZone: 'UTC'
|
||||
})
|
||||
try {
|
||||
// console.log('mydate', mydate, DateFormatter)
|
||||
if (DateFormatter) {
|
||||
const date1 = new Date(mydate)
|
||||
return DateFormatter.format(date1)
|
||||
}
|
||||
return mydate
|
||||
} catch (e) {
|
||||
return ''
|
||||
}
|
||||
},
|
||||
|
||||
getMinutesDuration(mydatestart: any, mydateend: any) {
|
||||
return date.getDateDiff(mydateend, mydatestart, 'minutes')
|
||||
},
|
||||
|
||||
getDateTimeShortStr(mydate: any) {
|
||||
const DateFormatter = new Intl.DateTimeFormat(func_tools.getLocale() || void 0, {
|
||||
hour: 'numeric',
|
||||
minute: 'numeric',
|
||||
day: 'numeric',
|
||||
month: 'short',
|
||||
// timeZone: 'UTC'
|
||||
})
|
||||
if (DateFormatter) {
|
||||
const date1 = new Date(mydate)
|
||||
return DateFormatter.format(date1)
|
||||
}
|
||||
return mydate
|
||||
},
|
||||
}
|
||||
|
||||
export const toolsext = {
|
||||
TABUSER: 'users',
|
||||
TABNAVI: 'navi',
|
||||
TABLISTAINGRESSO: 'listaingressos',
|
||||
TABGRADUATORIA: 'graduatorias',
|
||||
TABEXTRALIST: 'extralist',
|
||||
TABNEWSLETTER: 'newstosent',
|
||||
TABGALLERY: 'gallery',
|
||||
TABMAILINGLIST: 'mailinglist',
|
||||
TABMYPAGE: 'mypage',
|
||||
TABCALZOOM: 'calzoom',
|
||||
TABGROUPS: 'groups',
|
||||
TABTEMPLEMAIL: 'templemail',
|
||||
TABOPZEMAIL: 'opzemail',
|
||||
TABSHAREWITHUS: 'sharewithus',
|
||||
SERVKEY_VERS: 'vers',
|
||||
|
||||
ERR_GENERICO: -1,
|
||||
ERR_SERVERFETCH: -2,
|
||||
ERR_AUTHENTICATION: -5,
|
||||
|
||||
localStorage: {
|
||||
teleg_id: 'ti',
|
||||
verified_email: 'vf',
|
||||
made_gift: 'mg',
|
||||
wasAlreadySubOnDb: 'sb',
|
||||
categorySel: 'cs',
|
||||
isLogged: 'ilog',
|
||||
expirationDate: 'expdate',
|
||||
leftDrawerOpen: 'ldo',
|
||||
userId: 'uid',
|
||||
token: 'tk',
|
||||
username: 'uname',
|
||||
name: 'nm',
|
||||
surname: 'sn',
|
||||
perm: 'pm',
|
||||
lang: 'lg',
|
||||
img: 'img',
|
||||
},
|
||||
|
||||
getLocale(vero?: boolean): string {
|
||||
const userStore = useUserStore()
|
||||
if (userStore) {
|
||||
return userStore.lang
|
||||
}
|
||||
return process.env.LANG_DEFAULT ? process.env.LANG_DEFAULT : 'it'
|
||||
},
|
||||
isLang(whichlang: string): boolean {
|
||||
const loc = func_tools.getLocale()
|
||||
return (loc === whichlang)
|
||||
},
|
||||
getlangforQuasar(mylang: string) {
|
||||
if (mylang === 'enUs') return 'en-us'
|
||||
return mylang
|
||||
},
|
||||
setLangAtt(mylang: string) {
|
||||
/** ++Todo: SISTEMARE
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
const $q = useQuasar()
|
||||
|
||||
console.log('setLangAtt =', mylang)
|
||||
// console.log('PRIMA this.$q.lang.isoName', this.$q.lang.isoName)
|
||||
|
||||
// dynamic import, so loading on demand only
|
||||
import(`quasar/lang/${this.getlangforQuasar(mylang)}`).then((lang) => {
|
||||
console.log(' Import dinamically lang =', lang)
|
||||
|
||||
$q.lang.set(this.getlangforQuasar(lang.default))
|
||||
import('../../public/i18n').then(() => {
|
||||
console.log(' *** MY LANG DOPO=', $q.lang.isoName)
|
||||
})
|
||||
})
|
||||
|
||||
globalStore.addDynamicPages()
|
||||
|
||||
*/
|
||||
|
||||
// this.$q.lang.set(mylang)
|
||||
},
|
||||
|
||||
getValDb(keystr: string, serv: boolean, def?: any, table?: string, subkey?: string, id?: any, idmain?: any): any | undefined {
|
||||
|
||||
/** ++Todo: SISTEMARE
|
||||
const userStore = useUserStore()
|
||||
const globalStore = useGlobalStore()
|
||||
if (table === 'users') {
|
||||
if (keystr === 'profile') {
|
||||
if (subkey) { // @ts-ignore
|
||||
return userStore.my.profile[subkey]
|
||||
}
|
||||
} else if (keystr) { // @ts-ignore
|
||||
return userStore.my[keystr]
|
||||
}
|
||||
/* } else if (table === 'todos') {
|
||||
// console.log('id', id, 'idmain', idmain)
|
||||
const indcat = Todos.categories.indexOf(idmain)
|
||||
console.log('indcat', indcat)
|
||||
if (indcat >= 0) {
|
||||
const myrec = Todos.todos[indcat].find((rec) => rec._id === id)
|
||||
console.log('myrec', myrec)
|
||||
let ris = null
|
||||
if (myrec) {
|
||||
ris = myrec[keystr]
|
||||
}
|
||||
console.log('ris', ris)
|
||||
return ris
|
||||
}
|
||||
|
||||
return ''
|
||||
|
||||
} else {
|
||||
const ris = globalStore.getValueSettingsByKey(keystr, serv)
|
||||
|
||||
if (ris === '') {
|
||||
if (def !== undefined) return def
|
||||
return ''
|
||||
}
|
||||
return ris
|
||||
}
|
||||
*/
|
||||
return ''
|
||||
|
||||
},
|
||||
|
||||
sito_online(pertutti: boolean): boolean {
|
||||
const userStore = useUserStore()
|
||||
|
||||
let ris = true
|
||||
const online = this.getValDb('SITO_ONLINE', false, true)
|
||||
ris = userStore.isAdmin && !pertutti ? true : online
|
||||
// console.log('isadmin', userStore.isAdmin)
|
||||
return ris
|
||||
},
|
||||
|
||||
checkLangPassed(mylangprop: string) {
|
||||
// console.log('checkLangPassed ', mylang)
|
||||
|
||||
let mylang = mylangprop
|
||||
|
||||
const $q = useQuasar()
|
||||
|
||||
const userStore = useUserStore()
|
||||
const mybrowserLang = $q.lang.isoName
|
||||
|
||||
if (mylang !== '') {
|
||||
if ((mylang.toLowerCase() === 'enus') || (mylang.toLowerCase() === 'en-us') || (mylang.toLowerCase() === 'uk')
|
||||
|| (mylang.toLowerCase() === 'uk-uk') || (mylang.toLowerCase() === 'en-uk') || (mylang.toLowerCase() === 'en-gb')
|
||||
|| (mylang.toLowerCase() === 'gb-gb')) {
|
||||
mylang = 'enUs'
|
||||
}
|
||||
if ((mylang.toLowerCase() === 'es') || (mylang.toLowerCase() === 'es-es') || (mylang.toLowerCase() === 'eses')) {
|
||||
mylang = 'es'
|
||||
}
|
||||
if ((mylang.toLowerCase() === 'pt') || (mylang.toLowerCase() === 'pt-pt') || (mylang.toLowerCase() === 'ptpt')) {
|
||||
mylang = 'pt'
|
||||
}
|
||||
if ((mylang.toLowerCase() === 'fr') || (mylang.toLowerCase() === 'fr-fr') || (mylang.toLowerCase() === 'frfr')) {
|
||||
mylang = 'fr'
|
||||
}
|
||||
if ((mylang.toLowerCase() === 'it') || (mylang.toLowerCase() === 'it-it') || (mylang.toLowerCase() === 'itit')) {
|
||||
mylang = 'it'
|
||||
}
|
||||
if ((mylang.toLowerCase() === 'si') || (mylang.toLowerCase() === 'si-si') || (mylang.toLowerCase() === 'sisi')) {
|
||||
mylang = 'si'
|
||||
}
|
||||
|
||||
if (!(static_data.arrLangUsed.includes(mylang))) {
|
||||
// console.log('non incluso ', mylang)
|
||||
// mylang = static_data.arrLangUsed[0]
|
||||
mylang = 'it'
|
||||
|
||||
// Metti come default
|
||||
userStore.setlang(mylang)
|
||||
}
|
||||
}
|
||||
|
||||
if (!mylang) {
|
||||
if (process.env.LANG_DEFAULT) mylang = process.env.LANG_DEFAULT
|
||||
console.log('LANG DEFAULT: ', mylang)
|
||||
}
|
||||
|
||||
if (this.getLocale(true) === '') {
|
||||
userStore.setlang(mylang)
|
||||
}
|
||||
|
||||
// console.log('mylang calc : ', mylang)
|
||||
|
||||
return mylang
|
||||
},
|
||||
}
|
||||
|
||||
// export const costanti_tools = {
|
||||
// DateFormatter: new Intl.DateTimeFormat(func_this.getLocale() || void 0, {
|
||||
// weekday: 'long',
|
||||
// day: 'numeric',
|
||||
// month: 'long',
|
||||
// year: 'numeric'
|
||||
// // timeZone: 'UTC'
|
||||
// })
|
||||
// }
|
||||
77
src/store/Modules/translation.ts
Executable file
77
src/store/Modules/translation.ts
Executable file
@@ -0,0 +1,77 @@
|
||||
export const translation = {
|
||||
it: {
|
||||
fase: 'Fase',
|
||||
privacy: {
|
||||
all: 'Tutti',
|
||||
friends: 'Amici',
|
||||
mygroup: 'Gruppo',
|
||||
onlyme: 'Solo io',
|
||||
inherited: 'Ereditato',
|
||||
},
|
||||
tipovisu: {
|
||||
simplelist: 'Lista Semplice',
|
||||
taskProgress: 'Statistiche',
|
||||
responsabili: 'Responsabili',
|
||||
},
|
||||
proj: {
|
||||
newproj: 'Nuovo Progetto',
|
||||
newsubproj: 'Nuovo Sotto-Progetto',
|
||||
themecolor: 'Tema Colore',
|
||||
themebgcolor: 'Tema Colore Sfondo',
|
||||
},
|
||||
task: {
|
||||
showtask: 'Mostra Task',
|
||||
showposiz: 'Mostra Ordine',
|
||||
},
|
||||
action: {
|
||||
paste: 'Incolla',
|
||||
},
|
||||
end: '',
|
||||
},
|
||||
es: {
|
||||
fase: 'Fase',
|
||||
privacy: {
|
||||
all: 'Todos',
|
||||
friends: 'Amigos',
|
||||
mygroup: 'Grupos',
|
||||
onlyme: 'Solo yo',
|
||||
inherited: 'Ereditato',
|
||||
},
|
||||
proj: {
|
||||
newproj: 'Nuevo Projecto',
|
||||
newsubproj: 'Nuevo Sub-Projecto',
|
||||
themecolor: 'Tema Colores',
|
||||
themebgcolor: 'Tema Colores Fondo',
|
||||
},
|
||||
task: {
|
||||
showtask: 'Mostrar Tarea',
|
||||
},
|
||||
action: {
|
||||
paste: 'Pegar',
|
||||
},
|
||||
end: '',
|
||||
},
|
||||
enUs: {
|
||||
fase: 'Phase',
|
||||
privacy: {
|
||||
all: 'All',
|
||||
friends: 'Friends',
|
||||
mygroup: 'Group',
|
||||
onlyme: 'Only me',
|
||||
inherited: 'Inherited',
|
||||
},
|
||||
proj: {
|
||||
newproj: 'New Project',
|
||||
newsubproj: 'New Sub-Project',
|
||||
themecolor: 'Theme Color',
|
||||
themebgcolor: 'Theme Background Color',
|
||||
},
|
||||
task: {
|
||||
showtask: 'Show Task',
|
||||
},
|
||||
action: {
|
||||
paste: 'Paste',
|
||||
},
|
||||
end: '',
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user