Made expression preview dialog for text transform operation also support repeat option.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@189 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-03-04 02:25:42 +00:00
parent cde6a02cbb
commit 70df6821a0
3 changed files with 48 additions and 7 deletions

View File

@ -39,6 +39,16 @@ public class PreviewExpressionCommand extends Command {
return; return;
} }
boolean repeat = "true".equals(request.getParameter("repeat"));
int repeatCount = 10;
if (repeat) {
String repeatCountString = request.getParameter("repeatCount");
try {
repeatCount = Math.max(Math.min(Integer.parseInt(repeatCountString), 10), 0);
} catch (Exception e) {
}
}
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json"); response.setHeader("Content-Type", "application/json");
@ -63,10 +73,25 @@ public class PreviewExpressionCommand extends Command {
Row row = project.rows.get(rowIndex); Row row = project.rows.get(rowIndex);
Cell cell = row.getCell(cellIndex); Cell cell = row.getCell(cellIndex);
ExpressionUtils.bind(bindings, row, rowIndex, cell);
try { try {
ExpressionUtils.bind(bindings, row, rowIndex, cell);
result = eval.evaluate(bindings); result = eval.evaluate(bindings);
if (repeat) {
for (int r = 0; r < repeatCount; r++) {
Cell newCell = new Cell(result, (cell != null) ? cell.recon : null);
ExpressionUtils.bind(bindings, row, rowIndex, newCell);
Object newResult = eval.evaluate(bindings);
if (ExpressionUtils.isError(newResult)) {
break;
} else if (ExpressionUtils.sameValue(result, newResult)) {
break;
}
result = newResult;
}
}
} catch (Exception e) { } catch (Exception e) {
// ignore // ignore
} }

View File

@ -102,7 +102,7 @@ ExpressionPreviewDialog.Widget = function(
.select() .select()
.focus(); .focus();
this._update(); this.update();
this._renderExpressionHistoryTab(); this._renderExpressionHistoryTab();
this._renderHelpTab(); this._renderHelpTab();
}; };
@ -237,7 +237,7 @@ ExpressionPreviewDialog.Widget.prototype._renderExpressionHistory = function(dat
$('<a href="javascript:{}">Re-use</a>').appendTo(tr.insertCell(2)).click(function() { $('<a href="javascript:{}">Re-use</a>').appendTo(tr.insertCell(2)).click(function() {
self._elmts.expressionPreviewTextarea[0].value = entry.code; self._elmts.expressionPreviewTextarea[0].value = entry.code;
self._elmts.expressionPreviewTextarea.select().focus(); self._elmts.expressionPreviewTextarea.select().focus();
self._update(); self.update();
$("#expression-preview-tabs").tabs('option', 'selected', 0); $("#expression-preview-tabs").tabs('option', 'selected', 0);
}); });
}; };
@ -253,15 +253,21 @@ ExpressionPreviewDialog.Widget.prototype._scheduleUpdate = function() {
window.clearTimeout(this._timerID); window.clearTimeout(this._timerID);
} }
var self = this; var self = this;
this._timerID = window.setTimeout(function() { self._update(); }, 300); this._timerID = window.setTimeout(function() { self.update(); }, 300);
}; };
ExpressionPreviewDialog.Widget.prototype._update = function() { ExpressionPreviewDialog.Widget.prototype.update = function() {
var self = this; var self = this;
var expression = this.expression = $.trim(this._elmts.expressionPreviewTextarea[0].value); var expression = this.expression = $.trim(this._elmts.expressionPreviewTextarea[0].value);
var params = {
project: theProject.id,
expression: expression,
cellIndex: this._cellIndex
};
this._prepareUpdate(params);
$.post( $.post(
"/command/preview-expression?" + $.param({ project: theProject.id, expression: expression, cellIndex: this._cellIndex }), "/command/preview-expression?" + $.param(params),
{ {
rowIndices: JSON.stringify(this._rowIndices) rowIndices: JSON.stringify(this._rowIndices)
}, },
@ -277,6 +283,9 @@ ExpressionPreviewDialog.Widget.prototype._update = function() {
); );
}; };
ExpressionPreviewDialog.Widget.prototype._prepareUpdate = function(params) {
};
ExpressionPreviewDialog.Widget.prototype._renderPreview = function(expression, data) { ExpressionPreviewDialog.Widget.prototype._renderPreview = function(expression, data) {
var container = this._elmts.expressionPreviewPreviewContainer.empty(); var container = this._elmts.expressionPreviewPreviewContainer.empty();
var table = $('<table width="100%"></table>').appendTo(container)[0]; var table = $('<table width="100%"></table>').appendTo(container)[0];

View File

@ -479,6 +479,13 @@ DataTableColumnHeaderUI.prototype._doTextTransformPrompt = function() {
o.values, o.values,
"value" "value"
); );
previewWidget._prepareUpdate = function(params) {
params.repeat = bodyElmts.repeatCheckbox[0].checked;
params.repeatCount = bodyElmts.repeatCountInput[0].value;
};
bodyElmts.repeatCheckbox.click(function() {
previewWidget.update();
});
}; };
DataTableColumnHeaderUI.prototype._doReconcile = function() { DataTableColumnHeaderUI.prototype._doReconcile = function() {