#8246 modified addressFk field to use dashIfEmpty filter #1208

Open
jon wants to merge 4 commits from 8246-ZoneAddressFk2 into dev
3 changed files with 21 additions and 27 deletions

View File

@ -1,7 +1,7 @@
<script setup> <script setup>
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { ref } from 'vue'; import { computed, ref } from 'vue';
import FetchData from 'components/FetchData.vue'; import FetchData from 'components/FetchData.vue';
import FormModel from 'src/components/FormModel.vue'; import FormModel from 'src/components/FormModel.vue';
import VnRow from 'components/ui/VnRow.vue'; import VnRow from 'components/ui/VnRow.vue';
@ -19,6 +19,11 @@ const agencyFilter = {
limit: 30, limit: 30,
}; };
const agencyOptions = ref([]); const agencyOptions = ref([]);
const validAddresses = ref([]);
const filterWhere = computed(() => ({
id: { inq: validAddresses.value.map((item) => item.addressFk) },
}));
</script> </script>
<template> <template>
@ -28,7 +33,11 @@ const agencyOptions = ref([]);
auto-load auto-load
url="AgencyModes/isActive" url="AgencyModes/isActive"
/> />
<FetchData
url="RoadmapAddresses"
auto-load
@on-fetch="(data) => (validAddresses = data)"
/>
<FormModel :url="`Zones/${route.params.id}`" auto-load model="zone"> <FormModel :url="`Zones/${route.params.id}`" auto-load model="zone">
<template #form="{ data, validate }"> <template #form="{ data, validate }">
<VnRow> <VnRow>
@ -128,6 +137,8 @@ const agencyOptions = ref([]);
hide-selected hide-selected
map-options map-options
:rules="validate('data.addressFk')" :rules="validate('data.addressFk')"
:filter-options="['id']"
:where="filterWhere"
/> />
</VnRow> </VnRow>
<VnRow> <VnRow>

View File

@ -28,9 +28,6 @@ const exprBuilder = (param, value) => {
<VnSearchbar <VnSearchbar
data-key="ZonesList" data-key="ZonesList"
url="Zones" url="Zones"
:filter="{
include: { relation: 'agencyMode', scope: { fields: ['name'] } },
}"
:expr-builder="exprBuilder" :expr-builder="exprBuilder"
:label="t('list.searchZone')" :label="t('list.searchZone')"
:info="t('list.searchInfo')" :info="t('list.searchInfo')"

View File

@ -4,7 +4,7 @@ import { useRouter } from 'vue-router';
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import axios from 'axios'; import axios from 'axios';
import { toCurrency } from 'src/filters'; import { dashIfEmpty, toCurrency } from 'src/filters';
import { toTimeFormat } from 'src/filters/date'; import { toTimeFormat } from 'src/filters/date';
import { useVnConfirm } from 'composables/useVnConfirm'; import { useVnConfirm } from 'composables/useVnConfirm';
import useNotify from 'src/composables/useNotify.js'; import useNotify from 'src/composables/useNotify.js';
@ -17,7 +17,6 @@ import VnInputTime from 'src/components/common/VnInputTime.vue';
import RightMenu from 'src/components/common/RightMenu.vue'; import RightMenu from 'src/components/common/RightMenu.vue';
import ZoneFilterPanel from './ZoneFilterPanel.vue'; import ZoneFilterPanel from './ZoneFilterPanel.vue';
import ZoneSearchbar from './Card/ZoneSearchbar.vue'; import ZoneSearchbar from './Card/ZoneSearchbar.vue';
import FetchData from 'src/components/FetchData.vue';
const { t } = useI18n(); const { t } = useI18n();
const router = useRouter(); const router = useRouter();
@ -26,9 +25,8 @@ const { viewSummary } = useSummaryDialog();
const { openConfirmationModal } = useVnConfirm(); const { openConfirmationModal } = useVnConfirm();
const tableRef = ref(); const tableRef = ref();
const warehouseOptions = ref([]); const warehouseOptions = ref([]);
const validAddresses = ref([]);
const tableFilter = { const tableFilter = computed(() => ({
include: [ include: [
{ {
relation: 'agencyMode', relation: 'agencyMode',
@ -63,7 +61,7 @@ const tableFilter = {
}, },
}, },
], ],
}; }));
const columns = computed(() => [ const columns = computed(() => [
{ {
@ -165,26 +163,14 @@ const handleClone = (id) => {
); );
}; };
function showValidAddresses(row) { function formatRow(row) {
if (row.addressFk) { if (!row?.address) return '-';
const isValid = validAddresses.value.some( return dashIfEmpty(`${row?.address?.nickname},
(address) => address.addressFk === row.addressFk ${row?.address?.postcode?.town?.name} (${row?.address?.province?.name})`);
);
if (isValid)
return `${row.address?.nickname},
${row.address?.postcode?.town?.name} (${row.address?.province?.name})`;
else return '-';
}
return '-';
} }
</script> </script>
<template> <template>
<FetchData
url="RoadmapAddresses"
auto-load
@on-fetch="(data) => (validAddresses = data)"
/>
<ZoneSearchbar /> <ZoneSearchbar />
<RightMenu> <RightMenu>
<template #right-panel> <template #right-panel>
@ -207,7 +193,7 @@ function showValidAddresses(row) {
:right-search="false" :right-search="false"
> >
<template #column-addressFk="{ row }"> <template #column-addressFk="{ row }">
{{ showValidAddresses(row) }} {{ dashIfEmpty(formatRow(row)) }}
</template> </template>
<template #more-create-dialog="{ data }"> <template #more-create-dialog="{ data }">
<VnSelect <VnSelect