Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • geocontrib/geocontrib-frontend
  • ext_matthieu/geocontrib-frontend
  • fnecas/geocontrib-frontend
  • MatthieuE/geocontrib-frontend
4 results
Show changes
Commits on Source (14)
{ {
"name": "geocontrib-frontend", "name": "geocontrib-frontend",
"version": "2.3.1", "version": "2.3.2-rc1",
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "npm run init-proxy & npm run init-serve", "serve": "npm run init-proxy & npm run init-serve",
......
...@@ -49,7 +49,7 @@ L.TileLayer.BetterWMS = L.TileLayer.WMS.extend({ ...@@ -49,7 +49,7 @@ L.TileLayer.BetterWMS = L.TileLayer.WMS.extend({
getFeatureInfo: function (evt) { getFeatureInfo: function (evt) {
if (this.wmsParams.basemapId != undefined) { if (this.wmsParams.basemapId != undefined) {
const queryableLayerSelected = document.getElementById(`queryable-layers-selector-${this.wmsParams.basemapId}`).getElementsByClassName('selected')[0].innerHTML; const queryableLayerSelected = document.getElementById(`queryable-layers-selector-${this.wmsParams.basemapId}`).getElementsByClassName('selected')[0].textContent;
if (queryableLayerSelected.trim() === this.wmsParams.title.trim()) { if (queryableLayerSelected.trim() === this.wmsParams.title.trim()) {
// Make an AJAX request to the server and hope for the best // Make an AJAX request to the server and hope for the best
var params = this.getFeatureInfoUrl(evt.latlng); var params = this.getFeatureInfoUrl(evt.latlng);
...@@ -181,7 +181,7 @@ const mapUtil = { ...@@ -181,7 +181,7 @@ const mapUtil = {
], ],
!zoom ? mapDefaultViewZoom : zoom !zoom ? mapDefaultViewZoom : zoom
); );
map.setMaxBounds( [[-90,-180], [90,180]] )
if (zoomControl) { if (zoomControl) {
L.control L.control
.zoom({ .zoom({
...@@ -226,6 +226,7 @@ const mapUtil = { ...@@ -226,6 +226,7 @@ const mapUtil = {
layers.forEach((layer) => { layers.forEach((layer) => {
if (layer) { if (layer) {
const options = layer.options; const options = layer.options;
options.noWrap=true;
if (options) { if (options) {
options.opacity = layer.opacity; options.opacity = layer.opacity;
...@@ -250,6 +251,7 @@ const mapUtil = { ...@@ -250,6 +251,7 @@ const mapUtil = {
} }
}); });
} else { } else {
optionsMap.noWrap=true;
L.tileLayer(serviceMap, optionsMap).addTo(map); L.tileLayer(serviceMap, optionsMap).addTo(map);
} }
}, },
...@@ -307,6 +309,7 @@ const mapUtil = { ...@@ -307,6 +309,7 @@ const mapUtil = {
addVectorTileLayer: function (url, project_slug, featureTypes, form_filters) { addVectorTileLayer: function (url, project_slug, featureTypes, form_filters) {
layerMVT = L.vectorGrid.protobuf(url, { layerMVT = L.vectorGrid.protobuf(url, {
noWrap:true,
vectorTileLayerStyles: { vectorTileLayerStyles: {
"default": (properties) => { "default": (properties) => {
const featureType = featureTypes.find((x) => x.slug.split('-')[0] === '' + properties.feature_type_id); const featureType = featureTypes.find((x) => x.slug.split('-')[0] === '' + properties.feature_type_id);
......
import axios from '@/axios-client.js'; import axios from '@/axios-client.js';
import router from '../../router' import router from '../../router'
// axios.defaults.headers.common['X-CSRFToken'] = (name => {
// var re = new RegExp(name + "=([^;]+)");
// var value = re.exec(document.cookie);
// return (value !== null) ? unescape(value[1]) : null;
// })('csrftoken');
const feature = { const feature = {
namespaced: true, namespaced: true,
...@@ -98,7 +92,6 @@ const feature = { ...@@ -98,7 +92,6 @@ const feature = {
}, },
ADD_ATTACHMENT_TO_DELETE(state, attachementId) { ADD_ATTACHMENT_TO_DELETE(state, attachementId) {
// state.attachmentFormset = state.attachmentFormset.filter(el => el.id !== attachementId);
state.attachmentsToDelete.push(attachementId); state.attachmentsToDelete.push(attachementId);
}, },
...@@ -131,7 +124,7 @@ const feature = { ...@@ -131,7 +124,7 @@ const feature = {
url = url.concat('', `${url.includes('?') ? '&' : '?'}ordering=${ordering}`); url = url.concat('', `${url.includes('?') ? '&' : '?'}ordering=${ordering}`);
} }
if (search) { if (search) {
url = url.concat('', `${url.includes('?') ? '&' : '?'}title__contains=${search}`); url = url.concat('', `${url.includes('?') ? '&' : '?'}title__icontains=${search}`);
} }
if (limit) { if (limit) {
url = url.concat('', `${url.includes('?') ? '&' : '?'}limit=${limit}`); url = url.concat('', `${url.includes('?') ? '&' : '?'}limit=${limit}`);
...@@ -144,7 +137,6 @@ const feature = { ...@@ -144,7 +137,6 @@ const feature = {
commit("SET_FEATURES", features); commit("SET_FEATURES", features);
const features_count = response.data.count; const features_count = response.data.count;
commit("SET_FEATURES_COUNT", features_count); commit("SET_FEATURES_COUNT", features_count);
//dispatch("map/ADD_FEATURES", null, { root: true }); //todo: should check if map was initiated
} }
return response; return response;
}) })
...@@ -180,7 +172,6 @@ const feature = { ...@@ -180,7 +172,6 @@ const feature = {
SEND_FEATURE({ state, rootState, commit, dispatch }, routeName) { SEND_FEATURE({ state, rootState, commit, dispatch }, routeName) {
commit("DISPLAY_LOADER", "Le signalement est en cours de création", { root: true }) commit("DISPLAY_LOADER", "Le signalement est en cours de création", { root: true })
const message = routeName === "editer-signalement" ? "Le signalement a été mis à jour" : "Le signalement a été crée"; const message = routeName === "editer-signalement" ? "Le signalement a été mis à jour" : "Le signalement a été crée";
function redirect(featureId) { function redirect(featureId) {
dispatch( dispatch(
'GET_PROJECT_FEATURE', 'GET_PROJECT_FEATURE',
...@@ -228,110 +219,66 @@ const feature = { ...@@ -228,110 +219,66 @@ const feature = {
} }
} }
let url = `${rootState.configuration.VUE_APP_DJANGO_API_BASE}features/`
if (routeName === "editer-signalement") { if (routeName === "editer-signalement") {
return axios url += `${state.form.feature_id}/?` +
.put(`${rootState.configuration.VUE_APP_DJANGO_API_BASE}features/${state.form.feature_id}/?` + `feature_type__slug=${rootState.feature_type.current_feature_type_slug}` +
`feature_type__slug=${rootState.feature_type.current_feature_type_slug}` + `&project__slug=${rootState.project_slug}`
`&project__slug=${rootState.project_slug}` }
, geojson)
.then((response) => {
if (response.status === 200 && response.data) {
if (state.attachmentFormset.length > 0 || state.linkedFormset.length > 0) {
handleOtherForms(response.data.id)
} else {
redirect(response.data.id)
}
}
})
.catch((error) => {
commit("DISCARD_LOADER", null, { root: true })
if (error.message === "Network Error" || window.navigator.onLine === false) {
let arraysOffline = [];
let localStorageArray = localStorage.getItem("geocontrib_offline");
if (localStorageArray) {
arraysOffline = JSON.parse(localStorageArray);
}
let updateMsg = {
project: rootState.project_slug,
type: 'put',
featureId: state.form.feature_id,
geojson: geojson
};
arraysOffline.push(updateMsg);
localStorage.setItem("geocontrib_offline", JSON.stringify(arraysOffline));
router.push({
name: "offline-signalement",
params: {
slug_type_signal: rootState.feature_type.current_feature_type_slug
},
});
return axios({
url,
method: routeName === "editer-signalement" ? "PUT" : "POST",
data: geojson
}).then((response) => {
if ((response.status === 200 || response.status === 201) && response.data) {
if (state.attachmentFormset.length > 0 || state.linkedFormset.length > 0 || state.attachmentFormset.length > 0 || state.attachmentsToDelete.length > 0) {
handleOtherForms(response.data.id)
} else {
redirect(response.data.id)
} }
else { }
console.log(error) })
throw error; .catch((error) => {
commit("DISCARD_LOADER", null, { root: true })
if (error.message === "Network Error" || window.navigator.onLine === false) {
let arraysOffline = [];
let localStorageArray = localStorage.getItem("geocontrib_offline");
if (localStorageArray) {
arraysOffline = JSON.parse(localStorageArray);
} }
let updateMsg = {
project: rootState.project_slug,
type: 'put',
featureId: state.form.feature_id,
geojson: geojson
};
arraysOffline.push(updateMsg);
localStorage.setItem("geocontrib_offline", JSON.stringify(arraysOffline));
router.push({
name: "offline-signalement",
params: {
slug_type_signal: rootState.feature_type.current_feature_type_slug
},
});
}
else {
console.error(error)
throw error; throw error;
}); }
} else { throw error;
return axios });
.post(`${rootState.configuration.VUE_APP_DJANGO_API_BASE}features/`, geojson)
.then((response) => {
if (response.status === 201 && response.data) {
if (state.attachmentFormset.length > 0 || state.linkedFormset.length > 0) {
handleOtherForms(response.data.id)
} else {
redirect(response.data.id)
}
}
})
.catch((error) => {
commit("DISCARD_LOADER", null, { root: true })
if (error.message === "Network Error" || window.navigator.onLine === false) {
let arraysOffline = [];
let localStorageArray = localStorage.getItem("geocontrib_offline");
if (localStorageArray) {
arraysOffline = JSON.parse(localStorageArray);
}
let updateMsg = {
project: rootState.project_slug,
type: 'post',
geojson: geojson
};
arraysOffline.push(updateMsg);
localStorage.setItem("geocontrib_offline", JSON.stringify(arraysOffline));
router.push({
name: "offline-signalement",
params: {
slug_type_signal: rootState.feature_type.current_feature_type_slug
},
});
}
else {
console.log(error)
throw error;
}
});
}
// this.$store.dispatch("GET_ALL_PROJECTS"), //* & refresh project list
}, },
async SEND_ATTACHMENTS({ state, rootState, dispatch }, featureId) { async SEND_ATTACHMENTS({ state, rootState, dispatch }, featureId) {
const DJANGO_API_BASE = rootState.configuration.VUE_APP_DJANGO_API_BASE; const DJANGO_API_BASE = rootState.configuration.VUE_APP_DJANGO_API_BASE;
function addFile(attachment, attchmtId) { function addFile(attachment, attchmtId) {
let formdata = new FormData(); let formdata = new FormData();
formdata.append("file", attachment.fileToImport, attachment.fileToImport.name); formdata.append("file", attachment.fileToImport, attachment.fileToImport.name);
return axios return axios
.put(`${DJANGO_API_BASE}features/${featureId}/attachments/${attchmtId}/upload-file/`, formdata) .put(`${DJANGO_API_BASE}features/${featureId}/attachments/${attchmtId}/upload-file/`, formdata)
.then((response) => { .then((response) => {
console.log(response)
if (response && response.status === 200) {
console.log(response.status)
}
return response; return response;
}) })
.catch((error) => { .catch((error) => {
...@@ -345,37 +292,25 @@ const feature = { ...@@ -345,37 +292,25 @@ const feature = {
formdata.append("title", attachment.title); formdata.append("title", attachment.title);
formdata.append("info", attachment.info); formdata.append("info", attachment.info);
if (!attachment.id) { //* used to check if doesn't exist in DB and should be send through post (useless now) let url = `${DJANGO_API_BASE}features/${featureId}/attachments/`
return axios if (attachment.id) {
.post(`${DJANGO_API_BASE}features/${featureId}/attachments/`, formdata) url += `${attachment.id}/`
.then((response) => {
console.log(response)
if (response && response.status === 201 && attachment.fileToImport) {
console.log(response.status)
return addFile(attachment, response.data.id);
}
return response
})
.catch((error) => {
console.error(error);
return error
});
} else {
return axios
.put(`${DJANGO_API_BASE}features/${featureId}/attachments/${attachment.id}/`, formdata)
.then((response) => {
console.log(response)
if (response && response.status === 200 && attachment.fileToImport) {
console.log(response.status)
return addFile(attachment, response.data.id);
}
})
.catch((error) => {
console.error(error);
return error
});
} }
return axios({
url,
method: attachment.id ? "PUT" : "POST",
data: formdata
}).then((response) => {
if (response && (response.status === 200 || response.status === 201) && attachment.fileToImport) {
return addFile(attachment, response.data.id);
}
return response
})
.catch((error) => {
console.error(error);
return error
});
} }
function deleteAttachement(attachmentsId, featureId) { function deleteAttachement(attachmentsId, featureId) {
...@@ -386,6 +321,7 @@ const feature = { ...@@ -386,6 +321,7 @@ const feature = {
return dispatch("DELETE_ATTACHMENTS", payload) return dispatch("DELETE_ATTACHMENTS", payload)
.then((response) => response); .then((response) => response);
} }
const promisesResult = await Promise.all([ const promisesResult = await Promise.all([
...state.attachmentFormset.map((attachment) => putOrPostAttachement(attachment)), ...state.attachmentFormset.map((attachment) => putOrPostAttachement(attachment)),
...state.attachmentsToDelete.map((attachmentsId) => deleteAttachement(attachmentsId, featureId)) ...state.attachmentsToDelete.map((attachmentsId) => deleteAttachement(attachmentsId, featureId))
......
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
>Niveau d'autorisation requis : >Niveau d'autorisation requis :
{{ project.access_level_pub_feature }}</span {{ project.access_level_pub_feature }}</span
><br /> ><br />
<span> <span v-if="user">
Mon niveau d'autorisation : Mon niveau d'autorisation :
<span v-if="USER_LEVEL_PROJECTS && project">{{ <span v-if="USER_LEVEL_PROJECTS && project">{{
USER_LEVEL_PROJECTS[project.slug] USER_LEVEL_PROJECTS[project.slug]
......
...@@ -181,11 +181,6 @@ ...@@ -181,11 +181,6 @@
/> />
<div class="ui tab active map-container" data-tab="map"> <div class="ui tab active map-container" data-tab="map">
<div id="map" ref="map"></div> <div id="map" ref="map"></div>
<!-- // todo: ajouter v-if -->
<!-- {% if serialized_base_maps|length > 0 %} {% include
"geocontrib/map-layers/sidebar-layers.html" with
basemaps=serialized_base_maps layers=serialized_layers
project=project.slug%} {% endif %} -->
<SidebarLayers v-if="basemaps && map" /> <SidebarLayers v-if="basemaps && map" />
</div> </div>
</div> </div>
...@@ -850,7 +845,10 @@ export default { ...@@ -850,7 +845,10 @@ export default {
if (this.currentRouteName === "editer-signalement") { if (this.currentRouteName === "editer-signalement") {
this.map.addControl(this.drawControlEditOnly); this.map.addControl(this.drawControlEditOnly);
} else this.map.addControl(this.drawControlFull); } else {
this.map.addControl(this.drawControlFull);
}
this.changeMobileBtnOrder();
this.map.on( this.map.on(
"draw:created", "draw:created",
...@@ -984,6 +982,24 @@ export default { ...@@ -984,6 +982,24 @@ export default {
} }
}, },
changeMobileBtnOrder() { //* move large toolbar for polygon creation, cutting map in the middle
function changeDisplay() {
let buttons = document.querySelector(".leaflet-draw-actions.leaflet-draw-actions-top.leaflet-draw-actions-bottom")
if (buttons && buttons.style) {
buttons.style.display = "flex"
buttons.style["flex-direction"] = "column"
}
}
if (window.screen.availWidth < 767) { //* change button order all the time to keep homogeinity on mobile
let wrapper = document.querySelector(".leaflet-top.leaflet-right");
if (wrapper) wrapper.appendChild(wrapper.children[0]);
if (this.feature_type.geom_type === "polygon") { //* if it's a polygon, change tools direction to vertical
let polygonBtn = document.querySelector(".leaflet-draw-draw-polygon"); //* since elements are generated
if (polygonBtn) polygonBtn.addEventListener("click", changeDisplay) //* it should be done at each click
}
}
},
getFeatureAttachments() { getFeatureAttachments() {
featureAPI featureAPI
.getFeatureAttachments(this.$route.params.slug_signal) .getFeatureAttachments(this.$route.params.slug_signal)
......
...@@ -945,6 +945,10 @@ export default { ...@@ -945,6 +945,10 @@ export default {
setTimeout(() => (this.tempMessage = null), 5000); //* hide message after 5 seconds setTimeout(() => (this.tempMessage = null), 5000); //* hide message after 5 seconds
} }
}, },
destroyed() {
this.CLEAR_RELOAD_INTERVAL_ID();
},
}; };
</script> </script>
......