2019-11-05 23:53:18 +01:00
|
|
|
import Vue from 'vue'
|
|
|
|
|
|
|
|
|
|
import Component from 'vue-class-component'
|
|
|
|
|
import { func_tools } from '../store/Modules/toolsext'
|
|
|
|
|
import { tools } from '../store/Modules/tools'
|
|
|
|
|
import { toolsext } from '@src/store/Modules/toolsext'
|
|
|
|
|
import { GlobalStore } from '../store/Modules'
|
2019-12-04 02:04:54 +01:00
|
|
|
import { fieldsTable } from '@src/store/Modules/fieldsTable'
|
|
|
|
|
import { CalendarStore } from '@store'
|
2019-12-27 12:43:42 +01:00
|
|
|
import MixinMetaTags from '@src/mixins/mixin-metatags'
|
2019-11-05 23:53:18 +01:00
|
|
|
|
|
|
|
|
// You can declare a mixin as the same style as components.
|
|
|
|
|
@Component
|
2019-12-27 12:43:42 +01:00
|
|
|
export default class MixinBase extends MixinMetaTags {
|
2019-11-05 23:53:18 +01:00
|
|
|
public mythis() {
|
|
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get toolsext() {
|
|
|
|
|
return toolsext
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-04 02:04:54 +01:00
|
|
|
get db_fieldsTable() {
|
|
|
|
|
return fieldsTable
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-05 23:53:18 +01:00
|
|
|
get func_tools() {
|
|
|
|
|
return func_tools
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get tools() {
|
|
|
|
|
return tools
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-04 02:04:54 +01:00
|
|
|
public getValDb(keystr, serv, def?) {
|
|
|
|
|
const ris = GlobalStore.getters.getValueSettingsByKey(keystr, serv)
|
2019-11-15 00:32:39 +01:00
|
|
|
if (ris === '')
|
2019-12-04 18:21:17 +01:00
|
|
|
if (def !== undefined)
|
|
|
|
|
return def
|
|
|
|
|
else
|
|
|
|
|
return ''
|
2019-11-15 00:32:39 +01:00
|
|
|
else
|
|
|
|
|
return ris
|
2019-11-05 23:53:18 +01:00
|
|
|
}
|
2019-12-04 02:04:54 +01:00
|
|
|
|
|
|
|
|
public async setValDb(key, value, type, serv: boolean) {
|
|
|
|
|
|
|
|
|
|
console.log('setValDb', key, value, serv)
|
|
|
|
|
GlobalStore.mutations.setValueSettingsByKey({ key, value, serv })
|
|
|
|
|
|
|
|
|
|
let myrec = GlobalStore.getters.getrecSettingsByKey(key, serv)
|
|
|
|
|
if (myrec === undefined) {
|
|
|
|
|
myrec = {
|
|
|
|
|
idapp: process.env.APP_ID,
|
|
|
|
|
key,
|
|
|
|
|
type
|
|
|
|
|
}
|
|
|
|
|
myrec.serv = serv
|
|
|
|
|
if (myrec.type === tools.FieldType.date)
|
|
|
|
|
myrec.value_date = value
|
|
|
|
|
else if (myrec.type === tools.FieldType.number)
|
|
|
|
|
myrec.value_num = value
|
|
|
|
|
else if (myrec.type === tools.FieldType.boolean)
|
|
|
|
|
myrec.value_bool = value
|
|
|
|
|
else
|
|
|
|
|
myrec.value_str = value
|
|
|
|
|
|
|
|
|
|
myrec = await tools.createNewRecord(this, 'settings', myrec).then((myrecris) => {
|
|
|
|
|
// console.log('myrec')
|
|
|
|
|
let recsett = null
|
|
|
|
|
if (serv)
|
|
|
|
|
recsett = GlobalStore.state.serv_settings
|
|
|
|
|
else
|
|
|
|
|
recsett = GlobalStore.state.settings
|
|
|
|
|
|
|
|
|
|
recsett.push(myrecris)
|
|
|
|
|
return recsett.find((rec) => rec.key === key)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
console.log('myrec', myrec)
|
|
|
|
|
|
|
|
|
|
const mydatatosave = {
|
|
|
|
|
id: myrec._id,
|
|
|
|
|
table: 'settings',
|
|
|
|
|
fieldsvalue: myrec
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('mydatatosave', mydatatosave)
|
|
|
|
|
|
|
|
|
|
GlobalStore.actions.saveFieldValue(mydatatosave).then((esito) => {
|
|
|
|
|
if (esito) {
|
|
|
|
|
tools.showPositiveNotif(this.$q, this.$t('db.recupdated'))
|
|
|
|
|
} else {
|
|
|
|
|
tools.showNegativeNotif(this.$q, this.$t('db.recfailed'))
|
|
|
|
|
// Undo...
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getarrValDb(keystr, serv) {
|
|
|
|
|
const myval = GlobalStore.getters.getValueSettingsByKey(keystr, serv)
|
2019-11-05 23:53:18 +01:00
|
|
|
// console.log('myval', myval)
|
2019-11-06 22:28:45 +01:00
|
|
|
try {
|
|
|
|
|
if (myval) {
|
|
|
|
|
const myrec = JSON.parse(myval)
|
2019-12-27 12:43:42 +01:00
|
|
|
console.log('*************** getarrValDb')
|
|
|
|
|
console.table(myrec)
|
2019-11-06 22:28:45 +01:00
|
|
|
return myrec
|
|
|
|
|
} else {
|
|
|
|
|
return []
|
|
|
|
|
}
|
2019-12-04 02:04:54 +01:00
|
|
|
} catch (e) {
|
2019-11-05 23:53:18 +01:00
|
|
|
return []
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-04 02:04:54 +01:00
|
|
|
|
2019-11-05 23:53:18 +01:00
|
|
|
}
|