From 223d16db390f42aeff3de8861870fd9729c3ce8a Mon Sep 17 00:00:00 2001 From: TonyO Date: Sun, 25 Mar 2018 21:01:53 -0500 Subject: [PATCH] added ignore facet and trim column name options --- .../exporters/sql/SqlCreateBuilder.java | 12 +++- .../modules/core/langs/translation-en.json | 6 +- .../scripts/dialogs/sql-exporter-dialog.html | 12 +++- .../scripts/dialogs/sql-exporter-dialog.js | 60 ++++++++++++------- 4 files changed, 63 insertions(+), 27 deletions(-) diff --git a/main/src/com/google/refine/exporters/sql/SqlCreateBuilder.java b/main/src/com/google/refine/exporters/sql/SqlCreateBuilder.java index 588b208ba..32e043c88 100755 --- a/main/src/com/google/refine/exporters/sql/SqlCreateBuilder.java +++ b/main/src/com/google/refine/exporters/sql/SqlCreateBuilder.java @@ -59,6 +59,9 @@ public class SqlCreateBuilder { StringBuffer createSB = new StringBuffer(); JSONArray columnOptionArray = options == null ? null : JSONUtilities.getArray(options, "columns"); + + final boolean trimColNames = options == null ? true + : JSONUtilities.getBoolean(options, "trimColumnNames", false); int count = columnOptionArray.length(); @@ -68,9 +71,14 @@ public class SqlCreateBuilder { String name = JSONUtilities.getString(columnOptions, "name", null); String type = JSONUtilities.getString(columnOptions, "type", "VARCHAR"); String size = JSONUtilities.getString(columnOptions, "size", ""); + if (name != null) { - createSB.append(name + " "); - + if(trimColNames) { + createSB.append(name.trim() + " "); + }else{ + createSB.append(name + " "); + } + if (type.equals("VARCHAR")) { if (size.isEmpty()) { size = "255"; diff --git a/main/webapp/modules/core/langs/translation-en.json b/main/webapp/modules/core/langs/translation-en.json index be9ca529a..b727fe5fa 100644 --- a/main/webapp/modules/core/langs/translation-en.json +++ b/main/webapp/modules/core/langs/translation-en.json @@ -278,7 +278,11 @@ "for-include-structure-checkbox": "Include Schema", "for-include-drop-statement-checkbox": "Include Drop Statement", "for-include-content-checkbox": "Include Content", - "tableNameLabel": "Table Name:" + "tableNameLabel": "Table Name:", + "sqlExporterTrimColumns": "Trim Column Names", + "sqlExporterIgnoreFacets": "Ignore facets and filters and export all rows", + "sqlExporterOutputEmptyRows":"Output empty row (i.e. all cells null)" + }, "core-facets": { diff --git a/main/webapp/modules/core/scripts/dialogs/sql-exporter-dialog.html b/main/webapp/modules/core/scripts/dialogs/sql-exporter-dialog.html index 136ef7a53..b76756c3b 100755 --- a/main/webapp/modules/core/scripts/dialogs/sql-exporter-dialog.html +++ b/main/webapp/modules/core/scripts/dialogs/sql-exporter-dialog.html @@ -51,9 +51,15 @@
- - - + + + + + + + + +
diff --git a/main/webapp/modules/core/scripts/dialogs/sql-exporter-dialog.js b/main/webapp/modules/core/scripts/dialogs/sql-exporter-dialog.js index 411003f9f..ec6ffdea8 100755 --- a/main/webapp/modules/core/scripts/dialogs/sql-exporter-dialog.js +++ b/main/webapp/modules/core/scripts/dialogs/sql-exporter-dialog.js @@ -57,7 +57,7 @@ function SqlExporterDialog(options) { this._elmts.selectAllButton.html($.i18n._('core-buttons')["select-all"]); this._elmts.deselectAllButton.html($.i18n._('core-buttons')["deselect-all"]); - this._elmts.or_dialog_outEmptyRow.html($.i18n._('core-dialogs')["out-empty-row"]); + this._elmts.downloadPreviewButton.html($.i18n._('core-buttons')["preview"]); this._elmts.downloadButton.html($.i18n._('core-buttons')["download"]); @@ -70,7 +70,13 @@ function SqlExporterDialog(options) { this._elmts.includeStructureLabel.html($.i18n._('core-dialogs')["for-include-structure-checkbox"]); this._elmts.includeDropStatementLabel.html($.i18n._('core-dialogs')["for-include-drop-statement-checkbox"]); this._elmts.includeContentLabel.html($.i18n._('core-dialogs')["for-include-content-checkbox"]); - + + + this._elmts.sqlExportIgnoreFacetsLabel.html($.i18n._('core-dialogs')["sqlExporterIgnoreFacets"]); + this._elmts.sqlExportTrimAllColumnsLabel.html($.i18n._('core-dialogs')["sqlExporterTrimColumns"]); + this._elmts.sqlExportOutputEmptyRowsLabel.html($.i18n._('core-dialogs')["sqlExporterOutputEmptyRows"]); + + $("#sql-exporter-tabs-content").css("display", ""); $("#sql-exporter-tabs-download").css("display", ""); @@ -88,20 +94,29 @@ function SqlExporterDialog(options) { var sizeInputName = 'sizeInputRow' + i; var applyAllBtnName = 'applyAllBtn' + i; - var arr = [ - {val : 'VARCHAR', text: 'VARCHAR'}, - {val : 'TEXT', text: 'TEXT'}, - {val : 'INT', text: 'INT'}, - {val : 'NUMERIC', text: 'NUMERIC'}, - {val : 'CHAR', text: 'CHAR'}, - {val : 'DATE', text: 'DATE'}, - {val : 'TIMESTAMP', text: 'TIMESTAMP'} - ]; +// var arr = [ +// {val : 'VARCHAR', text: 'VARCHAR'}, +// {val : 'TEXT', text: 'TEXT'}, +// {val : 'INT', text: 'INT'}, +// {val : 'NUMERIC', text: 'NUMERIC'}, +// {val : 'CHAR', text: 'CHAR'}, +// {val : 'DATE', text: 'DATE'}, +// {val : 'TIMESTAMP', text: 'TIMESTAMP'} +// ]; var sel = $('') .attr("name", "options") .attr("value", JSON.stringify(options)) @@ -365,11 +382,12 @@ function SqlExporterDialog(options) { options.separator = ';'; options.encoding = 'UTF-8'; - options.outputBlankRows = this._elmts.outputEmptyRowsCheckbox[0].checked; + options.outputBlankRows = this._elmts.sqlExportOutputEmptyRowsCheckbox[0].checked; options.includeStructure = this._elmts.includeStructureCheckbox[0].checked; options.includeDropStatement = this._elmts.includeDropStatementCheckbox[0].checked; options.includeContent = this._elmts.includeContentCheckbox[0].checked; options.tableName = $.trim(this._elmts.tableNameTextBox.val().replace(/\W/g, ' ')).replace(/\s+/g, '-'); + options.trimColumnNames = this._elmts.sqlExportTrimAllColumnsCheckbox[0].checked; options.columns = [];