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:
parent
cde6a02cbb
commit
70df6821a0
@ -39,6 +39,16 @@ public class PreviewExpressionCommand extends Command {
|
||||
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.setHeader("Content-Type", "application/json");
|
||||
|
||||
@ -63,10 +73,25 @@ public class PreviewExpressionCommand extends Command {
|
||||
Row row = project.rows.get(rowIndex);
|
||||
Cell cell = row.getCell(cellIndex);
|
||||
|
||||
ExpressionUtils.bind(bindings, row, rowIndex, cell);
|
||||
|
||||
try {
|
||||
ExpressionUtils.bind(bindings, row, rowIndex, cell);
|
||||
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) {
|
||||
// ignore
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ ExpressionPreviewDialog.Widget = function(
|
||||
.select()
|
||||
.focus();
|
||||
|
||||
this._update();
|
||||
this.update();
|
||||
this._renderExpressionHistoryTab();
|
||||
this._renderHelpTab();
|
||||
};
|
||||
@ -237,7 +237,7 @@ ExpressionPreviewDialog.Widget.prototype._renderExpressionHistory = function(dat
|
||||
$('<a href="javascript:{}">Re-use</a>').appendTo(tr.insertCell(2)).click(function() {
|
||||
self._elmts.expressionPreviewTextarea[0].value = entry.code;
|
||||
self._elmts.expressionPreviewTextarea.select().focus();
|
||||
self._update();
|
||||
self.update();
|
||||
$("#expression-preview-tabs").tabs('option', 'selected', 0);
|
||||
});
|
||||
};
|
||||
@ -253,15 +253,21 @@ ExpressionPreviewDialog.Widget.prototype._scheduleUpdate = function() {
|
||||
window.clearTimeout(this._timerID);
|
||||
}
|
||||
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 expression = this.expression = $.trim(this._elmts.expressionPreviewTextarea[0].value);
|
||||
var params = {
|
||||
project: theProject.id,
|
||||
expression: expression,
|
||||
cellIndex: this._cellIndex
|
||||
};
|
||||
this._prepareUpdate(params);
|
||||
|
||||
$.post(
|
||||
"/command/preview-expression?" + $.param({ project: theProject.id, expression: expression, cellIndex: this._cellIndex }),
|
||||
"/command/preview-expression?" + $.param(params),
|
||||
{
|
||||
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) {
|
||||
var container = this._elmts.expressionPreviewPreviewContainer.empty();
|
||||
var table = $('<table width="100%"></table>').appendTo(container)[0];
|
||||
|
@ -479,6 +479,13 @@ DataTableColumnHeaderUI.prototype._doTextTransformPrompt = function() {
|
||||
o.values,
|
||||
"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() {
|
||||
|
Loading…
Reference in New Issue
Block a user