- add set cookies to table

- fix filters
This commit is contained in:
Paolo Arena
2021-12-16 10:56:57 +01:00
parent 48297094ae
commit c6e0c23650
16 changed files with 496 additions and 214 deletions

View File

@@ -41,46 +41,62 @@ export default defineComponent({
]*/
function getFilterSkills(recSkill: any, index: number, arr: any) {
const recsectors:any = searchList.value.find((rec) => rec.table === 'sectors')
if (recsectors) {
return recSkill.idSector.includes(recsectors.value)
} else {
return true
}
}
searchList.value = [
{
label: 'Settore',
table: 'sectors',
key: 'idSector',
value: costanti.FILTER_TUTTI,
value: tools.getCookie(tools.COOK_SEARCH + 'sectors', costanti.FILTER_TUTTI),
arrvalue: [],
type: costanti.FieldType.select,
filter: null,
notinsearch: true,
},
{
label: 'Competenza',
table: 'skills',
key: 'idSkill',
value: costanti.FILTER_TUTTI,
value: tools.getCookie(tools.COOK_SEARCH + 'skills', costanti.FILTER_TUTTI),
arrvalue: [],
type: costanti.FieldType.select,
filter: getFilterSkills,
},
{
label: 'Citta',
table: 'cities',
key: 'idCity',
value: costanti.FILTER_TUTTI,
value: 0,
type: costanti.FieldType.multiselect,
arrvalue: [costanti.FILTER_TUTTI],
arrvalue: tools.getCookie(tools.COOK_SEARCH + 'cities', [costanti.FILTER_TUTTI]),
filter: null,
},
{
label: 'Livello',
table: 'levels',
key: 'numLevel',
value: costanti.FILTER_TUTTI,
value: tools.getCookie(tools.COOK_SEARCH + 'levels', costanti.FILTER_TUTTI),
arrvalue: [],
type: costanti.FieldType.select,
filter: null,
},
{
label: 'Stato',
table: 'statusSkills',
key: 'idStatusSkill',
value: costanti.FILTER_TUTTI,
arrvalue: [],
value: 0,
arrvalue: tools.getCookie(tools.COOK_SEARCH + 'statusSkills', [costanti.FILTER_TUTTI]),
type: costanti.FieldType.multiselect,
filter: null,
},
]
@@ -88,6 +104,7 @@ export default defineComponent({
filtercustom.value = []
}
async function createNewRecordInUserTable() {
console.log('createNewRecordInUserTable')
@@ -125,14 +142,51 @@ export default defineComponent({
function extraparams() {
return {
lk_tab: 'users',
lk_LF: 'userId',
lk_FF: '_id',
lk_as: 'user',
af_objId_tab: 'myId',
lk_proj: {
idSkill: 1, idStatusSkill: 1, idCity: 1, numLevel: 1, photos: 1, note: 1, subTitle: 1, date_created:1, date_updated: 1,
userId: 1, username: 1, name: 1, surname: 1
lookup1: {
lk_tab: 'users',
lk_LF: 'userId',
lk_FF: '_id',
lk_as: 'user',
af_objId_tab: 'myId',
lk_proj: {
'sector.idSector': 1,
idSkill: 1,
idStatusSkill: 1,
idCity: 1,
numLevel: 1,
photos: 1,
note: 1,
subTitle: 1,
date_created: 1,
date_updated: 1,
userId: 1,
username: 1,
name: 1,
surname: 1
}
},
lookup2: {
lk_tab: 'sectors',
lk_LF: 'idSkill',
lk_FF: '_id',
lk_as: 'sector',
af_objId_tab: '',
lk_proj: {
'sector.idSector': 1,
idSkill: 1,
idStatusSkill: 1,
idCity: 1,
numLevel: 1,
photos: 1,
note: 1,
subTitle: 1,
date_created: 1,
date_updated: 1,
userId: 1,
username: 1,
name: 1,
surname: 1
}
}
}
}

View File

@@ -2,13 +2,14 @@
<div>
<div class="q-ma-sm q-gutter-sm q-pa-xs">
<CGridTableRec
v-if="searchList.length > 0"
prop_mytable="myskills"
prop_mytitle=""
:prop_mycolumns="colmySkills"
prop_colkey="idSkill"
col_title="subTitle"
:vertical="true"
nodataLabel="Nessuna Competenza inserita"
nodataLabel="Nessuna Competenza trovata"
:prop_search="true"
:finder="true"
:butt_modif_new="false"
@@ -16,6 +17,7 @@
:arrfilters="arrfilterand"
:filtercustom="filtercustom"
:prop_searchList="searchList"
keyMain="idSkill"
:defaultnewrec="getdefaultnewrec"
:extraparams="extraparams()">

View File

@@ -14,7 +14,7 @@ import {
IParamDialog,
IEvents,
IDataToSet,
IMySkill
IMySkill, ISkill
} from '../../model'
import { lists } from '../../store/Modules/lists'
import { IParamsQuery } from '../../model/GlobalStore'
@@ -78,6 +78,11 @@ export default defineComponent({
required: false,
default: '',
},
keyMain: {
type: String,
required: false,
default: '',
},
nodataLabel: {
type: String,
required: false,
@@ -170,6 +175,8 @@ export default defineComponent({
const loading = ref(false)
const startsearch = ref(false)
const serverData: any = ref([])
const spinner_visible = ref(false)
const searchList = toRef(props, 'prop_searchList')
@@ -181,7 +188,6 @@ 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)
@@ -199,11 +205,13 @@ export default defineComponent({
const mycodeid = toRef(props, 'prop_codeId')
watch(searchList.value, (to: any, from: any) => {
console.log('watch searchlist', to)
refresh()
})
function searchval(newval: any) {
console.log('searchval')
function searchval(newval: any, table: any) {
console.log('searchval', newval, table)
tools.setCookie(tools.COOK_SEARCH + table, newval)
refresh()
}
@@ -240,7 +248,7 @@ export default defineComponent({
// emulate ajax call
// SELECT * FROM ... WHERE...LIMIT...
async function fetchFromServer(startRow: any, endRow: any, param_myfilter: any, param_myfilterand: any, filtercustom: any, sortBy: any, descending: any) {
async function fetchFromServer(startRow: any, endRow: any, param_myfilter: any, param_myfilterand: any, sortBy: any, descending: any) {
let myobj: any = {}
if (sortBy) {
@@ -254,35 +262,76 @@ export default defineComponent({
// console.log('sortBy', sortBy)
let filtersearch: ISearchList[] = []
let filtersearch: any[] = []
let recSector = searchList.value.find((item: ISearchList) => item.table === 'sectors')
let idSector = recSector ? recSector.value : 0
if (searchList.value) {
searchList.value.forEach((item: ISearchList) => {
let myarr: ISearchList
let objitem: any = {}
if (item.value > 0) {
objitem[item.key] = item.value
filtersearch.push(objitem)
} else if (item.arrvalue.length > 0) {
const myarr = item.arrvalue.filter((value) => value > 0)
if (!item.notinsearch) {
let objitem: any = {}
if (item.value > 0) {
objitem[item.key] = item.value
filtersearch.push(objitem)
} else if (item.arrvalue.length > 0) {
const myarr = item.arrvalue.filter((value: any) => value > 0)
let arr2: any = []
let arr2: any = []
myarr.forEach((myval) => {
let objitem2: any = {}
objitem2[item.key] = myval
arr2.push(objitem2)
})
myarr.forEach((myval: any) => {
let objitem2: any = {}
objitem2[item.key] = myval
arr2.push(objitem2)
})
let obj2: any = {
$or: arr2
let obj2: any = {
$or: arr2
}
if (arr2.length > 0)
filtersearch.push(obj2)
} else {
if (item.table === 'skills' && item.value === costanti.FILTER_TUTTI) {
// idSector
let obj2: any = {
idSector: idSector
}
filtersearch.push(obj2)
}
}
if (arr2.length > 0)
filtersearch.push(obj2)
}
})
}
console.log('filtersearch', filtersearch)
if (props.prop_search) {
let nosearch = false
if (filtersearch.length <= 0 && !param_myfilter) {
nosearch = true
returnedData.value = []
returnedCount = 0
} else {
if (props.keyMain) {
nosearch = true
filtersearch.forEach((rec: any) => {
console.log('rec', rec)
if (!!rec[props.keyMain]) {
nosearch = false
}
})
}
}
if (false && nosearch && props.finder) {
returnedData.value = []
returnedCount = 0
return true
}
}
console.log('filtercustom', props.filtercustom)
let params: IParamsQuery = {
table: mytable.value,
@@ -292,7 +341,8 @@ export default defineComponent({
filterand: param_myfilterand,
// @ts-ignore
filtersearch: filtersearch,
filtercustom,
// @ts-ignore
filtercustom: props.filtercustom,
sortBy: myobj,
descending,
userId: userStore.my._id,
@@ -329,13 +379,14 @@ export default defineComponent({
const { page, rowsPerPage, rowsNumber, sortBy, descending } = props.pagination
const myfilternow = myfilter.value
const myfilterandnow = myfilterand.value
const myfiltercustomnow = myfiltercustom.value
savefilter()
if (!mytable.value)
return
// console.log('myfilterandnow', myfilterandnow, 'myfilterandnow', myfilterandnow)
// console.log('onRequest', 'myfilter = ', myfilter.value)
loading.value = true
@@ -356,7 +407,7 @@ export default defineComponent({
serverData.value = []
// fetch data from "server"
return fetchFromServer(startRow, endRow, myfilternow, myfilterandnow, myfiltercustomnow, sortBy, descending).then((ris: any) => {
return fetchFromServer(startRow, endRow, myfilternow, myfilterandnow, sortBy, descending).then((ris: any) => {
pagination.value.rowsNumber = getRowsNumberCount(myfilter)
@@ -403,6 +454,9 @@ export default defineComponent({
function refresh() {
// console.log('refresh')
if (!startsearch.value)
return false
serverData.value = []
search.value = search.value.trim()
@@ -423,12 +477,13 @@ export default defineComponent({
refresh()
})
watch(() => myfilterand.value, (newval, oldval) => {
/*watch(() => myfilterand.value, (newval, oldval) => {
refresh()
})
})*/
watch(() => myfiltercustom.value, (newval, oldval) => {
refresh()
watch(() => props.filtercustom, (newval, oldval) => {
// console.log('myfiltercustom change')
// refresh()
})
function isTutor() {
@@ -638,12 +693,14 @@ export default defineComponent({
function mounted() {
// console.log('GridTable mounted', tablesel.value)
console.log('props.filtercustom', props.filtercustom)
if (!!props.tablesList) {
canEdit.value = tools.getCookie(tools.CAN_EDIT, canEdit) === 'true'
tablesel.value = tools.getCookie('tablesel', tablesel.value)
}
myfilterand.value = props.filterdef
myfiltercustom.value = props.filtercustom
// myfiltercustom.value = props.filtercustom
// console.log('tablesel', tablesel)
if (tablesel.value === '') {
@@ -838,6 +895,8 @@ export default defineComponent({
}
}
startsearch.value = true
refresh()
}
@@ -990,12 +1049,12 @@ export default defineComponent({
return props.labelBtnAddRow !== addRow.value
}
// onMounted(mounted)
created()
mounted()
return {
selItem,
SaveValdb,
@@ -1052,7 +1111,6 @@ export default defineComponent({
spinner_visible,
tablesel,
myfilterand,
myfiltercustom,
tools,
costanti,
fieldsTable,

View File

@@ -136,18 +136,18 @@
v-if="item.type === costanti.FieldType.select"
:label="item.label"
v-model:value="item.value"
@update:value="searchval"
@update:value="searchval(item.value, item.table)"
:addall="true"
:optval="fieldsTable.getKeyByTable(item.table)"
:optlab="fieldsTable.getLabelByTable(item.table)"
:options="globalStore.getTableJoinByName(item.table, true)"
:options="globalStore.getTableJoinByName(item.table, true, item.filter)"
:useinput="false">
</CMySelect>
<q-select
v-if="item.type === costanti.FieldType.multiselect"
v-model="item.arrvalue"
@update:model-value="searchval"
@update:model-value="searchval(item.arrvalue, item.table)"
rounded
outlined
multiple
@@ -156,7 +156,7 @@
:display-value="fieldsTable.getTitleByTable(item.table)"
emit-value
map-options
:options="globalStore.getTableJoinByName(item.table)"
:options="globalStore.getTableJoinByName(item.table, item.filter)"
style="min-width: 150px"
:option-value="fieldsTable.getKeyByTable(item.table)"
>

View File

@@ -33,14 +33,16 @@ export default defineComponent({
function extraparams() {
return {
lk_tab: 'users',
lk_LF: 'userId',
lk_FF: '_id',
lk_as: 'user',
af_objId_tab: 'myId',
lk_proj: {
todoId: 1, userId: 1, descr: 1, date: 1, time_start: 1, time_end: 1, hours: 1,
username: 1, name: 1, surname: 1
lookup1: {
lk_tab: 'users',
lk_LF: 'userId',
lk_FF: '_id',
lk_as: 'user',
af_objId_tab: 'myId',
lk_proj: {
todoId: 1, userId: 1, descr: 1, date: 1, time_start: 1, time_end: 1, hours: 1,
username: 1, name: 1, surname: 1
}
}
}
}

View File

@@ -18,6 +18,13 @@ export default defineComponent({
type: Function,
required: false,
},
filtercustom: {
type: Array,
required: false,
default: () => {
return []
}
},
},
components: {
CMyFieldDb, CGridTableRec,
@@ -64,14 +71,27 @@ export default defineComponent({
function extraparams() {
return {
lk_tab: 'users',
lk_LF: 'userId',
lk_FF: '_id',
lk_as: 'user',
af_objId_tab: 'myId',
lk_proj: {
idSkill: 1, idStatusSkill: 1, idCity: 1, numLevel: 1, photos: 1, note: 1, subTitle: 1, date_created:1, date_updated: 1,
userId: 1, username: 1, name: 1, surname: 1
lookup1: {
lk_tab: 'users',
lk_LF: 'userId',
lk_FF: '_id',
lk_as: 'user',
af_objId_tab: 'myId',
lk_proj: {
idSkill: 1,
idStatusSkill: 1,
idCity: 1,
numLevel: 1,
photos: 1,
note: 1,
subTitle: 1,
date_created: 1,
date_updated: 1,
userId: 1,
username: 1,
name: 1,
surname: 1
}
}
}
}

View File

@@ -12,6 +12,7 @@
:prop_search="false"
noresultLabel="Il filtro selezionato non ha trovato nessun risultato"
:defaultnewrec="getdefaultnewrec"
:filtercustom="filtercustom"
:extraparams="extraparams()">
</CGridTableRec>