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

use blob to download file

parent 4b1d61f4
No related branches found
No related tags found
1 merge request!139REDMINE_ISSUE-12407
This commit is part of merge request !139. Comments created here will be created in the context of that merge request.
...@@ -77,6 +77,19 @@ const featureAPI = { ...@@ -77,6 +77,19 @@ const featureAPI = {
return null; return null;
} }
}, },
async getFeaturesBlob(url) {
const response = await axios
.get(url, { responseType: "blob" })
if (
response.status === 200 &&
response.data
) {
return response.data;
} else {
return null;
}
},
} }
export default featureAPI; export default featureAPI;
...@@ -102,7 +102,8 @@ ...@@ -102,7 +102,8 @@
</div> </div>
<div :class="['content', { active: !showImport }]"> <div :class="['content', { active: !showImport }]">
<p> <p>
Vous pouvez télécharger tous les signalements qui vous sont accessibles. Vous pouvez télécharger tous les signalements qui vous sont
accessibles.
</p> </p>
<button <button
type="button" type="button"
...@@ -192,6 +193,7 @@ ...@@ -192,6 +193,7 @@
<script> <script>
import { mapGetters, mapState } from "vuex"; import { mapGetters, mapState } from "vuex";
import ImportTask from "@/components/ImportTask"; import ImportTask from "@/components/ImportTask";
import featureAPI from "@/services/feature-api";
export default { export default {
name: "Feature_type_detail", name: "Feature_type_detail",
...@@ -284,14 +286,10 @@ export default { ...@@ -284,14 +286,10 @@ export default {
options: el.options, options: el.options,
}; };
}); });
console.log({ json, fields });
for (const feature of json.features) { for (const feature of json.features) {
console.log(feature.properties);
for (const { name, field_type, options } of fields) { for (const { name, field_type, options } of fields) {
console.log("name", name, "field_type", field_type);
//* check if custom field is present //* check if custom field is present
if (!(name in feature.properties)) { if (!(name in feature.properties)) {
console.log("NOT present");
return false; return false;
} }
const fieldInFeature = feature.properties[name]; const fieldInFeature = feature.properties[name];
...@@ -302,12 +300,10 @@ export default { ...@@ -302,12 +300,10 @@ export default {
if (field_type === "list") { if (field_type === "list") {
//*then check if the value is an available option //*then check if the value is an available option
if (!options.includes(fieldInFeature)) { if (!options.includes(fieldInFeature)) {
console.log("NOT an element of list options");
return false; return false;
} }
} else if (customType !== field_type) { } else if (customType !== field_type) {
//* check if custom field value match //* check if custom field value match
console.log("NOT matched");
this.importError = `Le fichier est invalide: Un champ de type ${field_type} ne peut pas avoir la valeur [ ${fieldInFeature} ]`; this.importError = `Le fichier est invalide: Un champ de type ${field_type} ne peut pas avoir la valeur [ ${fieldInFeature} ]`;
return false; return false;
} }
...@@ -344,8 +340,15 @@ export default { ...@@ -344,8 +340,15 @@ export default {
exportFeatures() { exportFeatures() {
const url = `${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${this.$route.params.slug}/feature-type/${this.$route.params.feature_type_slug}/export/`; const url = `${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${this.$route.params.slug}/feature-type/${this.$route.params.feature_type_slug}/export/`;
console.log(url); featureAPI
window.open(url); .getFeaturesBlob(url)
.then((blob) => {
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = `${this.project.title}-${this.structure.title}.json`;
link.click();
URL.revokeObjectURL(link.href);
})
}, },
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment