0
0
Fork 0

Item list filter

This commit is contained in:
William Buezas 2024-04-23 15:34:52 -03:00
parent b7ba664e45
commit f3b5bf7f4b
4 changed files with 171 additions and 69 deletions

View File

@ -156,9 +156,10 @@ export function useArrayData(key, userOptions) {
delete store.userParams[param]; delete store.userParams[param];
delete params[param]; delete params[param];
if (store.filter?.where) { if (store.filter?.where) {
delete store.filter.where[ const key = Object.keys(
Object.keys(exprBuilder ? exprBuilder(param) : param)[0] exprBuilder && exprBuilder(param) ? exprBuilder(param) : param
]; );
if (key[0]) delete store.filter.where[key[0]];
if (Object.keys(store.filter.where).length === 0) { if (Object.keys(store.filter.where).length === 0) {
delete store.filter.where; delete store.filter.where;
} }

View File

@ -70,7 +70,7 @@ const exprBuilder = (param, value) => {
} }
}; };
const params = reactive({}); const params = reactive({ isFloramondo: false, isActive: true });
const applyColumnFilter = async (col) => { const applyColumnFilter = async (col) => {
try { try {

View File

@ -4,13 +4,14 @@ import { useI18n } from 'vue-i18n';
import { onMounted } from 'vue'; import { onMounted } from 'vue';
import { useStateStore } from 'stores/useStateStore'; import { useStateStore } from 'stores/useStateStore';
import FetchData from 'components/FetchData.vue';
import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue'; import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue';
import VnSelectFilter from 'src/components/common/VnSelectFilter.vue'; import VnSelectFilter from 'src/components/common/VnSelectFilter.vue';
import VnInput from 'src/components/common/VnInput.vue'; import VnInput from 'src/components/common/VnInput.vue';
import FetchData from 'components/FetchData.vue'; import { QCheckbox } from 'quasar';
import VnInputDate from 'src/components/common/VnInputDate.vue';
import { useArrayData } from 'composables/useArrayData'; import { useArrayData } from 'composables/useArrayData';
import { useValidator } from 'src/composables/useValidator';
import axios from 'axios'; import axios from 'axios';
const { t } = useI18n(); const { t } = useI18n();
@ -23,6 +24,7 @@ const props = defineProps({
}); });
const stateStore = useStateStore(); const stateStore = useStateStore();
const validationsStore = useValidator();
const itemTypesRef = ref(null); const itemTypesRef = ref(null);
const categoriesOptions = ref([]); const categoriesOptions = ref([]);
@ -30,19 +32,27 @@ const itemTypesOptions = ref([]);
const buyersOptions = ref([]); const buyersOptions = ref([]);
const suppliersOptions = ref([]); const suppliersOptions = ref([]);
const tagValues = ref([]); const tagValues = ref([]);
const fieldFiltersValues = ref([]);
const moreFields = ref([]);
const arrayData = useArrayData(props.dataKey); const arrayData = useArrayData(props.dataKey);
const itemTypesFilter = computed(() => { const itemTypesFilter = {
return {
fields: ['id', 'name', 'categoryFk'], fields: ['id', 'name', 'categoryFk'],
include: 'category', include: 'category',
order: 'name ASC', order: 'name ASC',
where: { categoryFk: arrayData.store?.userParams?.categoryFk }, where: {},
}; };
});
// TODO: checkear este watch que fetchee cuando cambie categoryFk const onCategoryChange = async (categoryFk, search) => {
watch(itemTypesFilter.value.where.categoryFk, () => itemTypesRef.value.fetch()); if (!categoryFk) {
itemTypesFilter.where.categoryFk = null;
delete itemTypesFilter.where.categoryFk;
} else {
itemTypesFilter.where.categoryFk = categoryFk;
}
search();
await itemTypesRef.value.fetch();
};
const getSelectedTagValues = async (tag) => { const getSelectedTagValues = async (tag) => {
try { try {
@ -62,45 +72,60 @@ const getSelectedTagValues = async (tag) => {
} }
}; };
// const applyColumnFilter = async (col) => { const applyTags = (params, search) => {
// try { params.tags = tagValues.value
// params[col.field] = col.columnFilter.filterValue;
// await arrayData.addFilter({ params });
// } catch (err) {
// console.error('Error applying column filter', err);
// }
// };
const applyTags = () => {
// params.tags = tagValues.value
// .filter((tag) => tag.selectedTag && tag.value)
// .map((tag) => ({
// tagFk: tag.selectedTag.id,
// tagName: tag.selectedTag.name,
// value: tag.value,
// }));
console.log('apply tags');
const params = {
tags: tagValues.value
.filter((tag) => tag.selectedTag && tag.value) .filter((tag) => tag.selectedTag && tag.value)
.map((tag) => ({ .map((tag) => ({
tagFk: tag.selectedTag.id, tagFk: tag.selectedTag.id,
tagName: tag.selectedTag.name, tagName: tag.selectedTag.name,
value: tag.value, value: tag.value,
})), }));
}; search();
console.log('params:: ', params);
arrayData.addFilter({ params });
// search();
}; };
const removeTag = (index, params, search) => { const removeTag = (index, params, search) => {
(tagValues.value || []).splice(index, 1); (tagValues.value || []).splice(index, 1);
// applyTags(params, search); applyTags(params, search);
};
const applyFieldFilters = (params) => {
fieldFiltersValues.value.forEach((fieldFilter) => {
if (
fieldFilter.selectedField &&
(fieldFilter.value !== null ||
fieldFilter.value !== '' ||
fieldFilter.value !== undefined)
) {
params[fieldFilter.name] = fieldFilter.value;
}
});
arrayData.applyFilter({ params });
};
const removeFieldFilter = (index, params, search) => {
delete params[fieldFiltersValues.value[index].name];
(fieldFiltersValues.value || []).splice(index, 1);
applyFieldFilters(params, search);
}; };
onMounted(async () => { onMounted(async () => {
stateStore.rightDrawer = true; stateStore.rightDrawer = true;
if (arrayData.store?.userParams?.categoryFk)
itemTypesFilter.where.categoryFk = arrayData.store?.userParams?.categoryFk;
await itemTypesRef.value.fetch();
const { models } = validationsStore;
const properties = models.Item?.properties || {};
const _moreFields = ['id', 'description', 'name', 'isActive'];
_moreFields.forEach((field) => {
let prop = properties[field];
moreFields.value.push({
name: field,
label: prop ? prop.description : field,
type: prop ? prop.type : null,
});
});
}); });
</script> </script>
@ -116,7 +141,6 @@ onMounted(async () => {
url="ItemTypes" url="ItemTypes"
:filter="itemTypesFilter" :filter="itemTypesFilter"
@on-fetch="(data) => (itemTypesOptions = data)" @on-fetch="(data) => (itemTypesOptions = data)"
auto-load
/> />
<FetchData <FetchData
url="TicketRequests/getItemTypeWorker" url="TicketRequests/getItemTypeWorker"
@ -126,7 +150,7 @@ onMounted(async () => {
/> />
<FetchData <FetchData
url="Suppliers" url="Suppliers"
:filter="{ fields: ['name', 'nickname'], order: 'name ASC' }" :filter="{ fields: ['id', 'name', 'nickname'], order: 'name ASC' }"
@on-fetch="(data) => (suppliersOptions = data)" @on-fetch="(data) => (suppliersOptions = data)"
auto-load auto-load
/> />
@ -136,16 +160,16 @@ onMounted(async () => {
auto-load auto-load
@on-fetch="(data) => (tagOptions = data)" @on-fetch="(data) => (tagOptions = data)"
/> />
<!-- <pre>categoryFkparam:: {{ itemTypesFilter }}</pre> --> <pre>{{ itemTypesFilter }}</pre>
<!-- <pre>{{ tagValues }}</pre> --> <VnFilterPanel
<VnFilterPanel :data-key="props.dataKey" :search-button="true"> :data-key="props.dataKey"
:search-button="true"
:hidden-tags="tagValues.length === 0 ? ['tags'] : []"
>
<template #tags="{ tag, formatFn }"> <template #tags="{ tag, formatFn }">
<div v-if="tag.label !== 'tags'" class="q-gutter-x-xs"> <div>
<strong>{{ t(`params.${tag.label}`) }}: </strong> <strong>{{ t(`params.${tag.label}`) }}</strong>
<span>{{ formatFn(tag.value) }}</span> <span v-if="tag.label !== 'tags'">: {{ formatFn(tag.value) }}</span>
</div>
<div v-else class="q-gutter-x-xs">
<strong>{{ t('params.tags') }} </strong>
</div> </div>
</template> </template>
<template #body="{ params, searchFn }"> <template #body="{ params, searchFn }">
@ -163,7 +187,9 @@ onMounted(async () => {
<VnSelectFilter <VnSelectFilter
:label="t('params.categoryFk')" :label="t('params.categoryFk')"
v-model="params.categoryFk" v-model="params.categoryFk"
@update:model-value="searchFn()" @update:model-value="
($event) => onCategoryChange($event, searchFn)
"
:options="categoriesOptions" :options="categoriesOptions"
option-value="id" option-value="id"
option-label="name" option-label="name"
@ -243,6 +269,7 @@ onMounted(async () => {
</VnSelectFilter> </VnSelectFilter>
</QItemSection> </QItemSection>
</QItem> </QItem>
<!-- Tags filter -->
<QItem class="row items-center"> <QItem class="row items-center">
<QItemLabel> <QItemLabel>
{{ t('params.tags') }} {{ t('params.tags') }}
@ -290,7 +317,7 @@ onMounted(async () => {
use-input use-input
:disable="!tag" :disable="!tag"
:is-clearable="false" :is-clearable="false"
@update:model-value="applyTags()" @update:model-value="applyTags(params, searchFn)"
/> />
<VnInput <VnInput
v-else v-else
@ -299,7 +326,7 @@ onMounted(async () => {
:disable="!tag" :disable="!tag"
is-outlined is-outlined
:is-clearable="false" :is-clearable="false"
@keyup.enter="applyTags()" @keydown.enter.prevent="applyTags(params, searchFn)"
/> />
</QItemSection> </QItemSection>
<QIcon <QIcon
@ -310,16 +337,78 @@ onMounted(async () => {
@click="removeTag(index, params, searchFn)" @click="removeTag(index, params, searchFn)"
/> />
</QItem> </QItem>
<!-- Filter fields -->
<!-- <QItem> <QItem class="row items-center">
<QItemSection> <QItemLabel>
<QCheckbox {{ t('More fields') }}
:label="t('params.isOrdered')" </QItemLabel>
v-model="params.isOrdered" <QIcon
toggle-indeterminate name="add_circle"
class="fill-icon-on-hover q-ml-md"
size="sm"
color="primary"
@click="fieldFiltersValues.push({})"
/>
</QItem>
<QItem
v-for="(fieldFilter, index) in fieldFiltersValues"
:key="index"
class="row items-center"
>
<QItemSection class="col">
<VnSelectFilter
:label="t('params.tag')"
v-model="fieldFilter.name"
:options="moreFields"
option-label="label"
dense
outlined
rounded
:emit-value="false"
use-input
:is-clearable="false"
@update:model-value="
($event) => {
fieldFilter.name = $event.name;
fieldFilter.selectedField = $event;
}
"
/> />
</QItemSection> </QItemSection>
</QItem> --> <QItemSection class="col">
<QCheckbox
v-if="fieldFilter.selectedField?.type === 'boolean'"
v-model="fieldFilter.value"
:label="t('params.value')"
@update:model-value="applyFieldFilters(params, searchFn)"
/>
<VnInput
v-else
v-model="fieldFilter.value"
:label="t('params.value')"
:disable="!fieldFilter.selectedField"
is-outlined
@keydown.enter="applyFieldFilters(params, searchFn)"
/>
</QItemSection>
<QIcon
name="delete"
class="fill-icon-on-hover q-ml-xs"
size="sm"
color="primary"
@click="removeFieldFilter(index, params, searchFn)"
/>
</QItem>
<QItem>
<QItemSection>
<QCheckbox
:label="t('params.isFloramondo')"
v-model="params.isFloramondo"
toggle-indeterminate
@update:model-value="searchFn()"
/>
</QItemSection>
</QItem>
</template> </template>
</VnFilterPanel> </VnFilterPanel>
</template> </template>
@ -335,7 +424,13 @@ en:
tags: Tags tags: Tags
tag: Tag tag: Tag
value: Value value: Value
isFloramondo: Floramondo
isActive: Active
description: Description
name: Name
id: ID
es: es:
More fields: Más campos
params: params:
search: Búsqueda general search: Búsqueda general
categoryFk: Reino categoryFk: Reino
@ -345,4 +440,9 @@ es:
tags: Etiquetas tags: Etiquetas
tag: Etiqueta tag: Etiqueta
value: Valor value: Valor
isFloramondo: Floramondo
isActive: Activo
description: Descripción
name: Nombre
id: ID
</i18n> </i18n>

View File

@ -6,6 +6,7 @@ export default {
meta: { meta: {
title: 'items', title: 'items',
icon: 'vn:item', icon: 'vn:item',
moduleName: 'Item',
}, },
component: RouterView, component: RouterView,
redirect: { name: 'ItemMain' }, redirect: { name: 'ItemMain' },