diff --git a/src/components/generic/address-input/AddressInput.scss b/src/components/generic/address-input/AddressInput.scss deleted file mode 100644 index 1adfc3aea..000000000 --- a/src/components/generic/address-input/AddressInput.scss +++ /dev/null @@ -1,36 +0,0 @@ -.address-input { - position: relative; - display: inline-block; - - &__suggestions { - position: absolute; - z-index: 1; - top: 100%; - left: 0; - width: 100%; - margin-top: calc(var(--spacing-unit) / 2); - padding: calc(var(--spacing-unit) / 2) 0; - border-radius: 2px; - box-shadow: var(--box-shadow); - background-color: var(--color-white); - - &__item { - display: flex; - align-items: center; - gap: calc(var(--spacing-unit) / 2); - padding: var(--spacing-unit); - cursor: pointer; - - &.hovered, - &:hover { - background-color: var(--color-silver-light); - } - - &__icon { - width: 16px; - height: 16px; - color: var(--color-primary); - } - } - } -} diff --git a/src/components/generic/address-input/AddressInput.vue b/src/components/generic/address-input/AddressInput.vue index b827e263d..5b87c71bc 100644 --- a/src/components/generic/address-input/AddressInput.vue +++ b/src/components/generic/address-input/AddressInput.vue @@ -138,4 +138,41 @@ export default { }; - + diff --git a/src/components/specific/models/model-location-form/ModelLocationForm.css b/src/components/specific/models/model-location-form/ModelLocationForm.css index 54094a487..7b6062ffc 100644 --- a/src/components/specific/models/model-location-form/ModelLocationForm.css +++ b/src/components/specific/models/model-location-form/ModelLocationForm.css @@ -19,13 +19,25 @@ gap: var(--spacing-unit); padding: calc(var(--spacing-unit) / 2) var(--spacing-unit); + transition: padding-bottom 0.3s ease-out; + + &.submit { + padding-bottom: calc(var(--spacing-unit) * 2); + } + .model-location-form__form-control__input { flex-grow: 1; font-size: 1rem; } + .model-location-form__form-control__checkbox { + position: absolute; + bottom: calc(0px - var(--spacing-unit) * 2); + text-wrap: nowrap; + } + .model-location-form__form-control__close-btn { color: var(--color-granite-light); } } -} +} \ No newline at end of file diff --git a/src/components/specific/models/model-location-form/ModelLocationForm.vue b/src/components/specific/models/model-location-form/ModelLocationForm.vue index 43b619baa..ce6a3cf2d 100644 --- a/src/components/specific/models/model-location-form/ModelLocationForm.vue +++ b/src/components/specific/models/model-location-form/ModelLocationForm.vue @@ -5,7 +5,7 @@ :longitude="inputLongitude" :latitude="inputLatitude" /> -
+
@@ -81,7 +89,7 @@ const props = defineProps({ const emit = defineEmits(["close", "location-updated"]); -const { createModelLocation, updateModelLocation } = useModels(); +const { createModelLocation, updateModelLocation, updateProjectModelsLocation } = useModels(); const isSubmitStep = ref(false); const checkLoading = ref(false); @@ -90,6 +98,7 @@ const submitLoading = inject("loading", false); const inputAddress = ref(""); const inputLongitude = ref(0); const inputLatitude = ref(0); +const applyToAllModels = ref(false); const checkAddress = async () => { if (inputAddress.value) { @@ -106,17 +115,19 @@ const checkAddress = async () => { const submitAddress = async () => { const [latDMS, longDMS] = DD2DMS(inputLatitude.value, inputLongitude.value) - console.log([inputLatitude.value, inputLongitude.value]) - console.log([latDMS, longDMS]) + const location = { site: props.site, address: inputAddress.value, longitude: longDMS, latitude: latDMS }; + try { submitLoading.value = true; - if (props.site) { + if (applyToAllModels.value) { + await updateProjectModelsLocation(props.project, location); + } else if (props.site) { await updateModelLocation(props.project, props.model, location); } else { await createModelLocation(props.project, props.model, location); @@ -127,9 +138,10 @@ const submitAddress = async () => { } }; -const cancel = () => { +const changeAddress = () => { isSubmitStep.value = false; }; + const close = () => { inputAddress.value = ""; isSubmitStep.value = false; diff --git a/src/i18n/lang/en.json b/src/i18n/lang/en.json index 63d5ac73e..49ab7322c 100644 --- a/src/i18n/lang/en.json +++ b/src/i18n/lang/en.json @@ -228,7 +228,8 @@ "addLocationButtonText": "Fill in" }, "ModelLocationForm": { - "addressInputPlaceholder": "Enter address" + "addressInputPlaceholder": "Enter address", + "applyToAllModels": "Apply to all models" }, "ModelsActionBar": { "mergeButtonText": "Merge" @@ -981,4 +982,4 @@ "title": "Delete {visasCount} visas", "message": "You are about to delete the visas on the following files:" } -} +} \ No newline at end of file diff --git a/src/i18n/lang/fr.json b/src/i18n/lang/fr.json index 42dc966f4..fa257f708 100644 --- a/src/i18n/lang/fr.json +++ b/src/i18n/lang/fr.json @@ -321,7 +321,8 @@ "addLocationButtonText": "Renseigner" }, "ModelLocationForm": { - "addressInputPlaceholder": "Entrer une adresse" + "addressInputPlaceholder": "Entrer une adresse", + "applyToAllModels": "Appliquer à tous les modèles" }, "ModelsActionBar": { "mergeButtonText": "Fusionner" @@ -981,4 +982,4 @@ "title": "Suppression de {visasCount} visas", "message": "Vous êtes sur le point de supprimer les visas sur les fichiers suivants :" } -} +} \ No newline at end of file diff --git a/src/services/FileService.js b/src/services/FileService.js index 8e90feb0d..9aca0a6e1 100644 --- a/src/services/FileService.js +++ b/src/services/FileService.js @@ -1,4 +1,3 @@ -import eachLimit from "async/eachLimit"; import { FILE_TYPE } from "../config/files.js"; import { download } from "../utils/download.js"; import { segregate } from "../utils/file-structure.js"; diff --git a/src/state/models.js b/src/state/models.js index 1eacfdbf2..4a87396d9 100644 --- a/src/state/models.js +++ b/src/state/models.js @@ -1,3 +1,4 @@ +import eachLimit from "async/eachLimit"; import { reactive, readonly, toRefs } from "vue"; import ModelService from "../services/ModelService.js"; @@ -80,18 +81,12 @@ const fetchModelLocation = async (project, model) => { ); let siteAddressValue, refLongitudeValue, refLatitudeValue; if (site && site.attributes) { - // Extract SiteAddress, RefLongitude and RefLatitude - // values from model site attributes. + // Extract SiteAddress, RefLongitude and RefLatitude values from model site attributes. const { properties } = site.attributes; - siteAddressValue = ( - properties.find(p => p.definition.name === "SiteAddress") || {} - ).value; - refLongitudeValue = ( - properties.find(p => p.definition.name === "RefLongitude") || {} - ).value; - refLatitudeValue = ( - properties.find(p => p.definition.name === "RefLatitude") || {} - ).value; + const prop = name => properties.find(p => p.definition.name === name); + siteAddressValue = prop("SiteAddress")?.value; + refLongitudeValue = prop("RefLongitude")?.value; + refLatitudeValue = prop("RefLatitude")?.value; } return { site, @@ -138,18 +133,14 @@ const updateModelLocation = async ( { site, address, longitude, latitude } ) => { let siteAddressID, refLongitudeID, refLatitudeID; - // Extract SiteAddress, RefLongitude and RefLatitude - // IDs from model site attributes. + + // Extract SiteAddress, RefLongitude and RefLatitude IDs from model site attributes. const { properties } = site.attributes; - siteAddressID = ( - properties.find(p => p.definition.name === "SiteAddress") || {} - ).id; - refLongitudeID = ( - properties.find(p => p.definition.name === "RefLongitude") || {} - ).id; - refLatitudeID = ( - properties.find(p => p.definition.name === "RefLatitude") || {} - ).id; + const prop = name => properties.find(p => p.definition.name === name); + siteAddressID = prop("SiteAddress")?.id; + refLongitudeID = prop("RefLongitude")?.id; + refLatitudeID = prop("RefLatitude")?.id; + const props = [ { id: siteAddressID, name: "SiteAddress", value: address }, { id: refLongitudeID, name: "RefLongitude", value: longitude }, @@ -164,6 +155,25 @@ const updateModelLocation = async ( return newProperties; }; +const updateProjectModelsLocation = (project, location) => { + return eachLimit( + state.projectModels, + 5, + async model => { + const [site] = await ModelService.fetchModelElementsByType( + project, + model, + "IfcSite" + ); + if (site) { + await updateModelLocation(project, model, { ...location, site }); + } else { + await createModelLocation(project, model, location); + } + } + ); +}; + export function useModels() { const readonlyState = readonly(state); return { @@ -181,6 +191,7 @@ export function useModels() { softDeleteModels, fetchModelLocation, createModelLocation, - updateModelLocation + updateModelLocation, + updateProjectModelsLocation, }; }