- Load Events
- Edit Events - When a field is updated: undate also memory list record - Duplicate Event
This commit is contained in:
@@ -13,15 +13,16 @@ import { costanti } from '@src/store/Modules/costanti'
|
||||
import { tools } from '@src/store/Modules/tools'
|
||||
import { toolsext } from '@src/store/Modules/toolsext'
|
||||
import * as ApiTables from '@src/store/Modules/ApiTables'
|
||||
import { GlobalStore, Projects, Todos, UserStore } from '@store'
|
||||
import { CalendarStore, GlobalStore, Projects, Todos, UserStore } from '@store'
|
||||
import messages from '../../statics/i18n'
|
||||
import globalroutines from './../../globalroutines/index'
|
||||
|
||||
import { cfgrouter } from '../../router/route-config'
|
||||
import { static_data } from '@src/db/static_data'
|
||||
import { IParamsQuery } from '@src/model/GlobalStore'
|
||||
import { IDataPass, IParamsQuery } from '@src/model/GlobalStore'
|
||||
import { serv_constants } from '@src/store/Modules/serv_constants'
|
||||
import { IUserState } from '@src/model'
|
||||
import { Calendar } from 'element-ui'
|
||||
// import { static_data } from '@src/db/static_data'
|
||||
|
||||
let stateConnDefault = 'online'
|
||||
@@ -268,6 +269,41 @@ namespace Mutations {
|
||||
|
||||
}
|
||||
|
||||
function getListByTable(table): any[] {
|
||||
if (table === 'events')
|
||||
return CalendarStore.state.eventlist
|
||||
else if (table === 'operators')
|
||||
return CalendarStore.state.operators
|
||||
else if (table === 'bookings')
|
||||
return CalendarStore.state.bookedevent
|
||||
else if (table === 'users')
|
||||
return UserStore.state.usersList
|
||||
else
|
||||
return null
|
||||
|
||||
}
|
||||
|
||||
function UpdateValuesInMemory(mystate: IGlobalState, mydata: IDataPass) {
|
||||
|
||||
const id = mydata.id
|
||||
const table = mydata.table
|
||||
|
||||
try {
|
||||
const mylist = getListByTable(table)
|
||||
|
||||
const myrec = mylist.find((event) => event._id === id)
|
||||
// console.log('myrec', myrec)
|
||||
if (myrec) {
|
||||
for (const [key, value] of Object.entries(mydata.fieldsvalue)) {
|
||||
console.log('key', value, myrec[key])
|
||||
myrec[key] = value
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
export const mutations = {
|
||||
setConta: b.commit(setConta),
|
||||
setleftDrawerOpen: b.commit(setleftDrawerOpen),
|
||||
@@ -278,7 +314,8 @@ namespace Mutations {
|
||||
setPaoArray: b.commit(setPaoArray),
|
||||
setPaoArray_Delete: b.commit(setPaoArray_Delete),
|
||||
NewArray: b.commit(NewArray),
|
||||
setShowType: b.commit(setShowType)
|
||||
setShowType: b.commit(setShowType),
|
||||
UpdateValuesInMemory: b.commit(UpdateValuesInMemory)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -533,14 +570,15 @@ namespace Actions {
|
||||
})
|
||||
}
|
||||
|
||||
async function saveFieldValue(context, mydata: object) {
|
||||
async function saveFieldValue(context, mydata: IDataPass) {
|
||||
console.log('saveFieldValue', mydata)
|
||||
|
||||
return await Api.SendReq(`/chval`, 'PATCH', { data: mydata })
|
||||
.then((res) => {
|
||||
if (res)
|
||||
if (res) {
|
||||
Mutations.mutations.UpdateValuesInMemory(mydata)
|
||||
return (res.data.code === serv_constants.RIS_CODE_OK)
|
||||
else
|
||||
} else
|
||||
return false
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -566,6 +604,24 @@ namespace Actions {
|
||||
})
|
||||
}
|
||||
|
||||
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
|
||||
})
|
||||
}
|
||||
|
||||
export const actions = {
|
||||
setConta: b.dispatch(setConta),
|
||||
createPushSubscription: b.dispatch(createPushSubscription),
|
||||
@@ -578,7 +634,8 @@ namespace Actions {
|
||||
saveFieldValue: b.dispatch(saveFieldValue),
|
||||
loadTable: b.dispatch(loadTable),
|
||||
saveTable: b.dispatch(saveTable),
|
||||
DeleteRec: b.dispatch(DeleteRec)
|
||||
DeleteRec: b.dispatch(DeleteRec),
|
||||
DuplicateRec: b.dispatch(DuplicateRec)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ const state: ICalendarState = {
|
||||
editable: false,
|
||||
eventlist: [],
|
||||
bookedevent: [],
|
||||
operators: [],
|
||||
// ---------------
|
||||
titlebarHeight: 0,
|
||||
locale: 'it-IT',
|
||||
@@ -92,7 +93,7 @@ namespace Actions {
|
||||
// console.log('CalendarStore: loadAfterLogin')
|
||||
// Load local data
|
||||
state.editable = db_data.userdata.calendar_editable
|
||||
state.eventlist = db_data.events
|
||||
// state.eventlist = db_data.events
|
||||
// state.bookedevent = db_data.userdata.bookedevent
|
||||
|
||||
if (UserStore.getters.isUserInvalid) {
|
||||
@@ -109,11 +110,10 @@ namespace Actions {
|
||||
|
||||
ris = await Api.SendReq('/booking/' + UserStore.state.userId + '/' + process.env.APP_ID + '/' + showall, 'GET', null)
|
||||
.then((res) => {
|
||||
if (res.data.bookedevent) {
|
||||
state.bookedevent = res.data.bookedevent
|
||||
} else {
|
||||
state.bookedevent = []
|
||||
}
|
||||
state.bookedevent = (res.data.bookedevent) ? res.data.bookedevent : []
|
||||
state.eventlist = (res.data.eventlist) ? res.data.eventlist : []
|
||||
state.operators = (res.data.operators) ? res.data.operators : []
|
||||
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error dbLoad', error)
|
||||
|
||||
@@ -16,6 +16,7 @@ export const lists = {
|
||||
THEMEBG: 211,
|
||||
|
||||
DELETE_RECTABLE: 300,
|
||||
DUPLICATE_RECTABLE: 310,
|
||||
|
||||
CAN_EDIT_TABLE: 400,
|
||||
SHOW_PREV_REC: 401,
|
||||
|
||||
@@ -45,6 +45,8 @@ export const tools = {
|
||||
DUPLICATE_EMAIL_ID: 11000,
|
||||
DUPLICATE_USERNAME_ID: 11100,
|
||||
|
||||
NOFIELD: 'nofield',
|
||||
|
||||
TYPE_AUDIO: 1,
|
||||
|
||||
NUMSEC_CHECKUPDATE: 20000,
|
||||
@@ -1333,11 +1335,20 @@ export const tools = {
|
||||
console.log('param1', par.param1)
|
||||
GlobalStore.actions.DeleteRec({ table, id: par.param1 }).then((ris) => {
|
||||
if (ris) {
|
||||
myself.ActionAfterYes(func, par.param2)
|
||||
myself.ActionAfterYes(func, par.param2, null)
|
||||
tools.showPositiveNotif(myself.$q, myself.$t('db.deletedrecord'))
|
||||
} else
|
||||
tools.showNegativeNotif(myself.$q, myself.$t('db.recdelfailed'))
|
||||
})
|
||||
} else if (func === lists.MenuAction.DUPLICATE_RECTABLE) {
|
||||
console.log('param1', par.param1)
|
||||
GlobalStore.actions.DuplicateRec({ table, id: par.param1 }).then((ris) => {
|
||||
if (ris) {
|
||||
myself.ActionAfterYes(func, par.param2, ris.data)
|
||||
tools.showPositiveNotif(myself.$q, myself.$t('db.duplicatedrecord'))
|
||||
} else
|
||||
tools.showNegativeNotif(myself.$q, myself.$t('db.recdupfailed'))
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1551,7 +1562,7 @@ export const tools = {
|
||||
}
|
||||
}
|
||||
|
||||
let i = 0
|
||||
// let i2 = 0
|
||||
while (sortedList.length < linkedList.length) {
|
||||
// get the item with a previous item ID referencing the current item
|
||||
const nextItem = linkedList[map.get(currentId)]
|
||||
@@ -1561,7 +1572,7 @@ export const tools = {
|
||||
sortedList.push(nextItem)
|
||||
// tools.logelemprj('FATTO:' + i, nextItem)
|
||||
currentId = String(nextItem._id)
|
||||
i++
|
||||
// i2++
|
||||
}
|
||||
|
||||
if (sortedList.length < linkedList.length) {
|
||||
@@ -1628,10 +1639,18 @@ export const tools = {
|
||||
return ''
|
||||
},
|
||||
|
||||
getstrTime(mytimestamp) {
|
||||
// console.log('getstrDate', mytimestamp)
|
||||
if (!!mytimestamp)
|
||||
return date.formatDate(mytimestamp, 'HH:mm')
|
||||
else
|
||||
return ''
|
||||
},
|
||||
|
||||
getstrDateTime(mytimestamp) {
|
||||
// console.log('getstrDate', mytimestamp)
|
||||
if (!!mytimestamp)
|
||||
return date.formatDate(mytimestamp, 'DD/MM/YYYY HH:MM')
|
||||
return date.formatDate(mytimestamp, 'DD/MM/YYYY HH:mm')
|
||||
else
|
||||
return ''
|
||||
},
|
||||
@@ -1683,8 +1702,11 @@ export const tools = {
|
||||
return ''
|
||||
}
|
||||
try {
|
||||
return value.substring(0, numchars) + '...'
|
||||
}catch (e) {
|
||||
let mycar = value.substring(0, numchars)
|
||||
if (value.length > numchars)
|
||||
mycar += '...'
|
||||
return mycar
|
||||
} catch (e) {
|
||||
return value
|
||||
}
|
||||
},
|
||||
@@ -2121,7 +2143,8 @@ export const tools = {
|
||||
return msg
|
||||
},
|
||||
gettextevent(myevent: IEvents) {
|
||||
return '"' + myevent.title + '" (' + func_tools.getDateStr(myevent.date) + ') - ' + myevent.time
|
||||
// return '"' + myevent.title + '" (' + func_tools.getDateStr(myevent.date) + ') - ' + myevent.time
|
||||
return '"' + myevent.title + '" (' + tools.getstrDateTime(myevent.date)
|
||||
},
|
||||
|
||||
setLangAtt(mylang) {
|
||||
|
||||
Reference in New Issue
Block a user