forked from verdnatura/salix-front
Reviewed-on: verdnatura/salix-front#503 Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
commit
0fd53872d0
|
@ -1,6 +1,6 @@
|
|||
<script setup>
|
||||
import { onBeforeMount, computed } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useRoute, onBeforeRouteUpdate } from 'vue-router';
|
||||
import { useArrayData } from 'src/composables/useArrayData';
|
||||
import { useStateStore } from 'stores/useStateStore';
|
||||
import useCardSize from 'src/composables/useCardSize';
|
||||
|
@ -41,6 +41,15 @@ onBeforeMount(async () => {
|
|||
if (!props.baseUrl) arrayData.store.filter.where = { id: route.params.id };
|
||||
await arrayData.fetch({ append: false });
|
||||
});
|
||||
|
||||
if (props.baseUrl) {
|
||||
onBeforeRouteUpdate(async (to, from) => {
|
||||
if (to.params.id !== from.params.id) {
|
||||
arrayData.store.url = `${props.baseUrl}/${to.params.id}`;
|
||||
await arrayData.fetch({ append: false, updateRouter: false });
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<QDrawer
|
||||
|
|
|
@ -46,7 +46,7 @@ let arrayData;
|
|||
let store;
|
||||
let entity;
|
||||
const isLoading = ref(false);
|
||||
|
||||
const isSameDataKey = computed(() => $props.dataKey === route.meta.moduleName);
|
||||
defineExpose({ getData });
|
||||
|
||||
onBeforeMount(async () => {
|
||||
|
@ -58,10 +58,12 @@ onBeforeMount(async () => {
|
|||
store = arrayData.store;
|
||||
entity = computed(() => (Array.isArray(store.data) ? store.data[0] : store.data));
|
||||
// It enables to load data only once if the module is the same as the dataKey
|
||||
if ($props.dataKey !== route.meta.moduleName || !route.params.id) await getData();
|
||||
if (!isSameDataKey.value || !route.params.id) await getData();
|
||||
watch(
|
||||
() => [$props.url, $props.filter],
|
||||
async () => await getData()
|
||||
async () => {
|
||||
if (!isSameDataKey.value) await getData();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -77,6 +79,19 @@ async function getData() {
|
|||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function getValueFromPath(path) {
|
||||
if (!path) return;
|
||||
const keys = path.toString().split('.');
|
||||
let current = entity.value;
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
if (current[keys[i]] === undefined) return undefined;
|
||||
else current = current[keys[i]];
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
const emit = defineEmits(['onFetch']);
|
||||
</script>
|
||||
|
||||
|
@ -139,8 +154,8 @@ const emit = defineEmits(['onFetch']);
|
|||
<QList dense>
|
||||
<QItemLabel header class="ellipsis text-h5" :lines="1">
|
||||
<div class="title">
|
||||
<span v-if="$props.title" :title="$props.title">
|
||||
{{ entity[title] ?? $props.title }}
|
||||
<span v-if="$props.title" :title="getValueFromPath(title)">
|
||||
{{ getValueFromPath(title) ?? $props.title }}
|
||||
</span>
|
||||
<slot v-else name="description" :entity="entity">
|
||||
<span :title="entity.name">
|
||||
|
@ -151,7 +166,7 @@ const emit = defineEmits(['onFetch']);
|
|||
</QItemLabel>
|
||||
<QItem dense>
|
||||
<QItemLabel class="subtitle" caption>
|
||||
#{{ $props.subtitle ?? entity.id }}
|
||||
#{{ getValueFromPath(subtitle) ?? entity.id }}
|
||||
</QItemLabel>
|
||||
</QItem>
|
||||
</QList>
|
||||
|
|
|
@ -114,6 +114,7 @@ async function search(evt) {
|
|||
store.userParamsChanged = true;
|
||||
store.filter.skip = 0;
|
||||
store.skip = 0;
|
||||
store.page = 1;
|
||||
const { params: newParams } = await arrayData.addFilter({ params: userParams.value });
|
||||
userParams.value = newParams;
|
||||
|
||||
|
@ -126,7 +127,8 @@ async function search(evt) {
|
|||
async function reload() {
|
||||
isLoading.value = true;
|
||||
const params = Object.values(userParams.value).filter((param) => param);
|
||||
|
||||
store.skip = 0;
|
||||
store.page = 1;
|
||||
await arrayData.fetch({ append: false });
|
||||
if (!$props.showAll && !params.length) store.data = [];
|
||||
isLoading.value = false;
|
||||
|
@ -138,6 +140,7 @@ async function clearFilters() {
|
|||
store.userParamsChanged = true;
|
||||
store.filter.skip = 0;
|
||||
store.skip = 0;
|
||||
store.page = 1;
|
||||
// Filtrar los params no removibles
|
||||
const removableFilters = Object.keys(userParams.value).filter((param) =>
|
||||
$props.unremovableParams.includes(param)
|
||||
|
|
|
@ -104,6 +104,7 @@ async function search() {
|
|||
([key, value]) => value && (props.staticParams || []).includes(key)
|
||||
);
|
||||
store.skip = 0;
|
||||
store.page = 1;
|
||||
|
||||
if (props.makeFetch)
|
||||
await arrayData.applyFilter({
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { onMounted, ref, computed } from 'vue';
|
||||
import { onMounted, computed } from 'vue';
|
||||
import { useRouter, useRoute } from 'vue-router';
|
||||
import axios from 'axios';
|
||||
import { useArrayDataStore } from 'stores/useArrayDataStore';
|
||||
|
@ -16,8 +16,6 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
|||
const router = useRouter();
|
||||
let canceller = null;
|
||||
|
||||
const page = ref(1);
|
||||
|
||||
onMounted(() => {
|
||||
setOptions();
|
||||
store.skip = 0;
|
||||
|
@ -87,13 +85,13 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
|||
}
|
||||
|
||||
Object.assign(filter, store.userFilter, exprFilter);
|
||||
Object.assign(store.filter, { ...filter, skip: store.skip });
|
||||
const params = {
|
||||
filter: JSON.stringify(store.filter),
|
||||
};
|
||||
Object.assign(store.filter, filter);
|
||||
const params = { filter: store.filter };
|
||||
|
||||
Object.assign(params, userParams);
|
||||
params.filter.skip = store.skip;
|
||||
|
||||
params.filter = JSON.stringify(params.filter);
|
||||
store.currentFilter = params;
|
||||
store.isLoading = true;
|
||||
const response = await axios.get(store.url, {
|
||||
|
@ -154,8 +152,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
|||
store.userParams = userParams;
|
||||
store.skip = 0;
|
||||
store.filter.skip = 0;
|
||||
page.value = 1;
|
||||
|
||||
store.page = 1;
|
||||
await fetch({ append: false });
|
||||
return { filter, params };
|
||||
}
|
||||
|
@ -187,10 +184,11 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
|||
async function loadMore() {
|
||||
if (!store.hasMoreData) return;
|
||||
|
||||
store.skip = store.limit * page.value;
|
||||
page.value += 1;
|
||||
store.skip = store.limit * store.page;
|
||||
store.page += 1;
|
||||
|
||||
await fetch({ append: true });
|
||||
updateStateParams();
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
|
|
|
@ -56,8 +56,7 @@ onMounted(async () => {
|
|||
:url="`Claims/${entityId}`"
|
||||
:filter="filter"
|
||||
module="Claim"
|
||||
:title="data.title"
|
||||
:subtitle="data.subtitle"
|
||||
title="client.name"
|
||||
@on-fetch="setData"
|
||||
data-key="Claim"
|
||||
>
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useArrayData } from 'src/composables/useArrayData';
|
||||
import CardDescriptor from 'components/ui/CardDescriptor.vue';
|
||||
import VnLv from 'components/ui/VnLv.vue';
|
||||
|
||||
|
@ -17,8 +16,7 @@ const props = defineProps({
|
|||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const entityId = computed(() => props.id || route.params.id);
|
||||
const { store } = useArrayData('Parking');
|
||||
const parking = computed(() => store.data);
|
||||
|
||||
const filter = {
|
||||
fields: ['id', 'sectorFk', 'code', 'pickingOrder', 'row', 'column'],
|
||||
include: [{ relation: 'sector', scope: { fields: ['id', 'description'] } }],
|
||||
|
@ -29,15 +27,13 @@ const filter = {
|
|||
module="Parking"
|
||||
data-key="Parking"
|
||||
:url="`Parkings/${entityId}`"
|
||||
:title="parking?.code"
|
||||
:subtitle="parking?.id"
|
||||
title="code"
|
||||
:filter="filter"
|
||||
@on-fetch="(data) => (parking = data)"
|
||||
>
|
||||
<template #body>
|
||||
<VnLv :label="t('globals.code')" :value="parking.code" />
|
||||
<VnLv :label="t('parking.pickingOrder')" :value="parking.pickingOrder" />
|
||||
<VnLv :label="t('parking.sector')" :value="parking.sector?.description" />
|
||||
<template #body="{ entity }">
|
||||
<VnLv :label="t('globals.code')" :value="entity.code" />
|
||||
<VnLv :label="t('parking.pickingOrder')" :value="entity.pickingOrder" />
|
||||
<VnLv :label="t('parking.sector')" :value="entity.sector?.description" />
|
||||
</template>
|
||||
</CardDescriptor>
|
||||
</template>
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
<script setup>
|
||||
import { ref, computed } from 'vue';
|
||||
import { computed } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import CardSummary from 'components/ui/CardSummary.vue';
|
||||
import VnLv from 'components/ui/VnLv.vue';
|
||||
import { useArrayData } from 'src/composables/useArrayData';
|
||||
|
||||
const $props = defineProps({
|
||||
id: {
|
||||
|
@ -15,9 +14,7 @@ const $props = defineProps({
|
|||
const router = useRoute();
|
||||
const { t } = useI18n();
|
||||
const entityId = computed(() => $props.id || router.params.id);
|
||||
const { store } = useArrayData('Parking');
|
||||
|
||||
const parking = ref(store.data);
|
||||
const filter = {
|
||||
fields: ['id', 'sectorFk', 'code', 'pickingOrder', 'row', 'column'],
|
||||
include: [{ relation: 'sector', scope: { fields: ['id', 'description'] } }],
|
||||
|
@ -26,14 +23,9 @@ const filter = {
|
|||
|
||||
<template>
|
||||
<div class="q-pa-md">
|
||||
<CardSummary
|
||||
:url="`Parkings/${entityId}`"
|
||||
:filter="filter"
|
||||
@on-fetch="(data) => (parking = data)"
|
||||
data-key="Parking"
|
||||
>
|
||||
<template #header>{{ parking.code }}</template>
|
||||
<template #body>
|
||||
<CardSummary :url="`Parkings/${entityId}`" data-key="Parking" :filter="filter">
|
||||
<template #header="{ entity }">{{ entity.code }}</template>
|
||||
<template #body="{ entity }">
|
||||
<QCard class="vn-one">
|
||||
<QCardSection class="q-pa-none">
|
||||
<a
|
||||
|
@ -44,17 +36,17 @@ const filter = {
|
|||
<QIcon name="open_in_new" />
|
||||
</a>
|
||||
</QCardSection>
|
||||
<VnLv :label="t('globals.code')" :value="parking.code" />
|
||||
<VnLv :label="t('globals.code')" :value="entity.code" />
|
||||
<VnLv
|
||||
:label="t('parking.pickingOrder')"
|
||||
:value="parking.pickingOrder"
|
||||
:value="entity.pickingOrder"
|
||||
/>
|
||||
<VnLv
|
||||
:label="t('parking.sector')"
|
||||
:value="parking.sector?.description"
|
||||
:value="entity.sector?.description"
|
||||
/>
|
||||
<VnLv :label="t('parking.row')" :value="parking.row" />
|
||||
<VnLv :label="t('parking.column')" :value="parking.column" />
|
||||
<VnLv :label="t('parking.row')" :value="entity.row" />
|
||||
<VnLv :label="t('parking.column')" :value="entity.column" />
|
||||
</QCard>
|
||||
</template>
|
||||
</CardSummary>
|
||||
|
|
|
@ -23,6 +23,7 @@ export const useArrayDataStore = defineStore('arrayDataStore', () => {
|
|||
exprBuilder: null,
|
||||
searchUrl: 'params',
|
||||
navigate: null,
|
||||
page: 1,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue