Merge branch 'master' into Hotfix-VnSearchbarRemoveParams
gitea/salix-front/pipeline/pr-master This commit looks good Details

This commit is contained in:
Jon Elias 2024-12-27 09:40:16 +00:00
commit 976b891a75
16 changed files with 75 additions and 52 deletions

View File

@ -74,6 +74,10 @@ const props = defineProps({
type: Boolean,
default: false,
},
mapKey: {
type: String,
default: '',
},
});
const emit = defineEmits(['onFetch', 'onPaginate', 'onChange']);
@ -96,6 +100,7 @@ const arrayData = useArrayData(props.dataKey, {
exprBuilder: props.exprBuilder,
keepOpts: props.keepOpts,
searchUrl: props.searchUrl,
mapKey: props.mapKey,
});
const store = arrayData.store;

View File

@ -49,6 +49,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
'exprBuilder',
'searchUrl',
'navigate',
'mapKey',
];
if (typeof userOptions === 'object') {
for (const option in userOptions) {
@ -119,17 +120,12 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
const { limit } = filter;
store.hasMoreData = limit && response.data.length >= limit;
if (append) {
if (!store.data) store.data = [];
for (const row of response.data) store.data.push(row);
} else {
store.data = response.data;
if (!isDialogOpened()) updateRouter && updateStateParams();
}
processData(response.data, { map: !!store.mapKey, append });
if (!append && !isDialogOpened()) updateRouter && updateStateParams();
store.isLoading = false;
canceller = null;
return response;
}
@ -288,6 +284,31 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
router.replace(newUrl);
}
function processData(data, { map = true, append = true }) {
if (!append) {
store.data = [];
store.map = new Map();
}
if (!Array.isArray(data)) store.data = data;
else if (!map && append) for (const row of data) store.data.push(row);
else
for (const row of data) {
const key = row[store.mapKey];
const val = { ...row, key };
if (store.map.has(key)) {
const { position } = store.map.get(key);
val.position = position;
store.map.set(key, val);
store.data[position] = val;
} else {
val.position = store.map.size;
store.map.set(key, val);
store.data.push(val);
}
}
}
const totalRows = computed(() => (store.data && store.data.length) || 0);
const isLoading = computed(() => store.isLoading || false);

View File

