0
0
Fork 0

Merge pull request 'refactor(ticketsms): refs #6259 add vnSms create customerSms' (!137) from 6259-ticketSmsToClientSms into dev

Reviewed-on: verdnatura/salix-front#137
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Pablo Natek 2024-01-08 07:59:29 +00:00
commit b670f6b3ee
10 changed files with 177 additions and 120 deletions

View File

@ -1,8 +1,10 @@
<script setup> <script setup>
import { useSession } from 'src/composables/useSession'; import { useSession } from 'src/composables/useSession';
import WorkerDescriptorProxy from 'pages/Worker/Card/WorkerDescriptorProxy.vue';
const $props = defineProps({ const $props = defineProps({
worker: { type: Number, required: true }, worker: { type: Number, required: true },
description: { type: String, default: null }, description: { type: String, default: null },
clickable: { type: Boolean, default: false },
}); });
const session = useSession(); const session = useSession();
const token = session.getToken(); const token = session.getToken();
@ -22,5 +24,6 @@ const token = session.getToken();
</p> </p>
</slot> </slot>
</div> </div>
<WorkerDescriptorProxy :v-if="$props.clickable" :id="$props.worker" />
</div> </div>
</template> </template>

110
src/components/ui/VnSms.vue Normal file
View File

@ -0,0 +1,110 @@
<script setup>
import { onBeforeMount } from 'vue';
import { date } from 'quasar';
import VnPaginate from 'src/components/ui/VnPaginate.vue';
import VnAvatar from '../ui/VnAvatar.vue';
const $props = defineProps({
url: { type: String, default: null },
where: { type: Object, default: () => {} },
});
const filter = {
fields: ['smsFk'],
include: {
relation: 'sms',
scope: {
fields: [
'senderFk',
'sender',
'destination',
'message',
'statusCode',
'status',
'created',
],
include: {
relation: 'sender',
scope: {
fields: ['name'],
},
},
},
},
};
onBeforeMount(() => (filter.where = $props.where));
function formatNumber(number) {
if (number.length <= 10) return number;
return number.slice(0, 4) + ' ' + number.slice(4);
}
</script>
<template>
<div class="column items-center">
<div class="list">
<VnPaginate
:data-key="$props.url"
:url="$props.url"
:filter="filter"
order="smsFk DESC"
:offset="100"
:limit="5"
auto-load
>
<template #body="{ rows }">
<QCard
flat
bordered
class="card q-pa-md q-mb-sm smsCard"
v-for="row of rows"
:key="row.smsFk"
>
<QItem>
<QItemSection side top>
<VnAvatar
class="cursor-pointer"
:worker="row.sms.senderFk"
:title="row.sms.sender.name"
:clickable="true"
/>
</QItemSection>
<QSeparator />
<QItemSection>
<QItemLabel caption>{{
formatNumber(row.sms.destination)
}}</QItemLabel>
<QItemLabel>{{ row.sms.message }}</QItemLabel>
</QItemSection>
<QItemSection side>
<QItemLabel caption>{{
date.formatDate(
row.sms.created,
'YYYY-MM-DD HH:mm:ss'
)
}}</QItemLabel>
<QItemLabel class="row center">
<QChip
:color="
row.sms.status == 'OK'
? 'positive'
: 'negative'
"
>
{{ row.sms.status }}
</QChip>
</QItemLabel>
</QItemSection>
</QItem>
</QCard>
</template>
</VnPaginate>
</div>
</div>
</template>
<style lang="scss" scoped>
.q-item__section--side {
align-items: center;
}
</style>

View File

@ -155,7 +155,9 @@ export function useArrayData(key, userOptions) {
delete store.userParams[param]; delete store.userParams[param];
delete params[param]; delete params[param];
if (store.filter?.where) { if (store.filter?.where) {
delete store.filter.where[Object.keys(exprBuilder ? exprBuilder(param) : param)[0]]; delete store.filter.where[
Object.keys(exprBuilder ? exprBuilder(param) : param)[0]
];
if (Object.keys(store.filter.where).length === 0) { if (Object.keys(store.filter.where).length === 0) {
delete store.filter.where; delete store.filter.where;
} }

View File

@ -114,6 +114,7 @@ export default {
createCustomer: 'Create customer', createCustomer: 'Create customer',
summary: 'Summary', summary: 'Summary',
basicData: 'Basic Data', basicData: 'Basic Data',
sms: 'Sms',
}, },
list: { list: {
phone: 'Phone', phone: 'Phone',

View File

@ -113,6 +113,7 @@ export default {
createCustomer: 'Crear cliente', createCustomer: 'Crear cliente',
basicData: 'Datos básicos', basicData: 'Datos básicos',
summary: 'Resumen', summary: 'Resumen',
sms: 'Sms',
}, },
list: { list: {
phone: 'Teléfono', phone: 'Teléfono',

View File

@ -38,15 +38,6 @@ function viewSummary(id) {
}, },
}); });
} }
function viewDescriptor(id) {
quasar.dialog({
component: CustomerDescriptorProxy,
componentProps: {
id,
},
});
}
</script> </script>
<template> <template>

