Made facets' expressions editable.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@527 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
b8adb42c4e
commit
0778b324de
@ -40,7 +40,7 @@ public class PreviewExpressionCommand extends Command {
|
||||
Project project = getProject(request);
|
||||
|
||||
int cellIndex = Integer.parseInt(request.getParameter("cellIndex"));
|
||||
String columnName = project.columnModel.getColumnByCellIndex(cellIndex).getName();
|
||||
String columnName = cellIndex < 0 ? "" : project.columnModel.getColumnByCellIndex(cellIndex).getName();
|
||||
|
||||
String expression = request.getParameter("expression");
|
||||
String rowIndicesString = request.getParameter("rowIndices");
|
||||
|
@ -71,7 +71,7 @@ public class Row implements HasFields, Jsonizable {
|
||||
}
|
||||
|
||||
public Cell getCell(int cellIndex) {
|
||||
if (cellIndex < cells.size()) {
|
||||
if (cellIndex >= 0 && cellIndex < cells.size()) {
|
||||
return cells.get(cellIndex);
|
||||
} else {
|
||||
return null;
|
||||
@ -79,7 +79,7 @@ public class Row implements HasFields, Jsonizable {
|
||||
}
|
||||
|
||||
public Object getCellValue(int cellIndex) {
|
||||
if (cellIndex < cells.size()) {
|
||||
if (cellIndex >= 0 && cellIndex < cells.size()) {
|
||||
Cell cell = cells.get(cellIndex);
|
||||
if (cell != null) {
|
||||
return cell.value;
|
||||
|
@ -98,7 +98,7 @@ ExpressionPreviewDialog.Widget = function(
|
||||
if (colon > 0) {
|
||||
var l = expression.substring(0, colon);
|
||||
if (l == "gel" || l == "jython" || l == "clojure") {
|
||||
expression = expression.substring(colon + 1);
|
||||
this.expression = expression.substring(colon + 1);
|
||||
language = l;
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ ListFacet.prototype._initializeUI = function() {
|
||||
this._elmts = DOM.bind(this._div);
|
||||
|
||||
this._elmts.titleSpan.text(this._config.name);
|
||||
this._elmts.expressionDiv.text(this._config.expression);
|
||||
this._elmts.expressionDiv.text(this._config.expression).click(function() { self._editExpression(); });
|
||||
this._elmts.removeButton.click(function() { self._remove(); });
|
||||
this._elmts.resetButton.click(function() { self._reset(); });
|
||||
|
||||
@ -491,3 +491,29 @@ ListFacet.prototype._remove = function() {
|
||||
ListFacet.prototype._updateRest = function() {
|
||||
Gridworks.update({ engineChanged: true });
|
||||
};
|
||||
|
||||
ListFacet.prototype._editExpression = function() {
|
||||
var self = this;
|
||||
var title = (this._config.columnName) ?
|
||||
("Edit Facet's Expression based on Column " + this._config.columnName) :
|
||||
"Edit Facet's Expression"
|
||||
|
||||
var column = Gridworks.columnNameToColumn(this._config.columnName);
|
||||
var o = DataTableView.sampleVisibleRows(column);
|
||||
|
||||
new ExpressionPreviewDialog(
|
||||
title,
|
||||
column ? column.cellIndex : -1,
|
||||
o.rowIndices,
|
||||
o.values,
|
||||
this._config.expression,
|
||||
function(expr) {
|
||||
if (expr != self._config.expression) {
|
||||
self._config.expression = expr;
|
||||
self._elmts.expressionDiv.text(self._config.expression);
|
||||
self.reset();
|
||||
self._updateRest();
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
@ -115,7 +115,7 @@ RangeFacet.prototype._initializeUI = function() {
|
||||
this._elmts = DOM.bind(this._div);
|
||||
|
||||
this._elmts.facetTitle.text(this._config.name);
|
||||
this._elmts.expressionDiv.text(this._config.expression);
|
||||
this._elmts.expressionDiv.text(this._config.expression).click(function() { self._editExpression(); });
|
||||
|
||||
this._elmts.resetButton.click(function() {
|
||||
self.reset();
|
||||
@ -330,3 +330,32 @@ RangeFacet.prototype._remove = function() {
|
||||
RangeFacet.prototype._updateRest = function() {
|
||||
Gridworks.update({ engineChanged: true });
|
||||
};
|
||||
|
||||
RangeFacet.prototype._editExpression = function() {
|
||||
var self = this;
|
||||
var title = (this._config.columnName) ?
|
||||
("Edit Facet's Expression based on Column " + this._config.columnName) :
|
||||
"Edit Facet's Expression"
|
||||
|
||||
var column = Gridworks.columnNameToColumn(this._config.columnName);
|
||||
var o = DataTableView.sampleVisibleRows(column);
|
||||
|
||||
new ExpressionPreviewDialog(
|
||||
title,
|
||||
column ? column.cellIndex : -1,
|
||||
o.rowIndices,
|
||||
o.values,
|
||||
this._config.expression,
|
||||
function(expr) {
|
||||
if (expr != self._config.expression) {
|
||||
self._config.expression = expr;
|
||||
self._elmts.expressionDiv.text(self._config.expression);
|
||||
|
||||
self.reset();
|
||||
self._from = null;
|
||||
self._to = null;
|
||||
self._updateRest();
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
@ -295,6 +295,16 @@ Gridworks.cellIndexToColumn = function(cellIndex) {
|
||||
}
|
||||
return null;
|
||||
};
|
||||
Gridworks.columnNameToColumn = function(columnName) {
|
||||
var columns = theProject.columnModel.columns;
|
||||
for (var i = 0; i < columns.length; i++) {
|
||||
var column = columns[i];
|
||||
if (column.name == columnName) {
|
||||
return column;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
Gridworks.preparePool = function(pool) {
|
||||
for (var id in pool.recons) {
|
||||
|
@ -419,7 +419,7 @@ DataTableView.sampleVisibleRows = function(column) {
|
||||
rowIndices.push(row.i);
|
||||
|
||||
var v = null;
|
||||
if (column.cellIndex < row.cells.length) {
|
||||
if (column && column.cellIndex < row.cells.length) {
|
||||
var cell = row.cells[column.cellIndex];
|
||||
if (cell !== null) {
|
||||
v = cell.v;
|
||||
|
@ -60,6 +60,7 @@ li.facet-container {
|
||||
font-family: monospace;
|
||||
font-size: 11px;
|
||||
background: #eee;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.facet-status {
|
||||
|
Loading…
Reference in New Issue
Block a user