- Add New Record directly by the QSelect

This commit is contained in:
paoloar77
2022-01-28 00:57:28 +01:00
parent 5842fa69e1
commit 5f51c231eb
19 changed files with 434 additions and 181 deletions

View File

@@ -470,6 +470,48 @@ export const useGlobalStore = defineStore('GlobalStore', {
}
},
UpdateValuesInMemoryByTable(mydata: any, table: string): void {
try {
const mylist = this.getListByTable(table)
const mykey = fieldsTable.getKeyByTable(table)
const id = mydata[mykey]
console.log('mylist', mylist)
console.log('mykey', mykey)
console.log('id', id)
if (mylist) {
const myrec = mylist.find((event: any) => event[mykey] === id)
// console.log('myrec', myrec)
if (myrec) {
// console.log('key', value, myrec[key])
for (const [key, value] of Object.entries(mydata)) {
myrec[key] = value
}
}
console.log('update: ', myrec)
}
} catch (e) {
console.error(e)
}
},
newValueInMemoryByTable(mydata: any, table: string): void {
try {
const mylist = this.getListByTable(table)
if (mylist) {
mylist.push(mydata)
}
} catch (e) {
console.error(e)
}
},
createPushSubscription() {
// If Already subscribed, don't send to the Server DB
@@ -799,6 +841,27 @@ export const useGlobalStore = defineStore('GlobalStore', {
})
},
async saveNewRecord(mytable: string, myrec: any) {
const userStore = useUserStore()
console.log('saveNewRecord', mytable, myrec)
const mydata: any = {
table: mytable,
data: myrec
}
mydata.data.userId = userStore.my._id
const ris = await this.saveTable(mydata)
if (ris) {
this.newValueInMemoryByTable(ris, mytable);
}
console.log('saveNewRecord', ris)
return ris
},
async saveFieldValue(mydata: IDataToSet) {
// const userStore = useUserStore()
return Api.SendReq('/chval', 'PATCH', { data: mydata })