WIP: #7701: Make FormModel use url #1653

Draft
jon wants to merge 10 commits from 7701-FormModelUseUrl into dev
7 changed files with 38 additions and 7 deletions

View File

@ -0,0 +1,4 @@
import setDefault from './setDefault';
import { QDialog } from 'quasar';
setDefault(QDialog, 'noRouteDismiss', true);

View File

@ -2,3 +2,4 @@
export * from './defaults/qTable'; export * from './defaults/qTable';
export * from './defaults/qInput'; export * from './defaults/qInput';
export * from './defaults/qSelect'; export * from './defaults/qSelect';
export * from './defaults/qDialog';

View File

@ -21,6 +21,7 @@ const { t } = useI18n();
const { validate, validations } = useValidator(); const { validate, validations } = useValidator();
const { notify } = useNotify(); const { notify } = useNotify();
const route = useRoute(); const route = useRoute();
const router = useRouter();
const myForm = ref(null); const myForm = ref(null);
const attrs = useAttrs(); const attrs = useAttrs();
const $props = defineProps({ const $props = defineProps({
@ -99,6 +100,10 @@ const $props = defineProps({
type: Function, type: Function,
default: () => {}, default: () => {},
}, },
searchUrl: {
type: [String, Boolean],
default: 'form',
},
}); });
const emit = defineEmits(['onFetch', 'onDataSaved']); const emit = defineEmits(['onFetch', 'onDataSaved']);
const modelValue = computed( const modelValue = computed(
@ -139,6 +144,11 @@ const submitForm = async (evt) => {
}; };
onMounted(async () => { onMounted(async () => {
const urlInitalData =
$props.searchUrl && JSON.parse(route?.query[$props.searchUrl] ?? '{}');
originalData.value = JSON.parse(
JSON.stringify(urlInitalData ?? $props.formInitialData ?? {}),
);
nextTick(() => (componentIsRendered.value = true)); nextTick(() => (componentIsRendered.value = true));
// Podemos enviarle al form la estructura de data inicial sin necesidad de fetchearla // Podemos enviarle al form la estructura de data inicial sin necesidad de fetchearla
@ -187,6 +197,24 @@ watch(
}, },
); );
watch(
() => formData.value,
async (newData, oldData) => {
if (JSON.stringify(newData) === JSON.stringify(oldData)) return;
if (!$props.searchUrl) return;
if (!newData) return;
const urlParams = JSON.stringify(newData);
await nextTick();
router.replace({
query: {
...route.query,
createForm: urlParams,
},
});
},
{ deep: true },
);
onBeforeRouteLeave((to, from, next) => { onBeforeRouteLeave((to, from, next) => {
if (hasChanges.value && $props.observeFormChanges) if (hasChanges.value && $props.observeFormChanges)
quasar.dialog({ quasar.dialog({

View File

@ -208,13 +208,6 @@ onMounted(async () => {
...['tableActions'], ...['tableActions'],
]; ];
createForm.value = $props.create; createForm.value = $props.create;
if ($props.create && route?.query?.createForm) {
showForm.value = true;
createForm.value = {
...createForm.value,
...{ formInitialData: JSON.parse(route?.query?.createForm) },
};
}
}); });
onUnmounted(async () => { onUnmounted(async () => {

View File

@ -4,6 +4,8 @@ describe('Client web-access', () => {
cy.viewport(1280, 720); cy.viewport(1280, 720);
cy.login('developer'); cy.login('developer');
}); });
//falla
it('Should test buttons ', () => { it('Should test buttons ', () => {
cy.visit('#/customer/1101/web-access'); cy.visit('#/customer/1101/web-access');
cy.get('.q-page').should('be.visible'); cy.get('.q-page').should('be.visible');

View File

@ -12,6 +12,7 @@ describe('Item botanical', () => {
cy.checkNotification('Data saved'); cy.checkNotification('Data saved');
}); });
//falla
it('should create a new Genus', () => { it('should create a new Genus', () => {
cy.dataCy('Genus_icon').click(); cy.dataCy('Genus_icon').click();
cy.dataCy('Latin genus name_input').type('Test'); cy.dataCy('Latin genus name_input').type('Test');
@ -19,6 +20,7 @@ describe('Item botanical', () => {
cy.checkNotification('Data created'); cy.checkNotification('Data created');
}); });
//falla
it('should create a new specie', () => { it('should create a new specie', () => {
cy.dataCy('Species_icon').click(); cy.dataCy('Species_icon').click();
cy.dataCy('Latin species name_input').type('Test specie'); cy.dataCy('Latin species name_input').type('Test specie');

View File

@ -13,6 +13,7 @@ describe('Item summary', () => {
cy.dataCy('itemTags').should('be.visible'); cy.dataCy('itemTags').should('be.visible');
}); });
//falla
it('should regularize stock', () => { it('should regularize stock', () => {
cy.dataCy('descriptor-more-opts').click(); cy.dataCy('descriptor-more-opts').click();
cy.get('.q-menu > .q-list > :nth-child(1) > .q-item__section').click(); cy.get('.q-menu > .q-list > :nth-child(1) > .q-item__section').click();