Skip to content

Commit

Permalink
Merge pull request #353 from AgenceBio/fix/export-certipaq
Browse files Browse the repository at this point in the history
  • Loading branch information
thom4parisot authored Apr 16, 2024
2 parents 5dba33f + ed50716 commit 0881d12
Show file tree
Hide file tree
Showing 23 changed files with 38 additions and 22 deletions.
6 changes: 4 additions & 2 deletions src/components/Features/ExportStrategies/BaseExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class BaseExporter {
* @param {Feature[]} features
* @returns {String}
*/
export function generateAutresInfos (features, { withAnnotations = false, withCode = true, withCulture = true, withDate = true, withName = true, withNotes = true, withSurface = true, withVariete = true, pivot = null, initialCulture, permissions = {} } = {}) {
export function generateAutresInfos (features, { withAnnotations = false, withCode = true, withCulture = true, withDate = true, withExplicitName = false, withName = true, withNotes = true, withSurface = true, withVariete = true, pivot = null, initialCulture, permissions = {} } = {}) {
const dateFmnt = new Intl.DateTimeFormat('fr-FR', {
timeZone: 'Europe/Paris',
day: 'numeric',
Expand All @@ -77,7 +77,9 @@ export function generateAutresInfos (features, { withAnnotations = false, withCo
const dropEmptyItem = (d) => d

return features.map(feature => {
const name = withName ? featureName(feature, { ilotLabel: '', parcelleLabel: '', separator: '.', placeholder: '' }) : ''
const name = withName
? featureName(feature, { ilotLabel: '', parcelleLabel: '', separator: '.', placeholder: '', explicitName: withExplicitName })
: (withExplicitName ? (feature.properties.NOM ?? '') : '')
const notes = withNotes ? feature.properties.auditeur_notes : ''
const annotations = withAnnotations && permissions.canExportAnnotations && Array.isArray(feature.properties.annotations) ? aggregateAnnotations(feature.properties.annotations) : ''

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function getSheet () {

getFeatureGroups(featureCollection, [GROUPE_CULTURE, GROUPE_NIVEAU_CONVERSION, GROUPE_DATE_ENGAGEMENT]).forEach(({ features, mainKey, surface }, index) => {
const culture = fromCodeCpf(mainKey)
const autresInfos = generateAutresInfos(features, { pivot: mainKey })
const autresInfos = generateAutresInfos(features, { pivot: mainKey, withExplicitName: true, withName: true })
const varietes = generateAutresInfos(features, { pivot: mainKey, withNotes: false, withDate: false, withName: false, withSurface: false })

sheet_add_aoa(sheet, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('BureauVeritasExporter', () => {
"Luzerne",
"1125",
"",
"Ilots : 1.1 ; 1.2",
"Ilots : 1.1 (nom personnalisé) ; 1.2",
2.092976314534671,
"ha",
"C1",
Expand Down
3 changes: 2 additions & 1 deletion src/components/Features/ExportStrategies/CertipaqExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function getSheet () {
], { origin: 'A4'})

const ilotOptions = {
explicitName: false,
ilotLabel: '',
parcelleLabel: '',
separator: '_',
Expand All @@ -84,7 +85,7 @@ function getSheet () {
// Libellé Culture #C
culture?.libelle_code_cpf ?? `[ERREUR] culture inconnue (${props.cultures?.at(0).CPF})`,
// Variété / infos #D
generateAutresInfos([{ id, geometry, properties: props }], { withCode: false, withDate: false, withName: false, withNotes: true, withSurface: false, withVariete: true, initialCulture: culture?.code_cpf }),
generateAutresInfos([{ id, geometry, properties: props }], { withCode: false, withDate: false, withExplicitName: true, withName: false, withNotes: true, withSurface: false, withVariete: true, initialCulture: culture?.code_cpf }),
// C0 - AB - C1 - C2 - C3
props.conversion_niveau === 'CONV' ? surfaceHa : '',
props.conversion_niveau === 'AB' ? surfaceHa : '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('CertipaqExporter', () => {
'',
'1_1',
'Luzerne',
'',
'nom personnalisé',
'',
'',
'1,05',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('CertisExporter', () => {
"Id. Parcelle"
],
[
'',
'nom personnalisé',
'1',
'1',
1.0464881572673355,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function getSheet () {

getFeatureGroups(featureCollection, [GROUPE_CULTURE, GROUPE_NIVEAU_CONVERSION, GROUPE_DATE_ENGAGEMENT]).forEach(({ features, mainKey, surface }, index) => {
const culture = fromCodeCpf(mainKey)
const autresInfos = generateAutresInfos(features, { withAnnotations: true, pivot: mainKey, permissions })
const autresInfos = generateAutresInfos(features, { withAnnotations: true, withExplicitName: true, withName: true, pivot: mainKey, permissions })

sheet_add_aoa(sheet, [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('CertisudExporter', () => {
'Luzerne',
// expect.closeTo(2.1), // in vite@5 + vitest@1
2.092976314534671,
'1.1, Visitée ; 1.2, Prélèvement effectué, À risque',
'1.1 (nom personnalisé), Visitée ; 1.2, Prélèvement effectué, À risque',
'C1',
new Date('2023-01-01T00:00:00.000Z'),
'1,2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function getSheet () {
surfaceHa,
props.engagement_date ? new Date(props.engagement_date) : '',
props.conversion_niveau,
generateAutresInfos([{ properties: props }], { withAnnotations: true, initialCulture: culture?.code_cpf, permissions }),
generateAutresInfos([{ properties: props }], { withAnnotations: true, withExplicitName: true, withName: true, initialCulture: culture?.code_cpf, permissions }),
String(props.id),
culture?.code_cpf
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('ControlUnionExporter', () => {
1.0464881572673355,
new Date('2023-01-01T00:00:00.000Z'),
'C1',
'1.1, Visitée',
'1.1 (nom personnalisé), Visitée',
'1',
'01.19.10.8',
],
Expand Down
6 changes: 3 additions & 3 deletions src/components/Features/ExportStrategies/OcaciaExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ function getSheet () {
// Commune
props.COMMUNE_LABEL,
// Ilot
featureName({ properties: props }, { ilotLabel: '', parcelleLabel: '', separator: '.', placeholder: '' }),
featureName({ properties: props }, { explicitName: false, ilotLabel: '', parcelleLabel: '', separator: '.', placeholder: '' }),
// Culture
culture?.libelle_code_cpf ?? `[ERREUR] culture inconnue (${props.cultures.at(0)?.CPF})`,
// N° Cadastre
props.cadastre,
// Variété / infos
generateAutresInfos([{ id, geometry, properties: props }], { withDate: false, withName: false, withNotes: false, withSurface: false, withVariete: true, initialCulture: culture?.code_cpf }),
generateAutresInfos([{ id, geometry, properties: props }], { withDate: false, withExplicitName: false, withName: false, withNotes: false, withSurface: false, withVariete: true, initialCulture: culture?.code_cpf }),
// C0 - AB - C1 - C2 - C3
props.conversion_niveau === 'CONV' ? surfaceHa : '',
props.conversion_niveau === 'AB' ? surfaceHa : '',
Expand All @@ -68,7 +68,7 @@ function getSheet () {
// Date conv #K
props.engagement_date ? new Date(props.engagement_date) : '',
// Observation / date de semis
generateAutresInfos([{ id, geometry, properties: props }], { withAnnotations: true, withDate: true, withName: false, withNotes: true, withSurface: true, withVariete: false, initialCulture: culture?.code_cpf, permissions }),
generateAutresInfos([{ id, geometry, properties: props }], { withAnnotations: true, withDate: true, withExplicitName: true, withName: false, withNotes: true, withSurface: true, withVariete: false, initialCulture: culture?.code_cpf, permissions }),
// Précédent
'',
// Anté précédent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('OcaciaExporter', () => {
'',
'',
new Date('2023-01-01T00:00:00.000Z'),
'Visitée',
'nom personnalisé, Visitée',
'',
'',
'',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function getSheet () {
[
firstCulture?.code_cpf ?? `[ERREUR] culture inconnue (${properties.cultures.at(0)?.CPF})`,
autresInfos,
featureName({ properties }, { placeholder: '' }),
featureName({ properties }, { placeholder: '', explicitName: true }),
surface(geometry) / 10_000,
properties.conversion_niveau,
properties.engagement_date ? new Date(properties.engagement_date) : '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('QualisudExporter', () => {
[
'01.19.10.8',
'Visitée',
'ilot 1, parcelle 1',
'ilot 1, parcelle 1 (nom personnalisé)',
1.0464881572673355,
'C1',
new Date('2023-01-01T00:00:00.000Z'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"NUMERO_I": "1",
"NUMERO_P": "1",
"COMMUNE": "26108",
"NOM": "nom personnalisé",
"engagement_date": "2023-01-01",
"conversion_niveau": "C1",
"cultures": [
Expand Down
6 changes: 3 additions & 3 deletions src/components/Features/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@ export function getFeatureById (features, id) {

/**
* @param {Feature} feature
* @param {{ ilotLabel?: string, parcelleLabel?: string, separator?: string, placeholder?: string}} options
* @param {{ explicitName?: boolean, ilotLabel?: string, parcelleLabel?: string, separator?: string, placeholder?: string}} options
* @returns {String}
*/
export function featureName (feature, { ilotLabel = 'ilot ', parcelleLabel = 'parcelle ', separator = ', ', placeholder = '-'} = {}) {
export function featureName (feature, { explicitName = true, ilotLabel = 'ilot ', parcelleLabel = 'parcelle ', separator = ', ', placeholder = '-'} = {}) {
const NUMERO_I = parseInt(feature.properties.NUMERO_I, 10)
const NUMERO_P = parseInt(feature.properties.NUMERO_P, 10)

Expand All @@ -365,7 +365,7 @@ export function featureName (feature, { ilotLabel = 'ilot ', parcelleLabel = 'pa
return feature.properties.NOM ?? placeholder
}

return (ilotLabel && parcelleLabel && feature.properties.NOM ? `${name} (${feature.properties.NOM})` : (name ?? placeholder))
return `${name ?? placeholder}${explicitName && feature.properties.NOM ? ` (${feature.properties.NOM})` : ''}`
}

if (feature.properties.cadastre) {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Features/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ describe('featureName', () => {
}

expect(featureName(feature)).toEqual('ilot 1, parcelle 1 (les muriers)')
expect(featureName(feature, { ilotLabel: '', parcelleLabel: '', separator: '.' })).toEqual('1.1')
expect(featureName(feature, { explicitName: false, ilotLabel: '', parcelleLabel: '', separator: '.' })).toEqual('1.1')
expect(featureName(feature, { ilotLabel: '', parcelleLabel: '', separator: '.' })).toEqual('1.1 (les muriers)')
})

test('get as ILOT (because PARCELLE is not parseable)', () => {
Expand Down
1 change: 1 addition & 0 deletions src/pages/accessibilite.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<route lang="yaml">
meta:
generalAudience: true
seo:
title: Déclaration d'accessibilité du service en ligne
</route>
Expand Down
7 changes: 7 additions & 0 deletions src/pages/exploitations/[numeroBio]/import.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<route lang="yaml">
meta:
requiredPermissions: ['canCreateVersion']
seo:
title: Importer un parcellaire informatisé
</route>

<script setup>
import OperatorSetupFlow from "@/components/OperatorSetup/Flow.vue"
Expand Down
2 changes: 1 addition & 1 deletion src/pages/exploitations/[numeroBio]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
meta:
requiresAuth: true
seo:
title: Parcellaire
title: Parcellaires
</route>

<template>
Expand Down
1 change: 1 addition & 0 deletions src/pages/mentions-legales.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<route lang="yaml">
meta:
generalAudience: true
seo:
title: Mentions légales
</route>
Expand Down
1 change: 1 addition & 0 deletions src/pages/projet.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<route lang="yaml">
meta:
generalAudience: true
seo:
title: Stratégie et historique du projet CartoBio
</route>
Expand Down
1 change: 1 addition & 0 deletions src/pages/stats.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<route lang="yaml">
meta:
generalAudience: true&
seo:
title: Métriques de réussite du projet
</route>
Expand Down

0 comments on commit 0881d12

Please sign in to comment.