From bb70fa7786739b452c60cacef922f85b855a7f35 Mon Sep 17 00:00:00 2001 From: PhilippeL Date: Thu, 11 Jun 2020 14:06:16 -0400 Subject: [PATCH 1/2] feat(export): Allow the CSV semicolon delimiter export format --- .../import-export.component.html | 2 +- .../import-export/import-export.component.ts | 11 +++-- .../import-export/shared/export.service.ts | 42 ++++++++++++++----- .../lib/import-export/shared/export.type.ts | 2 +- packages/geo/src/locale/en.geo.json | 9 ++++ packages/geo/src/locale/fr.geo.json | 9 ++++ 6 files changed, 60 insertions(+), 15 deletions(-) diff --git a/packages/geo/src/lib/import-export/import-export/import-export.component.html b/packages/geo/src/lib/import-export/import-export/import-export.component.html index 4dfbee1e02..c76b93a6f8 100644 --- a/packages/geo/src/lib/import-export/import-export/import-export.component.html +++ b/packages/geo/src/lib/import-export/import-export/import-export.component.html @@ -61,7 +61,7 @@

{{'igo.geo.importExportForm.exportNoLayersExportable' | translate}}

formControlName="format" placeholder="{{'igo.geo.importExportForm.exportFormatPlaceholder' | translate}}"> - {{format.value}} + {{'igo.geo.export.format.' + format.value | translate}} diff --git a/packages/geo/src/lib/import-export/import-export/import-export.component.ts b/packages/geo/src/lib/import-export/import-export/import-export.component.ts index 81c79fa9db..6e412167ea 100644 --- a/packages/geo/src/lib/import-export/import-export/import-export.component.ts +++ b/packages/geo/src/lib/import-export/import-export/import-export.component.ts @@ -318,7 +318,8 @@ export class ImportExportComponent implements OnDestroy, OnInit { return formats .filter(format => { if ( - format.toUpperCase() === ExportFormat.CSV.toUpperCase() || + format.toUpperCase() === ExportFormat.CSVcomma.toUpperCase() || + format.toUpperCase() === ExportFormat.CSVsemicolon.toUpperCase() || format.toUpperCase() === ExportFormat.GML.toUpperCase() || format.toUpperCase() === ExportFormat.GPX.toUpperCase() || format.toUpperCase() === ExportFormat.GeoJSON.toUpperCase() || @@ -330,8 +331,12 @@ export class ImportExportComponent implements OnDestroy, OnInit { } }) .map(format => { - if (format.toUpperCase() === ExportFormat.CSV.toUpperCase()) { - format = ExportFormat.CSV; + if (format.toUpperCase() === ExportFormat.CSVcomma.toUpperCase()) { + format = ExportFormat.CSVcomma; + return format; + } + if (format.toUpperCase() === ExportFormat.CSVsemicolon.toUpperCase()) { + format = ExportFormat.CSVsemicolon; return format; } if (format.toUpperCase() === ExportFormat.GML.toUpperCase()) { diff --git a/packages/geo/src/lib/import-export/shared/export.service.ts b/packages/geo/src/lib/import-export/shared/export.service.ts index 0f9cf196ac..08832bc7ae 100644 --- a/packages/geo/src/lib/import-export/shared/export.service.ts +++ b/packages/geo/src/lib/import-export/shared/export.service.ts @@ -23,7 +23,8 @@ export class ExportService { GPX: 'gpx', KML: 'kml', Shapefile: 'ESRI Shapefile', - CSV: 'CSV' + CSVcomma: 'CSVcomma', + CSVsemicolon: 'CSVsemicolon' }; static noOgreFallbacks = ['GML', 'GPX', 'KML']; @@ -33,7 +34,9 @@ export class ExportService { constructor(private config: ConfigService) { this.ogreUrl = this.config.getConfig('importExport.url'); - const gpxAggregateInComment = this.config.getConfig('importExport.gpxAggregateInComment'); + const gpxAggregateInComment = this.config.getConfig( + 'importExport.gpxAggregateInComment' + ); if (gpxAggregateInComment !== undefined) { this.aggregateInComment = gpxAggregateInComment; } @@ -59,7 +62,8 @@ export class ExportService { private generateFeature( olFeatures: OlFeature[], - format: ExportFormat): OlFeature[] { + format: ExportFormat + ): OlFeature[] { if (format === ExportFormat.GPX && this.aggregateInComment) { return this.generateAggratedFeature(olFeatures); } @@ -187,12 +191,15 @@ export class ExportService { projectionIn: string, projectionOut: string ) { - const featuresText = new olformat.GeoJSON().writeFeatures(olFeatures, { - dataProjection: projectionOut, - featureProjection: projectionIn, - featureType: 'feature', - featureNS: 'http://example.com/feature' - }); + let featuresText: string = new olformat.GeoJSON().writeFeatures( + olFeatures, + { + dataProjection: projectionOut, + featureProjection: projectionIn, + featureType: 'feature', + featureNS: 'http://example.com/feature' + } + ); const url = `${this.ogreUrl}/convertJson`; const form = document.createElement('form'); @@ -201,9 +208,18 @@ export class ExportService { form.setAttribute('method', 'post'); form.setAttribute('target', '_blank'); form.setAttribute('action', url); + form.acceptCharset = 'UTF-8'; form.enctype = 'application/x-www-form-urlencoded; charset=utf-8;'; + if (format === 'CSVsemicolon') { + const options = document.createElement('input'); + options.setAttribute('type', 'hidden'); + options.setAttribute('name', 'lco'); + options.setAttribute('value', 'SEPARATOR=SEMICOLON'); + form.appendChild(options); + } + const geojsonField = document.createElement('input'); geojsonField.setAttribute('type', 'hidden'); geojsonField.setAttribute('name', 'json'); @@ -215,6 +231,9 @@ export class ExportService { format === 'Shapefile' ? `${title}.zip` : `${title}.${format.toLowerCase()}`; + if (format === 'CSVcomma' || format === 'CSVsemicolon') { + outputName = `${title}.csv`; + } outputName = outputName.replace(' ', '_'); outputName = outputName.normalize('NFD').replace(/[\u0300-\u036f]/g, ''); outputNameField.setAttribute('type', 'hidden'); @@ -222,7 +241,10 @@ export class ExportService { outputNameField.setAttribute('value', outputName); form.appendChild(outputNameField); - const ogreFormat = ExportService.ogreFormats[format]; + let ogreFormat = ExportService.ogreFormats[format]; + if (format === 'CSVcomma' || format === 'CSVsemicolon') { + ogreFormat = 'CSV'; + } const outputFormatField = document.createElement('input'); outputFormatField.setAttribute('type', 'hidden'); outputFormatField.setAttribute('name', 'format'); diff --git a/packages/geo/src/lib/import-export/shared/export.type.ts b/packages/geo/src/lib/import-export/shared/export.type.ts index 326c74ae1a..ff5f6770cb 100644 --- a/packages/geo/src/lib/import-export/shared/export.type.ts +++ b/packages/geo/src/lib/import-export/shared/export.type.ts @@ -1,4 +1,4 @@ import { strEnum } from '@igo2/utils'; -export const ExportFormat = strEnum(['GeoJSON', 'GML', 'GPX', 'KML', 'Shapefile', 'CSV', 'URL']); +export const ExportFormat = strEnum(['GeoJSON', 'GML', 'GPX', 'KML', 'Shapefile', 'CSVcomma', 'CSVsemicolon', 'URL']); export type ExportFormat = keyof typeof ExportFormat; diff --git a/packages/geo/src/locale/en.geo.json b/packages/geo/src/locale/en.geo.json index 4974bb46c5..4c4feec68e 100644 --- a/packages/geo/src/locale/en.geo.json +++ b/packages/geo/src/locale/en.geo.json @@ -54,6 +54,15 @@ "failed": { "text": "Failed to export", "title": "Failed to export features" + }, + "format": { + "GeoJSON": "GeoJSON", + "GML": "GML", + "GPX": "GPX", + "KML": "KML", + "Shapefile": "Shapefile", + "CSVcomma": "CSV (comma delimited)", + "CSVsemicolon": "CSV (semicolon delimited)" } }, "importExportForm": { diff --git a/packages/geo/src/locale/fr.geo.json b/packages/geo/src/locale/fr.geo.json index 18c22d42a4..8f4c9dca9e 100644 --- a/packages/geo/src/locale/fr.geo.json +++ b/packages/geo/src/locale/fr.geo.json @@ -54,6 +54,15 @@ "failed": { "text": "Impossible d’exporter, problème de donnée rencontré.", "title": "Problème d’exportation" + }, + "format": { + "GeoJSON": "GeoJSON", + "GML": "GML", + "GPX": "GPX", + "KML": "KML", + "Shapefile": "Shapefile", + "CSVcomma": "CSV (séparateur virgule)", + "CSVsemicolon": "CSV (séparateur point-virgule)" } }, "importExportForm": { From a717071ae157fe10d223c15fa5f9803efd9b2f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Barbeau?= Date: Tue, 16 Jun 2020 13:39:33 -0400 Subject: [PATCH 2/2] ... --- packages/geo/src/lib/import-export/shared/export.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/geo/src/lib/import-export/shared/export.service.ts b/packages/geo/src/lib/import-export/shared/export.service.ts index 08832bc7ae..17099105ed 100644 --- a/packages/geo/src/lib/import-export/shared/export.service.ts +++ b/packages/geo/src/lib/import-export/shared/export.service.ts @@ -191,7 +191,7 @@ export class ExportService { projectionIn: string, projectionOut: string ) { - let featuresText: string = new olformat.GeoJSON().writeFeatures( + const featuresText: string = new olformat.GeoJSON().writeFeatures( olFeatures, { dataProjection: projectionOut,