feat: refs #8224 exclude filter
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
e8ba5761cc
commit
4ad9a3e613
|
@ -9,18 +9,18 @@ const colField = ref();
|
||||||
let colValue = '';
|
let colValue = '';
|
||||||
let textValue = '';
|
let textValue = '';
|
||||||
|
|
||||||
|
defineExpose({ handler });
|
||||||
|
|
||||||
const arrayData = defineModel({
|
const arrayData = defineModel({
|
||||||
type: Array,
|
type: Array,
|
||||||
});
|
});
|
||||||
|
|
||||||
defineExpose({
|
|
||||||
handler,
|
|
||||||
});
|
|
||||||
|
|
||||||
function handler(event) {
|
function handler(event) {
|
||||||
|
const clickedElement = event.target.closest('td');
|
||||||
|
if (!clickedElement) return;
|
||||||
|
|
||||||
target.value = event.target;
|
target.value = event.target;
|
||||||
qmenuRef.value.show();
|
qmenuRef.value.show();
|
||||||
const clickedElement = event.target.closest('td');
|
|
||||||
colField.value = clickedElement.getAttribute('data-col-field');
|
colField.value = clickedElement.getAttribute('data-col-field');
|
||||||
colValue = isNaN(+clickedElement.getAttribute('data-col-value'))
|
colValue = isNaN(+clickedElement.getAttribute('data-col-value'))
|
||||||
? clickedElement.getAttribute('data-col-value')
|
? clickedElement.getAttribute('data-col-value')
|
||||||
|
@ -45,22 +45,22 @@ function getDeepestText(node) {
|
||||||
return lastText;
|
return lastText;
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectionFilter() {
|
async function selectionFilter() {
|
||||||
arrayData.value.addFilter({ params: { [colField.value]: colValue } });
|
await arrayData.value.addFilter({ params: { [colField.value]: colValue } });
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectionExclude() {
|
async function selectionExclude() {
|
||||||
arrayData.value.addFilter({
|
await arrayData.value.addFilter({
|
||||||
params: { [colField.value]: { neq: +colValue } },
|
params: { [colField.value]: { neq: colValue } },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectionRemoveFilter() {
|
async function selectionRemoveFilter() {
|
||||||
arrayData.value.addFilter({ params: { [colField.value]: undefined } });
|
await arrayData.value.addFilter({ params: { [colField.value]: undefined } });
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeAllFilters() {
|
async function removeAllFilters() {
|
||||||
arrayData.value.applyFilter({ params: {} });
|
await arrayData.value.applyFilter({ params: {} });
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyValue() {
|
function copyValue() {
|
||||||
|
@ -72,12 +72,42 @@ function copyValue() {
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<QMenu ref="qmenuRef" :target class="column q-pa-sm" auto-close>
|
<QMenu ref="qmenuRef" :target class="column q-pa-sm" auto-close no-parent-event>
|
||||||
<QBtn flat @click="selectionFilter()">{{ $t('Filter by selection') }}</QBtn>
|
<QBtn
|
||||||
<!-- <QBtn flat @click="selectionExclude()">{{ $t('* Exclude selection') }}</QBtn> -->
|
flat
|
||||||
<QBtn flat @click="selectionRemoveFilter()">{{ $t('Remove filter') }}</QBtn>
|
icon="filter_list"
|
||||||
<QBtn flat @click="removeAllFilters()">{{ $t('Remove all filters') }}</QBtn>
|
@click="selectionFilter()"
|
||||||
<QBtn flat @click="copyValue()">{{ $t('Copy value') }}</QBtn>
|
align="left"
|
||||||
|
:label="$t('Filter by selection')"
|
||||||
|
/>
|
||||||
|
<QBtn
|
||||||
|
flat
|
||||||
|
icon="dangerous"
|
||||||
|
@click="selectionExclude()"
|
||||||
|
align="left"
|
||||||
|
:label="$t('Exclude selection')"
|
||||||
|
/>
|
||||||
|
<QBtn
|
||||||
|
flat
|
||||||
|
icon="filter_list_off"
|
||||||
|
@click="selectionRemoveFilter()"
|
||||||
|
align="left"
|
||||||
|
:label="$t('Remove filter')"
|
||||||
|
/>
|
||||||
|
<QBtn
|
||||||
|
flat
|
||||||
|
icon="filter_list_off"
|
||||||
|
@click="removeAllFilters()"
|
||||||
|
align="left"
|
||||||
|
:label="$t('Remove all filters')"
|
||||||
|
/>
|
||||||
|
<QBtn
|
||||||
|
flat
|
||||||
|
icon="file_copy"
|
||||||
|
@click="copyValue()"
|
||||||
|
align="left"
|
||||||
|
:label="$t('Copy value')"
|
||||||
|
/>
|
||||||
</QMenu>
|
</QMenu>
|
||||||
</template>
|
</template>
|
||||||
<i18n>
|
<i18n>
|
||||||
|
|
|
@ -136,6 +136,9 @@ async function addFilter(value, name) {
|
||||||
value = value === '' ? undefined : value;
|
value = value === '' ? undefined : value;
|
||||||
let field = columnFilter.value?.name ?? $props.column.name ?? name;
|
let field = columnFilter.value?.name ?? $props.column.name ?? name;
|
||||||
|
|
||||||
|
delete arrayData.store?.userParams?.[field];
|
||||||
|
delete arrayData.store?.filter?.where?.[field];
|
||||||
|
|
||||||
if (columnFilter.value?.inWhere) {
|
if (columnFilter.value?.inWhere) {
|
||||||
if (columnFilter.value.alias) field = columnFilter.value.alias + '.' + field;
|
if (columnFilter.value.alias) field = columnFilter.value.alias + '.' + field;
|
||||||
return await arrayData.addFilterWhere({ [field]: value });
|
return await arrayData.addFilterWhere({ [field]: value });
|
||||||
|
|
|
@ -210,11 +210,11 @@ onBeforeMount(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
if ($props.isEditable) document.addEventListener('click', clickHandler);
|
||||||
document.addEventListener('contextmenu', (event) => {
|
document.addEventListener('contextmenu', (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
contextMenuRef.value.handler(event);
|
contextMenuRef.value.handler(event);
|
||||||
});
|
});
|
||||||
if ($props.isEditable) document.addEventListener('click', clickHandler);
|
|
||||||
mode.value =
|
mode.value =
|
||||||
quasar.platform.is.mobile && !$props.disableOption?.card
|
quasar.platform.is.mobile && !$props.disableOption?.card
|
||||||
? CARD_MODE
|
? CARD_MODE
|
||||||
|
@ -238,6 +238,7 @@ onMounted(async () => {
|
||||||
|
|
||||||
onUnmounted(async () => {
|
onUnmounted(async () => {
|
||||||
if ($props.isEditable) document.removeEventListener('click', clickHandler);
|
if ($props.isEditable) document.removeEventListener('click', clickHandler);
|
||||||
|
document.removeEventListener('contextmenu', {});
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|
|
@ -77,7 +77,12 @@ function columnName(col) {
|
||||||
<template #tags="{ tag, formatFn, getLocale }">
|
<template #tags="{ tag, formatFn, getLocale }">
|
||||||
<div class="q-gutter-x-xs">
|
<div class="q-gutter-x-xs">
|
||||||
<strong>{{ getLocale(`${tag.label}`) }}: </strong>
|
<strong>{{ getLocale(`${tag.label}`) }}: </strong>
|
||||||
<span>{{ formatFn(tag.value) }}</span>
|
<span
|
||||||
|
:class="{
|
||||||
|
'text-decoration-line-through': typeof chip === 'object',
|
||||||
|
}"
|
||||||
|
>{{ formatFn(tag) }}</span
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template v-for="(_, slotName) in $slots" #[slotName]="slotData" :key="slotName">
|
<template v-for="(_, slotName) in $slots" #[slotName]="slotData" :key="slotName">
|
||||||
|
|
|
@ -124,6 +124,7 @@ const {
|
||||||
} = toRefs($props);
|
} = toRefs($props);
|
||||||
const myOptions = ref([]);
|
const myOptions = ref([]);
|
||||||
const myOptionsOriginal = ref([]);
|
const myOptionsOriginal = ref([]);
|
||||||
|
const myOptionsMap = ref(new Map());
|
||||||
const vnSelectRef = ref();
|
const vnSelectRef = ref();
|
||||||
const lastVal = ref();
|
const lastVal = ref();
|
||||||
const noOneText = t('globals.noOne');
|
const noOneText = t('globals.noOne');
|
||||||
|
@ -140,7 +141,7 @@ const styleAttrs = computed(() => {
|
||||||
}
|
}
|
||||||
: {};
|
: {};
|
||||||
});
|
});
|
||||||
const isLoading = ref(false);
|
const hasFocus = ref(false);
|
||||||
const useURL = computed(() => $props.url);
|
const useURL = computed(() => $props.url);
|
||||||
const value = computed({
|
const value = computed({
|
||||||
get() {
|
get() {
|
||||||
|
@ -166,6 +167,10 @@ const computedSortBy = computed(() => {
|
||||||
return $props.sortBy || $props.optionLabel + ' ASC';
|
return $props.sortBy || $props.optionLabel + ' ASC';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const valueIsObject = computed(() => {
|
||||||
|
return modelValue.value && typeof modelValue.value == 'object';
|
||||||
|
});
|
||||||
|
|
||||||
const getVal = (val) => ($props.useLike ? { like: `%${val}%` } : val);
|
const getVal = (val) => ($props.useLike ? { like: `%${val}%` } : val);
|
||||||
|
|
||||||
watch(options, (newValue) => {
|
watch(options, (newValue) => {
|
||||||
|
@ -173,12 +178,22 @@ watch(options, (newValue) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(modelValue, async (newValue) => {
|
watch(modelValue, async (newValue) => {
|
||||||
|
if (newValue?.neq) newValue = newValue.neq;
|
||||||
if (!myOptions?.value?.some((option) => option[optionValue.value] == newValue))
|
if (!myOptions?.value?.some((option) => option[optionValue.value] == newValue))
|
||||||
await fetchFilter(newValue);
|
await fetchFilter(newValue);
|
||||||
|
|
||||||
if ($props.noOne) myOptions.value.unshift(noOneOpt.value);
|
if ($props.noOne) myOptions.value.unshift(noOneOpt.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => myOptionsOriginal.value,
|
||||||
|
(newValue) => {
|
||||||
|
for (const item of newValue) {
|
||||||
|
myOptionsMap.value.set(item[optionValue.value], item);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
setOptions(options.value);
|
setOptions(options.value);
|
||||||
if (useURL.value && $props.modelValue && !findKeyInOptions())
|
if (useURL.value && $props.modelValue && !findKeyInOptions())
|
||||||
|
@ -186,7 +201,7 @@ onMounted(() => {
|
||||||
if ($props.focusOnMount) setTimeout(() => vnSelectRef.value.showPopup(), 300);
|
if ($props.focusOnMount) setTimeout(() => vnSelectRef.value.showPopup(), 300);
|
||||||
});
|
});
|
||||||
|
|
||||||
const someIsLoading = computed(() => isLoading.value || !!arrayData?.isLoading?.value);
|
const isLoading = computed(() => !!arrayData?.isLoading?.value);
|
||||||
function findKeyInOptions() {
|
function findKeyInOptions() {
|
||||||
if (!$props.options) return;
|
if (!$props.options) return;
|
||||||
return filter($props.modelValue, $props.options)?.length;
|
return filter($props.modelValue, $props.options)?.length;
|
||||||
|
@ -222,6 +237,9 @@ function filter(val, options) {
|
||||||
|
|
||||||
async function fetchFilter(val) {
|
async function fetchFilter(val) {
|
||||||
if (!$props.url) return;
|
if (!$props.url) return;
|
||||||
|
if (val && typeof val == 'object') {
|
||||||
|
val = val.neq;
|
||||||
|
}
|
||||||
|
|
||||||
const { fields, include, limit } = $props;
|
const { fields, include, limit } = $props;
|
||||||
const sortBy = computedSortBy.value;
|
const sortBy = computedSortBy.value;
|
||||||
|
@ -296,13 +314,11 @@ async function onScroll({ to, direction, from, index }) {
|
||||||
if (from === 0 && index === 0) return;
|
if (from === 0 && index === 0) return;
|
||||||
if (!useURL.value && !$props.fetchRef) return;
|
if (!useURL.value && !$props.fetchRef) return;
|
||||||
if (direction === 'decrease') return;
|
if (direction === 'decrease') return;
|
||||||
if (to === lastIndex && arrayData.store.hasMoreData && !isLoading.value) {
|
if (to === lastIndex && arrayData.store.hasMoreData) {
|
||||||
isLoading.value = true;
|
|
||||||
await arrayData.loadMore();
|
await arrayData.loadMore();
|
||||||
setOptions(arrayData.store.data);
|
setOptions(arrayData.store.data);
|
||||||
vnSelectRef.value.scrollTo(lastIndex);
|
vnSelectRef.value.scrollTo(lastIndex);
|
||||||
await nextTick();
|
await nextTick();
|
||||||
isLoading.value = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,10 +361,20 @@ function getCaption(opt) {
|
||||||
if (optionCaption.value === false) return;
|
if (optionCaption.value === false) return;
|
||||||
return opt[optionCaption.value] || opt[optionValue.value];
|
return opt[optionCaption.value] || opt[optionValue.value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getOptionLabel(property) {
|
||||||
|
if (!myOptionsMap.value.size) return;
|
||||||
|
let value = modelValue.value;
|
||||||
|
if (property) {
|
||||||
|
value = modelValue.value[property];
|
||||||
|
}
|
||||||
|
return myOptionsMap.value.get(value)?.[optionLabel.value];
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<QSelect
|
<QSelect
|
||||||
|
ref="vnSelectRef"
|
||||||
v-model="value"
|
v-model="value"
|
||||||
:options="myOptions"
|
:options="myOptions"
|
||||||
:option-label="optionLabel"
|
:option-label="optionLabel"
|
||||||
|
@ -357,22 +383,27 @@ function getCaption(opt) {
|
||||||
@filter="filterHandler"
|
@filter="filterHandler"
|
||||||
:emit-value="nullishToTrue($attrs['emit-value'])"
|
:emit-value="nullishToTrue($attrs['emit-value'])"
|
||||||
:map-options="nullishToTrue($attrs['map-options'])"
|
:map-options="nullishToTrue($attrs['map-options'])"
|
||||||
:use-input="nullishToTrue($attrs['use-input'])"
|
:use-input="hasFocus || !value"
|
||||||
:hide-selected="nullishToTrue($attrs['hide-selected'])"
|
:hide-selected="hasFocus"
|
||||||
:fill-input="nullishToTrue($attrs['fill-input'])"
|
:fill-input="false"
|
||||||
ref="vnSelectRef"
|
|
||||||
lazy-rules
|
lazy-rules
|
||||||
:class="{ required: isRequired }"
|
:class="{ required: isRequired }"
|
||||||
:rules="mixinRules"
|
:rules="mixinRules"
|
||||||
virtual-scroll-slice-size="options.length"
|
virtual-scroll-slice-size="options.length"
|
||||||
hide-bottom-space
|
hide-bottom-space
|
||||||
:input-debounce="useURL ? '300' : '0'"
|
:input-debounce="useURL ? '300' : '0'"
|
||||||
:loading="someIsLoading"
|
:loading="isLoading"
|
||||||
:disable="someIsLoading"
|
|
||||||
@virtual-scroll="onScroll"
|
@virtual-scroll="onScroll"
|
||||||
@keydown="handleKeyDown"
|
@keydown="handleKeyDown"
|
||||||
:data-cy="$attrs.dataCy ?? $attrs.label + '_select'"
|
:data-cy="$attrs.dataCy ?? $attrs.label + '_select'"
|
||||||
:data-url="url"
|
:data-url="url"
|
||||||
|
@focus="
|
||||||
|
async () => {
|
||||||
|
hasFocus = true;
|
||||||
|
}
|
||||||
|
"
|
||||||
|
@blur="() => (hasFocus = false)"
|
||||||
|
@update:model-value="vnSelectRef.blur()"
|
||||||
>
|
>
|
||||||
<template #append>
|
<template #append>
|
||||||
<QIcon
|
<QIcon
|
||||||
|
@ -381,6 +412,7 @@ function getCaption(opt) {
|
||||||
@click="
|
@click="
|
||||||
() => {
|
() => {
|
||||||
value = null;
|
value = null;
|
||||||
|
vnSelectRef.blur();
|
||||||
emit('remove');
|
emit('remove');
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
|
@ -422,6 +454,11 @@ function getCaption(opt) {
|
||||||
</QItemSection>
|
</QItemSection>
|
||||||
</QItem>
|
</QItem>
|
||||||
</template>
|
</template>
|
||||||
|
<template #selected-item="scope" v-if="valueIsObject">
|
||||||
|
<span class="nowrap" @click="vnSelectRef.showPopup()">
|
||||||
|
<s class="nowrap" v-if="scope?.opt.neq" v-text="getOptionLabel('neq')" />
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
</QSelect>
|
</QSelect>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -429,4 +466,12 @@ function getCaption(opt) {
|
||||||
.q-field--outlined {
|
.q-field--outlined {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
.q-field__native {
|
||||||
|
@extend .nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nowrap {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: nowrap !important;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -460,6 +460,32 @@ function setReference(data) {
|
||||||
|
|
||||||
dialogData.value.value.description = newDescription;
|
dialogData.value.value.description = newDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function exprBuilder(param, value) {
|
||||||
|
switch (param) {
|
||||||
|
case 'stateFk':
|
||||||
|
return { 'ts.stateFk': value };
|
||||||
|
case 'provinceFk':
|
||||||
|
return { 'a.provinceFk': value };
|
||||||
|
case 'hour':
|
||||||
|
return { 'z.hour': value };
|
||||||
|
case 'shipped':
|
||||||
|
return {
|
||||||
|
't.shipped': {
|
||||||
|
between: this.dateRange(value),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
case 'departmentFk':
|
||||||
|
return { 'c.departmentFk': value };
|
||||||
|
case 'id':
|
||||||
|
case 'refFk':
|
||||||
|
case 'zoneFk':
|
||||||
|
case 'nickname':
|
||||||
|
case 'agencyModeFk':
|
||||||
|
case 'warehouseFk':
|
||||||
|
return { [`t.${param}`]: value };
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -654,17 +680,14 @@ function setReference(data) {
|
||||||
</VnSelect>
|
</VnSelect>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
<VnRow>
|
<VnRow>
|
||||||
<div class="col">
|
|
||||||
<VnInputDate
|
<VnInputDate
|
||||||
placeholder="dd-mm-aaa"
|
placeholder="dd-mm-aaa"
|
||||||
:label="t('globals.landed')"
|
:label="t('globals.landed')"
|
||||||
v-model="data.landed"
|
v-model="data.landed"
|
||||||
@update:model-value="() => fetchAvailableAgencies(data)"
|
@update:model-value="() => fetchAvailableAgencies(data)"
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
</VnRow>
|
</VnRow>
|
||||||
<VnRow>
|
<VnRow>
|
||||||
<div class="col">
|
|
||||||
<VnSelect
|
<VnSelect
|
||||||
url="Warehouses"
|
url="Warehouses"
|
||||||
:sort-by="['name']"
|
:sort-by="['name']"
|
||||||
|
@ -675,10 +698,8 @@ function setReference(data) {
|
||||||
required
|
required
|
||||||
@update:model-value="() => fetchAvailableAgencies(data)"
|
@update:model-value="() => fetchAvailableAgencies(data)"
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
</VnRow>
|
</VnRow>
|
||||||
<VnRow>
|
<VnRow>
|
||||||
<div class="col">
|
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('globals.agency')"
|
:label="t('globals.agency')"
|
||||||
v-model="data.agencyModeId"
|
v-model="data.agencyModeId"
|
||||||
|
@ -687,7 +708,6 @@ function setReference(data) {
|
||||||
option-label="agencyMode"
|
option-label="agencyMode"
|
||||||
hide-selected
|
hide-selected
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
</VnRow>
|
</VnRow>
|
||||||
</template>
|
</template>
|
||||||
</VnTable>
|
</VnTable>
|
||||||
|
|
Loading…
Reference in New Issue