View File

@ -0,0 +1,17 @@
<script setup>
import { useRoute } from 'vue-router';
import VnSms from 'src/components/ui/VnSms.vue';
const route = useRoute();
const id = route.params.id;
const where = {
clientFk: id,
ticketFk: null,
};
</script>
<template>
<div class="column items-center">
<VnSms url="clientSms" :where="where" />
</div>
</template>

View File

@ -1,118 +1,16 @@
<script setup> <script setup>
import { date } from 'quasar'; import { useRoute } from 'vue-router';
import { computed } from 'vue'; import VnSms from 'src/components/ui/VnSms.vue';
import { useRouter } from 'vue-router';
import { useSession } from 'src/composables/useSession'; const route = useRoute();
import VnPaginate from 'src/components/ui/VnPaginate.vue'; const id = route.params.id;
import WorkerDescriptorProxy from 'pages/Worker/Card/WorkerDescriptorProxy.vue';
const router = useRouter(); const where = {
const session = useSession(); ticketFk: id,
const token = session.getToken();
const entityId = computed(function () {
return router.currentRoute.value.params.id;
});
const filter = {
fields: ['ticketFk', 'smsFk'],
include: {
relation: 'sms',
scope: {
fields: [
'senderFk',
'sender',
'destination',
'message',
'statusCode',
'status',
'created',
],
include: {
relation: 'sender',
scope: {
fields: ['name'],
},
},
},
},
where: {
ticketFk: entityId,
},
}; };
function formatNumer(number) {
if (number.length <= 10) return number;
return number.slice(0, 4) + ' ' + number.slice(4);
}
</script> </script>
<template> <template>
<div class="column items-center"> <div class="column items-center">
<div class="list"> <VnSms url="clientSms" :where="where" />
<VnPaginate
data-key="TicketSms"
url="TicketSms"
:filter="filter"
order="smsFk DESC"
:offset="100"
:limit="5"
auto-load
>
<template #body="{ rows }">
<QCard
flat
bordered
class="card q-pa-md"
v-for="row of rows"
:key="row.smsFk"
>
<QItem>
<QItmSection top avatar>
<QItemLabel class="column items-center">
<QAvatar>
<QImg
:src="`/api/Images/user/160x160/${row.sms.senderFk}/download?access_token=${token}`"
spinner-color="white"
/>
</QAvatar>
<span class="link">
{{ row.sms.sender.name }}
<WorkerDescriptorProxy :id="row.sms.senderFk" />
</span>
</QItemLabel>
</QItmSection>
<QSeparator spaced inset="item" />
<QItemSection>
<QItemLabel caption>{{
formatNumer(row.sms.destination)
}}</QItemLabel>
<QItemLabel>{{ row.sms.message }}</QItemLabel>
</QItemSection>
<QItemSection side top>
<QItemLabel caption>{{
date.formatDate(
row.sms.created,
'YYYY-MM-DD HH:mm:ss'
)
}}</QItemLabel>
<QItemLabel>
<QChip
:color="
row.sms.status == 'OK'
? 'positive'
: 'negative'
"
>
{{ row.sms.status }}
</QChip>
</QItemLabel>
</QItemSection>
</QItem>
</QCard>
</template>
</VnPaginate>
</div>
</div> </div>
</template> </template>

View File

@ -11,7 +11,7 @@ export default {
redirect: { name: 'CustomerMain' }, redirect: { name: 'CustomerMain' },
menus: { menus: {
main: ['CustomerList', 'CustomerPayments'], main: ['CustomerList', 'CustomerPayments'],
card: ['CustomerBasicData'], card: ['CustomerBasicData', 'CustomerSms'],
}, },
children: [ children: [
{ {
@ -66,6 +66,15 @@ export default {
component: () => component: () =>
import('src/pages/Customer/Card/CustomerBasicData.vue'), import('src/pages/Customer/Card/CustomerBasicData.vue'),
}, },
{
path: 'sms',
name: 'CustomerSms',
meta: {
title: 'sms',
icon: 'sms',
},
component: () => import('src/pages/Customer/Card/CustomerSms.vue'),
},
], ],
}, },
], ],

View File

@ -0,0 +1,25 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper';
import VnSms from 'src/components/ui/VnSms.vue';
describe('VnSms', () => {
let vm;
beforeAll(() => {
vm = createWrapper(VnSms, {
global: {
stubs: ['VnPaginate'],
mocks: {},
},
}).vm;
});
afterEach(() => {
vi.clearAllMocks();
});
it('should format number correctly', () => {
const formattedNumber = vm.formatNumber('123456789012');
expect(formattedNumber).toBe('1234 56789012');
});
});