Cleaning Code, moving functions...
This commit is contained in:
@@ -23,10 +23,10 @@ const baseConfig = {
|
||||
'.ts', '.js', '.vue',
|
||||
],
|
||||
alias: {
|
||||
'@components': helpers.root('src/components/components/index.ts'),
|
||||
'@components': helpers.root('src/components/components'),
|
||||
'@views': helpers.root('src/components/views/index.ts'),
|
||||
'@views': helpers.root('src/components/views'),
|
||||
'@components': helpers.root('src/components/index.ts'),
|
||||
'@components': helpers.root('src/components'),
|
||||
'@views': helpers.root('src/views/index.ts'),
|
||||
'@views': helpers.root('src/views'),
|
||||
'@src': helpers.root('src'),
|
||||
'@icons': helpers.root('src/assets/icons'),
|
||||
'@images': helpers.root('src/assets/images'),
|
||||
@@ -112,4 +112,4 @@ const baseConfig = {
|
||||
],
|
||||
};
|
||||
|
||||
module.exports = baseConfig;
|
||||
module.exports = baseConfig;
|
||||
|
||||
@@ -14,7 +14,7 @@ const extendTypescriptToWebpack = (config) => {
|
||||
.alias
|
||||
.set('@components', helpers.root('src/components/index.ts'))
|
||||
// .set('@components', helpers.root('src/components'))
|
||||
.set('@views', helpers.root('src/components/views/index.ts'))
|
||||
.set('@views', helpers.root('src/views/index.ts'))
|
||||
// .set('@views', helpers.root('src/components/views'))
|
||||
.set('@src', helpers.root('src'))
|
||||
.set('@css', helpers.root('src/statics/css/variables.scss'))
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
export * from './SingleCat'
|
||||
export * from './category'
|
||||
export * from './tabledata'
|
||||
@@ -1,4 +1,3 @@
|
||||
export * from './categories'
|
||||
export * from '../views/categories'
|
||||
export * from './todos'
|
||||
export * from './logo'
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ $heightdescr: 20px;
|
||||
border-width: 1px 0px 1px 0px;
|
||||
border-style: solid;
|
||||
border-color: rgba(49, 68, 240, 0.6);
|
||||
background-color: rgba(83, 132, 250, 0.44) !important;
|
||||
background-color: rgba(160, 174, 255, 0.35) !important;
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ $heightdescr: 20px;
|
||||
@media screen and (min-width: 600px) {
|
||||
display: none;
|
||||
}
|
||||
color: #777;
|
||||
color: #939393;
|
||||
height: $heightitem;
|
||||
line-height: $heightitem;
|
||||
//visibility: hidden;
|
||||
|
||||
@@ -285,7 +285,7 @@ export default class SingleTodo extends Vue {
|
||||
}
|
||||
// console.log('exitEdit')
|
||||
this.inEdit = false
|
||||
this.updateClasses
|
||||
this.updateClasses()
|
||||
this.$emit('deselectAllRows', this.itemtodo, false, singola)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
<!--</q-popup-edit>-->
|
||||
</div>
|
||||
<div v-if="isTodo()" class="flex-item pos-item " @mousedown="clickRiga">
|
||||
<q-btn push
|
||||
<q-btn flat
|
||||
:class="clButtPopover"
|
||||
icon="menu">
|
||||
<q-menu ref="popmenu" self="top right">
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from './SingleTodo'
|
||||
export * from './SubMenus'
|
||||
export * from './todo'
|
||||
export * from '../../views/todo'
|
||||
|
||||
@@ -13,7 +13,7 @@ export let idbKeyval = (() => {
|
||||
|
||||
openreq.onupgradeneeded = () => {
|
||||
// First time setup: create an empty object store
|
||||
for (mytab of tools.allTables) {
|
||||
for (mytab of ApiTables.allTables) {
|
||||
openreq.result.createObjectStore(mytab, { keyPath: '_id' });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,7 +4,6 @@ import { UserStore } from '@modules'
|
||||
import { GlobalStore } from '@modules'
|
||||
import Vue from 'vue'
|
||||
import { Component, Prop } from 'vue-property-decorator'
|
||||
import { tools } from '@src/store/Modules/tools'
|
||||
|
||||
const namespace: string = 'GlobalModule'
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="no-border">
|
||||
<q-list class="rounded-borders text-primary">
|
||||
<template v-for="(parent, index) in getmenu">
|
||||
<div class="q-list-header">{{replaceUnderlineToSpace(index)}}</div>
|
||||
<!--<div class="q-list-header">{{replaceUnderlineToSpace(index)}}</div>-->
|
||||
<div v-for="item in parent.routes">
|
||||
<div v-if="item.routes2">
|
||||
<q-expansion-item
|
||||
|
||||
@@ -129,7 +129,7 @@ Router.beforeEach(async (to: IMyRoute, from: IMyRoute, next) => {
|
||||
} else if (to.matched.some((m) => m.meta.noAuth) && UserStore.state.isLogged) {
|
||||
next('/')
|
||||
} else {
|
||||
if (to.meta.asyncData) {
|
||||
if (!!to.meta.asyncData) {
|
||||
await getRouteData(to)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ export const routesList: IMyRouteConfig[] = [
|
||||
{
|
||||
path: '/todo/:category',
|
||||
name: 'Todos',
|
||||
component: () => import('@/components/todos/todo/todo.vue'),
|
||||
component: () => import('@/views/todo/todo.vue'),
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
async asyncData() {
|
||||
@@ -70,12 +70,12 @@ export const routesList: IMyRouteConfig[] = [
|
||||
{
|
||||
path: '/category',
|
||||
name: 'category',
|
||||
component: () => import('@/components/categories/category/category.vue')
|
||||
component: () => import('@/views/categories/category/category.vue')
|
||||
},
|
||||
{
|
||||
path: '/admin/cfgserv',
|
||||
name: 'cfgserv',
|
||||
component: () => import('@/components/admin/cfgServer/cfgServer.vue'),
|
||||
component: () => import('@/views/admin/cfgServer/cfgServer.vue'),
|
||||
meta: {
|
||||
requiresAuth: true
|
||||
// middleware: [auth]
|
||||
@@ -84,17 +84,17 @@ export const routesList: IMyRouteConfig[] = [
|
||||
{
|
||||
path: '/admin/testp1/:category',
|
||||
name: 'Categories',
|
||||
component: () => import('@/components/admin/testp1/testp1.vue')
|
||||
component: () => import('@/views/admin/testp1/testp1.vue')
|
||||
},
|
||||
{
|
||||
path: '/offline',
|
||||
name: 'Offline',
|
||||
component: () => import('@/components/offline/offline.vue')
|
||||
component: () => import('@/views/offline/offline.vue')
|
||||
},
|
||||
{
|
||||
path: '/projects',
|
||||
name: 'progetti',
|
||||
component: () => import('@/components/projects/proj-list/proj-list.vue'),
|
||||
component: () => import('@/views/projects/proj-list/proj-list.vue'),
|
||||
meta: {
|
||||
requiresAuth: true
|
||||
// middleware: [auth]
|
||||
|
||||
@@ -23,6 +23,4 @@ async function sendRequest(url: string, method: string, mydata: any) {
|
||||
return req
|
||||
}
|
||||
|
||||
|
||||
|
||||
export default sendRequest
|
||||
|
||||
@@ -15,6 +15,7 @@ import { serv_constants } from '@src/store/Modules/serv_constants'
|
||||
import router from '@router'
|
||||
import * as Types from '@src/store/Api/ApiTypes'
|
||||
import { costanti } from '@src/store/Modules/costanti'
|
||||
import * as ApiTables from '@src/store/Modules/ApiTables'
|
||||
|
||||
// const algoliaApi = new AlgoliaSearch()
|
||||
export namespace ApiTool {
|
||||
@@ -129,16 +130,8 @@ export namespace ApiTool {
|
||||
const table = multiparams[1]
|
||||
const method = multiparams[2]
|
||||
const token = multiparams[3]
|
||||
// let lang = multiparams[3]
|
||||
|
||||
if (cmd === tools.DB.CMD_SYNC) {
|
||||
// console.log('[Alternative] Syncing', cmd, table, method)
|
||||
|
||||
// const headers = new Headers()
|
||||
// headers.append('content-Type', 'application/json')
|
||||
// headers.append('Accept', 'application/json')
|
||||
// headers.append('x-auth', token)
|
||||
|
||||
if (cmd === ApiTables.DB.CMD_SYNC) {
|
||||
let errorfromserver = false
|
||||
let lettoqualcosa = false
|
||||
|
||||
@@ -149,25 +142,14 @@ export namespace ApiTool {
|
||||
// console.log('----------------------- LEGGO QUALCOSA ')
|
||||
|
||||
const promises = myrecs.map((rec) => {
|
||||
// console.log('syncing', table, '', rec.descr)
|
||||
// let link = String(process.env.MONGODB_HOST) + '/todos'
|
||||
let link = '/todos'
|
||||
|
||||
if (method !== 'POST') {
|
||||
link += '/' + rec._id
|
||||
}
|
||||
|
||||
// console.log(' [Alternative] ++++++++++++++++++ SYNCING !!!! ', rec.descr, table, 'FETCH: ', method, link, 'data:')
|
||||
|
||||
// Insert/Delete/Update table to the server
|
||||
return SendReq(link, method, rec)
|
||||
// return fetch(link, {
|
||||
// method: method,
|
||||
// headers: headers,
|
||||
// cache: 'no-cache',
|
||||
// mode: 'cors', // 'no-cors',
|
||||
// body: JSON.stringify(rec)
|
||||
// })
|
||||
.then(() => {
|
||||
lettoqualcosa = true
|
||||
return globalroutines(null, 'delete', table, null, rec._id)
|
||||
@@ -191,23 +173,18 @@ export namespace ApiTool {
|
||||
})
|
||||
|
||||
}).catch((e) => {
|
||||
// console.log('ERROR:', e)
|
||||
return (errorfromserver && !lettoqualcosa)
|
||||
})
|
||||
.then((errorfromserver) => {
|
||||
.then((error) => {
|
||||
// console.log('¨¨¨¨¨¨¨¨¨¨¨¨¨¨ errorfromserver:', errorfromserver)
|
||||
const mystate = errorfromserver ? 'offline' : 'online'
|
||||
const mystate = error ? 'offline' : 'online'
|
||||
GlobalStore.mutations.setStateConnection(mystate)
|
||||
GlobalStore.mutations.saveConfig( { _id: costanti.CONFIG_ID_STATE_CONN, value: mystate })
|
||||
|
||||
})
|
||||
|
||||
// console.log(' [Alternative] A2) ?????????????????????????? ESCO DAL LOOP !!!!!!!!!')
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
export default ApiTool
|
||||
|
||||
414
src/store/Modules/ApiTables.ts
Normal file
414
src/store/Modules/ApiTables.ts
Normal file
@@ -0,0 +1,414 @@
|
||||
import Api from '@api'
|
||||
import { ITodo } from '@src/model'
|
||||
import { GlobalStore, Todos, UserStore } from '@store'
|
||||
import globalroutines from './../../globalroutines/index'
|
||||
import { serv_constants } from '@src/store/Modules/serv_constants'
|
||||
import { tools } from '@src/store/Modules/tools'
|
||||
|
||||
export const allTables = ['todos', 'categories', 'sync_post_todos', 'sync_patch_todos', 'delete_todos', 'config', 'swmsg']
|
||||
|
||||
export const LIST_START = '0'
|
||||
|
||||
export const Priority = {
|
||||
PRIORITY_HIGH: 2,
|
||||
PRIORITY_NORMAL: 1,
|
||||
PRIORITY_LOW: 0
|
||||
}
|
||||
|
||||
export const DB = {
|
||||
CMD_SYNC: 'sync-',
|
||||
CMD_SYNC_NEW: 'sync-new-',
|
||||
CMD_DELETE: 'sync-delete-',
|
||||
TABLE_SYNC_POST: 'sync_post_',
|
||||
TABLE_SYNC_PATCH: 'sync_patch_',
|
||||
TABLE_DELETE: 'delete_'
|
||||
}
|
||||
|
||||
export async function dbInsertSave(call, item, method) {
|
||||
|
||||
let ret = true
|
||||
if (!('serviceWorker' in navigator)) {
|
||||
|
||||
console.log('dbInsertSave', item, method)
|
||||
|
||||
if (UserStore.state.userId === '') {
|
||||
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) => {
|
||||
console.log('dbInsertSave ', call, 'to the Server', res.data)
|
||||
|
||||
return (res.status === 200)
|
||||
})
|
||||
.catch((error) => {
|
||||
UserStore.mutations.setErrorCatch(error)
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
export async function dbDeleteItem(call, item) {
|
||||
|
||||
if (!('serviceWorker' in navigator)) {
|
||||
// console.log('dbdeleteItem', item)
|
||||
if (UserStore.state.userId === '') {
|
||||
return false
|
||||
} // Login not made
|
||||
|
||||
call = '/' + call
|
||||
|
||||
const res = await Api.SendReq(call + item._id, 'DELETE', item)
|
||||
.then((myres) => {
|
||||
console.log('dbdeleteItem to the Server')
|
||||
return myres
|
||||
})
|
||||
.catch((error) => {
|
||||
UserStore.mutations.setErrorCatch(error)
|
||||
return UserStore.getters.getServerCode
|
||||
})
|
||||
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
export async function Sync_Execute(cmd, table, method, item: ITodo, id, msg: String) {
|
||||
// Send to Server to Sync
|
||||
|
||||
// console.log('Sync_Execute', cmd, table, method, item.descr, id, msg)
|
||||
|
||||
let cmdSw = cmd
|
||||
if ((cmd === DB.CMD_SYNC_NEW) || (cmd === DB.CMD_DELETE)) {
|
||||
cmdSw = DB.CMD_SYNC
|
||||
}
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
return await navigator.serviceWorker.ready
|
||||
.then((sw) => {
|
||||
// console.log('---------------------- navigator.serviceWorker.ready')
|
||||
|
||||
return globalroutines(null, 'write', table, item, id)
|
||||
.then((id) => {
|
||||
// console.log('id', id)
|
||||
const sep = '|'
|
||||
|
||||
const multiparams = cmdSw + sep + table + sep + method + sep + UserStore.state.x_auth_token + sep + UserStore.state.lang
|
||||
const mymsgkey = {
|
||||
_id: multiparams,
|
||||
value: multiparams
|
||||
}
|
||||
return globalroutines(null, 'write', 'swmsg', mymsgkey, multiparams)
|
||||
.then((ris) => {
|
||||
// if ('SyncManager' in window) {
|
||||
// console.log(' SENDING... sw.sync.register', multiparams)
|
||||
// return sw.sync.register(multiparams)
|
||||
// } else {
|
||||
// #Todo ++ Alternative 2 to SyncManager
|
||||
return 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', table, err)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export async function Sync_ExecuteCmd(cmd, nametab: string, table, method, item: ITodo, id, msg: String) {
|
||||
// Send to Server to Sync
|
||||
|
||||
console.log('Sync_Execute', cmd, table, method, item.descr, id, msg)
|
||||
|
||||
const risdata = await Sync_Execute(cmd, table, method, item, id, msg)
|
||||
|
||||
if (cmd === DB.CMD_SYNC_NEW) {
|
||||
if ((method === 'POST') || (method === 'PATCH')) {
|
||||
await dbInsertSave(nametab, item, method)
|
||||
}
|
||||
} else if (cmd === DB.CMD_DELETE) {
|
||||
await dbDeleteItem(nametab, item)
|
||||
}
|
||||
|
||||
return risdata
|
||||
}
|
||||
|
||||
export async function Sync_SaveItem(nametab: string, method, item) {
|
||||
let table = ''
|
||||
if (method === 'POST') {
|
||||
table = DB.TABLE_SYNC_POST
|
||||
}
|
||||
else if (method === 'PATCH') {
|
||||
table = DB.TABLE_SYNC_PATCH
|
||||
}
|
||||
|
||||
return await Sync_ExecuteCmd(DB.CMD_SYNC_NEW, nametab, table + nametab, method, item, 0, '')
|
||||
}
|
||||
|
||||
export function Sync_DeleteItem(nametab: string, item, id) {
|
||||
Sync_ExecuteCmd(DB.CMD_DELETE, nametab, DB.TABLE_DELETE + nametab, 'DELETE', item, id, '')
|
||||
}
|
||||
|
||||
export async function aftercalling(ris, checkPending: boolean, nametabindex: string) {
|
||||
|
||||
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.getters.getServerCode, ris.status)
|
||||
}
|
||||
if ('serviceWorker' in navigator) {
|
||||
// Read all data from IndexedDB Store into Memory
|
||||
await updatefromIndexedDbToStateTodo(nametabindex)
|
||||
}
|
||||
} else {
|
||||
if (ris.status === tools.OK && checkPending) {
|
||||
waitAndcheckPendingMsg()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function checkPendingMsg() {
|
||||
// console.log('checkPendingMsg')
|
||||
|
||||
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.state.stateConnection) {
|
||||
GlobalStore.mutations.setStateConnection(config[1].stateconn)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
// Check if there is something
|
||||
return globalroutines(null, 'count', 'swmsg')
|
||||
.then((count) => {
|
||||
if (count > 0) {
|
||||
// console.log('count = ', count)
|
||||
return resolve(true)
|
||||
} else {
|
||||
return resolve(false)
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
return reject()
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// If something in the call of Service Worker went wrong (Network or Server Down), then retry !
|
||||
export async function sendSwMsgIfAvailable() {
|
||||
let something = false
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
console.log(' -------- sendSwMsgIfAvailable')
|
||||
|
||||
const count = await checkPendingMsg()
|
||||
if (count > 0) {
|
||||
return await navigator.serviceWorker.ready
|
||||
.then((sw) => {
|
||||
|
||||
return 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) {
|
||||
// console.log(' .... sw.sync.register ( ', rec._id)
|
||||
// if ('SyncManager' in window) {
|
||||
// sw.sync.register(rec._id)
|
||||
// } else {
|
||||
|
||||
// #Alternative to SyncManager
|
||||
promiseChain = promiseChain.then(() => {
|
||||
return Api.syncAlternative(rec._id)
|
||||
.then(() => {
|
||||
something = true
|
||||
})
|
||||
})
|
||||
|
||||
// }
|
||||
}
|
||||
return promiseChain
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(something)
|
||||
})
|
||||
}
|
||||
|
||||
export async function waitAndRefreshData() {
|
||||
return await Todos.actions.dbLoadTodo({ checkPending: false })
|
||||
}
|
||||
|
||||
export async function waitAndcheckPendingMsg() {
|
||||
|
||||
// await aspettansec(1000)
|
||||
|
||||
return await checkPendingMsg()
|
||||
.then((ris) => {
|
||||
if (ris) {
|
||||
// console.log('risPending = ', ris)
|
||||
return sendSwMsgIfAvailable()
|
||||
.then((something) => {
|
||||
if (something) {
|
||||
if (process.env.DEBUG === '1') {
|
||||
console.log('something')
|
||||
}
|
||||
// Refresh data
|
||||
return waitAndRefreshData()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export async function updatefromIndexedDbToStateTodo(nametab) {
|
||||
await globalroutines(null, 'updatefromIndexedDbToStateTodo', nametab, null)
|
||||
.then(() => {
|
||||
console.log('updatefromIndexedDbToStateTodo! ')
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
export function removeitemfromarray(myarray, ind) {
|
||||
// console.log('PRIMA state.todos', state.todos)
|
||||
// Delete Item in to Array
|
||||
if (ind >= 0) {
|
||||
myarray.splice(ind, 1)
|
||||
}
|
||||
// console.log('DOPO state.todos', state.todos, 'ind', ind)
|
||||
}
|
||||
|
||||
/*
|
||||
export async functionfunction testfunc() {
|
||||
while (true) {
|
||||
tools.consolelogpao('testfunc')
|
||||
// console.log('Todos.state.todos_changed:', Todos.state.todos_changed)
|
||||
await tools.aspettansec(5000)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
sendMessageToSW(recdata, method) {
|
||||
|
||||
navigator.serviceWorker.controller.postMessage({
|
||||
type: 'sync',
|
||||
recdata,
|
||||
method,
|
||||
cmd: 'sync-new-todos',
|
||||
token: UserStore.state.idToken,
|
||||
lang: UserStore.state.lang
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
||||
export function setmodifiedIfchanged(recOut, recIn, field) {
|
||||
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, myitem, fieldtochange) {
|
||||
|
||||
if (myitem === null) {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
const myobjsaved = tools.jsonCopy(myitem)
|
||||
|
||||
// get record from IndexedDb
|
||||
const miorec = await globalroutines(null, 'read', nametable, null, myobjsaved._id)
|
||||
if (miorec === undefined) {
|
||||
console.log('~~~~~~~~~~~~~~~~~~~~ !!!!!!!!!!!!!!!!!! Record not Found !!!!!! id=', myobjsaved._id)
|
||||
return
|
||||
}
|
||||
|
||||
if (nametable === 'todos') {
|
||||
if (setmodifiedIfchanged(miorec, myobjsaved, 'completed')) {
|
||||
miorec.completed_at = new Date().getDate()
|
||||
}
|
||||
}
|
||||
|
||||
fieldtochange.forEach((myfield) => {
|
||||
setmodifiedIfchanged(miorec, myobjsaved, myfield)
|
||||
})
|
||||
|
||||
if (miorec.modified) {
|
||||
console.log('Todo MODIFICATO! ', miorec.descr, miorec.pos, 'SALVALO SULLA IndexedDB todos')
|
||||
miorec.modify_at = new Date().getDate()
|
||||
miorec.modified = false
|
||||
|
||||
// 1) Permit to Update the Views
|
||||
tools.notifyarraychanged(miorec)
|
||||
|
||||
// 2) Modify on IndexedDb
|
||||
return globalroutines(null, 'write', nametable, miorec)
|
||||
.then((ris) => {
|
||||
|
||||
// 3) Modify on the Server (call)
|
||||
Sync_SaveItem(nametable, 'PATCH', miorec)
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function table_DeleteRecord(nametable, myobjtrov, id) {
|
||||
|
||||
// 1) Delete from the Todos Array
|
||||
Todos.mutations.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 isLoggedToSystem() {
|
||||
const tok = tools.getItemLS(tools.localStorage.token)
|
||||
return !!tok
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import Api from '@api'
|
||||
import * as Types from '@src/store/Api/ApiTypes'
|
||||
import { costanti } from '@src/store/Modules/costanti'
|
||||
import { tools } from '@src/store/Modules/tools'
|
||||
import * as ApiTables from '@src/store/Modules/ApiTables'
|
||||
import { GlobalStore, Todos, UserStore } from '@store'
|
||||
import messages from '../../statics/i18n'
|
||||
import globalroutines from './../../globalroutines/index'
|
||||
@@ -443,7 +444,7 @@ namespace Actions {
|
||||
console.log('clearDataAfterLogout')
|
||||
|
||||
// Clear all data from the IndexedDB
|
||||
for (const table of tools.allTables) {
|
||||
for (const table of ApiTables.allTables) {
|
||||
await globalroutines(null, 'clearalldata', table, null)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { storeBuilder } from './Store/Store'
|
||||
|
||||
import Api from '@api'
|
||||
import { tools } from './tools'
|
||||
import * as ApiTables from './ApiTables'
|
||||
import { GlobalStore, Todos, UserStore } from '@store'
|
||||
import globalroutines from './../../globalroutines/index'
|
||||
import { Mutation } from 'vuex-module-decorators'
|
||||
@@ -113,18 +114,12 @@ function getLastFirstElemPriority(cat: string, priority: number, atfirst: boolea
|
||||
|
||||
function getFirstList(cat) {
|
||||
const myarr = gettodosByCategory(cat)
|
||||
return myarr.find((elem) => elem.id_prev === tools.LIST_START)
|
||||
return myarr.find((elem) => elem.id_prev === ApiTables.LIST_START)
|
||||
}
|
||||
|
||||
function getLastListNotCompleted(cat) {
|
||||
const arr = Todos.getters.todos_dacompletare(cat)
|
||||
// console.log('cat', cat, 'arr', arr)
|
||||
if (arr.length > 0) {
|
||||
return arr[arr.length - 1]
|
||||
}
|
||||
else {
|
||||
return null
|
||||
}
|
||||
return (arr.length > 0) ? arr[arr.length - 1] : null
|
||||
}
|
||||
|
||||
function getstrelem(elem) {
|
||||
@@ -133,7 +128,7 @@ function getstrelem(elem) {
|
||||
|
||||
function update_idprev(indcat, indelemchange, indelemId) {
|
||||
if (indelemchange >= 0 && indelemchange < state.todos[indcat].length) {
|
||||
const id_prev = (indelemId >= 0) ? state.todos[indcat][indelemId]._id : tools.LIST_START
|
||||
const id_prev = (indelemId >= 0) ? state.todos[indcat][indelemId]._id : ApiTables.LIST_START
|
||||
if (state.todos[indcat][indelemchange].id_prev !== id_prev) {
|
||||
state.todos[indcat][indelemchange].id_prev = id_prev
|
||||
tools.notifyarraychanged(state.todos[indcat][indelemchange])
|
||||
@@ -235,7 +230,6 @@ namespace Mutations {
|
||||
if (indcat >= 0) {
|
||||
return state.todos[indcat].findIndex((elem) => elem._id === data.id)
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
@@ -268,18 +262,10 @@ namespace Mutations {
|
||||
const indcat = state.categories.indexOf(myitem.category)
|
||||
const ind = findIndTodoById(state, { id: myitem._id, categorySel: myitem.category })
|
||||
|
||||
console.log('PRIMA state.todos', state.todos)
|
||||
// Delete Item in to Array
|
||||
if (ind >= 0) {
|
||||
state.todos[indcat].splice(ind, 1)
|
||||
}
|
||||
|
||||
console.log('DOPO state.todos', state.todos, 'ind', ind)
|
||||
|
||||
ApiTables.removeitemfromarray(state.todos[indcat], ind)
|
||||
}
|
||||
|
||||
export const mutations = {
|
||||
// setTestpao: b.commit(setTestpao),
|
||||
deletemyitem: b.commit(deletemyitem),
|
||||
createNewItem: b.commit(createNewItem)
|
||||
}
|
||||
@@ -292,21 +278,18 @@ namespace Actions {
|
||||
console.log('dbLoadTodo', checkPending, 'userid=', UserStore.state.userId)
|
||||
|
||||
if (UserStore.state.userId === '') {
|
||||
return false
|
||||
} // Login not made
|
||||
return false // Login not made
|
||||
}
|
||||
|
||||
const ris = await Api.SendReq('/todos/' + UserStore.state.userId, 'GET', null)
|
||||
.then((res) => {
|
||||
if (res.data.todos) {
|
||||
// console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
if (res.data.todos) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
state.todos = res.data.todos
|
||||
state.categories = res.data.categories
|
||||
} else {
|
||||
state.todos = [[]]
|
||||
}
|
||||
|
||||
// console.log('PRIMA showtype = ', state.showtype)
|
||||
|
||||
state.showtype = parseInt(GlobalStore.getters.getConfigStringbyId({
|
||||
id: costanti.CONFIG_ID_SHOW_TYPE_TODOS,
|
||||
default: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED
|
||||
@@ -325,50 +308,7 @@ namespace Actions {
|
||||
return error
|
||||
})
|
||||
|
||||
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.getters.getServerCode, ris.status)
|
||||
}
|
||||
if ('serviceWorker' in navigator) {
|
||||
// Read all data from IndexedDB Store into Memory
|
||||
await tools.updatefromIndexedDbToStateTodo('categories')
|
||||
}
|
||||
} else {
|
||||
if (ris.status === tools.OK && checkPending) {
|
||||
tools.waitAndcheckPendingMsg()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function aspettansec(numsec) {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve('anything')
|
||||
}, numsec)
|
||||
})
|
||||
}
|
||||
|
||||
async function testfunc() {
|
||||
while (true) {
|
||||
tools.consolelogpao('testfunc')
|
||||
// console.log('Todos.state.todos_changed:', Todos.state.todos_changed)
|
||||
await aspettansec(5000)
|
||||
}
|
||||
}
|
||||
|
||||
function setmodifiedIfchanged(recOut, recIn, field) {
|
||||
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
|
||||
ApiTables.aftercalling(ris, checkPending, 'categories')
|
||||
}
|
||||
|
||||
async function deleteItem(context, { cat, idobj }) {
|
||||
@@ -381,30 +321,13 @@ namespace Actions {
|
||||
const myobjnext = getElemPrevById(cat, myobjtrov._id)
|
||||
|
||||
if (!!myobjnext) {
|
||||
// console.log('myobjnext', myobjnext.descr)
|
||||
myobjnext.id_prev = myobjtrov.id_prev
|
||||
myobjnext.modified = true
|
||||
// console.log('calling MODIFY 1 id_prev = ', myobjnext.id_prev)
|
||||
await modify(context, { myitem: myobjnext, field: 'id_prev' })
|
||||
}
|
||||
|
||||
// console.log(' MODIFY 2')
|
||||
|
||||
// 1) Delete from the Todos Array
|
||||
Todos.mutations.deletemyitem(myobjtrov)
|
||||
|
||||
// 2) Delete from the IndexedDb
|
||||
globalroutines(context, 'delete', nametable, null, idobj)
|
||||
.catch((error) => {
|
||||
console.log('err: ', error)
|
||||
})
|
||||
|
||||
// 3) Delete from the Server (call)
|
||||
tools.deleteItemToSyncAndDb(nametable, myobjtrov, idobj)
|
||||
|
||||
ApiTables.table_DeleteRecord(nametable, myobjtrov, idobj)
|
||||
}
|
||||
|
||||
// console.log('FINE deleteItem')
|
||||
}
|
||||
|
||||
async function insertTodo(context, { myobj, atfirst }) {
|
||||
@@ -419,8 +342,7 @@ namespace Actions {
|
||||
if (atfirst) {
|
||||
console.log('INSERT AT THE TOP')
|
||||
elemtochange = getFirstList(objtodo.category)
|
||||
objtodo.id_prev = tools.LIST_START
|
||||
// objtodo.pos = (elemtochange !== null) ? elemtochange.pos - 1 : 1
|
||||
objtodo.id_prev = ApiTables.LIST_START
|
||||
} else {
|
||||
console.log('INSERT AT THE BOTTOM')
|
||||
// INSERT AT THE BOTTOM , so GET LAST ITEM
|
||||
@@ -428,13 +350,11 @@ namespace Actions {
|
||||
|
||||
console.log('lastelem', lastelem)
|
||||
|
||||
objtodo.id_prev = (!!lastelem) ? lastelem._id : tools.LIST_START
|
||||
// objtodo.pos = (elemtochange !== null) ? elemtochange.pos + 1 : 1
|
||||
objtodo.id_prev = (!!lastelem) ? lastelem._id : ApiTables.LIST_START
|
||||
}
|
||||
console.log('elemtochange TORNATO:', elemtochange)
|
||||
objtodo.modified = false
|
||||
|
||||
console.log('objtodo', objtodo, 'ID_PREV=', objtodo.id_prev)
|
||||
// console.log('objtodo', objtodo, 'ID_PREV=', objtodo.id_prev)
|
||||
|
||||
// 1) Create record in Memory
|
||||
Todos.mutations.createNewItem({ objtodo, atfirst, categorySel: objtodo.category })
|
||||
@@ -443,8 +363,7 @@ namespace Actions {
|
||||
const id = await globalroutines(context, 'write', nametable, objtodo)
|
||||
|
||||
let field = ''
|
||||
// update also the last elem
|
||||
if (atfirst) {
|
||||
if (atfirst) { // update also the last elem
|
||||
if (!!elemtochange) {
|
||||
elemtochange.id_prev = id
|
||||
console.log('elemtochange', elemtochange)
|
||||
@@ -456,7 +375,7 @@ namespace Actions {
|
||||
}
|
||||
|
||||
// 3) send to the Server
|
||||
return await tools.saveItemToSyncAndDb(nametable, 'POST', objtodo)
|
||||
return await ApiTables.Sync_SaveItem(nametable, 'POST', objtodo)
|
||||
.then((ris) => {
|
||||
// Check if need to be moved...
|
||||
const indelem = getIndexById(objtodo.category, objtodo._id)
|
||||
@@ -497,55 +416,13 @@ namespace Actions {
|
||||
if (itemdragend) {
|
||||
swapElems(context, itemdragend)
|
||||
}
|
||||
|
||||
return ris
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async function modify(context, { myitem, field }) {
|
||||
if (myitem === null) {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
const myobjsaved = tools.jsonCopy(myitem)
|
||||
// get record from IndexedDb
|
||||
const miorec = await globalroutines(context, 'read', nametable, null, myobjsaved._id)
|
||||
if (miorec === undefined) {
|
||||
console.log('~~~~~~~~~~~~~~~~~~~~ !!!!!!!!!!!!!!!!!! Record not Found !!!!!! id=', myobjsaved._id)
|
||||
return
|
||||
}
|
||||
|
||||
if (setmodifiedIfchanged(miorec, myobjsaved, 'completed')) {
|
||||
miorec.completed_at = new Date().getDate()
|
||||
}
|
||||
|
||||
fieldtochange.forEach((myfield) => {
|
||||
setmodifiedIfchanged(miorec, myobjsaved, myfield)
|
||||
})
|
||||
|
||||
if (miorec.modified) {
|
||||
console.log('Todo MODIFICATO! ', miorec.descr, miorec.pos, 'SALVALO SULLA IndexedDB todos')
|
||||
miorec.modify_at = new Date().getDate()
|
||||
miorec.modified = false
|
||||
|
||||
// 1) Permit to Update the Views
|
||||
tools.notifyarraychanged(miorec)
|
||||
|
||||
// Todos.mutations.modifymyItem(miorec)
|
||||
|
||||
// this.logelem('modify', miorec)
|
||||
// 2) Modify on IndexedDb
|
||||
return globalroutines(context, 'write', nametable, miorec)
|
||||
.then((ris) => {
|
||||
|
||||
// 3) Modify on the Server (call)
|
||||
tools.saveItemToSyncAndDb(nametable, 'PATCH', miorec)
|
||||
|
||||
})
|
||||
}
|
||||
return await ApiTables.table_ModifyRecord(nametable, myitem, fieldtochange)
|
||||
}
|
||||
|
||||
async function swapElems(context, itemdragend: IDrag) {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import Api from '@api'
|
||||
import { ITodo } from '@src/model'
|
||||
import { GlobalStore, Todos, UserStore } from '@store'
|
||||
import { UserStore } from '@store'
|
||||
import globalroutines from './../../globalroutines/index'
|
||||
import { costanti } from './costanti'
|
||||
import Quasar from 'quasar'
|
||||
@@ -12,7 +10,6 @@ export interface INotify {
|
||||
}
|
||||
|
||||
export const tools = {
|
||||
allTables: ['todos', 'categories', 'sync_post_todos', 'sync_patch_todos', 'delete_todos', 'config', 'swmsg'],
|
||||
EMPTY: 0,
|
||||
CALLING: 10,
|
||||
OK: 20,
|
||||
@@ -24,9 +21,6 @@ export const tools = {
|
||||
|
||||
arrLangUsed: ['enUs', 'it', 'es'],
|
||||
|
||||
LIST_END: '10000000',
|
||||
LIST_START: '0',
|
||||
|
||||
SERVKEY_VERS: 'vers',
|
||||
|
||||
localStorage: {
|
||||
@@ -48,15 +42,6 @@ export const tools = {
|
||||
PRIORITY_LOW: 0
|
||||
},
|
||||
|
||||
DB: {
|
||||
CMD_SYNC: 'sync-',
|
||||
CMD_SYNC_NEW: 'sync-new-',
|
||||
CMD_DELETE: 'sync-delete-',
|
||||
TABLE_SYNC_POST: 'sync_post_',
|
||||
TABLE_SYNC_PATCH: 'sync_patch_',
|
||||
TABLE_DELETE: 'delete_'
|
||||
},
|
||||
|
||||
MenuAction: {
|
||||
DELETE: 100,
|
||||
TOGGLE_EXPIRING: 101,
|
||||
@@ -393,145 +378,6 @@ export const tools = {
|
||||
return result
|
||||
},
|
||||
|
||||
async cmdToSyncAndDb(cmd, table, method, item: ITodo, id, msg: String) {
|
||||
// Send to Server to Sync
|
||||
|
||||
// console.log('cmdToSyncAndDb', cmd, table, method, item.descr, id, msg)
|
||||
|
||||
let cmdSw = cmd
|
||||
if ((cmd === tools.DB.CMD_SYNC_NEW) || (cmd === tools.DB.CMD_DELETE)) {
|
||||
cmdSw = tools.DB.CMD_SYNC
|
||||
}
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
return await navigator.serviceWorker.ready
|
||||
.then((sw) => {
|
||||
// console.log('---------------------- navigator.serviceWorker.ready')
|
||||
|
||||
return globalroutines(null, 'write', table, item, id)
|
||||
.then((id) => {
|
||||
// console.log('id', id)
|
||||
const sep = '|'
|
||||
|
||||
const multiparams = cmdSw + sep + table + sep + method + sep + UserStore.state.x_auth_token + sep + UserStore.state.lang
|
||||
const mymsgkey = {
|
||||
_id: multiparams,
|
||||
value: multiparams
|
||||
}
|
||||
return globalroutines(null, 'write', 'swmsg', mymsgkey, multiparams)
|
||||
.then((ris) => {
|
||||
// if ('SyncManager' in window) {
|
||||
// console.log(' SENDING... sw.sync.register', multiparams)
|
||||
// return sw.sync.register(multiparams)
|
||||
// } else {
|
||||
// #Todo ++ Alternative 2 to SyncManager
|
||||
return 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', table, err)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async dbInsertSave(call, item, method) {
|
||||
|
||||
let ret = true
|
||||
if (!('serviceWorker' in navigator)) {
|
||||
|
||||
console.log('dbInsertSave', item, method)
|
||||
|
||||
if (UserStore.state.userId === '') {
|
||||
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) => {
|
||||
console.log('dbInsertSave ', call, 'to the Server', res.data)
|
||||
|
||||
return (res.status === 200)
|
||||
})
|
||||
.catch((error) => {
|
||||
UserStore.mutations.setErrorCatch(error)
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
return ret
|
||||
},
|
||||
|
||||
async dbdeleteItem(call, item) {
|
||||
|
||||
if (!('serviceWorker' in navigator)) {
|
||||
// console.log('dbdeleteItem', item)
|
||||
if (UserStore.state.userId === '') {
|
||||
return false
|
||||
} // Login not made
|
||||
|
||||
call = '/' + call
|
||||
|
||||
const res = await Api.SendReq(call + item._id, 'DELETE', item)
|
||||
.then((res) => {
|
||||
console.log('dbdeleteItem to the Server')
|
||||
return res
|
||||
})
|
||||
.catch((error) => {
|
||||
UserStore.mutations.setErrorCatch(error)
|
||||
return UserStore.getters.getServerCode
|
||||
})
|
||||
|
||||
return res
|
||||
}
|
||||
},
|
||||
|
||||
async cmdToSyncAndDbTable(cmd, nametab: string, table, method, item: ITodo, id, msg: String) {
|
||||
// Send to Server to Sync
|
||||
|
||||
console.log('cmdToSyncAndDb', cmd, table, method, item.descr, id, msg)
|
||||
|
||||
const risdata = await tools.cmdToSyncAndDb(cmd, table, method, item, id, msg)
|
||||
|
||||
if (cmd === tools.DB.CMD_SYNC_NEW) {
|
||||
if ((method === 'POST') || (method === 'PATCH')) {
|
||||
await tools.dbInsertSave(nametab, item, method)
|
||||
}
|
||||
} else if (cmd === tools.DB.CMD_DELETE) {
|
||||
await tools.dbdeleteItem(nametab, item)
|
||||
}
|
||||
|
||||
return risdata
|
||||
},
|
||||
|
||||
deleteItemToSyncAndDb(nametab: string, item, id) {
|
||||
tools.cmdToSyncAndDbTable(tools.DB.CMD_DELETE, nametab, tools.DB.TABLE_DELETE + nametab, 'DELETE', item, id, '')
|
||||
},
|
||||
|
||||
async saveItemToSyncAndDb(nametab: string, method, item) {
|
||||
let table = ''
|
||||
if (method === 'POST')
|
||||
table = tools.DB.TABLE_SYNC_POST
|
||||
else if (method === 'PATCH')
|
||||
table = tools.DB.TABLE_SYNC_PATCH
|
||||
|
||||
return await tools.cmdToSyncAndDbTable(tools.DB.CMD_SYNC_NEW, nametab, table + nametab, method, item, 0, '')
|
||||
},
|
||||
|
||||
showNotif(q: any, msg, data?: INotify | null) {
|
||||
let myicon = data ? data.icon : 'ion-add'
|
||||
if (!myicon) {
|
||||
@@ -562,6 +408,7 @@ export const tools = {
|
||||
mylang = 'es'
|
||||
}
|
||||
|
||||
|
||||
if (!(tools.arrLangUsed.includes(mylang))) {
|
||||
console.log('non incluso ', mylang)
|
||||
mylang = tools.arrLangUsed[0]
|
||||
@@ -587,124 +434,12 @@ export const tools = {
|
||||
globalroutines(null, 'log', strlog + ' ' + strlog2 + ' ' + strlog3, null)
|
||||
},
|
||||
|
||||
async checkPendingMsg() {
|
||||
// console.log('checkPendingMsg')
|
||||
|
||||
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.state.stateConnection) {
|
||||
GlobalStore.mutations.setStateConnection(config[1].stateconn)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
aspettansec(numsec) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Check if there is something
|
||||
return globalroutines(null, 'count', 'swmsg')
|
||||
.then((count) => {
|
||||
if (count > 0) {
|
||||
// console.log('count = ', count)
|
||||
return resolve(true)
|
||||
} else {
|
||||
return resolve(false)
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
return reject()
|
||||
})
|
||||
setTimeout(() => {
|
||||
resolve('anything')
|
||||
}, numsec)
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
// If something in the call of Service Worker went wrong (Network or Server Down), then retry !
|
||||
async sendSwMsgIfAvailable() {
|
||||
let something = false
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
console.log(' -------- sendSwMsgIfAvailable')
|
||||
|
||||
const count = await tools.checkPendingMsg()
|
||||
if (count > 0) {
|
||||
return await navigator.serviceWorker.ready
|
||||
.then((sw) => {
|
||||
|
||||
return 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) {
|
||||
// console.log(' .... sw.sync.register ( ', rec._id)
|
||||
// if ('SyncManager' in window) {
|
||||
// sw.sync.register(rec._id)
|
||||
// } else {
|
||||
|
||||
// #Alternative to SyncManager
|
||||
promiseChain = promiseChain.then(() => {
|
||||
return Api.syncAlternative(rec._id)
|
||||
.then(() => {
|
||||
something = true
|
||||
})
|
||||
})
|
||||
|
||||
// }
|
||||
}
|
||||
return promiseChain
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(something)
|
||||
})
|
||||
},
|
||||
|
||||
async waitAndRefreshData() {
|
||||
return await Todos.actions.dbLoadTodo({ checkPending: false })
|
||||
},
|
||||
|
||||
async waitAndcheckPendingMsg() {
|
||||
|
||||
// await aspettansec(1000)
|
||||
|
||||
return await tools.checkPendingMsg()
|
||||
.then((ris) => {
|
||||
if (ris) {
|
||||
// console.log('risPending = ', ris)
|
||||
return tools.sendSwMsgIfAvailable()
|
||||
.then((something) => {
|
||||
if (something) {
|
||||
if (process.env.DEBUG === '1') {
|
||||
console.log('something')
|
||||
}
|
||||
// Refresh data
|
||||
return tools.waitAndRefreshData()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
async updatefromIndexedDbToStateTodo(nametab) {
|
||||
await globalroutines(null, 'updatefromIndexedDbToStateTodo', nametab, null)
|
||||
.then(() => {
|
||||
console.log('updatefromIndexedDbToStateTodo! ')
|
||||
return true
|
||||
})
|
||||
},
|
||||
|
||||
isLoggedToSystem() {
|
||||
|
||||
@@ -33,8 +33,7 @@ export default class TableOnlyView extends Vue {
|
||||
this.loading = true
|
||||
setTimeout(() => {
|
||||
this.serverPagination = props.pagination
|
||||
let
|
||||
table = this.$refs.table,
|
||||
let table = this.$refs.table,
|
||||
rows = GlobalStore.state.cfgServer.slice(),
|
||||
{ page, rowsPerPage, sortBy, descending } = props.pagination
|
||||
|
||||
@@ -21,9 +21,9 @@
|
||||
</q-table>
|
||||
</q-page>
|
||||
</template>
|
||||
<script lang="ts" src="./tableOnlyView.ts">
|
||||
<script lang="ts" src="tableOnlyView.ts">
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import './tableOnlyView.scss';
|
||||
@import 'tableOnlyView';
|
||||
</style>
|
||||
@@ -3,7 +3,6 @@ import { Component } from 'vue-property-decorator'
|
||||
|
||||
import { GlobalStore } from '@store'
|
||||
|
||||
|
||||
@Component({})
|
||||
export default class CfgServer extends Vue {
|
||||
public loading: boolean = false
|
||||
@@ -39,21 +38,20 @@ export default class CfgServer extends Vue {
|
||||
public keysel: string = ''
|
||||
public userIdsel: string = ''
|
||||
|
||||
|
||||
get tableClass () {
|
||||
get tableClass() {
|
||||
if (this.dark) {
|
||||
return 'bg-black'
|
||||
}
|
||||
}
|
||||
|
||||
selItem(item) {
|
||||
public selItem(item) {
|
||||
console.log('item', item)
|
||||
this.keysel = item.chiave
|
||||
this.userIdsel = item.userid
|
||||
console.log('this.keysel', this.keysel)
|
||||
}
|
||||
|
||||
SaveValue(newVal, valinitial) {
|
||||
public SaveValue(newVal, valinitial) {
|
||||
console.log('SaveValue', newVal, 'selected', this.selected)
|
||||
|
||||
const mydata = {
|
||||
@@ -65,9 +63,8 @@ export default class CfgServer extends Vue {
|
||||
GlobalStore.actions.saveCfgServerKey(mydata)
|
||||
}
|
||||
|
||||
created() {
|
||||
public created() {
|
||||
this.serverData = GlobalStore.state.cfgServer.slice() // [{ chiave: 'chiave1', valore: 'valore 1' }]
|
||||
// this.serverData = GlobalStore.state.cfgServer.slice()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,5 +36,5 @@
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import './cfgServer.scss';
|
||||
@import './cfgServer';
|
||||
</style>
|
||||
@@ -3,7 +3,7 @@ import { Component, Watch } from 'vue-property-decorator'
|
||||
|
||||
import { GlobalStore, UserStore } from '@store'
|
||||
import { Getter } from "vuex-class"
|
||||
import { ICfgServer, IGlobalState, ITodo, ITodosState } from '@src/model'
|
||||
import { ICfgServer, IGlobalState, ITodo, ITodosState } from '../../../model/index'
|
||||
|
||||
const namespace: string = 'GlobalModule'
|
||||
|
||||
@@ -39,5 +39,5 @@
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import './testp1.scss';
|
||||
@import './testp1';
|
||||
</style>
|
||||
@@ -19,5 +19,5 @@
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import './SingleCat.scss';
|
||||
@import './SingleCat';
|
||||
</style>
|
||||
@@ -1,9 +1,9 @@
|
||||
import Vue from 'vue'
|
||||
import { Component, Watch } from 'vue-property-decorator'
|
||||
|
||||
import { SingleCat } from '../SingleCat'
|
||||
import { ICategory } from '@src/model'
|
||||
import { tools } from "@src/store/Modules/tools"
|
||||
import { SingleCat } from '../SingleCat/index'
|
||||
import { ICategory } from '../../../model/index'
|
||||
import { tools } from '../../../store/Modules/tools'
|
||||
|
||||
|
||||
@Component({
|
||||
@@ -63,5 +63,5 @@
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import './category.scss';
|
||||
@import './category';
|
||||
</style>
|
||||
3
src/views/categories/index.ts
Normal file
3
src/views/categories/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './SingleCat/index'
|
||||
export * from './category/index'
|
||||
export * from './tabledata/index'
|
||||
0
src/views/categories/tabledata/tabledata.scss
Normal file
0
src/views/categories/tabledata/tabledata.scss
Normal file
@@ -1,9 +1,9 @@
|
||||
import Vue from 'vue'
|
||||
import { Component, Watch } from 'vue-property-decorator'
|
||||
|
||||
import { ICategory } from '@src/model'
|
||||
import globalroutines from "@src/globalroutines"
|
||||
import { tools } from "@src/store/Modules/tools"
|
||||
import { ICategory } from '../../../model/index'
|
||||
import globalroutines from "../../../globalroutines/index"
|
||||
import { tools } from "../../../store/Modules/tools"
|
||||
|
||||
@Component({
|
||||
})
|
||||
@@ -57,9 +57,9 @@
|
||||
|
||||
|
||||
</template>
|
||||
<script lang="ts" src="./tabledata.ts">
|
||||
<script lang="ts" src="tabledata.ts">
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import './tabledata.scss';
|
||||
@import 'tabledata';
|
||||
</style>
|
||||
1
src/views/index.ts
Normal file
1
src/views/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './admin/cfgServer'
|
||||
@@ -7,5 +7,5 @@
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import './offline.scss';
|
||||
@import './offline';
|
||||
</style>
|
||||
@@ -1,10 +1,11 @@
|
||||
import Vue from 'vue'
|
||||
import { Component, Watch } from 'vue-property-decorator'
|
||||
|
||||
import { IDrag, ITodo, ITodosState } from '@src/model'
|
||||
import { SingleTodo } from '../../todos/SingleTodo'
|
||||
import { IDrag, ITodo, ITodosState } from '../../../model/index'
|
||||
import { SingleTodo } from '../../../components/todos/SingleTodo/index'
|
||||
|
||||
import { tools } from '../../../store/Modules/tools'
|
||||
import * as ApiTables from '../../../store/Modules/ApiTables'
|
||||
|
||||
import { GlobalStore, Todos } from '@store'
|
||||
import { UserStore } from '@store'
|
||||
@@ -56,7 +56,7 @@
|
||||
<div style="display: none">{{ prior = 0, priorcomplet = false }}</div>
|
||||
<div>
|
||||
<!--<q-infinite-scroll :handler="loadMoreTodo" :offset="7">-->
|
||||
<div class="container" v-dragula="todos_dacompletare(categoryAtt)" drake="first">
|
||||
<div class="container" v-dragula="todos_dacompletare(categoryAtt)" drake="second">
|
||||
<div :id="getmyid(mytodo._id)" :index="index"
|
||||
v-for="(mytodo, index) in todos_dacompletare(categoryAtt)"
|
||||
:key="mytodo._id" class="myitemdrag">
|
||||
@@ -96,5 +96,5 @@
|
||||
<script lang="ts" src="./proj-list.ts">
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@import './proj-list.scss';
|
||||
@import './proj-list';
|
||||
</style>
|
||||
@@ -1,21 +1,22 @@
|
||||
import Vue from 'vue'
|
||||
import { Component, Watch } from 'vue-property-decorator'
|
||||
|
||||
import { ICfgServer, IDrag, IGlobalState, ITodo, ITodosState } from '@src/model'
|
||||
import { SingleTodo } from '../SingleTodo'
|
||||
import { ICfgServer, IDrag, IGlobalState, ITodo, ITodosState } from '../../model/index'
|
||||
import { SingleTodo } from '../../components/todos/SingleTodo/index'
|
||||
|
||||
import { tools } from '../../../store/Modules/tools'
|
||||
import { tools } from '../../store/Modules/tools'
|
||||
import * as ApiTables from '../../store/Modules/ApiTables'
|
||||
|
||||
import { GlobalStore, Todos } from '@store'
|
||||
import { UserStore } from '@store'
|
||||
|
||||
// _.cloneDeep( Per clonare un oggetto
|
||||
|
||||
import { costanti } from '@src/store/Modules/costanti'
|
||||
import { costanti } from '../../store/Modules/costanti'
|
||||
import { Getter, Mutation, State } from 'vuex-class'
|
||||
const namespace: string = 'Todos'
|
||||
|
||||
import globalroutines from './../../../globalroutines/index'
|
||||
import globalroutines from '../../globalroutines/index'
|
||||
|
||||
@Component({
|
||||
|
||||
@@ -197,7 +198,7 @@ export default class Todo extends Vue {
|
||||
return !el.classList.contains('donotdrag') // elements are always draggable by default
|
||||
},
|
||||
accepts(el, target, source, sibling) {
|
||||
// console.log('accepts dragging '+ el.id + ' from ' + source.id + ' to ' + target.id)
|
||||
console.log('accepts dragging '+ el.id + ' from ' + source.id + ' to ' + target.id)
|
||||
return true // elements can be dropped in any of the `containers` by default
|
||||
},
|
||||
invalid(el, handle) {
|
||||
@@ -263,8 +264,8 @@ export default class Todo extends Vue {
|
||||
// Set last category selected
|
||||
localStorage.setItem(tools.localStorage.categorySel, this.categoryAtt)
|
||||
|
||||
for (const todosKey in tools.Todos) {
|
||||
this.listPriorityLabel.push(tools.Todos[todosKey])
|
||||
for (const todosKey in ApiTables.Priority) {
|
||||
this.listPriorityLabel.push(ApiTables.Priority[todosKey])
|
||||
}
|
||||
// console.log('Priority:' + this.listPriorityLabel)
|
||||
this.setarrPriority()
|
||||
@@ -336,37 +337,17 @@ export default class Todo extends Vue {
|
||||
category: this.categoryAtt
|
||||
}
|
||||
|
||||
// empty the field
|
||||
if (atfirst) {
|
||||
this.todotop = ''
|
||||
}
|
||||
else {
|
||||
this.todobottom = ''
|
||||
}
|
||||
|
||||
return Todos.actions.insertTodo({ myobj, atfirst })
|
||||
.then((data) => {
|
||||
|
||||
console.log('data', data)
|
||||
// if (data !== null) {
|
||||
// tools.showNotif(this.$q, data)
|
||||
// }
|
||||
|
||||
// empty the field
|
||||
if (atfirst) {
|
||||
this.todotop = ''
|
||||
}
|
||||
else {
|
||||
this.todobottom = ''
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
sendMessageToSW(recdata, method) {
|
||||
|
||||
navigator.serviceWorker.controller.postMessage({
|
||||
type: 'sync',
|
||||
recdata,
|
||||
method,
|
||||
cmd: 'sync-new-todos',
|
||||
token: UserStore.state.idToken,
|
||||
lang: UserStore.state.lang
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
||||
public async updateitem({ myitem, field }) {
|
||||
console.log('calling MODIFY updateitem', myitem, field)
|
||||
@@ -409,7 +390,7 @@ export default class Todo extends Vue {
|
||||
}
|
||||
|
||||
public checkUpdate() {
|
||||
tools.waitAndcheckPendingMsg()
|
||||
ApiTables.waitAndcheckPendingMsg()
|
||||
}
|
||||
|
||||
public loadMoreTodo(index, done) {
|
||||
@@ -150,5 +150,5 @@
|
||||
<script lang="ts" src="./todo.ts">
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@import './todo.scss';
|
||||
@import './todo';
|
||||
</style>
|
||||
Reference in New Issue
Block a user