forked from verdnatura/salix-front
Merge branch 'dev' into cypress_randomizeValue
This commit is contained in:
commit
582a3b333a
|
@ -17,10 +17,6 @@ const $props = defineProps({
|
|||
type: Number,
|
||||
default: null,
|
||||
},
|
||||
provinces: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
});
|
||||
const { t } = useI18n();
|
||||
|
||||
|
@ -56,7 +52,6 @@ const onDataSaved = (...args) => {
|
|||
:province-selected="$props.provinceSelected"
|
||||
:country-fk="$props.countryFk"
|
||||
v-model="data.provinceFk"
|
||||
:provinces="$props.provinces"
|
||||
/>
|
||||
</VnRow>
|
||||
</template>
|
||||
|
|
|
@ -56,10 +56,10 @@ async function onCityCreated(newTown, formData) {
|
|||
}
|
||||
|
||||
function setTown(newTown, data) {
|
||||
if (!newTown) return;
|
||||
town.value = newTown;
|
||||
data.provinceFk = newTown.provinceFk;
|
||||
data.countryFk = newTown.province.countryFk;
|
||||
if (!newTown) return;
|
||||
town.value = newTown;
|
||||
}
|
||||
|
||||
async function setProvince(id, data) {
|
||||
|
@ -73,7 +73,7 @@ async function onProvinceCreated(data) {
|
|||
await provincesFetchDataRef.value.fetch({
|
||||
where: { countryFk: postcodeFormData.countryFk },
|
||||
});
|
||||
postcodeFormData.provinceFk.value = data.id;
|
||||
postcodeFormData.provinceFk = data.id;
|
||||
}
|
||||
|
||||
watch(
|
||||
|
@ -90,22 +90,33 @@ watch(
|
|||
postcodeFormData.townFk = null;
|
||||
}
|
||||
if (oldValueFk !== newCountryFk) {
|
||||
await provincesFetchDataRef.value.fetch({
|
||||
where: {
|
||||
countryFk: newCountryFk,
|
||||
},
|
||||
});
|
||||
await townsFetchDataRef.value.fetch({
|
||||
where: {
|
||||
provinceFk: {
|
||||
inq: provincesOptions.value.map(({ id }) => id),
|
||||
},
|
||||
},
|
||||
});
|
||||
await fetchProvinces(newCountryFk);
|
||||
await fetchTowns(newCountryFk);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
async function fetchTowns(countryFk) {
|
||||
const townsFilter = countryFk
|
||||
? {
|
||||
where: {
|
||||
provinceFk: {
|
||||
inq: provincesOptions.value.map(({ id }) => id),
|
||||
},
|
||||
},
|
||||
}
|
||||
: {};
|
||||
await townsFetchDataRef.value.fetch(townsFilter);
|
||||
}
|
||||
async function fetchProvinces(countryFk) {
|
||||
const provincesFilter = countryFk
|
||||
? {
|
||||
where: {
|
||||
countryFk: countryFk,
|
||||
},
|
||||
}
|
||||
: {};
|
||||
await provincesFetchDataRef.value.fetch(provincesFilter);
|
||||
}
|
||||
watch(
|
||||
() => postcodeFormData.provinceFk,
|
||||
async (newProvinceFk, oldValueFk) => {
|
||||
|
@ -147,6 +158,13 @@ async function handleCountries(data) {
|
|||
auto-load
|
||||
url="Towns/location"
|
||||
/>
|
||||
<FetchData
|
||||
ref="CountriesFetchDataRef"
|
||||
:sort-by="['name ASC']"
|
||||
@on-fetch="handleCountries"
|
||||
auto-load
|
||||
url="Countries"
|
||||
/>
|
||||
|
||||
<FormModelPopup
|
||||
url-create="postcodes"
|
||||
|
@ -193,7 +211,6 @@ async function handleCountries(data) {
|
|||
<CreateNewCityForm
|
||||
:country-fk="data.countryFk"
|
||||
:province-selected="data.provinceFk"
|
||||
:provinces="provincesOptions"
|
||||
@on-data-saved="
|
||||
(_, requestResponse) =>
|
||||
onCityCreated(requestResponse, data)
|
||||
|
@ -209,14 +226,12 @@ async function handleCountries(data) {
|
|||
@update:model-value="(value) => setProvince(value, data)"
|
||||
v-model="data.provinceFk"
|
||||
:clearable="true"
|
||||
:provinces="provincesOptions"
|
||||
@on-province-created="onProvinceCreated"
|
||||
/>
|
||||
<VnSelect
|
||||
url="Countries"
|
||||
:sort-by="['name ASC']"
|
||||
:label="t('Country')"
|
||||
@update:options="handleCountries"
|
||||
:options="countriesOptions"
|
||||
hide-selected
|
||||
option-label="name"
|
||||
option-value="id"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<script setup>
|
||||
import { reactive, ref } from 'vue';
|
||||
import { computed, reactive, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
import FetchData from 'components/FetchData.vue';
|
||||
|
@ -34,6 +34,12 @@ const onDataSaved = (dataSaved, requestResponse) => {
|
|||
);
|
||||
emit('onDataSaved', dataSaved, requestResponse);
|
||||
};
|
||||
const where = computed(() => {
|
||||
if (!$props.countryFk) {
|
||||
return {};
|
||||
}
|
||||
return { countryFk: $props.countryFk };
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@ -41,9 +47,7 @@ const onDataSaved = (dataSaved, requestResponse) => {
|
|||
@on-fetch="(data) => (autonomiesOptions = data)"
|
||||
auto-load
|
||||
:filter="{
|
||||
where: {
|
||||
countryFk: $props.countryFk,
|
||||
},
|
||||
where,
|
||||
}"
|
||||
url="Autonomies/location"
|
||||
:sort-by="['name ASC']"
|
||||
|
|
|
@ -4,7 +4,7 @@ import { useI18n } from 'vue-i18n';
|
|||
|
||||
const emit = defineEmits(['onSubmit']);
|
||||
|
||||
defineProps({
|
||||
const $props = defineProps({
|
||||
title: {
|
||||
type: String,
|
||||
default: '',
|
||||
|
@ -25,16 +25,21 @@ defineProps({
|
|||
type: String,
|
||||
default: '',
|
||||
},
|
||||
submitOnEnter: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
});
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const closeButton = ref(null);
|
||||
const isLoading = ref(false);
|
||||
|
||||
const onSubmit = () => {
|
||||
emit('onSubmit');
|
||||
closeForm();
|
||||
if ($props.submitOnEnter) {
|
||||
emit('onSubmit');
|
||||
closeForm();
|
||||
}
|
||||
};
|
||||
|
||||
const closeForm = () => {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { ref, watch } from 'vue';
|
||||
import { useValidator } from 'src/composables/useValidator';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
|
@ -17,20 +17,23 @@ const $props = defineProps({
|
|||
type: Number,
|
||||
default: null,
|
||||
},
|
||||
provinces: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
});
|
||||
const provinceFk = defineModel({ type: Number, default: null });
|
||||
|
||||
const { validate } = useValidator();
|
||||
const { t } = useI18n();
|
||||
|
||||
const filter = ref({
|
||||
include: { relation: 'country' },
|
||||
where: {
|
||||
countryFk: $props.countryFk,
|
||||
},
|
||||
});
|
||||
const provincesOptions = ref($props.provinces);
|
||||
provinceFk.value = $props.provinceSelected;
|
||||
const provincesFetchDataRef = ref();
|
||||
|
||||
provinceFk.value = $props.provinceSelected;
|
||||
if (!$props.countryFk) {
|
||||
filter.value.where = {};
|
||||
}
|
||||
async function onProvinceCreated(_, data) {
|
||||
await provincesFetchDataRef.value.fetch({ where: { countryFk: $props.countryFk } });
|
||||
provinceFk.value = data.id;
|
||||
|
@ -39,23 +42,29 @@ async function onProvinceCreated(_, data) {
|
|||
async function handleProvinces(data) {
|
||||
provincesOptions.value = data;
|
||||
}
|
||||
|
||||
watch(
|
||||
() => $props.countryFk,
|
||||
async () => {
|
||||
if ($props.countryFk) {
|
||||
filter.value.where.countryFk = $props.countryFk;
|
||||
} else filter.value.where = {};
|
||||
await provincesFetchDataRef.value.fetch({});
|
||||
}
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FetchData
|
||||
ref="provincesFetchDataRef"
|
||||
:filter="{
|
||||
include: { relation: 'country' },
|
||||
where: {
|
||||
countryFk: $props.countryFk,
|
||||
},
|
||||
}"
|
||||
:filter="filter"
|
||||
@on-fetch="handleProvinces"
|
||||
url="Provinces"
|
||||
auto-load
|
||||
/>
|
||||
<VnSelectDialog
|
||||
:label="t('Province')"
|
||||
:options="$props.provinces"
|
||||
:options="provincesOptions"
|
||||
:tooltip="t('Create province')"
|
||||
hide-selected
|
||||
v-model="provinceFk"
|
||||
|
|
|
@ -132,10 +132,24 @@ const addFilter = async (filter, params) => {
|
|||
|
||||
async function fetch(params) {
|
||||
useArrayData(props.dataKey, params);
|
||||
arrayData.reset(['filter.skip', 'skip']);
|
||||
arrayData.reset(['filter.skip', 'skip', 'page']);
|
||||
await arrayData.fetch({ append: false });
|
||||
if (!store.hasMoreData) isLoading.value = false;
|
||||
return emitStoreData();
|
||||
}
|
||||
|
||||
async function update(params) {
|
||||
useArrayData(props.dataKey, params);
|
||||
const { limit, skip } = store;
|
||||
store.limit = limit + skip;
|
||||
store.skip = 0;
|
||||
await arrayData.fetch({ append: false });
|
||||
store.limit = limit;
|
||||
store.skip = skip;
|
||||
return emitStoreData();
|
||||
}
|
||||
|
||||
function emitStoreData() {
|
||||
if (!store.hasMoreData) isLoading.value = false;
|
||||
emit('onFetch', store.data);
|
||||
return store.data;
|
||||
}
|
||||
|
@ -181,7 +195,7 @@ async function onLoad(index, done) {
|
|||
done(isDone);
|
||||
}
|
||||
|
||||
defineExpose({ fetch, addFilter, paginate });
|
||||
defineExpose({ fetch, update, addFilter, paginate });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
@ -95,6 +95,7 @@ const columns = computed(() => [
|
|||
optionLabel: 'description',
|
||||
},
|
||||
},
|
||||
orderBy: 'priority',
|
||||
},
|
||||
{
|
||||
align: 'right',
|
||||
|
|
|
@ -350,7 +350,7 @@ const openTab = (id) =>
|
|||
class="q-mr-sm"
|
||||
dense
|
||||
flat
|
||||
@click="$refs.tableRef.reload()"
|
||||
@click="tableRef.CrudModelRef.vnPaginateRef.update()"
|
||||
>
|
||||
<QTooltip>{{ $t('globals.refresh') }}</QTooltip>
|
||||
</QBtn>
|
||||
|
|
|
@ -43,7 +43,7 @@ const { t } = useI18n();
|
|||
const { openConfirmationModal } = useVnConfirm();
|
||||
|
||||
const isNew = computed(() => props.isNewMode);
|
||||
const dated = ref(null);
|
||||
const dated = ref(props.date);
|
||||
const tickedNodes = ref();
|
||||
|
||||
const _excludeType = ref('all');
|
||||
|
@ -73,7 +73,6 @@ const exclusionCreate = async () => {
|
|||
await axios.post(`Zones/${route.params.id}/exclusions`, {
|
||||
dated: dated.value,
|
||||
});
|
||||
|
||||
await refetchEvents();
|
||||
};
|
||||
|
||||
|
@ -115,13 +114,14 @@ onMounted(() => {
|
|||
@on-submit="onSubmit()"
|
||||
:default-cancel-button="false"
|
||||
:default-submit-button="false"
|
||||
:submit-on-enter="false"
|
||||
>
|
||||
<template #form-inputs>
|
||||
<VnRow class="row q-gutter-md q-mb-lg">
|
||||
<VnInputDate
|
||||
:label="t('eventsInclusionForm.day')"
|
||||
v-model="dated"
|
||||
:model-value="props.date"
|
||||
:required="true"
|
||||
/>
|
||||
</VnRow>
|
||||
<div class="column q-gutter-y-sm q-mb-md">
|
||||
|
@ -182,6 +182,7 @@ onMounted(() => {
|
|||
:label="isNew ? t('globals.add') : t('globals.save')"
|
||||
type="submit"
|
||||
color="primary"
|
||||
@click="onSubmit()"
|
||||
/>
|
||||
</template>
|
||||
</FormPopup>
|
||||
|
|
|
@ -38,6 +38,7 @@ const datakey = 'ZoneLocations';
|
|||
const url = computed(() => `Zones/${route.params.id}/getLeaves`);
|
||||
const arrayData = useArrayData(datakey, {
|
||||
url: url.value,
|
||||
limit: null,
|
||||
});
|
||||
const store = arrayData.store;
|
||||
|
||||
|
@ -74,6 +75,7 @@ const onNodeExpanded = async (nodeKeysArray) => {
|
|||
if (response.data) {
|
||||
node.childs = response.data.map((n) => {
|
||||
if (n.sons > 0) n.childs = [{}];
|
||||
n.selected = isSelected(n.selected);
|
||||
return n;
|
||||
});
|
||||
}
|
||||
|
@ -90,21 +92,16 @@ const onNodeExpanded = async (nodeKeysArray) => {
|
|||
previousExpandedNodes.value = nodeKeysSet;
|
||||
};
|
||||
|
||||
const formatNodeSelected = (node) => {
|
||||
if (node.selected === 1) node.selected = true;
|
||||
else if (node.selected === 0) node.selected = false;
|
||||
|
||||
if (node.sons > 0 && !node.childs) node.childs = [{}];
|
||||
};
|
||||
|
||||
const fetchNodeLeaves = async (nodeKey) => {
|
||||
if (!treeRef.value) return;
|
||||
const node = treeRef.value?.getNodeByKey(nodeKey);
|
||||
if (node.selected === 1) node.selected = true;
|
||||
else if (node.selected === 0) node.selected = false;
|
||||
if (typeof node.selected === 'number') node.selected = !!node.selected;
|
||||
if (node.sons > 0 && !node.childs) {
|
||||
node.childs = [{}];
|
||||
const index = expanded.value.indexOf(node.id);
|
||||
expanded.value.splice(index, 1);
|
||||
}
|
||||
if (!node || node.sons === 0) return;
|
||||
|
||||
state.set('Tree', node);
|
||||
};
|
||||
|
||||
function getNodeIds(node) {
|
||||
|
@ -119,6 +116,10 @@ function getNodeIds(node) {
|
|||
return ids;
|
||||
}
|
||||
|
||||
function isSelected(selected) {
|
||||
if (typeof selected === 'number') return !!selected;
|
||||
}
|
||||
|
||||
watch(
|
||||
() => store.data,
|
||||
async (val) => {
|
||||
|
@ -128,18 +129,9 @@ watch(
|
|||
nodes.value[0].childs = [...val];
|
||||
const fetchedNodeKeys = val.flatMap(getNodeIds);
|
||||
state.set('Tree', [...fetchedNodeKeys]);
|
||||
|
||||
if (!store.userParams?.search) {
|
||||
val.forEach((n) => {
|
||||
formatNodeSelected(n);
|
||||
});
|
||||
store.data = null;
|
||||
expanded.value = [null];
|
||||
} else {
|
||||
for (let n of state.get('Tree')) {
|
||||
await fetchNodeLeaves(n);
|
||||
}
|
||||
expanded.value = [null, ...fetchedNodeKeys];
|
||||
expanded.value = [null, ...fetchedNodeKeys];
|
||||
for (let n of state.get('Tree')) {
|
||||
await fetchNodeLeaves(n);
|
||||
}
|
||||
previousExpandedNodes.value = new Set(expanded.value);
|
||||
},
|
||||
|
@ -147,13 +139,11 @@ watch(
|
|||
);
|
||||
|
||||
const reFetch = async () => {
|
||||
const { data } = await arrayData.fetch({ append: false });
|
||||
nodes.value = data;
|
||||
expanded.value = [null];
|
||||
await arrayData.fetch({});
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
if (store.userParams?.search) await arrayData.fetch({});
|
||||
await reFetch();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
|
@ -167,13 +157,13 @@ onUnmounted(() => {
|
|||
v-if="showSearchBar"
|
||||
v-model="store.userParams.search"
|
||||
:placeholder="$t('globals.search')"
|
||||
@update:model-value="reFetch()"
|
||||
@keydown.enter.stop.prevent="reFetch"
|
||||
>
|
||||
<template #prepend>
|
||||
<QBtn color="primary" icon="search" dense flat @click="reFetch()" />
|
||||
</template>
|
||||
</VnInput>
|
||||
<VnSearchbar :data-key="datakey" :url="url" :redirect="false" />
|
||||
<VnSearchbar v-if="!showSearchBar" :data-key="datakey" :url="url" :redirect="false" />
|
||||
<QTree
|
||||
ref="treeRef"
|
||||
:nodes="nodes"
|
||||
|
|
|
@ -101,7 +101,7 @@ describe('VnLocation', () => {
|
|||
});
|
||||
|
||||
it('Create postCode', () => {
|
||||
const postCode = '1234475';
|
||||
const postCode = Math.floor(100000 + Math.random() * 900000);
|
||||
const province = 'Valencia';
|
||||
cy.get(createLocationButton).click();
|
||||
cy.get('.q-card > h1').should('have.text', 'New postcode');
|
||||
|
@ -117,7 +117,8 @@ describe('VnLocation', () => {
|
|||
|
||||
checkVnLocation(postCode, province);
|
||||
});
|
||||
it('Create city', () => {
|
||||
|
||||
it('Create city without country', () => {
|
||||
const postCode = randomNumber();
|
||||
const province = randomString({ length: 4 });
|
||||
cy.get(createLocationButton).click();
|
||||
|
@ -133,6 +134,58 @@ describe('VnLocation', () => {
|
|||
checkVnLocation(postCode, province);
|
||||
});
|
||||
|
||||
it('Create province without country', () => {
|
||||
const provinceName = 'Saskatchew'.concat(Math.random(1 * 100));
|
||||
cy.get(createLocationButton).click();
|
||||
cy.get(
|
||||
`${createForm.prefix} > :nth-child(5) > .q-select > ${createForm.sufix} > :nth-child(2) `
|
||||
)
|
||||
.eq(0)
|
||||
.click();
|
||||
cy.selectOption('#q-portal--dialog--3 .q-select', 'one');
|
||||
cy.countSelectOptions('#q-portal--dialog--3 .q-select', 4);
|
||||
cy.get('#q-portal--dialog--3 .q-input').type(provinceName);
|
||||
|
||||
cy.get('#q-portal--dialog--3 .q-btn--standard').click();
|
||||
});
|
||||
|
||||
it('Create city with country', () => {
|
||||
const cityName = 'Saskatchew'.concat(Math.random(1 * 100));
|
||||
cy.get(createLocationButton).click();
|
||||
cy.selectOption(
|
||||
`${createForm.prefix} > :nth-child(5) > :nth-child(3) `,
|
||||
'Italia'
|
||||
);
|
||||
cy.get(
|
||||
`${createForm.prefix} > :nth-child(4) > .q-select > ${createForm.sufix} > :nth-child(2) > .q-icon`
|
||||
).click();
|
||||
cy.selectOption('#q-portal--dialog--4 .q-select', 'Province four');
|
||||
cy.countSelectOptions('#q-portal--dialog--4 .q-select', 1);
|
||||
|
||||
cy.get('#q-portal--dialog--4 .q-input').type(cityName);
|
||||
cy.get('#q-portal--dialog--4 .q-btn--standard').click();
|
||||
});
|
||||
|
||||
it('Create province with country', () => {
|
||||
const provinceName = 'Saskatchew'.concat(Math.random(1 * 100));
|
||||
cy.get(createLocationButton).click();
|
||||
cy.selectOption(
|
||||
`${createForm.prefix} > :nth-child(5) > :nth-child(3) `,
|
||||
'España'
|
||||
);
|
||||
cy.get(
|
||||
`${createForm.prefix} > :nth-child(5) > .q-select > ${createForm.sufix} > :nth-child(2) `
|
||||
)
|
||||
.eq(0)
|
||||
.click();
|
||||
|
||||
cy.selectOption('#q-portal--dialog--4 .q-select', 'one');
|
||||
cy.countSelectOptions('#q-portal--dialog--4 .q-select', 2);
|
||||
|
||||
cy.get('#q-portal--dialog--4 .q-input').type(provinceName);
|
||||
cy.get('#q-portal--dialog--4 .q-btn--standard').click();
|
||||
});
|
||||
|
||||
function checkVnLocation(postCode, province) {
|
||||
cy.get(`${createForm.prefix}`).should('not.exist');
|
||||
cy.get('.q-form > .q-card > .vn-row:nth-child(6)')
|
||||
|
|
|
@ -91,6 +91,11 @@ Cypress.Commands.add('selectOption', (selector, option) => {
|
|||
cy.get(selector).click();
|
||||
cy.get('.q-menu .q-item').contains(option).click();
|
||||
});
|
||||
Cypress.Commands.add('countSelectOptions', (selector, option) => {
|
||||
cy.waitForElement(selector);
|
||||
cy.get(selector).click();
|
||||
cy.get('.q-menu .q-item').should('have.length', option);
|
||||
});
|
||||
|
||||
Cypress.Commands.add('fillInForm', (obj, form = '.q-form > .q-card') => {
|
||||
cy.waitForElement('.q-form > .q-card');
|
||||
|
|
Loading…
Reference in New Issue