Make AccountLdap work again

This commit is contained in:
William Buezas 2024-06-07 09:35:36 -03:00
parent 4c84fd9326
commit 1e67a0feca
1 changed files with 23 additions and 14 deletions

View File

@ -7,12 +7,17 @@ import VnRow from 'components/ui/VnRow.vue';
import VnInput from 'src/components/common/VnInput.vue'; import VnInput from 'src/components/common/VnInput.vue';
import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue'; import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue';
import { useArrayData } from 'src/composables/useArrayData';
import useNotify from 'src/composables/useNotify.js'; import useNotify from 'src/composables/useNotify.js';
import axios from 'axios'; import axios from 'axios';
const { t } = useI18n(); const { t } = useI18n();
const { notify } = useNotify(); const { notify } = useNotify();
const arrayData = useArrayData('AccountLdap');
const URL_UPDATE = `LdapConfigs/${1}`;
const URL_CREATE = `LdapConfigs`;
const DEFAULT_DATA = { const DEFAULT_DATA = {
id: 1, id: 1,
hasData: false, hasData: false,
@ -31,15 +36,15 @@ const hasData = computed({
get: () => initialData.value.hasData, get: () => initialData.value.hasData,
set: (val) => { set: (val) => {
initialData.value.hasData = val; initialData.value.hasData = val;
if (!val) customFn.value = deleteMailForward; if (!val) formCustomFn.value = deleteMailForward;
else customFn.value = null; else formCustomFn.value = null;
}, },
}); });
const initialDataLoaded = ref(false); const initialDataLoaded = ref(false);
const urlCreate = ref(null); const formUrlCreate = ref(null);
const urlUpdate = ref(`LdapConfigs/${1}`); const formUrlUpdate = ref(`LdapConfigs/${1}`);
const customFn = ref(null); const formCustomFn = ref(null);
const onTestConection = async () => { const onTestConection = async () => {
try { try {
@ -53,19 +58,23 @@ const onTestConection = async () => {
const getInitialLdapConfig = async () => { const getInitialLdapConfig = async () => {
try { try {
initialDataLoaded.value = false; initialDataLoaded.value = false;
const { data } = await axios.get(urlUpdate.value); const { data } = await axios.get(URL_UPDATE);
initialData.value = data; initialData.value = data;
hasData.value = true; hasData.value = true;
return data; return data;
} catch (error) { } catch (error) {
hasData.value = false; hasData.value = false;
arrayData.destroy();
console.error('Error fetching initial LDAP config', error); console.error('Error fetching initial LDAP config', error);
return null; return null;
} finally { } finally {
if (hasData.value) urlCreate.value = null; // Si asignamos un valor a urlUpdate, debemos asignar null a urlCreate y viceversa, ya puede causar problemas en formModel
else { if (hasData.value) {
urlUpdate.value = null; formUrlUpdate.value = URL_UPDATE;
urlCreate.value = `LdapConfigs`; formUrlCreate.value = null;
} else {
formUrlUpdate.value = null;
formUrlCreate.value = URL_CREATE;
} }
initialDataLoaded.value = true; initialDataLoaded.value = true;
} }
@ -73,7 +82,7 @@ const getInitialLdapConfig = async () => {
const deleteMailForward = async () => { const deleteMailForward = async () => {
try { try {
await axios.delete(urlUpdate.value); await axios.delete(URL_UPDATE);
initialData.value = { ...DEFAULT_DATA }; initialData.value = { ...DEFAULT_DATA };
hasData.value = false; hasData.value = false;
notify(t('globals.dataSaved'), 'positive'); notify(t('globals.dataSaved'), 'positive');
@ -92,9 +101,9 @@ onMounted(async () => await getInitialLdapConfig());
:key="initialDataLoaded" :key="initialDataLoaded"
model="AccountLdap" model="AccountLdap"
:form-initial-data="initialData" :form-initial-data="initialData"
:url-create="urlCreate" :url-create="formUrlCreate"
:url-update="urlUpdate" :url-update="formUrlUpdate"
:save-fn="customFn" :save-fn="formCustomFn"
auto-load auto-load
@on-data-saved="getInitialLdapConfig()" @on-data-saved="getInitialLdapConfig()"
> >