Merge branch 'dev' into 8612-shelvinge2e
gitea/salix-front/pipeline/pr-dev This commit is unstable
Details
gitea/salix-front/pipeline/pr-dev This commit is unstable
Details
This commit is contained in:
commit
8ed3441007
|
@ -184,8 +184,11 @@ async function saveChanges(data) {
|
|||
if ($props.beforeSaveFn) {
|
||||
changes = await $props.beforeSaveFn(changes, getChanges);
|
||||
}
|
||||
|
||||
try {
|
||||
if (changes?.creates?.length === 0 && changes?.updates?.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
await axios.post($props.saveUrl || $props.url + '/crud', changes);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
|
|
|
@ -168,16 +168,18 @@ describe('CrudModel', () => {
|
|||
result = vm.isEmpty(dummyArray);
|
||||
|
||||
expect(result).toBe(false);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('resetData()', () => {
|
||||
it('should add $index to elements in data[] and sets originalData and formData with data', async () => {
|
||||
data = [{
|
||||
data = [
|
||||
{
|
||||
name: 'Tony',
|
||||
lastName: 'Stark',
|
||||
age: 42,
|
||||
}];
|
||||
},
|
||||
];
|
||||
|
||||
vm.resetData(data);
|
||||
|
||||
|
@ -210,11 +212,13 @@ describe('CrudModel', () => {
|
|||
});
|
||||
|
||||
describe('saveChanges()', () => {
|
||||
data = [{
|
||||
data = [
|
||||
{
|
||||
name: 'Tony',
|
||||
lastName: 'Stark',
|
||||
age: 42,
|
||||
}];
|
||||
},
|
||||
];
|
||||
|
||||
it('should call saveFn if exists', async () => {
|
||||
await wrapper.setProps({ saveFn: vi.fn() });
|
||||
|
@ -231,11 +235,13 @@ describe('CrudModel', () => {
|
|||
it("should use default url if there's not saveFn", async () => {
|
||||
const postMock = vi.spyOn(axios, 'post');
|
||||
|
||||
vm.formData = [{
|
||||
vm.formData = [
|
||||
{
|
||||
name: 'Bruce',
|
||||
lastName: 'Wayne',
|
||||
age: 45,
|
||||
}]
|
||||
},
|
||||
];
|
||||
|
||||
await vm.saveChanges(data);
|
||||
|
||||
|
|
|
@ -158,15 +158,10 @@ const getBadgeAttrs = (_date) => {
|
|||
|
||||
const scrollToToday = async () => {
|
||||
await nextTick();
|
||||
const todayCell = document.querySelector(`td[data-date="${today.toISOString()}"]`);
|
||||
if (todayCell) {
|
||||
todayCell.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
}
|
||||
};
|
||||
|
||||
const formatDateForAttribute = (dateValue) => {
|
||||
if (dateValue instanceof Date) return date.formatDate(dateValue, 'YYYY-MM-DD');
|
||||
return dateValue;
|
||||
const todayCell = document.querySelector(
|
||||
`td[data-date="${date.formatDate(today, 'YYYY-MM-DD')}"]`,
|
||||
);
|
||||
if (todayCell) todayCell.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
};
|
||||
|
||||
async function updateWarehouse(warehouseFk) {
|
||||
|
@ -242,7 +237,7 @@ async function updateWarehouse(warehouseFk) {
|
|||
</QTd>
|
||||
</template>
|
||||
<template #body-cell-date="{ row }">
|
||||
<QTd @click.stop :data-date="formatDateForAttribute(row.shipped)">
|
||||
<QTd @click.stop :data-date="row?.shipped.substring(0, 10)">
|
||||
<QBadge
|
||||
v-bind="getBadgeAttrs(row.shipped)"
|
||||
class="q-ma-none"
|
||||
|
|
|
@ -121,6 +121,50 @@ async function handleSave() {
|
|||
isSaving.value = false;
|
||||
}
|
||||
}
|
||||
function validateFields(item) {
|
||||
// Only validate fields that are being updated
|
||||
const shouldExist = (field) => !isUpdate || field in item;
|
||||
|
||||
if (!shouldExist('ticketServiceTypeFk') && !item.ticketServiceTypeFk) {
|
||||
notify('Description is required', 'negative');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!shouldExist('quantity') && (!item.quantity || item.quantity <= 0)) {
|
||||
notify('Quantity must be greater than 0', 'negative');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!shouldExist('price') && (!item.price || item.price < 0)) {
|
||||
notify('Price must be valid', 'negative');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function beforeSave(data) {
|
||||
const { creates = [], updates = [] } = data;
|
||||
const validData = { creates: [], updates: [] };
|
||||
|
||||
// Validate creates
|
||||
if (creates.length) {
|
||||
for (const create of creates) {
|
||||
create.ticketFk = route.params.id;
|
||||
if (validateFields(create)) {
|
||||
validData.creates.push(create);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Validate updates
|
||||
if (updates.length) {
|
||||
for (const update of updates) {
|
||||
validData.updates.push(update);
|
||||
}
|
||||
}
|
||||
return validData;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@ -141,6 +185,7 @@ async function handleSave() {
|
|||
v-model:selected="selected"
|
||||
:order="['description ASC']"
|
||||
:default-remove="false"
|
||||
:beforeSaveFn="beforeSave"
|
||||
>
|
||||
<template #moreBeforeActions>
|
||||
<QBtn
|
||||
|
@ -170,6 +215,7 @@ async function handleSave() {
|
|||
option-value="id"
|
||||
hide-selected
|
||||
sort-by="name ASC"
|
||||
:required="true"
|
||||
>
|
||||
<template #form>
|
||||
<TicketCreateServiceType
|
||||
|
@ -185,6 +231,7 @@ async function handleSave() {
|
|||
:label="col.label"
|
||||
v-model.number="row.quantity"
|
||||
type="number"
|
||||
:required="true"
|
||||
min="0"
|
||||
:info="t('service.quantityInfo')"
|
||||
/>
|
||||
|
@ -196,6 +243,7 @@ async function handleSave() {
|
|||
:label="col.label"
|
||||
v-model.number="row.price"
|
||||
type="number"
|
||||
:required="true"
|
||||
min="0"
|
||||
@keyup.enter="handleSave"
|
||||
/>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { ref, nextTick } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import VnInputDate from 'src/components/common/VnInputDate.vue';
|
||||
import FetchData from 'components/FetchData.vue';
|
||||
|
|
Loading…
Reference in New Issue