0
0
Fork 0

Merge pull request '6825-fix_vnSelectCache_and_autoload' (!557) from 6825-fix_vnSelectCache_and_autoload into test

Reviewed-on: verdnatura/salix-front#557
Reviewed-by: Javier Segarra <jsegarra@verdnatura.es>
This commit is contained in:
Alex Moreno 2024-07-19 06:01:56 +00:00
commit bcf4f34862
6 changed files with 56 additions and 27 deletions

View File

@ -48,6 +48,17 @@ const forceAttrs = {
label: $props.showTitle ? '' : $props.column.label, label: $props.showTitle ? '' : $props.column.label,
}; };
const selectComponent = {
component: markRaw(VnSelect),
event: updateEvent,
attrs: {
class: 'q-px-sm q-pb-xs q-pt-none fit',
dense: true,
filled: !$props.showTitle,
},
forceAttrs,
};
const components = { const components = {
input: { input: {
component: markRaw(VnInput), component: markRaw(VnInput),
@ -97,16 +108,8 @@ const components = {
}, },
forceAttrs, forceAttrs,
}, },
select: { select: selectComponent,
component: markRaw(VnSelect), rawSelect: selectComponent,
event: updateEvent,
attrs: {
class: 'q-px-sm q-pb-xs q-pt-none fit',
dense: true,
filled: !$props.showTitle,
},
forceAttrs,
},
}; };
async function addFilter(value) { async function addFilter(value) {

View File

@ -1,5 +1,5 @@
<script setup> <script setup>
import { ref, onMounted, computed, watch } from 'vue'; import { ref, onBeforeMount, onMounted, computed, watch } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import { useQuasar } from 'quasar'; import { useQuasar } from 'quasar';
@ -96,6 +96,7 @@ const DEFAULT_MODE = 'card';
const TABLE_MODE = 'table'; const TABLE_MODE = 'table';
const mode = ref(DEFAULT_MODE); const mode = ref(DEFAULT_MODE);
const selected = ref([]); const selected = ref([]);
const hasParams = ref(false);
const routeQuery = JSON.parse(route?.query[$props.searchUrl] ?? '{}'); const routeQuery = JSON.parse(route?.query[$props.searchUrl] ?? '{}');
const params = ref({ ...routeQuery, ...routeQuery.filter?.where }); const params = ref({ ...routeQuery, ...routeQuery.filter?.where });
const orders = ref(parseOrder(routeQuery.filter?.order)); const orders = ref(parseOrder(routeQuery.filter?.order));
@ -117,11 +118,14 @@ const tableModes = [
disable: $props.disableOption?.card, disable: $props.disableOption?.card,
}, },
]; ];
onBeforeMount(() => {
setUserParams(route.query[$props.searchUrl]);
hasParams.value = Object.keys(params.value).length !== 0;
});
onMounted(() => { onMounted(() => {
mode.value = quasar.platform.is.mobile ? DEFAULT_MODE : $props.defaultMode; mode.value = quasar.platform.is.mobile ? DEFAULT_MODE : $props.defaultMode;
stateStore.rightDrawer = true; stateStore.rightDrawer = true;
setUserParams(route.query[$props.searchUrl]);
columnsVisibilitySkiped.value = [ columnsVisibilitySkiped.value = [
...splittedColumns.value.columns ...splittedColumns.value.columns
.filter((c) => c.visible == false) .filter((c) => c.visible == false)
@ -295,6 +299,7 @@ defineExpose({
:disable-infinite-scroll="isTableMode" :disable-infinite-scroll="isTableMode"
@save-changes="reload" @save-changes="reload"
:has-sub-toolbar="$attrs['hasSubToolbar'] ?? isEditable" :has-sub-toolbar="$attrs['hasSubToolbar'] ?? isEditable"
:auto-load="hasParams || $attrs['auto-load']"
> >
<template <template
v-for="(_, slotName) in $slots" v-for="(_, slotName) in $slots"

View File

@ -125,7 +125,8 @@ function filter(val, options) {
}); });
} }
const id = row.id; if (!row) return;
const id = row[$props.optionValue];
const optionLabel = String(row[$props.optionLabel]).toLowerCase(); const optionLabel = String(row[$props.optionLabel]).toLowerCase();
return id == search || optionLabel.includes(search); return id == search || optionLabel.includes(search);

View File

@ -8,18 +8,31 @@ const $props = defineProps({
default: null, default: null,
}, },
find: { find: {
type: String, type: [String, Object],
default: null, default: null,
}, },
}); });
const options = ref([]); const options = ref([]);
onBeforeMount(async () => { onBeforeMount(async () => {
const { url } = useAttrs(); const { url, optionValue, optionLabel } = useAttrs();
const findBy = $props.find ?? url?.charAt(0)?.toLocaleLowerCase() + url?.slice(1, -1); const findBy = $props.find ?? url?.charAt(0)?.toLocaleLowerCase() + url?.slice(1, -1);
if (findBy) options.value = [$props.row[findBy]]; if (!findBy || !$props.row) return;
// is object
if (typeof findBy == 'object') {
const { value, label } = findBy;
if (!$props.row[value] || !$props.row[label]) return;
return (options.value = [
{
[optionValue ?? 'id']: $props.row[value],
[optionLabel ?? 'name']: $props.row[label],
},
]);
}
// is string
if ($props.row[findBy]) options.value = [$props.row[findBy]];
}); });
</script> </script>
<template> <template>
<VnSelect v-bind="$attrs" :options="$attrs.options ?? options" /> <VnSelect v-bind="$attrs" :options="$attrs.options ?? options" />
</template> </template>

View File

@ -72,10 +72,7 @@ const columns = computed(() => [
label: t('globals.warehouse'), label: t('globals.warehouse'),
component: 'select', component: 'select',
attrs: { attrs: {
url: 'warehouses', options: warehouses.value,
fields: ['id', 'name'],
optionLabel: 'name',
optionValue: 'id',
}, },
}, },
{ {

View File

@ -57,9 +57,13 @@ const columns = computed(() => [
component: 'select', component: 'select',
attrs: { attrs: {
url: 'Workers/activeWithInheritedRole', url: 'Workers/activeWithInheritedRole',
fields: ['id', 'nickname'], fields: ['id', 'name'],
optionValue: 'id', useLike: false,
optionLabel: 'nickname', optionFilter: 'firstName',
find: {
value: 'workerFk',
label: 'workerUserName',
},
}, },
useLike: false, useLike: false,
cardVisible: true, cardVisible: true,
@ -76,8 +80,10 @@ const columns = computed(() => [
attrs: { attrs: {
url: 'agencyModes', url: 'agencyModes',
fields: ['id', 'name'], fields: ['id', 'name'],
optionLabel: 'name', find: {
optionValue: 'id', value: 'agencyModeFk',
label: 'agencyName',
},
}, },
}, },
{ {
@ -91,7 +97,10 @@ const columns = computed(() => [
url: 'vehicles', url: 'vehicles',
fields: ['id', 'numberPlate'], fields: ['id', 'numberPlate'],
optionLabel: 'numberPlate', optionLabel: 'numberPlate',
optionValue: 'id', find: {
value: 'vehicleFk',
label: 'vehiclePlateNumber',
},
}, },
}, },
{ {
@ -248,6 +257,7 @@ const openTicketsDialog = (id) => {
:is-editable="true" :is-editable="true"
:filter="routeFilter" :filter="routeFilter"
redirect="route" redirect="route"
:row-click="false"
:create="{ :create="{
urlCreate: 'Routes', urlCreate: 'Routes',
title: t('Create route'), title: t('Create route'),