0
0
Fork 0

perf: minor clean code

This commit is contained in:
Javier Segarra 2024-09-08 12:56:40 +02:00
parent 754f047943
commit 53e6c67ff9
1 changed files with 19 additions and 22 deletions

View File

@ -263,8 +263,6 @@ const updateMinPrice = async (value, props) => {
};
const upsertPrice = async ({ row }, resetMinPrice = false) => {
// if (!validations(row, rowIndex, col)) return;
try {
if (resetMinPrice) row.hasMinPrice = 0;
row = await upsertFixedPrice(row);
@ -272,6 +270,7 @@ const upsertPrice = async ({ row }, resetMinPrice = false) => {
console.error('Error editing price', err);
}
};
async function upsertFixedPrice(row) {
try {
const { data } = await axios.patch('FixedPrices/upsertFixedPrice', row);
@ -280,6 +279,7 @@ async function upsertFixedPrice(row) {
console.error('Error editing price', err);
}
}
async function saveOnRowChange(row) {
if (rowsSelected.value.length > 1) return;
if (rowsSelected.value[0]?.id === row.id) return;
@ -298,11 +298,9 @@ function checkLastVisibleRow() {
}
});
if (lastVisibleRow) {
console.log('Última fila visible:', lastVisibleRow);
}
return lastVisibleRow;
}
const addRow = (original = null) => {
let copy = null;
if (!original) {
@ -340,8 +338,10 @@ const addRow = (original = null) => {
};
return { original, copy };
};
const getTableRows = () =>
document.getElementsByClassName('q-table')[0].querySelectorAll('tr.cursor-pointer');
function highlightNewRow({ $index: index }) {
const row = getTableRows()[index];
if (row) {
@ -354,10 +354,12 @@ function highlightNewRow({ $index: index }) {
const openEditTableCellDialog = () => {
editTableCellDialogRef.value.show();
};
const onEditCellDataSaved = async () => {
rowsSelected.value = [];
tableRef.value.reload();
};
const removeFuturePrice = async () => {
try {
rowsSelected.value.forEach(({ id }) => {
@ -368,6 +370,7 @@ const removeFuturePrice = async () => {
console.error('Error removing price', err);
}
};
function confirmRemove(item, isFuture) {
const promise = async () =>
isFuture ? removeFuturePrice(item.id) : removePrice(item.id);
@ -380,6 +383,7 @@ function confirmRemove(item, isFuture) {
},
});
}
const removePrice = async (id) => {
try {
await axios.delete(`FixedPrices/${id}`);
@ -389,6 +393,13 @@ const removePrice = async (id) => {
console.error('Error removing price', err);
}
};
const dateStyle = (date) =>
date
? {
'bg-color': 'warning',
'is-outlined': true,
}
: {};
function handleOnDataSave({ CrudModelRef }) {
const { original, copy } = addRow(CrudModelRef.formData[checkLastVisibleRow()]);
@ -566,14 +577,7 @@ function handleOnDataSave({ CrudModelRef }) {
:show-event="true"
v-model="props.row.started"
v-on="getRowUpdateInputEvents(props, false, 'date')"
v-bind="
isBigger(props.row.started)
? {
'bg-color': 'warning',
'is-outlined': true,
}
: {}
"
v-bind="dateStyle(isBigger(props.row.started))"
/>
</QTd>
</template>
@ -584,14 +588,7 @@ function handleOnDataSave({ CrudModelRef }) {
:show-event="true"
v-model="props.row.ended"
v-on="getRowUpdateInputEvents(props, false, 'date')"
v-bind="
isLower(props.row.started)
? {
'bg-color': 'warning',
'is-outlined': true,
}
: {}
"
v-bind="dateStyle(isLower(props.row.started))"
/>
</QTd>
</template>
@ -617,7 +614,7 @@ function handleOnDataSave({ CrudModelRef }) {
color="primary"
@click.stop="
openConfirmationModal(
t('This row will be removed'),
t('globals.rowWillBeRemoved'),
t('Do you want to clone this item?'),
() => removePrice(row.id, rowIndex)
)