Renamed "facet-based edit" operation and command to "mass edit", because it's not just facet-based.

Added option "apply to other cells with same original content" to single cell edit popup, so it can be used like a find&replace operation.
Renamed "do-text-transform" operation and command to just "text-transform".

git-svn-id: http://google-refine.googlecode.com/svn/trunk@223 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-03-07 00:25:00 +00:00
parent b9308e4034
commit e0d72c81e9
9 changed files with 97 additions and 48 deletions

View File

@ -16,9 +16,9 @@ import com.metaweb.gridworks.commands.edit.AnnotateRowsCommand;
import com.metaweb.gridworks.commands.edit.ApplyOperationsCommand; import com.metaweb.gridworks.commands.edit.ApplyOperationsCommand;
import com.metaweb.gridworks.commands.edit.CreateProjectCommand; import com.metaweb.gridworks.commands.edit.CreateProjectCommand;
import com.metaweb.gridworks.commands.edit.DeleteProjectCommand; import com.metaweb.gridworks.commands.edit.DeleteProjectCommand;
import com.metaweb.gridworks.commands.edit.DoTextTransformCommand; import com.metaweb.gridworks.commands.edit.TextTransformCommand;
import com.metaweb.gridworks.commands.edit.EditOneCellCommand; import com.metaweb.gridworks.commands.edit.EditOneCellCommand;
import com.metaweb.gridworks.commands.edit.FacetBasedEditCommand; import com.metaweb.gridworks.commands.edit.MassEditCommand;
import com.metaweb.gridworks.commands.edit.JoinMultiValueCellsCommand; import com.metaweb.gridworks.commands.edit.JoinMultiValueCellsCommand;
import com.metaweb.gridworks.commands.edit.RemoveColumnCommand; import com.metaweb.gridworks.commands.edit.RemoveColumnCommand;
import com.metaweb.gridworks.commands.edit.SaveProtographCommand; import com.metaweb.gridworks.commands.edit.SaveProtographCommand;
@ -76,14 +76,15 @@ public class GridworksServlet extends HttpServlet {
_commands.put("compute-facets", new ComputeFacetsCommand()); _commands.put("compute-facets", new ComputeFacetsCommand());
_commands.put("compute-clusters", new ComputeClustersCommand()); _commands.put("compute-clusters", new ComputeClustersCommand());
_commands.put("do-text-transform", new DoTextTransformCommand());
_commands.put("facet-based-edit", new FacetBasedEditCommand());
_commands.put("edit-one-cell", new EditOneCellCommand()); _commands.put("edit-one-cell", new EditOneCellCommand());
_commands.put("text-transform", new TextTransformCommand());
_commands.put("mass-edit", new MassEditCommand());
_commands.put("join-multi-value-cells", new JoinMultiValueCellsCommand());
_commands.put("split-multi-value-cells", new SplitMultiValueCellsCommand());
_commands.put("add-column", new AddColumnCommand()); _commands.put("add-column", new AddColumnCommand());
_commands.put("remove-column", new RemoveColumnCommand()); _commands.put("remove-column", new RemoveColumnCommand());
_commands.put("join-multi-value-cells", new JoinMultiValueCellsCommand());
_commands.put("split-multi-value-cells", new SplitMultiValueCellsCommand());
_commands.put("reconcile", new ReconcileCommand()); _commands.put("reconcile", new ReconcileCommand());
_commands.put("recon-match-best-candidates", new ReconMatchBestCandidatesCommand()); _commands.put("recon-match-best-candidates", new ReconMatchBestCandidatesCommand());

View File

@ -7,10 +7,10 @@ import org.json.JSONObject;
import com.metaweb.gridworks.commands.EngineDependentCommand; import com.metaweb.gridworks.commands.EngineDependentCommand;
import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.operations.FacetBasedEditOperation; import com.metaweb.gridworks.operations.MassEditOperation;
import com.metaweb.gridworks.util.ParsingUtilities; import com.metaweb.gridworks.util.ParsingUtilities;
public class FacetBasedEditCommand extends EngineDependentCommand { public class MassEditCommand extends EngineDependentCommand {
@Override @Override
protected AbstractOperation createOperation(Project project, protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception { HttpServletRequest request, JSONObject engineConfig) throws Exception {
@ -19,11 +19,11 @@ public class FacetBasedEditCommand extends EngineDependentCommand {
String expression = request.getParameter("expression"); String expression = request.getParameter("expression");
String editsString = request.getParameter("edits"); String editsString = request.getParameter("edits");
return new FacetBasedEditOperation( return new MassEditOperation(
engineConfig, engineConfig,
columnName, columnName,
expression, expression,
FacetBasedEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString)) MassEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString))
); );
} }
} }

View File

@ -9,7 +9,7 @@ import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.operations.TextTransformOperation; import com.metaweb.gridworks.operations.TextTransformOperation;
public class DoTextTransformCommand extends EngineDependentCommand { public class TextTransformCommand extends EngineDependentCommand {
@Override @Override
protected AbstractOperation createOperation(Project project, protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception { HttpServletRequest request, JSONObject engineConfig) throws Exception {

View File

@ -23,8 +23,9 @@ import com.metaweb.gridworks.model.Column;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row; import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.model.changes.CellChange; import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.util.ParsingUtilities;
public class FacetBasedEditOperation extends EngineDependentMassCellOperation { public class MassEditOperation extends EngineDependentMassCellOperation {
private static final long serialVersionUID = -7698202759999537298L; private static final long serialVersionUID = -7698202759999537298L;
final protected String _expression; final protected String _expression;
@ -59,7 +60,7 @@ public class FacetBasedEditOperation extends EngineDependentMassCellOperation {
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
JSONObject engineConfig = obj.getJSONObject("engineConfig"); JSONObject engineConfig = obj.getJSONObject("engineConfig");
return new FacetBasedEditOperation( return new MassEditOperation(
engineConfig, engineConfig,
obj.getString("columnName"), obj.getString("columnName"),
obj.getString("expression"), obj.getString("expression"),
@ -82,13 +83,21 @@ public class FacetBasedEditOperation extends EngineDependentMassCellOperation {
from.add(fromA.getString(j)); from.add(fromA.getString(j));
} }
edits.add(new Edit(from, editO.getString("to"))); Serializable to = (Serializable) editO.get("to");
if (editO.has("type")) {
String type = editO.getString("type");
if ("date".equals(type)) {
to = ParsingUtilities.stringToDate((String) to);
}
}
edits.add(new Edit(from, to));
} }
return edits; return edits;
} }
public FacetBasedEditOperation(JSONObject engineConfig, String columnName, String expression, List<Edit> edits) { public MassEditOperation(JSONObject engineConfig, String columnName, String expression, List<Edit> edits) {
super(engineConfig, columnName, true); super(engineConfig, columnName, true);
_expression = expression; _expression = expression;
_edits = edits; _edits = edits;
@ -113,13 +122,13 @@ public class FacetBasedEditOperation extends EngineDependentMassCellOperation {
} }
protected String getBriefDescription(Project project) { protected String getBriefDescription(Project project) {
return "Facet-based edit cells in column " + _columnName; return "Mass edit cells in column " + _columnName;
} }
protected String createDescription(Column column, protected String createDescription(Column column,
List<CellChange> cellChanges) { List<CellChange> cellChanges) {
return "Facet-based edit " + cellChanges.size() + return "Mass edit " + cellChanges.size() +
" cells in column " + column.getName(); " cells in column " + column.getName();
} }

View File

@ -35,5 +35,6 @@ public abstract class OperationRegistry {
register("save-protograph", SaveProtographOperation.class); register("save-protograph", SaveProtographOperation.class);
register("text-transform", TextTransformOperation.class); register("text-transform", TextTransformOperation.class);
register("mass-edit", MassEditOperation.class);
} }
} }

View File

@ -227,7 +227,7 @@ FacetBasedEditDialog.prototype._apply = function(onDone) {
if (edits.length > 0) { if (edits.length > 0) {
Gridworks.postProcess( Gridworks.postProcess(
"facet-based-edit", "mass-edit",
{}, {},
{ {
columnName: this._columnName, columnName: this._columnName,

View File

@ -288,16 +288,31 @@ DataTableCellUI.prototype._previewCandidateTopic = function(id, elmt) {
DataTableCellUI.prototype._startEdit = function(elmt) { DataTableCellUI.prototype._startEdit = function(elmt) {
self = this; self = this;
var originalContent = this._cell == null || ("v" in this._cell && this._cell.v == null) ? "" : this._cell.v;
var menu = MenuSystem.createMenu().width("350px"); var menu = MenuSystem.createMenu().width("350px");
menu.html( menu.html(
'<textarea class="data-table-cell-edit-editor" bind="textarea" />' +
'<table class="data-table-cell-edit-layout">' + '<table class="data-table-cell-edit-layout">' +
'<tr>' +
'<td colspan="4">' +
'<textarea class="data-table-cell-edit-editor" bind="textarea" />' +
'</td>' +
'</tr>' +
'<tr>' + '<tr>' +
'<td>' + '<td>' +
'<input type="radio" name="data-table-cell-edit-type" value="text" checked /> text ' + '<select bind="typeSelect">' +
'<input type="radio" name="data-table-cell-edit-type" value="number" /> number ' + '<option value="text">text</option>' +
'<input type="radio" name="data-table-cell-edit-type" value="boolean" /> boolean' + '<option value="number">number</option>' +
'<input type="radio" name="data-table-cell-edit-type" value="date" /> date' + '<option value="boolean">boolean</option>' +
'<option value="date">date</option>' +
'</select>' +
'</td>' +
'<td width="1%">' +
'<input type="checkbox" bind="applyOthersCheckbox" />' +
'</td>' +
'<td>' +
'apply to other cells with<br/>' +
'same original content' +
'</td>' + '</td>' +
'<td width="1%">' + '<td width="1%">' +
'<button bind="okButton">&nbsp;&nbsp;OK&nbsp;&nbsp;</button>' + '<button bind="okButton">&nbsp;&nbsp;OK&nbsp;&nbsp;</button>' +
@ -311,7 +326,9 @@ DataTableCellUI.prototype._startEdit = function(elmt) {
MenuSystem.positionMenuLeftRight(menu, $(this._td)); MenuSystem.positionMenuLeftRight(menu, $(this._td));
var commit = function() { var commit = function() {
var type = $('input["data-table-cell-edit-type"]:checked')[0].value; var type = elmts.typeSelect[0].value;
var applyOthers = elmts.applyOthersCheckbox[0].checked;
var text = elmts.textarea[0].value; var text = elmts.textarea[0].value;
var value = text; var value = text;
@ -334,16 +351,30 @@ DataTableCellUI.prototype._startEdit = function(elmt) {
MenuSystem.dismissAll(); MenuSystem.dismissAll();
var params = { if (applyOthers) {
Gridworks.postProcess(
"mass-edit",
{},
{
columnName: Gridworks.cellIndexToColumn(self._cellIndex).name,
expression: "value",
edits: JSON.stringify([{
from: [ originalContent ],
to: value,
type: type
}])
},
{ cellsChanged: true }
);
} else {
Gridworks.postProcess(
"edit-one-cell",
{
row: self._rowIndex, row: self._rowIndex,
cell: self._cellIndex, cell: self._cellIndex,
value: value, value: value,
type: type type: type
}; },
Gridworks.postProcess(
"edit-one-cell",
params,
null, null,
{}, {},
{ {
@ -353,11 +384,12 @@ DataTableCellUI.prototype._startEdit = function(elmt) {
} }
} }
); );
}
}; };
elmts.okButton.click(commit); elmts.okButton.click(commit);
elmts.textarea elmts.textarea
.text(this._cell == null || ("v" in this._cell && this._cell.v == null) ? "" : this._cell.v) .text(originalContent)
.keydown(function(evt) { .keydown(function(evt) {
if (evt.keyCode == 13) { if (evt.keyCode == 13) {
commit(); commit();

View File

@ -433,7 +433,7 @@ DataTableColumnHeaderUI.prototype._doFilterByExpressionPrompt = function(express
DataTableColumnHeaderUI.prototype._doTextTransform = function(expression, onError, repeat, repeatCount) { DataTableColumnHeaderUI.prototype._doTextTransform = function(expression, onError, repeat, repeatCount) {
Gridworks.postProcess( Gridworks.postProcess(
"do-text-transform", "text-transform",
{ {
columnName: this._column.name, columnName: this._column.name,
expression: expression, expression: expression,

View File

@ -167,14 +167,20 @@ table.data-table-cell-edit-layout {
width: 100%; width: 100%;
white-space: pre; white-space: pre;
} }
table.data-table-cell-edit-layout td { table.data-table-cell-edit-layout > tbody > tr > td {
padding: 5px; padding-right: 5px;
padding-bottom: 5px;
}
table.data-table-cell-edit-layout > tbody > tr > td:last-child {
padding-right: 0px;
}
table.data-table-cell-edit-layout > tbody > tr:last-child > td {
padding-bottom: 0px;
} }
textarea.data-table-cell-edit-editor { textarea.data-table-cell-edit-editor {
display: block; display: block;
width: 92%; width: 96%;
padding: 2%; padding: 2%;
margin: 2%;
height: 3em; height: 3em;
} }