@ -107,7 +107,7 @@ const setParams = (params) => {
const getPreview = async () => {
const params = {
recipientId: entityId,
recipientId: entityId.value,
};
const validationMessage = validateMessage();
if (validationMessage) return notify(t(validationMessage), 'negative');

View File

@ -29,7 +29,7 @@ const exprBuilder = (param, value) => {
return { 'a.supplierName': value };
case 'routeFk':
return { 'a.routeFk': value };
case 'created':
case 'dated':
case 'agencyFk':
case 'packages':
case 'm3':
@ -145,7 +145,7 @@ const exprBuilder = (param, value) => {
<QItem class="q-my-sm">
<QItemSection>
<VnInputDate
v-model="params.created"
v-model="params.dated"
:label="t('Date')"
is-outlined
/>

View File

@ -28,7 +28,7 @@ const filter = {
'id',
'workerFk',
'agencyModeFk',
'created',
'dated',
'm3',
'warehouseFk',
'description',
@ -78,7 +78,7 @@ const setData = (entity) => (data.value = useCardDescription(entity.code, entity
@on-fetch="setData"
>
<template #body="{ entity }">
<VnLv :label="t('Date')" :value="toDate(entity?.created)" />
<VnLv :label="t('Date')" :value="toDate(entity?.dated)" />
<VnLv :label="t('Agency')" :value="entity?.agencyMode?.name" />
<VnLv :label="t('Zone')" :value="entity?.zone?.name" />
<VnLv

View File

@ -19,7 +19,7 @@ const shelvingId = ref(route.params?.id || null);
const isNew = Boolean(!shelvingId.value);
const defaultInitialData = {
agencyModeFk: null,
created: null,
dated: null,
description: '',
vehicleFk: null,
workerFk: null,
@ -32,7 +32,7 @@ const routeFilter = {
'id',
'workerFk',
'agencyModeFk',
'created',
'dated',
'm3',
'warehouseFk',
'description',
@ -134,7 +134,7 @@ const onSave = (data, response) => {
option-label="name"
:input-debounce="0"
/>
<VnInputDate v-model="data.created" :label="t('Created')" />
<VnInputDate v-model="data.dated" :label="t('Dated')" />
</VnRow>
<template v-if="!isNew">
<VnRow>
@ -188,7 +188,7 @@ es:
Hour finished: Hora fin
Description: Descripción
Is served: Se ha servido
Created: Creado
Dated: Fecha
The km can not exceed: La distancia debe ser inferior a {maxDistance}
en:
The km can not exceed: Distance must be lesser than {maxDistance}

View File

@ -139,7 +139,7 @@ const ticketColumns = ref([
<QCard class="vn-one">
<VnLv
:label="t('route.summary.date')"
:value="toDate(entity?.route.created)"
:value="toDate(entity?.route.dated)"
/>
<VnLv
:label="t('route.summary.agency')"

View File

@ -46,10 +46,10 @@ const columns = computed(() => [
},
{
align: 'left',
name: 'created',
name: 'dated',
label: t('Date'),
columnFilter: false,
format: ({ created }) => toDate(created),
format: ({ dated }) => toDate(dated),
},
{
align: 'left',

View File

@ -111,7 +111,7 @@ const columns = computed(() => [
},
{
align: 'left',
name: 'created',
name: 'dated',
label: t('route.Date'),
columnFilter: false,
cardVisible: true,

View File

@ -45,7 +45,7 @@ const columns = computed(() => [
columnFilter: {
inWhere: true,
},
format: ({ created }) => toDate(created),
format: ({ dated }) => toDate(dated),
cardVisible: true,
},
{

View File

@ -109,7 +109,7 @@ const ticketList = ref([]);
const cloneRoutes = () => {
axios.post('Routes/clone', {
created: startingDate.value,
dated: startingDate.value,
ids: selectedRows.value.map((row) => row?.id),
});
refreshKey.value++;

View File

@ -5,7 +5,7 @@ route:
Description: Description
hourStarted: H.Start
hourFinished: H.End
createRoute: Create route
dated: Dated
From: From
To: To
Date: Date

View File

@ -441,6 +441,7 @@ watch(
<QPage class="column items-center q-pa-md">
<VnTable
data-key="advanceTickets"
:map-key="false"
ref="vnTableRef"
url="Tickets/getTicketsAdvance"
search-url="advanceTickets"

View File

@ -103,9 +103,12 @@ const formattedWeekTotalHours = computed(() =>
const onInputChange = async (date) => {
if (!date) return;
const { year, month, day } = date.scope.timestamp;
const { timestamp, outside } = date.scope;
const { year, month, day } = timestamp;
const _date = new Date(year, month - 1, day);
setDate(_date);
if (outside) getMailStates(_date);
};
const setDate = async (date) => {
@ -378,7 +381,7 @@ const isUnsatisfied = async (reason) => {
const resendEmail = async () => {
const params = {
recipient: worker.value?.user?.email,
recipient: worker.value[0]?.user?.emailUser?.email,
week: selectedWeekNumber.value,
year: selectedDate.value.getFullYear(),
workerId: Number(route.params.id),

View File

@ -17,6 +17,7 @@ export const useArrayDataStore = defineStore('arrayDataStore', () => {
searchUrl: 'params',
navigate: null,
page: 1,
mapKey: 'id',
};
function get(key) {
@ -46,6 +47,7 @@ export const useArrayDataStore = defineStore('arrayDataStore', () => {
function getDefaultState() {
return Object.assign(JSON.parse(JSON.stringify(defaultOpts)), {
data: ref(),
map: ref(new Map()),
});
}

View File

@ -4,7 +4,11 @@ import VnPaginate from 'src/components/ui/VnPaginate.vue';
describe('VnPaginate', () => {
const expectedUrl = '/api/customers';
const defaultData = [
{ id: 1, name: 'Tony Stark' },
{ id: 2, name: 'Jessica Jones' },
{ id: 3, name: 'Bruce Wayne' },
];
let vm;
beforeAll(() => {
const options = {
@ -28,11 +32,7 @@ describe('VnPaginate', () => {
describe('paginate()', () => {
it('should call to the paginate() method and set the data on the rows property', async () => {
vi.spyOn(vm.arrayData, 'loadMore');
vm.store.data = [
{ id: 1, name: 'Tony Stark' },
{ id: 2, name: 'Jessica Jones' },
{ id: 3, name: 'Bruce Wayne' },
];
vm.store.data = defaultData;
await vm.paginate();
@ -42,26 +42,25 @@ describe('VnPaginate', () => {
it('should call to the paginate() method and then call it again to paginate', async () => {
vi.spyOn(axios, 'get').mockResolvedValue({
data: [
{ id: 1, name: 'Tony Stark' },
{ id: 2, name: 'Jessica Jones' },
{ id: 3, name: 'Bruce Wayne' },
],
data: defaultData,
});
vm.store.hasMoreData = true;
await vm.$nextTick();
vm.store.data = [
{ id: 1, name: 'Tony Stark' },
{ id: 2, name: 'Jessica Jones' },
{ id: 3, name: 'Bruce Wayne' },
];
vm.store.data = defaultData;
await vm.paginate();
expect(vm.store.skip).toEqual(3);
expect(vm.store.data.length).toEqual(6);
vi.spyOn(axios, 'get').mockResolvedValue({
data: [
{ id: 4, name: 'Peter Parker' },
{ id: 5, name: 'Clark Kent' },
{ id: 6, name: 'Barry Allen' },
],
});
await vm.paginate();
expect(vm.store.skip).toEqual(6);
@ -85,11 +84,7 @@ describe('VnPaginate', () => {
const index = 1;
const done = vi.fn();
vm.store.data = [
{ id: 1, name: 'Tony Stark' },
{ id: 2, name: 'Jessica Jones' },
{ id: 3, name: 'Bruce Wayne' },
];
vm.store.data = defaultData;
await vm.onLoad(index, done);
@ -105,11 +100,7 @@ describe('VnPaginate', () => {
],
});
vm.store.data = [
{ id: 1, name: 'Tony Stark' },
{ id: 2, name: 'Jessica Jones' },
{ id: 3, name: 'Bruce Wayne' },
];
vm.store.data = defaultData;
expect(vm.pagination.page).toEqual(1);