Skip to content
Snippets Groups Projects
Commit 6515f54b authored by Timothee P's avatar Timothee P :sunflower:
Browse files

implement separation of put and post for basemaps

parent 3ce0841d
No related branches found
No related tags found
No related merge requests found
...@@ -122,7 +122,7 @@ export default { ...@@ -122,7 +122,7 @@ export default {
}, },
created() { created() {
if (this.basemap.layers) { if (this.basemap.layers) { //* add datakeys to layers coming from api
this.fillLayersWithDatakey(this.basemap.layers); this.fillLayersWithDatakey(this.basemap.layers);
} }
}, },
... ...
......
...@@ -148,17 +148,28 @@ const map = { ...@@ -148,17 +148,28 @@ const map = {
}, },
SAVE_BASEMAPS({ state, rootState, dispatch }) { SAVE_BASEMAPS({ state, rootState, dispatch }, newBasemapIds) {
for (let basemap of state.basemaps) { for (let basemap of state.basemaps) {
basemap["project"] = rootState.project_slug basemap["project"] = rootState.project_slug
// TODO: différencier PUT & POST // TODO: différencier PUT & POST
console.log(newBasemapIds.includes(basemap.id), newBasemapIds, basemap.id);
if (newBasemapIds.includes(basemap.id)) {
axios axios
.post(`${DJANGO_API_BASE}base-maps/`, basemap) .post(`${DJANGO_API_BASE}base-maps/`, basemap)
.then((response) => (console.log(response.data))) .then((response) => (console.log(response.data)))
.catch((error) => { .catch((error) => {
throw error; throw error;
}); });
} else {
axios
.put(`${DJANGO_API_BASE}base-maps/${basemap.id}/`, basemap)
.then((response) => (console.log(response.data)))
.catch((error) => {
throw error;
});
}
} }
//* delete in the backend the basemaps that was rewoved from the front
for (let basemapId of state.basemapsToDelete) { for (let basemapId of state.basemapsToDelete) {
dispatch("DELETE_BASEMAP", basemapId); dispatch("DELETE_BASEMAP", basemapId);
} }
... ...
......
...@@ -51,6 +51,12 @@ export default { ...@@ -51,6 +51,12 @@ export default {
ProjectMappingBasemap: Project_mapping_basemap, ProjectMappingBasemap: Project_mapping_basemap,
}, },
data() {
return {
newBasemapIds: [],
};
},
computed: { computed: {
...mapState("map", ["basemaps"]), ...mapState("map", ["basemaps"]),
...mapGetters("map", ["basemapMaxId"]), ...mapGetters("map", ["basemapMaxId"]),
...@@ -58,13 +64,13 @@ export default { ...@@ -58,13 +64,13 @@ export default {
methods: { methods: {
addBasemap() { addBasemap() {
this.newBasemapIds.push(this.basemapMaxId + 1); //* register new basemaps to seperate post and put
this.$store.commit("map/CREATE_BASEMAP", this.basemapMaxId + 1); this.$store.commit("map/CREATE_BASEMAP", this.basemapMaxId + 1);
}, },
saveChanges() { saveChanges() {
// ToDo : check if values are filled // ToDo : check if values are filled
this.$store.dispatch("map/SAVE_BASEMAPS"); this.$store.dispatch("map/SAVE_BASEMAPS", this.newBasemapIds);
}, },
}, },
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment