fix: vnLocation #577
|
@ -43,6 +43,15 @@ const onResponseError = (error) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (response?.status) {
|
switch (response?.status) {
|
||||||
|
case 422:
|
||||||
|
if (error.name == 'ValidationError')
|
||||||
|
message +=
|
||||||
|
' "' +
|
||||||
|
responseError.details.context +
|
||||||
|
'.' +
|
||||||
|
Object.keys(responseError.details.codes).join(',') +
|
||||||
|
'"';
|
||||||
|
break;
|
||||||
case 500:
|
case 500:
|
||||||
message = 'errors.statusInternalServerError';
|
message = 'errors.statusInternalServerError';
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -4,8 +4,8 @@ import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
import FetchData from 'components/FetchData.vue';
|
import FetchData from 'components/FetchData.vue';
|
||||||
import VnRow from 'components/ui/VnRow.vue';
|
import VnRow from 'components/ui/VnRow.vue';
|
||||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
import VnSelectProvince from 'components/VnSelectProvince.vue';
|
||||||
import VnInput from 'src/components/common/VnInput.vue';
|
import VnInput from 'components/common/VnInput.vue';
|
||||||
import FormModelPopup from './FormModelPopup.vue';
|
import FormModelPopup from './FormModelPopup.vue';
|
||||||
|
|
||||||
const emit = defineEmits(['onDataSaved']);
|
const emit = defineEmits(['onDataSaved']);
|
||||||
|
@ -45,15 +45,7 @@ const onDataSaved = (dataSaved) => {
|
||||||
v-model="data.name"
|
v-model="data.name"
|
||||||
:rules="validate('city.name')"
|
:rules="validate('city.name')"
|
||||||
/>
|
/>
|
||||||
<VnSelect
|
<VnSelectProvince v-model="data.provinceFk" />
|
||||||
:label="t('Province')"
|
|
||||||
:options="provincesOptions"
|
|
||||||
hide-selected
|
|
||||||
option-label="name"
|
|
||||||
option-value="id"
|
|
||||||
v-model="data.provinceFk"
|
|
||||||
:rules="validate('city.provinceFk')"
|
|
||||||
/>
|
|
||||||
</VnRow>
|
</VnRow>
|
||||||
</template>
|
</template>
|
||||||
</FormModelPopup>
|
</FormModelPopup>
|
||||||
|
|
|
@ -5,9 +5,9 @@ import { useI18n } from 'vue-i18n';
|
||||||
import FetchData from 'components/FetchData.vue';
|
import FetchData from 'components/FetchData.vue';
|
||||||
import VnRow from 'components/ui/VnRow.vue';
|
import VnRow from 'components/ui/VnRow.vue';
|
||||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||||
|
import VnSelectProvince from 'src/components/VnSelectProvince.vue';
|
||||||
import VnInput from 'src/components/common/VnInput.vue';
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
import CreateNewCityForm from './CreateNewCityForm.vue';
|
import CreateNewCityForm from './CreateNewCityForm.vue';
|
||||||
import CreateNewProvinceForm from './CreateNewProvinceForm.vue';
|
|
||||||
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
|
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
|
||||||
import FormModelPopup from './FormModelPopup.vue';
|
import FormModelPopup from './FormModelPopup.vue';
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ const countriesOptions = ref([]);
|
||||||
const provincesOptions = ref([]);
|
const provincesOptions = ref([]);
|
||||||
const townsLocationOptions = ref([]);
|
const townsLocationOptions = ref([]);
|
||||||
|
|
||||||
const onDataSaved = (formData) => {
|
function onDataSaved(formData) {
|
||||||
const newPostcode = {
|
const newPostcode = {
|
||||||
...formData,
|
...formData,
|
||||||
};
|
};
|
||||||
|
@ -43,25 +43,34 @@ const onDataSaved = (formData) => {
|
||||||
const countryObject = countriesOptions.value.find(
|
const countryObject = countriesOptions.value.find(
|
||||||
({ id }) => id === formData.countryFk
|
({ id }) => id === formData.countryFk
|
||||||
);
|
);
|
||||||
newPostcode.country = countryObject?.country;
|
newPostcode.country = countryObject?.name;
|
||||||
emit('onDataSaved', newPostcode);
|
emit('onDataSaved', newPostcode);
|
||||||
};
|
}
|
||||||
|
|
||||||
const onCityCreated = async ({ name, provinceFk }, formData) => {
|
async function onCityCreated({ name, provinceFk }, formData) {
|
||||||
await townsFetchDataRef.value.fetch();
|
await townsFetchDataRef.value.fetch();
|
||||||
|
await provincesFetchDataRef.value.fetch();
|
||||||
formData.townFk = townsLocationOptions.value.find((town) => town.name === name).id;
|
formData.townFk = townsLocationOptions.value.find((town) => town.name === name).id;
|
||||||
formData.provinceFk = provinceFk;
|
formData.provinceFk = provinceFk;
|
||||||
formData.countryFk = provincesOptions.value.find(
|
formData.countryFk = provincesOptions.value.find(
|
||||||
(province) => province.id === provinceFk
|
(province) => province.id === provinceFk
|
||||||
).countryFk;
|
).countryFk;
|
||||||
};
|
}
|
||||||
|
|
||||||
const onProvinceCreated = async ({ name }, formData) => {
|
function setTown(id, data) {
|
||||||
await provincesFetchDataRef.value.fetch();
|
const newTown = townsLocationOptions.value.find((town) => town.id == id);
|
||||||
formData.provinceFk = provincesOptions.value.find(
|
if (!newTown) return;
|
||||||
(province) => province.name === name
|
|
||||||
).id;
|
data.provinceFk = newTown.provinceFk;
|
||||||
};
|
data.countryFk = newTown.province.countryFk;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setProvince(id, data) {
|
||||||
|
const newProvince = provincesOptions.value.find((province) => province.id == id);
|
||||||
|
if (!newProvince) return;
|
||||||
|
|
||||||
|
data.countryFk = newProvince.countryFk;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -73,6 +82,7 @@ const onProvinceCreated = async ({ name }, formData) => {
|
||||||
/>
|
/>
|
||||||
<FetchData
|
<FetchData
|
||||||
ref="provincesFetchDataRef"
|
ref="provincesFetchDataRef"
|
||||||
|
:filter="{ include: { relation: 'country' } }"
|
||||||
@on-fetch="(data) => (provincesOptions = data)"
|
@on-fetch="(data) => (provincesOptions = data)"
|
||||||
auto-load
|
auto-load
|
||||||
url="Provinces"
|
url="Provinces"
|
||||||
|
@ -91,7 +101,7 @@ const onProvinceCreated = async ({ name }, formData) => {
|
||||||
@on-data-saved="onDataSaved"
|
@on-data-saved="onDataSaved"
|
||||||
>
|
>
|
||||||
<template #form-inputs="{ data, validate }">
|
<template #form-inputs="{ data, validate }">
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow>
|
||||||
<VnInput
|
<VnInput
|
||||||
:label="t('Postcode')"
|
:label="t('Postcode')"
|
||||||
v-model="data.code"
|
v-model="data.code"
|
||||||
|
@ -100,6 +110,7 @@ const onProvinceCreated = async ({ name }, formData) => {
|
||||||
<VnSelectDialog
|
<VnSelectDialog
|
||||||
:label="t('City')"
|
:label="t('City')"
|
||||||
:options="townsLocationOptions"
|
:options="townsLocationOptions"
|
||||||
|
@update:model-value="(value) => setTown(value, data)"
|
||||||
v-model="data.townFk"
|
v-model="data.townFk"
|
||||||
hide-selected
|
hide-selected
|
||||||
option-label="name"
|
option-label="name"
|
||||||
|
@ -107,30 +118,28 @@ const onProvinceCreated = async ({ name }, formData) => {
|
||||||
:rules="validate('postcode.city')"
|
:rules="validate('postcode.city')"
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
>
|
>
|
||||||
|
<template #option="{ itemProps, opt }">
|
||||||
|
<QItem v-bind="itemProps">
|
||||||
|
<QItemSection>
|
||||||
|
<QItemLabel>{{ opt.name }}</QItemLabel>
|
||||||
|
<QItemLabel caption>
|
||||||
|
{{ opt.province.name }},
|
||||||
|
{{ opt.province.country.name }}
|
||||||
|
</QItemLabel>
|
||||||
|
</QItemSection>
|
||||||
|
</QItem>
|
||||||
|
</template>
|
||||||
<template #form>
|
<template #form>
|
||||||
<CreateNewCityForm @on-data-saved="onCityCreated($event, data)" />
|
<CreateNewCityForm @on-data-saved="onCityCreated($event, data)" />
|
||||||
</template>
|
</template>
|
||||||
</VnSelectDialog>
|
</VnSelectDialog>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
<VnRow class="row q-gutter-md q-mb-xl">
|
<VnRow>
|
||||||
<VnSelectDialog
|
<VnSelectProvince
|
||||||
:label="t('Province')"
|
@update:model-value="(value) => setProvince(value, data)"
|
||||||
:options="provincesOptions"
|
|
||||||
hide-selected
|
|
||||||
option-label="name"
|
|
||||||
option-value="id"
|
|
||||||
v-model="data.provinceFk"
|
v-model="data.provinceFk"
|
||||||
:rules="validate('postcode.provinceFk')"
|
/>
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
<VnSelect
|
||||||
>
|
|
||||||
<template #form>
|
|
||||||
<CreateNewProvinceForm
|
|
||||||
@on-data-saved="onProvinceCreated($event, data)"
|
|
||||||
/>
|
|
||||||
</template> </VnSelectDialog
|
|
||||||
></VnRow>
|
|
||||||
<VnRow class="row q-gutter-md q-mb-xl"
|
|
||||||
><VnSelect
|
|
||||||
:label="t('Country')"
|
:label="t('Country')"
|
||||||
:options="countriesOptions"
|
:options="countriesOptions"
|
||||||
hide-selected
|
hide-selected
|
||||||
|
|
|
@ -19,8 +19,8 @@ const provinceFormData = reactive({
|
||||||
|
|
||||||
const autonomiesOptions = ref([]);
|
const autonomiesOptions = ref([]);
|
||||||
|
|
||||||
const onDataSaved = (dataSaved) => {
|
const onDataSaved = (dataSaved, requestResponse) => {
|
||||||
emit('onDataSaved', dataSaved);
|
emit('onDataSaved', dataSaved, requestResponse);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ const onDataSaved = (dataSaved) => {
|
||||||
url-create="provinces"
|
url-create="provinces"
|
||||||
model="province"
|
model="province"
|
||||||
:form-initial-data="provinceFormData"
|
:form-initial-data="provinceFormData"
|
||||||
@on-data-saved="onDataSaved($event)"
|
@on-data-saved="onDataSaved"
|
||||||
>
|
>
|
||||||
<template #form-inputs="{ data, validate }">
|
<template #form-inputs="{ data, validate }">
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow class="row q-gutter-md q-mb-md">
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
<script setup>
|
||||||
|
import { ref, watch } from 'vue';
|
||||||
|
import { useValidator } from 'src/composables/useValidator';
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
|
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
|
||||||
|
import FetchData from 'components/FetchData.vue';
|
||||||
|
import CreateNewProvinceForm from './CreateNewProvinceForm.vue';
|
||||||
|
|
||||||
|
const provinceFk = defineModel({ type: Number });
|
||||||
|
watch(provinceFk, async () => await provincesFetchDataRef.value.fetch());
|
||||||
|
|
||||||
|
const { validate } = useValidator();
|
||||||
|
const { t } = useI18n();
|
||||||
|
|
||||||
|
const provincesOptions = ref();
|
||||||
|
const provincesFetchDataRef = ref();
|
||||||
|
|
||||||
|
async function onProvinceCreated(_, { id }) {
|
||||||
|
await provincesFetchDataRef.value.fetch();
|
||||||
|
provinceFk.value = id;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<FetchData
|
||||||
|
ref="provincesFetchDataRef"
|
||||||
|
:filter="{ include: { relation: 'country' } }"
|
||||||
|
@on-fetch="(data) => (provincesOptions = data)"
|
||||||
|
auto-load
|
||||||
|
url="Provinces"
|
||||||
|
/>
|
||||||
|
<VnSelectDialog
|
||||||
|
:label="t('Province')"
|
||||||
|
:options="provincesOptions"
|
||||||
|
hide-selected
|
||||||
|
v-model="provinceFk"
|
||||||
|
:rules="validate && validate('postcode.provinceFk')"
|
||||||
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
|
>
|
||||||
|
<template #option="{ itemProps, opt }">
|
||||||
|
<QItem v-bind="itemProps">
|
||||||
|
<QItemSection>
|
||||||
|
<QItemLabel>{{ opt.name }}</QItemLabel>
|
||||||
|
<QItemLabel caption> {{ opt.country.name }} </QItemLabel>
|
||||||
|
</QItemSection>
|
||||||
|
</QItem>
|
||||||
|
</template>
|
||||||
|
<template #form>
|
||||||
|
<CreateNewProvinceForm @on-data-saved="onProvinceCreated" />
|
||||||
|
</template>
|
||||||
|
</VnSelectDialog>
|
||||||
|
</template>
|
||||||
|
<i18n>
|
||||||
|
es:
|
||||||
|
Province: Provincia
|
||||||
|
</i18n>
|
|
@ -1,123 +1,33 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, toRefs, computed, watch, onMounted } from 'vue';
|
|
||||||
import CreateNewPostcode from 'src/components/CreateNewPostcodeForm.vue';
|
import CreateNewPostcode from 'src/components/CreateNewPostcodeForm.vue';
|
||||||
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
|
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
|
||||||
import FetchData from 'components/FetchData.vue';
|
|
||||||
const emit = defineEmits(['update:modelValue', 'update:options']);
|
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const postcodesOptions = ref([]);
|
const value = defineModel({ type: [String, Number, Object] });
|
||||||
const postcodesRef = ref(null);
|
|
||||||
|
|
||||||
const $props = defineProps({
|
|
||||||
modelValue: {
|
|
||||||
type: [String, Number, Object],
|
|
||||||
default: null,
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
type: Array,
|
|
||||||
default: () => [],
|
|
||||||
},
|
|
||||||
optionLabel: {
|
|
||||||
type: String,
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
optionValue: {
|
|
||||||
type: String,
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
filterOptions: {
|
|
||||||
type: Array,
|
|
||||||
default: () => [],
|
|
||||||
},
|
|
||||||
isClearable: {
|
|
||||||
type: Boolean,
|
|
||||||
default: true,
|
|
||||||
},
|
|
||||||
defaultFilter: {
|
|
||||||
type: Boolean,
|
|
||||||
default: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const { options } = toRefs($props);
|
|
||||||
const myOptions = ref([]);
|
|
||||||
const myOptionsOriginal = ref([]);
|
|
||||||
|
|
||||||
const value = computed({
|
|
||||||
get() {
|
|
||||||
return $props.modelValue;
|
|
||||||
},
|
|
||||||
set(value) {
|
|
||||||
emit(
|
|
||||||
'update:modelValue',
|
|
||||||
postcodesOptions.value.find((p) => p.code === value)
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
locationFilter($props.modelValue);
|
|
||||||
});
|
|
||||||
|
|
||||||
function setOptions(data) {
|
|
||||||
myOptions.value = JSON.parse(JSON.stringify(data));
|
|
||||||
myOptionsOriginal.value = JSON.parse(JSON.stringify(data));
|
|
||||||
}
|
|
||||||
setOptions(options.value);
|
|
||||||
|
|
||||||
watch(options, (newValue) => {
|
|
||||||
setOptions(newValue);
|
|
||||||
});
|
|
||||||
|
|
||||||
function showLabel(data) {
|
function showLabel(data) {
|
||||||
return `${data.code} - ${data.town}(${data.province}), ${data.country}`;
|
return `${data.code} - ${data.town}(${data.province}), ${data.country}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function locationFilter(search = '') {
|
|
||||||
if (
|
|
||||||
search &&
|
|
||||||
(search.includes('undefined') || search.startsWith(`${$props.modelValue} - `))
|
|
||||||
)
|
|
||||||
return;
|
|
||||||
let where = { search };
|
|
||||||
postcodesRef.value.fetch({ filter: { where }, limit: 30 });
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleFetch(data) {
|
|
||||||
postcodesOptions.value = data;
|
|
||||||
}
|
|
||||||
function onDataSaved(newPostcode) {
|
|
||||||
postcodesOptions.value.push(newPostcode);
|
|
||||||
value.value = newPostcode.code;
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<FetchData
|
|
||||||
ref="postcodesRef"
|
|
||||||
url="Postcodes/filter"
|
|
||||||
@on-fetch="(data) => handleFetch(data)"
|
|
||||||
/>
|
|
||||||
<VnSelectDialog
|
<VnSelectDialog
|
||||||
v-if="postcodesRef"
|
|
||||||
:option-label="(opt) => showLabel(opt) ?? 'code'"
|
|
||||||
:option-value="(opt) => opt.code"
|
|
||||||
v-model="value"
|
v-model="value"
|
||||||
:options="postcodesOptions"
|
option-value="code"
|
||||||
|
option-filter-value="search"
|
||||||
|
:option-label="(opt) => showLabel(opt)"
|
||||||
|
url="Postcodes/filter"
|
||||||
|
:use-like="false"
|
||||||
:label="t('Location')"
|
:label="t('Location')"
|
||||||
:placeholder="t('search_by_postalcode')"
|
:placeholder="t('search_by_postalcode')"
|
||||||
@input-value="locationFilter"
|
|
||||||
:default-filter="false"
|
|
||||||
:input-debounce="300"
|
:input-debounce="300"
|
||||||
:class="{ required: $attrs.required }"
|
:class="{ required: $attrs.required }"
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
|
@update:model-value="(_, object) => (value = object)"
|
||||||
clearable
|
clearable
|
||||||
>
|
>
|
||||||
<template #form>
|
<template #form>
|
||||||
<CreateNewPostcode
|
<CreateNewPostcode @on-data-saved="(newValue) => (value = newValue)" />
|
||||||
@on-data-saved="onDataSaved"
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
<template #option="{ itemProps, opt }">
|
<template #option="{ itemProps, opt }">
|
||||||
<QItem v-bind="itemProps">
|
<QItem v-bind="itemProps">
|
||||||
|
|
|
@ -25,6 +25,10 @@ const $props = defineProps({
|
||||||
type: String,
|
type: String,
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
|
optionFilterValue: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
url: {
|
url: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
|
@ -70,7 +74,8 @@ const $props = defineProps({
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const requiredFieldRule = (val) => val ?? t('globals.fieldRequired');
|
const requiredFieldRule = (val) => val ?? t('globals.fieldRequired');
|
||||||
|
|
||||||
const { optionLabel, optionValue, optionFilter, options, modelValue } = toRefs($props);
|
const { optionLabel, optionValue, optionFilter, optionFilterValue, options, modelValue } =
|
||||||
|
toRefs($props);
|
||||||
const myOptions = ref([]);
|
const myOptions = ref([]);
|
||||||
const myOptionsOriginal = ref([]);
|
const myOptionsOriginal = ref([]);
|
||||||
const vnSelectRef = ref();
|
const vnSelectRef = ref();
|
||||||
|
@ -82,7 +87,12 @@ const value = computed({
|
||||||
return $props.modelValue;
|
return $props.modelValue;
|
||||||
},
|
},
|
||||||
set(value) {
|
set(value) {
|
||||||
emit('update:modelValue', value);
|
setOptions(myOptionsOriginal.value);
|
||||||
|
emit(
|
||||||
|
'update:modelValue',
|
||||||
|
value,
|
||||||
|
value && myOptions.value.find((o) => o[optionValue.value] == value)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -137,16 +147,19 @@ async function fetchFilter(val) {
|
||||||
if (!$props.url || !dataRef.value) return;
|
if (!$props.url || !dataRef.value) return;
|
||||||
|
|
||||||
const { fields, sortBy, limit } = $props;
|
const { fields, sortBy, limit } = $props;
|
||||||
let key = optionFilter.value ?? optionLabel.value;
|
const key =
|
||||||
|
optionFilterValue.value ??
|
||||||
if (new RegExp(/\d/g).test(val)) key = optionValue.value;
|
(new RegExp(/\d/g).test(val)
|
||||||
|
? optionValue.value
|
||||||
|
: optionFilter.value ?? optionLabel.value);
|
||||||
|
|
||||||
const defaultWhere = $props.useLike
|
const defaultWhere = $props.useLike
|
||||||
? { [key]: { like: `%${val}%` } }
|
? { [key]: { like: `%${val}%` } }
|
||||||
: { [key]: val };
|
: { [key]: val };
|
||||||
const where = { ...(val ? defaultWhere : {}), ...$props.where };
|
const where = { ...(val ? defaultWhere : {}), ...$props.where };
|
||||||
const fetchOptions = { where, order: sortBy, limit };
|
const fetchOptions = { where, limit };
|
||||||
if (fields) fetchOptions.fields = fields;
|
if (fields) fetchOptions.fields = fields;
|
||||||
|
if (sortBy) fetchOptions.order = sortBy;
|
||||||
return dataRef.value.fetch(fetchOptions);
|
return dataRef.value.fetch(fetchOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,12 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed } from 'vue';
|
import { ref, computed } from 'vue';
|
||||||
|
|
||||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
|
||||||
|
|
||||||
import { useRole } from 'src/composables/useRole';
|
import { useRole } from 'src/composables/useRole';
|
||||||
|
|
||||||
|
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||||
const emit = defineEmits(['update:modelValue']);
|
const emit = defineEmits(['update:modelValue']);
|
||||||
|
|
||||||
|
const value = defineModel({ type: [String, Number, Object] });
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
modelValue: {
|
|
||||||
type: [String, Number, Object],
|
|
||||||
default: null,
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
type: Array,
|
|
||||||
default: () => [],
|
|
||||||
},
|
|
||||||
rolesAllowedToCreate: {
|
rolesAllowedToCreate: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => ['developer'],
|
default: () => ['developer'],
|
||||||
|
@ -33,15 +24,6 @@ const $props = defineProps({
|
||||||
const role = useRole();
|
const role = useRole();
|
||||||
const showForm = ref(false);
|
const showForm = ref(false);
|
||||||
|
|
||||||
const value = computed({
|
|
||||||
get() {
|
|
||||||
return $props.modelValue;
|
|
||||||
},
|
|
||||||
set(value) {
|
|
||||||
emit('update:modelValue', value);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const isAllowedToCreate = computed(() => {
|
const isAllowedToCreate = computed(() => {
|
||||||
return role.hasAny($props.rolesAllowedToCreate);
|
return role.hasAny($props.rolesAllowedToCreate);
|
||||||
});
|
});
|
||||||
|
@ -52,7 +34,11 @@ const toggleForm = () => {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<VnSelect v-model="value" :options="options" v-bind="$attrs">
|
<VnSelect
|
||||||
|
v-model="value"
|
||||||
|
v-bind="$attrs"
|
||||||
|
@update:model-value="(...args) => emit('update:modelValue', ...args)"
|
||||||
|
>
|
||||||
<template v-if="isAllowedToCreate" #append>
|
<template v-if="isAllowedToCreate" #append>
|
||||||
<QIcon
|
<QIcon
|
||||||
@click.stop.prevent="toggleForm()"
|
@click.stop.prevent="toggleForm()"
|
||||||
|
|
|
@ -15,7 +15,6 @@ const route = useRoute();
|
||||||
|
|
||||||
const typesTaxes = ref([]);
|
const typesTaxes = ref([]);
|
||||||
const typesTransactions = ref([]);
|
const typesTransactions = ref([]);
|
||||||
const postcodesOptions = ref([]);
|
|
||||||
|
|
||||||
function handleLocation(data, location) {
|
function handleLocation(data, location) {
|
||||||
const { town, code, provinceFk, countryFk } = location ?? {};
|
const { town, code, provinceFk, countryFk } = location ?? {};
|
||||||
|
@ -95,7 +94,6 @@ function handleLocation(data, location) {
|
||||||
<VnLocation
|
<VnLocation
|
||||||
:rules="validate('Worker.postcode')"
|
:rules="validate('Worker.postcode')"
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
:options="postcodesOptions"
|
|
||||||
v-model="data.postcode"
|
v-model="data.postcode"
|
||||||
@update:model-value="(location) => handleLocation(data, location)"
|
@update:model-value="(location) => handleLocation(data, location)"
|
||||||
>
|
>
|
||||||
|
|
|
@ -18,7 +18,6 @@ const initialData = reactive({
|
||||||
|
|
||||||
const workersOptions = ref([]);
|
const workersOptions = ref([]);
|
||||||
const businessTypesOptions = ref([]);
|
const businessTypesOptions = ref([]);
|
||||||
const postcodesOptions = ref([]);
|
|
||||||
|
|
||||||
function handleLocation(data, location) {
|
function handleLocation(data, location) {
|
||||||
const { town, code, provinceFk, countryFk } = location ?? {};
|
const { town, code, provinceFk, countryFk } = location ?? {};
|
||||||
|
@ -88,7 +87,6 @@ function handleLocation(data, location) {
|
||||||
<VnLocation
|
<VnLocation
|
||||||
:rules="validate('Worker.postcode')"
|
:rules="validate('Worker.postcode')"
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
:options="postcodesOptions"
|
|
||||||
v-model="data.location"
|
v-model="data.location"
|
||||||
@update:model-value="(location) => handleLocation(data, location)"
|
@update:model-value="(location) => handleLocation(data, location)"
|
||||||
>
|
>
|
||||||
|
|
|
@ -15,7 +15,6 @@ import { toDate } from 'src/filters';
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const postcodesOptions = ref([]);
|
|
||||||
const tableRef = ref();
|
const tableRef = ref();
|
||||||
|
|
||||||
const columns = computed(() => [
|
const columns = computed(() => [
|
||||||
|
@ -420,7 +419,6 @@ function handleLocation(data, location) {
|
||||||
<template #more-create-dialog="{ data }">
|
<template #more-create-dialog="{ data }">
|
||||||
<VnLocation
|
<VnLocation
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
:options="postcodesOptions"
|
|
||||||
v-model="data.location"
|
v-model="data.location"
|
||||||
@update:model-value="(location) => handleLocation(data, location)"
|
@update:model-value="(location) => handleLocation(data, location)"
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -21,7 +21,6 @@ const formInitialData = reactive({ isDefaultAddress: false });
|
||||||
|
|
||||||
const urlCreate = ref('');
|
const urlCreate = ref('');
|
||||||
|
|
||||||
const postcodesOptions = ref([]);
|
|
||||||
const agencyModes = ref([]);
|
const agencyModes = ref([]);
|
||||||
const incoterms = ref([]);
|
const incoterms = ref([]);
|
||||||
const customsAgents = ref([]);
|
const customsAgents = ref([]);
|
||||||
|
@ -94,7 +93,6 @@ function handleLocation(data, location) {
|
||||||
<VnLocation
|
<VnLocation
|
||||||
:rules="validate('Worker.postcode')"
|
:rules="validate('Worker.postcode')"
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
:options="postcodesOptions"
|
|
||||||
v-model="data.location"
|
v-model="data.location"
|
||||||
@update:model-value="(location) => handleLocation(data, location)"
|
@update:model-value="(location) => handleLocation(data, location)"
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -18,7 +18,6 @@ const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const urlUpdate = ref('');
|
const urlUpdate = ref('');
|
||||||
const postcodesOptions = ref([]);
|
|
||||||
const agencyModes = ref([]);
|
const agencyModes = ref([]);
|
||||||
const incoterms = ref([]);
|
const incoterms = ref([]);
|
||||||
const customsAgents = ref([]);
|
const customsAgents = ref([]);
|
||||||
|
@ -178,7 +177,6 @@ function handleLocation(data, location) {
|
||||||
<VnLocation
|
<VnLocation
|
||||||
:rules="validate('Worker.postcode')"
|
:rules="validate('Worker.postcode')"
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
:options="postcodesOptions"
|
|
||||||
v-model="data.postalCode"
|
v-model="data.postalCode"
|
||||||
@update:model-value="(location) => handleLocation(data, location)"
|
@update:model-value="(location) => handleLocation(data, location)"
|
||||||
></VnLocation>
|
></VnLocation>
|
||||||
|
|
|
@ -11,7 +11,6 @@ const { t } = useI18n();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const postcodesOptions = ref([]);
|
|
||||||
const viewAction = ref();
|
const viewAction = ref();
|
||||||
const updateAddressId = ref(null);
|
const updateAddressId = ref(null);
|
||||||
const newAddressForm = reactive({
|
const newAddressForm = reactive({
|
||||||
|
@ -85,7 +84,6 @@ function handleLocation(data, location) {
|
||||||
<VnLocation
|
<VnLocation
|
||||||
:rules="validate('Worker.postcode')"
|
:rules="validate('Worker.postcode')"
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
:options="postcodesOptions"
|
|
||||||
v-model="data.location"
|
v-model="data.location"
|
||||||
@update:model-value="(location) => handleLocation(data, location)"
|
@update:model-value="(location) => handleLocation(data, location)"
|
||||||
>
|
>
|
||||||
|
|
|
@ -17,7 +17,6 @@ const sageTaxTypesOptions = ref([]);
|
||||||
const sageWithholdingsOptions = ref([]);
|
const sageWithholdingsOptions = ref([]);
|
||||||
const sageTransactionTypesOptions = ref([]);
|
const sageTransactionTypesOptions = ref([]);
|
||||||
const supplierActivitiesOptions = ref([]);
|
const supplierActivitiesOptions = ref([]);
|
||||||
const postcodesOptions = ref([]);
|
|
||||||
|
|
||||||
function handleLocation(data, location) {
|
function handleLocation(data, location) {
|
||||||
const { town, code, provinceFk, countryFk } = location ?? {};
|
const { town, code, provinceFk, countryFk } = location ?? {};
|
||||||
|
@ -131,7 +130,6 @@ function handleLocation(data, location) {
|
||||||
<VnLocation
|
<VnLocation
|
||||||
:rules="validate('Worker.postcode')"
|
:rules="validate('Worker.postcode')"
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
:options="postcodesOptions"
|
|
||||||
v-model="data.postCode"
|
v-model="data.postCode"
|
||||||
@update:model-value="(location) => handleLocation(data, location)"
|
@update:model-value="(location) => handleLocation(data, location)"
|
||||||
>
|
>
|
||||||
|
|
|
@ -21,7 +21,6 @@ const companiesOptions = ref([]);
|
||||||
const workersOptions = ref([]);
|
const workersOptions = ref([]);
|
||||||
const payMethodsOptions = ref([]);
|
const payMethodsOptions = ref([]);
|
||||||
const bankEntitiesOptions = ref([]);
|
const bankEntitiesOptions = ref([]);
|
||||||
const postcodesOptions = ref([]);
|
|
||||||
const formData = ref({ isFreelance: false });
|
const formData = ref({ isFreelance: false });
|
||||||
const defaultPayMethod = ref(0);
|
const defaultPayMethod = ref(0);
|
||||||
|
|
||||||
|
@ -173,7 +172,6 @@ onBeforeMount(async () => {
|
||||||
<VnLocation
|
<VnLocation
|
||||||
:rules="validate('Worker.postcode')"
|
:rules="validate('Worker.postcode')"
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
:options="postcodesOptions"
|
|
||||||
v-model="data.location"
|
v-model="data.location"
|
||||||
@update:model-value="(location) => handleLocation(data, location)"
|
@update:model-value="(location) => handleLocation(data, location)"
|
||||||
:disable="formData.isFreelance"
|
:disable="formData.isFreelance"
|
||||||
|
|
|
@ -1,30 +1,31 @@
|
||||||
const locationOptions = '[role="listbox"] > div.q-virtual-scroll__content > .q-item';
|
|
||||||
describe('VnLocation', () => {
|
describe('VnLocation', () => {
|
||||||
|
const locationOptions = '[role="listbox"] > div.q-virtual-scroll__content > .q-item';
|
||||||
const dialogInputs = '.q-dialog label input';
|
const dialogInputs = '.q-dialog label input';
|
||||||
|
const createLocationButton = '.q-form > .q-card > .vn-row:nth-child(6) .--add-icon';
|
||||||
|
const inputLocation = '.q-form input[aria-label="Location"]';
|
||||||
describe('Worker Create', () => {
|
describe('Worker Create', () => {
|
||||||
const inputLocation = '.q-form input[aria-label="Location"]';
|
// beforeEach(() => {
|
||||||
beforeEach(() => {
|
// cy.viewport(1280, 720);
|
||||||
cy.viewport(1280, 720);
|
// cy.login('developer');
|
||||||
cy.login('developer');
|
// cy.visit('/#/worker/create', { timeout: 5000 });
|
||||||
cy.visit('/#/worker/create', { timeout: 5000 });
|
// cy.waitForElement('.q-card');
|
||||||
cy.waitForElement('.q-card');
|
// });
|
||||||
});
|
// it('Show all options', function () {
|
||||||
it('Show all options', function () {
|
// cy.get(inputLocation).click();
|
||||||
cy.get(inputLocation).click();
|
// cy.get(locationOptions).should('have.length.at.least', 5);
|
||||||
cy.get(locationOptions).should('have.length.at.least', 5);
|
// });
|
||||||
});
|
// it('input filter location as "al"', function () {
|
||||||
it('input filter location as "al"', function () {
|
// cy.get(inputLocation).click();
|
||||||
cy.get(inputLocation).click();
|
// cy.get(inputLocation).clear();
|
||||||
cy.get(inputLocation).clear();
|
// cy.get(inputLocation).type('al');
|
||||||
cy.get(inputLocation).type('al');
|
// cy.get(locationOptions).should('have.length.at.least', 3);
|
||||||
cy.get(locationOptions).should('have.length.at.least', 3);
|
// });
|
||||||
});
|
// it('input filter location as "ecuador"', function () {
|
||||||
it('input filter location as "ecuador"', function () {
|
// cy.get(inputLocation).click();
|
||||||
cy.get(inputLocation).click();
|
// cy.get(inputLocation).clear();
|
||||||
cy.get(inputLocation).clear();
|
// cy.get(inputLocation).type('ecuador');
|
||||||
cy.get(inputLocation).type('ecuador');
|
// cy.get(locationOptions).should('have.length.at.least', 1);
|
||||||
cy.get(locationOptions).should('have.length.at.least', 1);
|
// });
|
||||||
});
|
|
||||||
});
|
});
|
||||||
describe('Fiscal-data', () => {
|
describe('Fiscal-data', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -32,25 +33,34 @@ describe('VnLocation', () => {
|
||||||
cy.login('developer');
|
cy.login('developer');
|
||||||
cy.visit('/#/supplier/567/fiscal-data', { timeout: 7000 });
|
cy.visit('/#/supplier/567/fiscal-data', { timeout: 7000 });
|
||||||
cy.waitForElement('.q-form');
|
cy.waitForElement('.q-form');
|
||||||
|
cy.get(createLocationButton).click();
|
||||||
});
|
});
|
||||||
it('Create postCode', function () {
|
it('Create postCode', () => {
|
||||||
cy.get('.q-form > .q-card > .vn-row:nth-child(6) .--add-icon').click();
|
const postCode = '1234453';
|
||||||
cy.get('.q-card > h1').should('have.text', 'New postcode');
|
cy.get('.q-card > h1').should('have.text', 'New postcode');
|
||||||
cy.get(dialogInputs).eq(0).clear('12');
|
cy.get(dialogInputs).eq(0).clear();
|
||||||
cy.get(dialogInputs).eq(0).type('1234453');
|
cy.get(dialogInputs).eq(0).type(postCode);
|
||||||
cy.selectOption(
|
cy.selectOption(
|
||||||
'.q-dialog__inner > .column > #formModel > .q-card > :nth-child(4) > .q-select > .q-field__inner > .q-field__control ',
|
'.q-dialog__inner > .column > #formModel > .q-card > :nth-child(4) > .q-select > .q-field__inner > .q-field__control ',
|
||||||
'Valencia'
|
'Valencia'
|
||||||
);
|
);
|
||||||
cy.selectOption(
|
|
||||||
'.q-dialog__inner > .column > #formModel > .q-card > :nth-child(5) > .q-select > .q-field__inner > .q-field__control ',
|
|
||||||
'Province one'
|
|
||||||
);
|
|
||||||
cy.selectOption(
|
|
||||||
'.q-dialog__inner > .column > #formModel > .q-card > :nth-child(6) > .q-select > .q-field__inner > .q-field__control ',
|
|
||||||
'España'
|
|
||||||
);
|
|
||||||
cy.get('.q-mt-lg > .q-btn--standard').click();
|
cy.get('.q-mt-lg > .q-btn--standard').click();
|
||||||
|
cy.get(':nth-child(6) > .q-input input').contains(postCode);
|
||||||
});
|
});
|
||||||
|
// it('Create city', () => {
|
||||||
|
// const postCode = '9011';
|
||||||
|
// const province = 'Saskatchewan';
|
||||||
|
// cy.get(dialogInputs).eq(0).type(postCode);
|
||||||
|
// // city create button
|
||||||
|
// cy.get(
|
||||||
|
// '.q-dialog__inner > .column > #formModel > .q-card > :nth-child(4) > .q-select > .q-field__inner > .q-field__control > :nth-child(2) > .q-icon'
|
||||||
|
// ).click();
|
||||||
|
// cy.selectOption('#q-portal--dialog--2 .q-select', 'one');
|
||||||
|
// cy.get('#q-portal--dialog--2 .q-input').type(province);
|
||||||
|
// cy.get('#q-portal--dialog--2 .q-btn--standard').click();
|
||||||
|
// cy.get('#q-portal--dialog--1 .q-btn--standard').click();
|
||||||
|
// cy.get(inputLocation).contains(postCode);
|
||||||
|
// cy.get(inputLocation).contains(province);
|
||||||
|
// });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue