forked from verdnatura/salix-front
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:
commit
bdbc3209f4
|
@ -1,8 +1,6 @@
|
|||
<script setup>
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ref, computed } from 'vue';
|
||||
|
||||
import FetchData from 'components/FetchData.vue';
|
||||
import { ref, computed, onMounted } from 'vue';
|
||||
|
||||
import { useState } from 'src/composables/useState';
|
||||
import axios from 'axios';
|
||||
|
@ -29,12 +27,6 @@ const { t } = useI18n();
|
|||
const popupProxyRef = ref(null);
|
||||
const user = state.getUser();
|
||||
const initialUserConfigViewData = ref(null);
|
||||
const userConfigFilter = {
|
||||
where: {
|
||||
tableCode: $props.tableCode,
|
||||
userFk: user.id,
|
||||
},
|
||||
};
|
||||
|
||||
const formattedCols = ref([]);
|
||||
|
||||
|
@ -43,13 +35,12 @@ const areAllChecksMarked = computed(() => {
|
|||
});
|
||||
|
||||
const setUserConfigViewData = (data) => {
|
||||
initialUserConfigViewData.value = data;
|
||||
if (data.length === 0) return;
|
||||
if (!data) return;
|
||||
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
|
||||
const obj = {
|
||||
name: col,
|
||||
active: data[0].configuration[col],
|
||||
active: data[col],
|
||||
};
|
||||
return obj;
|
||||
});
|
||||
|
@ -60,40 +51,98 @@ const toggleMarkAll = (val) => {
|
|||
formattedCols.value.forEach((col) => (col.active = val));
|
||||
};
|
||||
|
||||
const saveConfig = async () => {
|
||||
const fetchViewConfigData = async () => {
|
||||
try {
|
||||
const data = {
|
||||
id: initialUserConfigViewData.value[0].id,
|
||||
userFk: 9,
|
||||
tableCode: $props.tableCode,
|
||||
configuration: {},
|
||||
const userConfigFilter = {
|
||||
where: {
|
||||
tableCode: $props.tableCode,
|
||||
userFk: user.id,
|
||||
},
|
||||
};
|
||||
|
||||
formattedCols.value.forEach((col) => {
|
||||
data.configuration[col.name] = col.active;
|
||||
const userViewConfigResponse = await axios.get('UserConfigViews', {
|
||||
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();
|
||||
popupProxyRef.value.hide();
|
||||
} catch (err) {
|
||||
console.error('Error saving user view config');
|
||||
}
|
||||
};
|
||||
|
||||
const emitSavedConfig = () => {
|
||||
const filteredCols = formattedCols.value.filter((col) => col.active);
|
||||
const mappedCols = filteredCols.map((col) => col.name);
|
||||
emit('onConfigSaved', mappedCols);
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
await fetchViewConfigData();
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<fetch-data
|
||||
v-if="user"
|
||||
url="UserConfigViews"
|
||||
:filter="userConfigFilter"
|
||||
@on-fetch="(data) => setUserConfigViewData(data)"
|
||||
auto-load
|
||||
/>
|
||||
<QBtn color="primary" icon="view_column">
|
||||
<QPopupProxy ref="popupProxyRef">
|
||||
<QCard class="column q-pa-md">
|
||||
|
|
|
@ -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];
|
||||
}
|
|
@ -7,6 +7,7 @@ import toCurrency from './toCurrency';
|
|||
import toPercentage from './toPercentage';
|
||||
import toLowerCamel from './toLowerCamel';
|
||||
import dashIfEmpty from './dashIfEmpty';
|
||||
import dateRange from './dateRange';
|
||||
|
||||
export {
|
||||
toLowerCase,
|
||||
|
@ -18,4 +19,5 @@ export {
|
|||
toCurrency,
|
||||
toPercentage,
|
||||
dashIfEmpty,
|
||||
dateRange,
|
||||
};
|
||||
|
|
|
@ -7,6 +7,7 @@ import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue';
|
|||
import VnSelectFilter from 'components/common/VnSelectFilter.vue';
|
||||
import VnInput from 'src/components/common/VnInput.vue';
|
||||
import VnInputDate from 'components/common/VnInputDate.vue';
|
||||
import { dateRange } from 'src/filters';
|
||||
|
||||
const props = defineProps({
|
||||
dataKey: {
|
||||
|
@ -32,6 +33,48 @@ const sageTransactionTypesOptions = ref([]);
|
|||
|
||||
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) => {
|
||||
return visibleColumnsSet.value.has(colName);
|
||||
};
|
||||
|
@ -88,7 +131,11 @@ const shouldRenderColumn = (colName) => {
|
|||
auto-load
|
||||
@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 }">
|
||||
<div class="q-gutter-x-xs">
|
||||
<strong
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<script setup>
|
||||
import { reactive, ref } from 'vue';
|
||||
import { ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
import FetchData from 'components/FetchData.vue';
|
||||
|
|
Loading…
Reference in New Issue