From 5f160363f60064135fb9bf1fabf4d7c45833456a Mon Sep 17 00:00:00 2001 From: kappu Date: Wed, 21 Feb 2018 17:25:21 +0100 Subject: [PATCH 1/3] Closes geosolutions-it/austrocontrol-C125#26 --- web/client/utils/FileFormatUtils.js | 46 +++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/web/client/utils/FileFormatUtils.js b/web/client/utils/FileFormatUtils.js index 8046bbd9ad..3cb5f48164 100644 --- a/web/client/utils/FileFormatUtils.js +++ b/web/client/utils/FileFormatUtils.js @@ -3,8 +3,8 @@ const formats = [{ outputFormat: "shape-zip", extension: "zip" }, { - outputFormat: "csv", - extension: "csv" + outputFormat: "csv", + extension: "csv" }, { outputFormat: "excel", extension: "xls" @@ -17,6 +17,48 @@ const formats = [{ }, { outputFormat: "dxf-zip", extension: "zip" + }, { + outputFormat: "application/vnd.google-earth.kml+xml", + extension: "kml" + }, { + outputFormat: "application/json", + extension: "json" + }, { + outputFormat: "gml3", + extension: "gml" + }, { + outputFormat: "GML2", + extension: "gml" + }, { + outputFormat: "application/vnd.googlxml", + extension: "kml" + }, { + outputFormat: "OGR-CSV", + extension: "csv" + }, { + outputFormat: "OGR-FileGDB", + extension: "gdb" + }, { + outputFormat: "OGR-GPKG", + extension: "gpkg" + }, { + outputFormat: "OGR-KML", + extension: "kml" + }, { + outputFormat: "OGR-MIF", + extension: "mif" + }, { + outputFormat: "OGR-TAB", + extension: "tab" + }, { + outputFormat: "SHAPE-ZIP", + extension: "zip" + }, { + outputFormat: "gml32", + extension: "gml" + }, { + outputFormat: "application/x-gpk", + extension: "gpk" } ]; From 497dd832d9dce53d68cf6f0014033ab7a5239828 Mon Sep 17 00:00:00 2001 From: kappu Date: Fri, 23 Feb 2018 12:43:00 +0100 Subject: [PATCH 2/3] Fixes on Mauro's comment --- web/client/utils/FileFormatUtils.js | 8 +++++++- .../utils/__tests__/FileFormatUtils-test.js | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 web/client/utils/__tests__/FileFormatUtils-test.js diff --git a/web/client/utils/FileFormatUtils.js b/web/client/utils/FileFormatUtils.js index 3cb5f48164..9c6033f730 100644 --- a/web/client/utils/FileFormatUtils.js +++ b/web/client/utils/FileFormatUtils.js @@ -1,4 +1,10 @@ const {head} = require('lodash'); + +const getFormatByName = (outF) => { + const extension = outF.split('-')[1]; + return extension ? {outputFormat: outF, extension: extension.toLowerCase()} : undefined; + +}; const formats = [{ outputFormat: "shape-zip", extension: "zip" @@ -64,5 +70,5 @@ const formats = [{ module.exports = { formats, - getByOutputFormat: (outF) => head(formats.filter(format => format.outputFormat === outF)) + getByOutputFormat: (outF) => head(formats.filter(format => format.outputFormat === outF)) || getFormatByName(outF) }; diff --git a/web/client/utils/__tests__/FileFormatUtils-test.js b/web/client/utils/__tests__/FileFormatUtils-test.js new file mode 100644 index 0000000000..ddc1915860 --- /dev/null +++ b/web/client/utils/__tests__/FileFormatUtils-test.js @@ -0,0 +1,19 @@ +/** + * Copyright 2018, GeoSolutions Sas. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ +var expect = require('expect'); +var FileFormatUtils = require('../FileFormatUtils'); + + +describe('FileFormatUtils', () => { + it('getByOutputFormat custom format', () => { + const result = FileFormatUtils.getByOutputFormat("TEST-CSV"); + expect(result).toExist(); + expect(result.extension).toBe("csv"); + expect(result.outputFormat).toBe("TEST-CSV"); + }); +}); From 5f50380af776f48e1b13a1ef02803c645f323e9d Mon Sep 17 00:00:00 2001 From: kappu Date: Tue, 27 Feb 2018 13:15:17 +0100 Subject: [PATCH 3/3] Fixed split search pattern --- web/client/utils/FileFormatUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/client/utils/FileFormatUtils.js b/web/client/utils/FileFormatUtils.js index 9c6033f730..88cefea30d 100644 --- a/web/client/utils/FileFormatUtils.js +++ b/web/client/utils/FileFormatUtils.js @@ -1,7 +1,7 @@ const {head} = require('lodash'); const getFormatByName = (outF) => { - const extension = outF.split('-')[1]; + const extension = outF.split(/[^\w]/)[1]; return extension ? {outputFormat: outF, extension: extension.toLowerCase()} : undefined; };