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

fixing project_mapping forms (WIP)

parent fb250f52
No related branches found
No related tags found
3 merge requests!3add export-geojson & fix slug vs title in feature_list route,!2add extra_form to feature_edit,!1format date for derniers signalements, detect click outside menu dropdown and...
...@@ -32,11 +32,7 @@ ...@@ -32,11 +32,7 @@
@click="updateLayer({ ...layer, queryable: !layer.queryable })" @click="updateLayer({ ...layer, queryable: !layer.queryable })"
class="ui checkbox" class="ui checkbox"
> >
<input <input type="checkbox" v-model="layer.queryable" name="queryable" />
type="checkbox"
:checked="layer.queryable"
name="queryable"
/>
<label for="queryable"> Requêtable</label> <label for="queryable"> Requêtable</label>
</div> </div>
<!-- {{ form.queryable.errors }} --> <!-- {{ form.queryable.errors }} -->
...@@ -65,25 +61,41 @@ export default { ...@@ -65,25 +61,41 @@ export default {
components: { components: {
Dropdown, Dropdown,
}, },
/*
data() {
return {
matchingLayer: null,
};
},
watch: {
layer(newVal) {
console.log()
this.matchingLayer = this.layers.find((el) => el.title === newVal.title);
},
}, */
computed: { computed: {
...mapState("map", ["layers", "availableLayers"]), ...mapState("map", ["layers", "availableLayers"]),
selectedLayer: { selectedLayer: {
get() { get() {
const matchingLayer = this.retrieveLayer(this.layer.title);
return { return {
name: this.layer name: matchingLayer ? matchingLayer.service : "",
? this.layers.find((el) => el.title === this.layer.title).service
: "",
value: this.layer ? this.layer.title : "", value: this.layer ? this.layer.title : "",
// id: matchingLayer ? matchingLayer.id : null, //? what could be the default value ?
}; };
}, },
set(newValue) { set(newValue) {
// console.log(newValue)
const matchingLayer = this.retrieveLayer(this.layer.title);
this.updateLayer({ this.updateLayer({
...this.layer, ...this.layer,
service: newValue.name, service: newValue.name,
title: newValue.value, title: newValue.value,
id: matchingLayer.id,
}); });
}, },
}, },
...@@ -111,13 +123,19 @@ export default { ...@@ -111,13 +123,19 @@ export default {
}, },
methods: { methods: {
retrieveLayer(title) {
return this.layers.find((el) => el.title === title);
},
removeLayer() { removeLayer() {
this.$store.commit("map/DELETE_BASEMAP_LAYER", { this.$store.commit("map/DELETE_BASEMAP_LAYER", {
basemapId: this.basemapid, basemapId: this.basemapid,
layerId: this.layer.dataKey, layerId: this.layer.dataKey,
}); });
}, },
updateLayer(layer) { updateLayer(layer) {
console.log(layer);
this.$store.commit("map/UPDATE_BASEMAP_LAYER", { this.$store.commit("map/UPDATE_BASEMAP_LAYER", {
basemapId: this.basemapid, basemapId: this.basemapid,
layerId: this.layer.dataKey, layerId: this.layer.dataKey,
...@@ -125,5 +143,15 @@ export default { ...@@ -125,5 +143,15 @@ export default {
}); });
}, },
}, },
mounted() {
const matchingLayer = this.retrieveLayer(this.layer.title);
this.updateLayer({
...this.layer,
service: matchingLayer.service,
title: matchingLayer.title,
id: matchingLayer.id,
});
},
}; };
</script> </script>
\ No newline at end of file
...@@ -2,7 +2,14 @@ ...@@ -2,7 +2,14 @@
<div class="ui segment"> <div class="ui segment">
<div class="field required"> <div class="field required">
<label for="basemap-title">Titre</label> <label for="basemap-title">Titre</label>
<input v-model="title" type="text" name="basemap-title" required /> <!-- v-model="title" -->
<input
:value="basemap.title"
@blur="updateTitle"
type="text"
name="basemap-title"
required
/>
<!-- {{ basemapForm.title.errors }} --> <!-- {{ basemapForm.title.errors }} -->
</div> </div>
...@@ -68,18 +75,6 @@ export default { ...@@ -68,18 +75,6 @@ export default {
} }
}, 0); }, 0);
}, },
title: {
get() {
return this.basemap.title || `Fond ${this.basemap.id}`;
},
set(newValue) {
this.$store.commit("map/UPDATE_BASEMAP", {
id: this.basemap.id,
title: newValue,
});
},
},
}, },
methods: { methods: {
...@@ -98,6 +93,15 @@ export default { ...@@ -98,6 +93,15 @@ export default {
this.$store.commit("map/UPDATE_BASEMAP", { this.$store.commit("map/UPDATE_BASEMAP", {
layers: [...this.basemap.layers, newLayer], layers: [...this.basemap.layers, newLayer],
id: this.basemap.id, id: this.basemap.id,
title: this.basemap.title,
});
},
updateTitle(evt) {
console.log(evt);
this.$store.commit("map/UPDATE_BASEMAP", {
id: this.basemap.id,
title: evt.target.value,
}); });
}, },
...@@ -105,6 +109,15 @@ export default { ...@@ -105,6 +109,15 @@ export default {
this.layers = this.layers.filter((layer) => layer.dataKey !== dataKey); this.layers = this.layers.filter((layer) => layer.dataKey !== dataKey);
}, },
}, },
// mounted() { //* not present in original
// if (!this.basemap.title) {
// this.$store.commit("map/UPDATE_BASEMAP", {
// id: this.basemap.id,
// title: newValue,
// });
// }
// },
}; };
</script> </script>
......
...@@ -33,6 +33,7 @@ const map = { ...@@ -33,6 +33,7 @@ const map = {
state.basemaps = basemaps; state.basemaps = basemaps;
}, },
UPDATE_BASEMAP(state, { title, id, layers }) { UPDATE_BASEMAP(state, { title, id, layers }) {
console.log(title, id, layers)
const index = state.basemaps.findIndex((el) => el.id === id); const index = state.basemaps.findIndex((el) => el.id === id);
if (index !== -1) { if (index !== -1) {
if (title) { if (title) {
...@@ -41,6 +42,7 @@ const map = { ...@@ -41,6 +42,7 @@ const map = {
if (layers) { if (layers) {
state.basemaps[index].layers = layers state.basemaps[index].layers = layers
} }
console.log(state.basemaps[index])
} }
}, },
DELETE_BASEMAP(state, basemapId) { DELETE_BASEMAP(state, basemapId) {
...@@ -142,11 +144,12 @@ const map = { ...@@ -142,11 +144,12 @@ const map = {
}, },
SAVE_BASEMAPS({ state, dispatch }) { SAVE_BASEMAPS({ state, rootState, dispatch }) {
console.log("SAVE_BASEMAPS", state.basemaps); console.log("SAVE_BASEMAPS", state.basemaps);
for (let basemap of state.basemaps) { for (let basemap of state.basemaps) {
basemap["project"] = rootState.project_slug
console.log("BASEMAP", basemap); console.log("BASEMAP", basemap);
// TODO: À transformer en PUT dès que dispo // TODO: différencier PUT & POST
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)))
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
id="title" id="title"
v-model="form.title" v-model="form.title"
/> />
<!-- {{ form.title.errors }} // ? des erreurs possibles ? --> <!-- {{ form.title.errors }} -->
</div> </div>
<div class="field"> <div class="field">
<label>Illustration du projet</label> <label>Illustration du projet</label>
...@@ -36,8 +36,7 @@ ...@@ -36,8 +36,7 @@
: DJANGO_BASE_URL + form.thumbnail : DJANGO_BASE_URL + form.thumbnail
" "
/> />
<label class="ui icon button" for="thumbnail" <label class="ui icon button" for="thumbnail">
><!-- // todo : send image to the backend and display it after -->
<i class="file icon"></i> <i class="file icon"></i>
<span class="label">{{ <span class="label">{{
form.thumbnail_name ? form.thumbnail_name : fileToImport.name form.thumbnail_name ? form.thumbnail_name : fileToImport.name
...@@ -124,7 +123,7 @@ ...@@ -124,7 +123,7 @@
<div class="ui checkbox"> <div class="ui checkbox">
<input <input
type="checkbox" type="checkbox"
:checked="form.moderation" v-model="form.moderation"
name="moderation" name="moderation"
id="moderation" id="moderation"
/> />
...@@ -137,7 +136,7 @@ ...@@ -137,7 +136,7 @@
<div class="ui checkbox"> <div class="ui checkbox">
<input <input
type="checkbox" type="checkbox"
:checked="form.is_project_type" v-model="form.is_project_type"
name="is_project_type" name="is_project_type"
id="is_project_type" id="is_project_type"
/> />
...@@ -201,7 +200,7 @@ export default { ...@@ -201,7 +200,7 @@ export default {
nb_contributors: 0, nb_contributors: 0,
is_project_type: false, is_project_type: false,
}, },
thumbnailFileSrc: require('@/assets/img/default.png'), thumbnailFileSrc: "",
}; };
}, },
...@@ -303,7 +302,14 @@ export default { ...@@ -303,7 +302,14 @@ export default {
if (this.action === "create" || this.action === "duplicate") { if (this.action === "create" || this.action === "duplicate") {
await axios await axios
<<<<<<< Updated upstream
.post(`${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/`, projectData) .post(`${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/`, projectData)
=======
.post(
`${configuration.VUE_APP_DJANGO_API_BASE}projects/`,
projectData
)
>>>>>>> Stashed changes
.then((response) => { .then((response) => {
if (response && response.status === 201 && response.data) { if (response && response.status === 201 && response.data) {
//* send thumbnail after feature_type was created //* send thumbnail after feature_type was created
...@@ -340,7 +346,9 @@ export default { ...@@ -340,7 +346,9 @@ export default {
created() { created() {
this.definePageType(); this.definePageType();
if (this.action !== "create") { if (this.action === "create") {
this.thumbnailFileSrc = require("@/assets/img/default.png");
} else if (this.action === "edit") {
if (!this.project) { if (!this.project) {
this.$store.dispatch("GET_PROJECT_INFO", this.$route.params.slug); this.$store.dispatch("GET_PROJECT_INFO", this.$route.params.slug);
} }
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<div class="ui"> <div class="ui">
<ProjectMappingBasemap <ProjectMappingBasemap
v-for="basemap in basemaps" v-for="basemap in basemaps"
:key="basemap.dataKey" :key="basemap.id"
:basemap="basemap" :basemap="basemap"
/> />
</div> </div>
...@@ -62,6 +62,8 @@ export default { ...@@ -62,6 +62,8 @@ export default {
}, },
saveChanges() { saveChanges() {
// ToDo : check if values are filled
this.$store.dispatch("map/SAVE_BASEMAPS"); this.$store.dispatch("map/SAVE_BASEMAPS");
}, },
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment