- Aggiunto Filtri
- Finder
This commit is contained in:
@@ -3,10 +3,13 @@ import { useI18n } from '@src/boot/i18n'
|
||||
|
||||
import { tools } from '../../store/Modules/tools'
|
||||
|
||||
import { fieldsTable } from '@store/Modules/fieldsTable'
|
||||
|
||||
import {
|
||||
IColGridTable,
|
||||
IFilter,
|
||||
ITableRec,
|
||||
ISearchList,
|
||||
IPagination,
|
||||
IParamDialog,
|
||||
IEvents,
|
||||
@@ -16,6 +19,8 @@ import {
|
||||
import { lists } from '../../store/Modules/lists'
|
||||
import { IParamsQuery } from '../../model/GlobalStore'
|
||||
import { CMyPopupEdit } from '../CMyPopupEdit'
|
||||
import { CMyFieldDb } from '../CMyFieldDb'
|
||||
import { CMySelect } from '../CMySelect'
|
||||
import { CTitleBanner } from '../CTitleBanner'
|
||||
|
||||
import { useUserStore } from '@store/UserStore'
|
||||
@@ -53,6 +58,16 @@ export default defineComponent({
|
||||
required: false,
|
||||
default: true,
|
||||
},
|
||||
butt_modif_new: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: true,
|
||||
},
|
||||
finder: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: false,
|
||||
},
|
||||
vertical: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
@@ -83,6 +98,11 @@ export default defineComponent({
|
||||
required: false,
|
||||
default: null,
|
||||
},
|
||||
prop_searchList: {
|
||||
type: Object as PropType<ISearchList[]>,
|
||||
required: false,
|
||||
default: null,
|
||||
},
|
||||
arrfilters: {
|
||||
type: Object as PropType<IFilter[]>,
|
||||
required: false,
|
||||
@@ -95,6 +115,13 @@ export default defineComponent({
|
||||
return []
|
||||
}
|
||||
},
|
||||
filtercustom: {
|
||||
type: Array,
|
||||
required: false,
|
||||
default: () => {
|
||||
return []
|
||||
}
|
||||
},
|
||||
extraparams: {
|
||||
required: false,
|
||||
default: {},
|
||||
@@ -116,7 +143,7 @@ export default defineComponent({
|
||||
default: '',
|
||||
},
|
||||
},
|
||||
components: { CMyPopupEdit, CTitleBanner },
|
||||
components: { CMyPopupEdit, CTitleBanner, CMyFieldDb, CMySelect },
|
||||
setup(props, { emit }) {
|
||||
const $q = useQuasar()
|
||||
const { t } = useI18n()
|
||||
@@ -145,6 +172,7 @@ export default defineComponent({
|
||||
|
||||
const serverData: any = ref([])
|
||||
const spinner_visible = ref(false)
|
||||
const searchList = toRef(props, 'prop_searchList')
|
||||
|
||||
let idsel = ''
|
||||
let colsel = ref(<IColGridTable | null>{ name: '', field: '' })
|
||||
@@ -153,6 +181,7 @@ export default defineComponent({
|
||||
let separator: 'horizontal'
|
||||
const myfilter = ref('')
|
||||
const myfilterand: any = ref([])
|
||||
const myfiltercustom: any = ref([])
|
||||
let rowsel: any = {}
|
||||
let dark = true
|
||||
const canEdit = ref(false)
|
||||
@@ -169,6 +198,15 @@ export default defineComponent({
|
||||
|
||||
const mycodeid = toRef(props, 'prop_codeId')
|
||||
|
||||
watch(searchList.value, (to: any, from: any) => {
|
||||
refresh()
|
||||
})
|
||||
|
||||
function searchval(newval: any) {
|
||||
console.log('searchval')
|
||||
refresh()
|
||||
}
|
||||
|
||||
// emulate 'SELECT count(*) FROM ...WHERE...'
|
||||
function getRowsNumberCount(myfilter?: any) {
|
||||
|
||||
@@ -188,7 +226,7 @@ export default defineComponent({
|
||||
|
||||
// emulate ajax call
|
||||
// SELECT * FROM ... WHERE...LIMIT...
|
||||
async function fetchFromServer(startRow: any, endRow: any, param_myfilter: any, param_myfilterand: any, sortBy: any, descending: any) {
|
||||
async function fetchFromServer(startRow: any, endRow: any, param_myfilter: any, param_myfilterand: any, filtercustom: any, sortBy: any, descending: any) {
|
||||
|
||||
let myobj: any = {}
|
||||
if (sortBy) {
|
||||
@@ -202,12 +240,29 @@ export default defineComponent({
|
||||
|
||||
// console.log('sortBy', sortBy)
|
||||
|
||||
let filtersearch: ISearchList[] = []
|
||||
|
||||
if (searchList.value) {
|
||||
searchList.value.forEach((item: ISearchList) => {
|
||||
if (item.value > 0) {
|
||||
let myarr: ISearchList
|
||||
let objitem: any = {}
|
||||
objitem[item.key] = item.value
|
||||
filtersearch.push(objitem)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
let params: IParamsQuery = {
|
||||
table: mytable.value,
|
||||
startRow,
|
||||
endRow,
|
||||
filter: param_myfilter,
|
||||
filterand: param_myfilterand,
|
||||
// @ts-ignore
|
||||
filtersearch: filtersearch,
|
||||
filtercustom,
|
||||
sortBy: myobj,
|
||||
descending,
|
||||
userId: userStore.my._id,
|
||||
@@ -217,6 +272,7 @@ export default defineComponent({
|
||||
params.codeId = mycodeid.value
|
||||
|
||||
// console.log('params', params)
|
||||
console.log('props.extraparams', props.extraparams)
|
||||
|
||||
params = { ...params, ...props.extraparams }
|
||||
|
||||
@@ -243,6 +299,7 @@ export default defineComponent({
|
||||
const { page, rowsPerPage, rowsNumber, sortBy, descending } = props.pagination
|
||||
const myfilternow = myfilter.value
|
||||
const myfilterandnow = myfilterand.value
|
||||
const myfiltercustomnow = myfiltercustom.value
|
||||
|
||||
savefilter()
|
||||
|
||||
@@ -269,7 +326,7 @@ export default defineComponent({
|
||||
serverData.value = []
|
||||
|
||||
// fetch data from "server"
|
||||
return fetchFromServer(startRow, endRow, myfilternow, myfilterandnow, sortBy, descending).then((ris: any) => {
|
||||
return fetchFromServer(startRow, endRow, myfilternow, myfilterandnow, myfiltercustomnow, sortBy, descending).then((ris: any) => {
|
||||
|
||||
pagination.value.rowsNumber = getRowsNumberCount(myfilter)
|
||||
|
||||
@@ -340,6 +397,10 @@ export default defineComponent({
|
||||
refresh()
|
||||
})
|
||||
|
||||
watch(() => myfiltercustom.value, (newval, oldval) => {
|
||||
refresh()
|
||||
})
|
||||
|
||||
function isTutor() {
|
||||
return userStore.isTutor
|
||||
}
|
||||
@@ -542,7 +603,6 @@ export default defineComponent({
|
||||
mycolumns.value = props.prop_mycolumns
|
||||
colkey.value = props.prop_colkey
|
||||
pagination.value = props.prop_pagination
|
||||
|
||||
}
|
||||
|
||||
function mounted() {
|
||||
@@ -553,6 +613,7 @@ export default defineComponent({
|
||||
tablesel.value = tools.getCookie('tablesel', tablesel.value)
|
||||
}
|
||||
myfilterand.value = props.filterdef
|
||||
myfiltercustom.value = props.filtercustom
|
||||
// console.log('tablesel', tablesel)
|
||||
|
||||
if (tablesel.value === '') {
|
||||
@@ -867,6 +928,8 @@ export default defineComponent({
|
||||
|
||||
mydata.data = recModif.value
|
||||
|
||||
const oldrec = serverData.value.find((rec: IMySkill) => rec._id === recModif.value._id)
|
||||
|
||||
const data = await globalStore.saveTable(mydata)
|
||||
.then((ris) => {
|
||||
if (ris) {
|
||||
@@ -874,6 +937,11 @@ export default defineComponent({
|
||||
editRecordBool.value = false
|
||||
const indrec = serverData.value.findIndex((rec: IMySkill) => rec._id === ris._id)
|
||||
console.log('indrec', indrec, serverData.value[indrec])
|
||||
mycolumns.value.forEach((col:IColGridTable) => {
|
||||
if (!col.foredit) {
|
||||
ris[col.name] = oldrec[col.name]
|
||||
}
|
||||
})
|
||||
if (indrec >= 0)
|
||||
serverData.value[indrec] = ris
|
||||
}
|
||||
@@ -954,7 +1022,13 @@ export default defineComponent({
|
||||
spinner_visible,
|
||||
tablesel,
|
||||
myfilterand,
|
||||
myfiltercustom,
|
||||
tools,
|
||||
costanti,
|
||||
fieldsTable,
|
||||
globalStore,
|
||||
searchList,
|
||||
searchval,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -43,20 +43,22 @@
|
||||
<div class="q-gutter-md q-ma-xs row">
|
||||
<div class="q-table__title" style="min-width: 150px;">{{ mytitle }}</div>
|
||||
<q-space></q-space>
|
||||
<q-btn
|
||||
v-if="mytable" rounded dense size="sm" flat :color="canEdit ? 'positive' : 'light-gray'"
|
||||
:disable="disabilita()"
|
||||
:val="lists.MenuAction.CAN_EDIT_TABLE"
|
||||
icon="fas fa-pencil-alt" @update:model-value="changefuncAct"
|
||||
@click="canEdit = !canEdit">
|
||||
</q-btn>
|
||||
<q-btn
|
||||
v-if="mytable" rounded dense size="sm" flat color="light-gray"
|
||||
:disable="loading"
|
||||
icon="fas fa-plus"
|
||||
@click="createNewRecord">
|
||||
<div v-if="butt_modif_new">
|
||||
<q-btn
|
||||
v-if="mytable" rounded dense size="sm" flat :color="canEdit ? 'positive' : 'light-gray'"
|
||||
:disable="disabilita()"
|
||||
:val="lists.MenuAction.CAN_EDIT_TABLE"
|
||||
icon="fas fa-pencil-alt" @update:model-value="changefuncAct"
|
||||
@click="canEdit = !canEdit">
|
||||
</q-btn>
|
||||
<q-btn
|
||||
v-if="mytable" rounded dense size="sm" flat color="light-gray"
|
||||
:disable="loading"
|
||||
icon="fas fa-plus"
|
||||
@click="createNewRecord">
|
||||
|
||||
</q-btn>
|
||||
</q-btn>
|
||||
</div>
|
||||
</div>
|
||||
<q-inner-loading :showing="spinner_visible">
|
||||
<q-spinner-tail size="2em" color="primary"/>
|
||||
@@ -126,6 +128,55 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
<template v-slot:top-left v-if="searchList">
|
||||
<div class="row">
|
||||
<div v-for="(item, index) in searchList" :key="index">
|
||||
<CMySelect
|
||||
v-if="item.type === costanti.FieldType.select"
|
||||
:label="item.label"
|
||||
v-model:value="item.value"
|
||||
@update:value="searchval"
|
||||
:addall="true"
|
||||
:optval="fieldsTable.getKeyByTable(item.table)"
|
||||
:optlab="fieldsTable.getLabelByTable(item.table)"
|
||||
:options="globalStore.getTableJoinByName(item.table, true)"
|
||||
:useinput="false">
|
||||
</CMySelect>
|
||||
|
||||
<q-select
|
||||
v-if="item.type === costanti.FieldType.multiselect"
|
||||
v-model="item.value"
|
||||
rounded
|
||||
outlined
|
||||
multiple
|
||||
dense
|
||||
options-dense
|
||||
:display-value="fieldsTable.getTitleByTable(item.table)"
|
||||
emit-value
|
||||
map-options
|
||||
:options="globalStore.getTableJoinByName(item.table)"
|
||||
style="min-width: 150px"
|
||||
:option-value="fieldsTable.getKeyByTable(item.table)"
|
||||
@update:model-value="searchval">
|
||||
|
||||
<template v-slot:option="{ itemProps, opt, selected, toggleOption }">
|
||||
<q-item v-bind="itemProps">
|
||||
|
||||
<q-item-section>
|
||||
<q-item-label>{{ opt[fieldsTable.getLabelByTable(item.table)] }}</q-item-label>
|
||||
</q-item-section>
|
||||
<q-item-section side>
|
||||
<q-toggle :model-value="selected" @update:value="toggleOption(opt)"/>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
</template>
|
||||
|
||||
</q-select>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-slot:body="props">
|
||||
<q-tr :props="props" class="trclass">
|
||||
<q-td auto-width class="tdclass">
|
||||
@@ -137,7 +188,7 @@
|
||||
v-if="colVisib.includes(col.field + col.subfield)" class="tdclass">
|
||||
<div :class="getclrow(props.row)">
|
||||
<CMyPopupEdit
|
||||
:table="prop_mytable"
|
||||
:table="mytable"
|
||||
:canEdit="canEdit"
|
||||
:disable="disabilita()"
|
||||
:mycol="col"
|
||||
@@ -177,7 +228,7 @@
|
||||
<q-card :class="props.selected ? 'bg-grey-2' : ''">
|
||||
<q-bar dense class="bg-primary text-white">
|
||||
<span class="ellipsis"> {{ props.row[col_title] }} </span>
|
||||
<q-space />
|
||||
<q-space/>
|
||||
<q-btn
|
||||
flat round color="white" icon="fas fa-pencil-alt" size="sm"
|
||||
@click="clickFunz(props.row, prop_mycolumns.find((rec) => rec.action === lists.MenuAction.CAN_EDIT_TABLE))"></q-btn>
|
||||
@@ -202,7 +253,7 @@
|
||||
<div :class="getclrow(props.row)">
|
||||
|
||||
<CMyPopupEdit
|
||||
:table="prop_mytable"
|
||||
:table="mytable"
|
||||
:canEdit="canEdit"
|
||||
:disable="disabilita()"
|
||||
:mycol="col"
|
||||
@@ -258,7 +309,7 @@
|
||||
@click="colclicksel = mycol">
|
||||
|
||||
<CMyPopupEdit
|
||||
:table="prop_mytable"
|
||||
:table="mytable"
|
||||
:canEdit="true"
|
||||
:disable="disabilita()"
|
||||
view="field"
|
||||
@@ -282,18 +333,18 @@
|
||||
<q-card :style="`min-width: `+ tools.myheight_dialog() + `px;`">
|
||||
<q-bar dense class="bg-primary text-white">
|
||||
Nuovo:
|
||||
<q-space />
|
||||
<q-space/>
|
||||
<q-btn flat round color="white" icon="close" v-close-popup></q-btn>
|
||||
</q-bar>
|
||||
<q-card-section class="inset-shadow">
|
||||
<div
|
||||
v-for="col in mycolumns" :key="col.name" class="newrec_fields">
|
||||
<div
|
||||
v-if="colVisib.includes(col.field + col.subfield)">
|
||||
v-if="colVisib.includes(col.field + col.subfield) && col.foredit">
|
||||
<div class="">
|
||||
|
||||
<CMyPopupEdit
|
||||
:table="prop_mytable"
|
||||
:table="mytable"
|
||||
:canEdit="true"
|
||||
:mycol="col"
|
||||
v-model:row="newRecord"
|
||||
@@ -322,17 +373,17 @@
|
||||
<q-bar dense class="bg-primary text-white">
|
||||
<span v-if="mytitle">{{ mytitle }}</span>
|
||||
<span v-else>{{ recModif[col_title] }}</span>
|
||||
<q-space />
|
||||
<q-space/>
|
||||
<q-btn flat round color="white" icon="close" v-close-popup></q-btn>
|
||||
</q-bar>
|
||||
<q-card-section class="inset-shadow">
|
||||
<div
|
||||
v-for="col in mycolumns" :key="col.name">
|
||||
<div
|
||||
v-if="colVisib.includes(col.field + col.subfield)">
|
||||
v-if="colVisib.includes(col.field + col.subfield) && col.foredit">
|
||||
<div>
|
||||
<CMyPopupEdit
|
||||
:table="prop_mytable"
|
||||
:table="mytable"
|
||||
:canEdit="true"
|
||||
:mycol="col"
|
||||
:isInModif="true"
|
||||
|
||||
Reference in New Issue
Block a user