Skip to content

Commit

Permalink
fix issue: location url not being registered when creating map view
Browse files Browse the repository at this point in the history
  • Loading branch information
manuGil committed Jul 1, 2024
1 parent 054108d commit 2e9dc37
Showing 1 changed file with 43 additions and 14 deletions.
57 changes: 43 additions & 14 deletions frontend/stores/mapview.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const useMapViewStore = defineStore('mapView', {
id: null,
url: null,
name: null,
description: '',
location: null,
mapServiceUrl: null,
zoomLevel: null,
Expand Down Expand Up @@ -51,34 +52,28 @@ export const useMapViewStore = defineStore('mapView', {
updateLocation(location) {
this.location = location
},
async createMapview() {
async createLocations(){
/**
* Create a new mapview in the backend with the current state of the store
* Creates locations using the geometries in state.geometries
*
* returns new state of location.
*/
// const csrftoken = user.getCookie('csrftoken');
// var location_url;
const config = setRequestConfig({ method: 'POST', headers:{
'Content-Type': 'application/json'
}, body: this.getFormattedBody })

// create the location collection, if there are geometries
if (Object.keys(this.geometries).length !== 0) {
const {data, error, pending } = await useAsyncData( () => $cmsApi(`/locations/`,
{ method: 'POST',
headers: {'Content-Type': 'application/json'},
body: {
name: this.name,
description: 'created from mapview store'
description: this.description,
}
}
));

if (data.value) {
this.location = data.value.url
// console.log('location_url //> ', data)
} else {
throw new Error('Error creating location collection //>', data)
}
}

if (error.value) {
throw new Error('Error creating location collection //> ', error.value)
Expand Down Expand Up @@ -117,10 +112,33 @@ export const useMapViewStore = defineStore('mapView', {
}
})


} else {
this.location = null
};
return this.location

},
async createMapview() {
/**
* Create a new mapview in the backend with the current state of the store
*/
// const csrftoken = user.getCookie('csrftoken');
// var location_url;

const location_url = await this.createLocations();

const config = setRequestConfig({ method: 'POST', headers:{
'Content-Type': 'application/json'
}, body: {
name: this.name,
map_service_url: this.mapServiceUrl,
options: {
zoom: this.zoomLevel,
center: this.center
},
location: location_url
}
})

const global = useGlobalStore()
// const config = setRequestConfig({ method: 'POST', body: this.getFormattedBody })
Expand Down Expand Up @@ -148,7 +166,18 @@ export const useMapViewStore = defineStore('mapView', {
async updateMapview(mapview_url) {
const global = useGlobalStore()
// console.log('mapview url at store //> ', mapview_url)
const config = setRequestConfig({ method: 'PATCH', body: this.getFormattedBody })
const config = setRequestConfig({ method: 'PATCH',
body: {
name: this.name,
map_service_url: this.mapServiceUrl,
options: {
zoom: this.zoomLevel,
center: this.center
},
location: this.location,
}
})

const { data, error, refresh } = await useAsyncData( () => $cmsApi(`${mapview_url}`, config));

if (error.value) {
Expand Down

0 comments on commit 2e9dc37

Please sign in to comment.