diff --git a/src/components/CrudModel.vue b/src/components/CrudModel.vue index 19e990862..b1c7606e6 100644 --- a/src/components/CrudModel.vue +++ b/src/components/CrudModel.vue @@ -10,6 +10,7 @@ import VnPaginate from 'components/ui/VnPaginate.vue'; import VnConfirm from 'components/ui/VnConfirm.vue'; import SkeletonTable from 'components/ui/SkeletonTable.vue'; import { tMobile } from 'src/composables/tMobile'; +import getDifferences from 'src/filters/getDifferences'; const { push } = useRouter(); const quasar = useQuasar(); @@ -175,14 +176,13 @@ async function saveChanges(data) { const changes = data || getChanges(); try { await axios.post($props.saveUrl || $props.url + '/crud', changes); - } catch (e) { - return (isLoading.value = false); + } finally { + isLoading.value = false; } originalData.value = JSON.parse(JSON.stringify(formData.value)); if (changes.creates?.length) await vnPaginateRef.value.fetch(); hasChanges.value = false; - isLoading.value = false; emit('saveChanges', data); quasar.notify({ type: 'positive', @@ -268,28 +268,6 @@ function getChanges() { return changes; } -function getDifferences(obj1, obj2) { - let diff = {}; - delete obj1.$index; - delete obj2.$index; - - for (let key in obj1) { - if (obj2[key] && JSON.stringify(obj1[key]) !== JSON.stringify(obj2[key])) { - diff[key] = obj2[key]; - } - } - for (let key in obj2) { - if ( - obj1[key] === undefined || - JSON.stringify(obj1[key]) !== JSON.stringify(obj2[key]) - ) { - diff[key] = obj2[key]; - } - } - - return diff; -} - function isEmpty(obj) { if (obj == null) return true; if (obj === undefined) return true; diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index c668769e5..4504ea6ad 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -106,6 +106,7 @@ const originalData = ref({}); const formData = computed(() => state.get(modelValue)); const defaultButtons = computed(() => ({ save: { + dataCy: 'saveDefaultBtn', color: 'primary', icon: 'save', label: 'globals.save', @@ -113,6 +114,7 @@ const defaultButtons = computed(() => ({ type: 'submit', }, reset: { + dataCy: 'resetDefaultBtn', color: 'primary', icon: 'restart_alt', label: 'globals.reset', @@ -203,7 +205,9 @@ async function save() { isLoading.value = true; try { formData.value = trimData(formData.value); - const body = $props.mapper ? $props.mapper(formData.value) : formData.value; + const body = $props.mapper + ? $props.mapper(formData.value, originalData.value) + : formData.value; const method = $props.urlCreate ? 'post' : 'patch'; const url = $props.urlCreate || $props.urlUpdate || $props.url || arrayData.store.url; @@ -317,6 +321,7 @@ defineExpose({ :title="t(defaultButtons.reset.label)" /> - diff --git a/src/components/ui/VnNotes.vue b/src/components/ui/VnNotes.vue index dbcb2f3fe..bcbf0945e 100644 --- a/src/components/ui/VnNotes.vue +++ b/src/components/ui/VnNotes.vue @@ -101,6 +101,7 @@ onBeforeRouteLeave((to, from, next) => { @click="insert" class="q-mb-xs" dense + data-cy="saveNote" /> diff --git a/src/filters/getDifferences.js b/src/filters/getDifferences.js new file mode 100644 index 000000000..3e1061aba --- /dev/null +++ b/src/filters/getDifferences.js @@ -0,0 +1,21 @@ +export default function getDifferences(obj1, obj2) { + let diff = {}; + delete obj1.$index; + delete obj2.$index; + + for (let key in obj1) { + if (obj2[key] && JSON.stringify(obj1[key]) !== JSON.stringify(obj2[key])) { + diff[key] = obj2[key]; + } + } + for (let key in obj2) { + if ( + obj1[key] === undefined || + JSON.stringify(obj1[key]) !== JSON.stringify(obj2[key]) + ) { + diff[key] = obj2[key]; + } + } + + return diff; +} diff --git a/src/filters/getUpdatedValues.js b/src/filters/getUpdatedValues.js new file mode 100644 index 000000000..5b9622fd0 --- /dev/null +++ b/src/filters/getUpdatedValues.js @@ -0,0 +1,6 @@ +export default function getUpdatedValues(keys, formData) { + return keys.reduce((acc, key) => { + acc[key] = formData[key]; + return acc; + }, {}); +} diff --git a/src/filters/index.js b/src/filters/index.js index 1f7ac77dd..a92d2eb07 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -11,11 +11,15 @@ import dashIfEmpty from './dashIfEmpty'; import dateRange from './dateRange'; import toHour from './toHour'; import dashOrCurrency from './dashOrCurrency'; +import getDifferences from './getDifferences'; +import getUpdatedValues from './getUpdatedValues'; import getParamWhere from './getParamWhere'; import parsePhone from './parsePhone'; import isDialogOpened from './isDialogOpened'; export { + getUpdatedValues, + getDifferences, isDialogOpened, parsePhone, toLowerCase, diff --git a/src/i18n/locale/en.yml b/src/i18n/locale/en.yml index 3e3df7a0f..31a6931a4 100644 --- a/src/i18n/locale/en.yml +++ b/src/i18n/locale/en.yml @@ -766,7 +766,7 @@ travel: thermographs: Thermographs hb: HB basicData: - daysInForward: Days in forward + daysInForward: Automatic movement (Raid) isRaid: Raid thermographs: temperature: Temperature @@ -861,6 +861,7 @@ components: cardDescriptor: mainList: Main list summary: Summary + moreOptions: More options leftMenu: addToPinned: Add to pinned removeFromPinned: Remove from pinned diff --git a/src/i18n/locale/es.yml b/src/i18n/locale/es.yml index 58ddc98ef..ccc21e225 100644 --- a/src/i18n/locale/es.yml +++ b/src/i18n/locale/es.yml @@ -760,7 +760,7 @@ travel: thermographs: Termógrafos hb: HB basicData: - daysInForward: Días redada + daysInForward: Desplazamiento automatico (redada) isRaid: Redada thermographs: temperature: Temperatura diff --git a/src/pages/Account/Card/AccountMailForwarding.vue b/src/pages/Account/Card/AccountMailForwarding.vue index aa92e5072..30849d44a 100644 --- a/src/pages/Account/Card/AccountMailForwarding.vue +++ b/src/pages/Account/Card/AccountMailForwarding.vue @@ -41,8 +41,12 @@ const fetchAccountExistence = async () => { }; const fetchMailForwards = async () => { - const response = await axios.get(`MailForwards/${route.params.id}`); - return response.data; + try { + const response = await axios.get(`MailForwards/${route.params.id}`); + return response.data; + } catch { + return null; + } }; const deleteMailForward = async () => { diff --git a/src/pages/Customer/Card/CustomerAddress.vue b/src/pages/Customer/Card/CustomerAddress.vue index 5e896c84f..657cc7ae7 100644 --- a/src/pages/Customer/Card/CustomerAddress.vue +++ b/src/pages/Customer/Card/CustomerAddress.vue @@ -2,6 +2,7 @@ import { onBeforeMount, ref, watch } from 'vue'; import { useI18n } from 'vue-i18n'; import { useRoute, useRouter } from 'vue-router'; +import FetchData from 'components/FetchData.vue'; import axios from 'axios'; @@ -52,7 +53,6 @@ const addressFilter = { onBeforeMount(() => { const { id } = route.params; - getAddressesData(id); getClientData(id); }); @@ -60,23 +60,10 @@ watch( () => route.params.id, (newValue) => { if (!newValue) return; - getAddressesData(newValue); getClientData(newValue); } ); -const getAddressesData = async (id) => { - try { - const { data } = await axios.get(`Clients/${id}/addresses`, { - params: { filter: JSON.stringify(addressFilter) }, - }); - addresses.value = data; - sortAddresses(); - } catch (error) { - return error; - } -}; - const getClientData = async (id) => { try { const { data } = await axios.get(`Clients/${id}`); @@ -101,9 +88,9 @@ const setDefault = (address) => { }); }; -const sortAddresses = () => { - if (!client.value || !addresses.value) return; - addresses.value = addresses.value.sort((a, b) => { +const sortAddresses = (data) => { + if (!client.value || !data) return; + addresses.value = data.sort((a, b) => { return isDefaultAddress(b) - isDefaultAddress(a); }); }; @@ -124,8 +111,17 @@ const toCustomerAddressEdit = (addressId) => {