0
0
Fork 0

Merge pull request 'feature/ms-114-ImproveExtendedListFilters' (#53) from feature/ms-114-ImproveExtendedListFilters into dev

Reviewed-on: hyervoni/salix-front-mindshore#53
This commit is contained in:
William Buezas 2024-01-03 19:58:24 +00:00
commit bdbc3209f4
5 changed files with 136 additions and 30 deletions

View File

@ -1,8 +1,6 @@
<script setup> <script setup>
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { ref, computed } from 'vue'; import { ref, computed, onMounted } from 'vue';
import FetchData from 'components/FetchData.vue';
import { useState } from 'src/composables/useState'; import { useState } from 'src/composables/useState';
import axios from 'axios'; import axios from 'axios';
@ -29,12 +27,6 @@ const { t } = useI18n();
const popupProxyRef = ref(null); const popupProxyRef = ref(null);
const user = state.getUser(); const user = state.getUser();
const initialUserConfigViewData = ref(null); const initialUserConfigViewData = ref(null);
const userConfigFilter = {
where: {
tableCode: $props.tableCode,
userFk: user.id,
},
};
const formattedCols = ref([]); const formattedCols = ref([]);
@ -43,13 +35,12 @@ const areAllChecksMarked = computed(() => {
}); });
const setUserConfigViewData = (data) => { const setUserConfigViewData = (data) => {
initialUserConfigViewData.value = data; if (!data) return;
if (data.length === 0) return;
formattedCols.value = $props.allColumns.map((col) => { formattedCols.value = $props.allColumns.map((col) => {
// Importante: El name de las columnas de la tabla debe conincidir con el name de las variables que devuelve la view config // Importante: El name de las columnas de la tabla debe conincidir con el name de las variables que devuelve la view config
const obj = { const obj = {
name: col, name: col,
active: data[0].configuration[col], active: data[col],
}; };
return obj; return obj;
}); });
@ -60,40 +51,98 @@ const toggleMarkAll = (val) => {
formattedCols.value.forEach((col) => (col.active = val)); formattedCols.value.forEach((col) => (col.active = val));
}; };
const saveConfig = async () => { const fetchViewConfigData = async () => {
try { try {
const data = { const userConfigFilter = {
id: initialUserConfigViewData.value[0].id, where: {
userFk: 9, tableCode: $props.tableCode,
tableCode: $props.tableCode, userFk: user.id,
configuration: {}, },
}; };
formattedCols.value.forEach((col) => { const userViewConfigResponse = await axios.get('UserConfigViews', {
data.configuration[col.name] = col.active; params: { filter: userConfigFilter },
}); });
await axios.patch('UserConfigViews', data); if (userViewConfigResponse.data && userViewConfigResponse.data.length > 0) {
initialUserConfigViewData.value = userViewConfigResponse.data[0];
setUserConfigViewData(userViewConfigResponse.data[0].configuration);
return;
}
const defaultConfigFilter = {
where: {
tableCode: $props.tableCode,
},
};
const defaultViewConfigResponse = await axios.get('DefaultViewConfigs', {
params: { filter: defaultConfigFilter },
});
if (defaultViewConfigResponse.data && defaultViewConfigResponse.data.length > 0) {
setUserConfigViewData(defaultViewConfigResponse.data[0].columns);
return;
}
} catch (err) {
console.err('Error fetching config view data');
}
};
const saveConfig = async () => {
try {
const params = {};
const configuration = {};
formattedCols.value.forEach((col) => {
configuration[col.name] = col.active;
});
// Si existe una view config del usuario hacemos un update si no la creamos
if (initialUserConfigViewData.value) {
params.updates = [
{
data: {
configuration: configuration,
},
where: {
id: initialUserConfigViewData.value.id,
},
},
];
} else {
params.creates = [
{
userFk: user.value.id,
tableCode: $props.tableCode,
tableConfig: $props.tableCode,
configuration: configuration,
},
];
}
const response = await axios.post('UserConfigViews/crud', params);
if (response.data && response.data[0]) {
initialUserConfigViewData.value = response.data[0];
}
emitSavedConfig(); emitSavedConfig();
popupProxyRef.value.hide(); popupProxyRef.value.hide();
} catch (err) { } catch (err) {
console.error('Error saving user view config'); console.error('Error saving user view config');
} }
}; };
const emitSavedConfig = () => { const emitSavedConfig = () => {
const filteredCols = formattedCols.value.filter((col) => col.active); const filteredCols = formattedCols.value.filter((col) => col.active);
const mappedCols = filteredCols.map((col) => col.name); const mappedCols = filteredCols.map((col) => col.name);
emit('onConfigSaved', mappedCols); emit('onConfigSaved', mappedCols);
}; };
onMounted(async () => {
await fetchViewConfigData();
});
</script> </script>
<template> <template>
<fetch-data
v-if="user"
url="UserConfigViews"
:filter="userConfigFilter"
@on-fetch="(data) => setUserConfigViewData(data)"
auto-load
/>
<QBtn color="primary" icon="view_column"> <QBtn color="primary" icon="view_column">
<QPopupProxy ref="popupProxyRef"> <QPopupProxy ref="popupProxyRef">
<QCard class="column q-pa-md"> <QCard class="column q-pa-md">

8
src/filters/dateRange.js Normal file
View File

@ -0,0 +1,8 @@
export default function dateRange(value) {
const minHour = new Date(value);
minHour.setHours(0, 0, 0, 0);
const maxHour = new Date(value);
maxHour.setHours(23, 59, 59, 59);
return [minHour, maxHour];
}

View File

@ -7,6 +7,7 @@ import toCurrency from './toCurrency';
import toPercentage from './toPercentage'; import toPercentage from './toPercentage';
import toLowerCamel from './toLowerCamel'; import toLowerCamel from './toLowerCamel';
import dashIfEmpty from './dashIfEmpty'; import dashIfEmpty from './dashIfEmpty';
import dateRange from './dateRange';
export { export {
toLowerCase, toLowerCase,
@ -18,4 +19,5 @@ export {
toCurrency, toCurrency,
toPercentage, toPercentage,
dashIfEmpty, dashIfEmpty,
dateRange,
}; };

View File

@ -7,6 +7,7 @@ import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue';
import VnSelectFilter from 'components/common/VnSelectFilter.vue'; import VnSelectFilter from 'components/common/VnSelectFilter.vue';
import VnInput from 'src/components/common/VnInput.vue'; import VnInput from 'src/components/common/VnInput.vue';
import VnInputDate from 'components/common/VnInputDate.vue'; import VnInputDate from 'components/common/VnInputDate.vue';
import { dateRange } from 'src/filters';
const props = defineProps({ const props = defineProps({
dataKey: { dataKey: {
@ -32,6 +33,48 @@ const sageTransactionTypesOptions = ref([]);
const visibleColumnsSet = computed(() => new Set(props.visibleColumns)); const visibleColumnsSet = computed(() => new Set(props.visibleColumns));
const exprBuilder = (param, value) => {
switch (param) {
case 'created':
return {
'c.created': {
between: dateRange(value),
},
};
case 'id':
case 'name':
case 'socialName':
case 'fi':
case 'credit':
case 'creditInsurance':
case 'phone':
case 'mobile':
case 'street':
case 'city':
case 'postcode':
case 'email':
case 'isActive':
case 'isVies':
case 'isTaxDataChecked':
case 'isEqualizated':
case 'isFreezed':
case 'hasToInvoice':
case 'hasToInvoiceByAddress':
case 'isToBeMailed':
case 'hasSepaVnl':
case 'hasLcr':
case 'hasCoreVnl':
case 'countryFk':
case 'provinceFk':
case 'salesPersonFk':
case 'businessTypeFk':
case 'payMethodFk':
case 'sageTaxTypeFk':
case 'sageTransactionTypeFk':
return { [`c.${param}`]: value };
}
};
const shouldRenderColumn = (colName) => { const shouldRenderColumn = (colName) => {
return visibleColumnsSet.value.has(colName); return visibleColumnsSet.value.has(colName);
}; };
@ -88,7 +131,11 @@ const shouldRenderColumn = (colName) => {
auto-load auto-load
@on-fetch="(data) => (sageTransactionTypesOptions = data)" @on-fetch="(data) => (sageTransactionTypesOptions = data)"
/> />
<VnFilterPanel :data-key="props.dataKey" :search-button="true"> <VnFilterPanel
:data-key="props.dataKey"
:search-button="true"
:expr-builder="exprBuilder"
>
<template #tags="{ tag, formatFn }"> <template #tags="{ tag, formatFn }">
<div class="q-gutter-x-xs"> <div class="q-gutter-x-xs">
<strong <strong

View File

@ -1,5 +1,5 @@
<script setup> <script setup>
import { reactive, ref } from 'vue'; import { ref } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import FetchData from 'components/FetchData.vue'; import FetchData from 'components/FetchData.vue';