Skip to content

Commit

Permalink
feat(telepac): l'onglet Telepac accepte aussi le dossier XML
Browse files Browse the repository at this point in the history
  • Loading branch information
thom4parisot committed Apr 3, 2024
1 parent 0296674 commit 1d7273e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
17 changes: 2 additions & 15 deletions src/cartobio-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,10 @@ export function setAuthorization (userToken) {
* @param {File} archive
* @returns {Promise<CartoBioFeatureCollection>}
*/
export async function convertShapefileArchiveToGeoJSON (archive) {
export async function convertTelepacFileToGeoJSON (archive) {
const form = new FormData()
form.append('archive', archive)
const { data: geojson } = await apiClient.post(`/v2/convert/shapefile/geojson`, form)
return geojson
}

/**
* Turn a Telepac XML file into a GeoJSON
*
* @param {File} archive
* @returns {GeoJSON}
*/
export async function convertTelepacXMLToGeoJSON (file) {
const form = new FormData()
form.append('file', file)
const { data: geojson } = await apiClient.post(`/v2/convert/telepac-xml/geojson`, form)
const { data: geojson } = await apiClient.post(`/v2/convert/telepac/geojson`, form)
return geojson
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/OperatorSetup/Sources/MesParcelles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<script setup>
import { ref } from 'vue'
import { convertTelepacXMLToGeoJSON } from '@/cartobio-api.js'
import { convertTelepacFileToGeoJSON } from '@/cartobio-api.js'
import { sources } from "@/referentiels/imports.js"
const emit = defineEmits(['upload:start', 'upload:complete'])
Expand All @@ -40,7 +40,7 @@ async function handleFileUpload () {
emit('upload:start')
try {
const geojson = await convertTelepacXMLToGeoJSON(file)
const geojson = await convertTelepacFileToGeoJSON(file)
const metadata = {
pacage: geojson.features.at(0)?.properties?.PACAGE,
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/OperatorSetup/Sources/Telepac.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div>
<div class="fr-upload-group fr-mb-5w">
<input type="file" ref="fileInput" accept=".zip" @change="handleFileUpload" hidden />
<input type="file" ref="fileInput" accept=".zip,.xml" @change="handleFileUpload" hidden />
<button class="fr-btn fr-icon-upload-line fr-btn--icon-left" @click="fileInput.click()">
Sélectionner ma dernière déclaration PAC
</button>
Expand All @@ -25,7 +25,7 @@

<script setup>
import { ref } from 'vue'
import { convertShapefileArchiveToGeoJSON } from '@/cartobio-api.js'
import { convertTelepacFileToGeoJSON } from '@/cartobio-api.js'
import { useTélépac } from '@/referentiels/pac.js'
const emit = defineEmits(['upload:start', 'upload:complete'])
Expand All @@ -42,7 +42,7 @@ async function handleFileUpload () {
emit('upload:start')
try {
const geojson = await convertShapefileArchiveToGeoJSON(archive)
const geojson = await convertTelepacFileToGeoJSON(archive)
const metadata = {
campagne: geojson.features.at(0)?.properties?.CAMPAGNE,
pacage: geojson.features.at(0)?.properties?.PACAGE,
Expand Down

0 comments on commit 1d7273e

Please sign in to comment.