From 2fe8f98e4e4303fec7fc39a849aecd9c1c1f09db Mon Sep 17 00:00:00 2001 From: David Huynh Date: Thu, 4 Mar 2010 00:00:46 +0000 Subject: [PATCH] Added repeat and repeatCount options for text transform operation. This lets us fix those &amp;amp; repeated encoding problems easily. git-svn-id: http://google-refine.googlecode.com/svn/trunk@179 7d457c2a-affb-35e4-300a-418c747d4874 --- .../commands/edit/DoTextTransformCommand.java | 13 +++- .../operations/TextTransformOperation.java | 36 ++++++++++- .../dialogs/expression-preview-dialog.js | 8 +-- .../views/data-table-column-header-ui.js | 62 ++++++++++++------- src/main/webapp/styles/common.css | 6 +- 5 files changed, 95 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/metaweb/gridworks/commands/edit/DoTextTransformCommand.java b/src/main/java/com/metaweb/gridworks/commands/edit/DoTextTransformCommand.java index a35da29e7..79a194b50 100644 --- a/src/main/java/com/metaweb/gridworks/commands/edit/DoTextTransformCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/edit/DoTextTransformCommand.java @@ -17,11 +17,22 @@ public class DoTextTransformCommand extends EngineDependentCommand { String columnName = request.getParameter("columnName"); String expression = request.getParameter("expression"); String onError = request.getParameter("onError"); + boolean repeat = "true".equals(request.getParameter("repeat")); + + int repeatCount = 10; + String repeatCountString = request.getParameter("repeatCount"); + try { + repeatCount = Math.max(Math.min(Integer.parseInt(repeatCountString), 10), 0); + } catch (Exception e) { + } return new TextTransformOperation( engineConfig, columnName, expression, - TextTransformOperation.stringToOnError(onError)); + TextTransformOperation.stringToOnError(onError), + repeat, + repeatCount + ); } } diff --git a/src/main/java/com/metaweb/gridworks/operations/TextTransformOperation.java b/src/main/java/com/metaweb/gridworks/operations/TextTransformOperation.java index fd44aca9b..28befc626 100644 --- a/src/main/java/com/metaweb/gridworks/operations/TextTransformOperation.java +++ b/src/main/java/com/metaweb/gridworks/operations/TextTransformOperation.java @@ -27,8 +27,10 @@ public class TextTransformOperation extends EngineDependentMassCellOperation { StoreError } - final protected String _expression; + final protected String _expression; final protected OnError _onError; + final protected boolean _repeat; + final protected int _repeatCount; static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { JSONObject engineConfig = obj.getJSONObject("engineConfig"); @@ -37,7 +39,9 @@ public class TextTransformOperation extends EngineDependentMassCellOperation { engineConfig, obj.getString("columnName"), obj.getString("expression"), - stringToOnError(obj.getString("onError")) + stringToOnError(obj.getString("onError")), + obj.getBoolean("repeat"), + obj.getInt("repeatCount") ); } @@ -60,10 +64,19 @@ public class TextTransformOperation extends EngineDependentMassCellOperation { } } - public TextTransformOperation(JSONObject engineConfig, String columnName, String expression, OnError onError) { + public TextTransformOperation( + JSONObject engineConfig, + String columnName, + String expression, + OnError onError, + boolean repeat, + int repeatCount + ) { super(engineConfig, columnName, true); _expression = expression; _onError = onError; + _repeat = repeat; + _repeatCount = repeatCount; } public void write(JSONWriter writer, Properties options) @@ -76,6 +89,8 @@ public class TextTransformOperation extends EngineDependentMassCellOperation { writer.key("columnName"); writer.value(_columnName); writer.key("expression"); writer.value(_expression); writer.key("onError"); writer.value(onErrorToString(_onError)); + writer.key("repeat"); writer.value(_repeat); + writer.key("repeatCount"); writer.value(_repeatCount); writer.endObject(); } @@ -127,6 +142,21 @@ public class TextTransformOperation extends EngineDependentMassCellOperation { if (!ExpressionUtils.sameValue(oldValue, newValue)) { Cell newCell = new Cell(newValue, (cell != null) ? cell.recon : null); + + if (_repeat) { + for (int i = 0; i < _repeatCount; i++) { + ExpressionUtils.bind(bindings, row, rowIndex, newCell); + + newValue = eval.evaluate(bindings); + if (ExpressionUtils.isError(newValue)) { + break; + } else if (ExpressionUtils.sameValue(newCell.value, newValue)) { + break; + } + + newCell = new Cell(newValue, newCell.recon); + } + } CellChange cellChange = new CellChange(rowIndex, cellIndex, cell, newCell); cellChanges.add(cellChange); diff --git a/src/main/webapp/scripts/dialogs/expression-preview-dialog.js b/src/main/webapp/scripts/dialogs/expression-preview-dialog.js index 296da327c..1e38c223b 100644 --- a/src/main/webapp/scripts/dialogs/expression-preview-dialog.js +++ b/src/main/webapp/scripts/dialogs/expression-preview-dialog.js @@ -32,7 +32,7 @@ function ExpressionPreviewDialog(title, cellIndex, rowIndices, values, expressio }; ExpressionPreviewDialog.generateWidgetHtml = function() { - return '' + + return '
' + '' + '' + '' + @@ -48,7 +48,7 @@ ExpressionPreviewDialog.generateWidgetHtml = function() { '' + '' + '' + - '' + + '' + '' + '' + '
ExpressionLanguage
' + @@ -61,7 +61,7 @@ ExpressionPreviewDialog.generateWidgetHtml = function() { '
' + '
' + '
' + - '
' + + '' + '