Skip to content
Snippets Groups Projects
Commit b4c02d89 authored by leandro's avatar leandro
Browse files

add import json

parent 41c00082
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...
...@@ -64,21 +64,17 @@ ...@@ -64,21 +64,17 @@
Importer des signalements Importer des signalements
</div> </div>
<div :class="['content', { active: showImport }]"> <div :class="['content', { active: showImport }]">
<form <div
id="form-import-features" id="form-import-features"
action="{% url 'geocontrib:import_from_geojson' slug=project.slug feature_type_slug=feature_type.slug %}"
method="post"
enctype="multipart/form-data"
class="ui form" class="ui form"
> >
<div class="field"> <div class="field">
<label <label
@click="importGeoJson"
class="ui icon button" class="ui icon button"
for="json_file" for="json_file"
> >
<i class="file icon"></i> <i class="file icon"></i>
<span class="label">Sélectionner un fichier GeoJSON ...</span> <span class="label">{{filenameToImport.name}}</span>
</label> </label>
<input <input
type="file" type="file"
...@@ -86,14 +82,14 @@ ...@@ -86,14 +82,14 @@
style="display: none" style="display: none"
name="json_file" name="json_file"
id="json_file" id="json_file"
@change="onFileChange"
/> />
</div> </div>
// todo import file <button @click="importGeoJson" class="ui fluid teal icon button">
<button type="submit" class="ui fluid teal icon button">
<i class="upload icon"></i> Lancer l'import <i class="upload icon"></i> Lancer l'import
</button> </button>
<ImportTask v-if="dataImport" :data="dataImport"/> <ImportTask v-if="dataImport.length" :data="dataImport"/>
</form> </div>
</div> </div>
<div <div
@click="showExport = !showExport" @click="showExport = !showExport"
...@@ -204,6 +200,8 @@ export default { ...@@ -204,6 +200,8 @@ export default {
data() { data() {
return { return {
filenameToImport: {name: "Sélectionner un fichier GeoJSON ..."},
fileToImport: {},
showImport: false, showImport: false,
showExport: true, showExport: true,
dataImport: [], dataImport: [],
...@@ -211,11 +209,39 @@ export default { ...@@ -211,11 +209,39 @@ export default {
}, },
methods: { methods: {
onFileChange(e) {
var files = e.target.files || e.dataTransfer.files;
if (!files.length)
return;
// this.fileToImport = files[0]
this.filenameToImport = files[0]
},
toggleImport() { toggleImport() {
console.log("toggleImport"); console.log("toggleImport");
}, },
importGeoJson() { importGeoJson() {
console.log("Comment faire pour importer le geoJson ?"); console.log("Comment faire pour importer le geoJson ?");
console.log(this.$route.params);
// POST ICI
// path('projet/<slug:slug>/type-signalement/<slug:feature_type_slug>/importer-geojson/',
// ImportFromGeoJSON.as_view(), name='import_from_geojson'),
var formData = new FormData();
var jsonFile = document.querySelector('#json_file');
formData.append("image", jsonFile);
let url = process.env.DOMAIN + 'projet/' + this.$route.params.slug + '/ype-signalement/'+this.$route.params.feature_type_slug + '/importer-geojson/' ;
axios.post(url, formData, { headers: {
'Content-Type': 'multipart/form-data'
}
})
.then((response) => {
console.log(response.data)
})
.catch(err => {
console.log(err)
});
}, },
getImports(){ getImports(){
let url = process.env.VUE_APP_DJANGO_API_BASE + 'import-tasks?feature_type_id=' + this.structure.feature_type; let url = process.env.VUE_APP_DJANGO_API_BASE + 'import-tasks?feature_type_id=' + this.structure.feature_type;
...@@ -228,6 +254,7 @@ export default { ...@@ -228,6 +254,7 @@ export default {
}); });
} }
}, },
created() { created() {
if (!this.project) { if (!this.project) {
this.$store.commit("SET_PROJECT_SLUG", this.$route.params.slug); this.$store.commit("SET_PROJECT_SLUG", this.$route.params.slug);
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment