Allow operations to be extracted in abstract forms.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@99 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
32157ce76b
commit
8c41af9c12
@ -28,6 +28,7 @@ import com.metaweb.gridworks.commands.info.ExportRowsCommand;
|
|||||||
import com.metaweb.gridworks.commands.info.GetAllProjectMetadataCommand;
|
import com.metaweb.gridworks.commands.info.GetAllProjectMetadataCommand;
|
||||||
import com.metaweb.gridworks.commands.info.GetModelsCommand;
|
import com.metaweb.gridworks.commands.info.GetModelsCommand;
|
||||||
import com.metaweb.gridworks.commands.info.GetHistoryCommand;
|
import com.metaweb.gridworks.commands.info.GetHistoryCommand;
|
||||||
|
import com.metaweb.gridworks.commands.info.GetOperationsCommand;
|
||||||
import com.metaweb.gridworks.commands.info.GetProcessesCommand;
|
import com.metaweb.gridworks.commands.info.GetProcessesCommand;
|
||||||
import com.metaweb.gridworks.commands.info.GetProjectMetadataCommand;
|
import com.metaweb.gridworks.commands.info.GetProjectMetadataCommand;
|
||||||
import com.metaweb.gridworks.commands.info.GetRowsCommand;
|
import com.metaweb.gridworks.commands.info.GetRowsCommand;
|
||||||
@ -56,6 +57,7 @@ public class GridworksServlet extends HttpServlet {
|
|||||||
_commands.put("get-rows", new GetRowsCommand());
|
_commands.put("get-rows", new GetRowsCommand());
|
||||||
_commands.put("get-processes", new GetProcessesCommand());
|
_commands.put("get-processes", new GetProcessesCommand());
|
||||||
_commands.put("get-history", new GetHistoryCommand());
|
_commands.put("get-history", new GetHistoryCommand());
|
||||||
|
_commands.put("get-operations", new GetOperationsCommand());
|
||||||
|
|
||||||
_commands.put("undo-redo", new UndoRedoCommand());
|
_commands.put("undo-redo", new UndoRedoCommand());
|
||||||
_commands.put("compute-facets", new ComputeFacetsCommand());
|
_commands.put("compute-facets", new ComputeFacetsCommand());
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
package com.metaweb.gridworks.commands.info;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.commands.Command;
|
||||||
|
import com.metaweb.gridworks.history.HistoryEntry;
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
|
||||||
|
public class GetOperationsCommand extends Command {
|
||||||
|
@Override
|
||||||
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
|
||||||
|
Project project = getProject(request);
|
||||||
|
|
||||||
|
try {
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setHeader("Content-Type", "application/json");
|
||||||
|
|
||||||
|
Properties options = new Properties();
|
||||||
|
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||||
|
|
||||||
|
writer.object();
|
||||||
|
writer.key("operations"); writer.array();
|
||||||
|
|
||||||
|
for (HistoryEntry entry : project.history.getLastPastEntries(-1)) {
|
||||||
|
if (entry.operation != null) {
|
||||||
|
entry.operation.write(writer, options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writer.endArray();
|
||||||
|
writer.endObject();
|
||||||
|
} catch (JSONException e) {
|
||||||
|
respondException(response, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,7 @@ package com.metaweb.gridworks.history;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@ -42,7 +43,11 @@ public class History implements Serializable, Jsonizable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<HistoryEntry> getLastPastEntries(int count) {
|
public List<HistoryEntry> getLastPastEntries(int count) {
|
||||||
return _pastEntries.subList(Math.max(_pastEntries.size() - count, 0), _pastEntries.size());
|
if (count <= 0) {
|
||||||
|
return new LinkedList<HistoryEntry>(_pastEntries);
|
||||||
|
} else {
|
||||||
|
return _pastEntries.subList(Math.max(_pastEntries.size() - count, 0), _pastEntries.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void undoRedo(long lastDoneEntryID) {
|
public void undoRedo(long lastDoneEntryID) {
|
||||||
|
@ -27,6 +27,7 @@ public class ApproveNewReconOperation extends EngineDependentMassCellOperation {
|
|||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
|
writer.key("op"); writer.value("approve-new-recon");
|
||||||
writer.key("description"); writer.value("Approve new topics in column " + _columnName);
|
writer.key("description"); writer.value("Approve new topics in column " + _columnName);
|
||||||
writer.key("engineConfig"); writer.value(_engineConfig);
|
writer.key("engineConfig"); writer.value(_engineConfig);
|
||||||
writer.key("columnName"); writer.value(_columnName);
|
writer.key("columnName"); writer.value(_columnName);
|
||||||
|
@ -24,8 +24,13 @@ public class ApproveReconOperation extends EngineDependentMassCellOperation {
|
|||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
|
writer.object();
|
||||||
|
writer.key("op"); writer.value("approve-recon");
|
||||||
|
writer.key("description"); writer.value("Approve best recon matches in column " + _columnName);
|
||||||
|
writer.key("engineConfig"); writer.value(_engineConfig);
|
||||||
|
writer.key("columnName"); writer.value(_columnName);
|
||||||
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String createDescription(Column column,
|
protected String createDescription(Column column,
|
||||||
|
@ -76,8 +76,21 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
|
|||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
writer.object();
|
||||||
|
writer.key("op"); writer.value("add-column");
|
||||||
|
writer.key("description"); writer.value(
|
||||||
|
"Create column " + _headerLabel +
|
||||||
|
" at index " + _columnInsertIndex +
|
||||||
|
" based on column " + _baseColumnName +
|
||||||
|
" using expression " + _expression);
|
||||||
|
|
||||||
|
writer.key("engineConfig"); writer.value(_engineConfig);
|
||||||
|
writer.key("headerLabel"); writer.value(_headerLabel);
|
||||||
|
writer.key("columnInsertIndex"); writer.value(_columnInsertIndex);
|
||||||
|
writer.key("baseColumnName"); writer.value(_baseColumnName);
|
||||||
|
writer.key("expression"); writer.value(_expression);
|
||||||
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String createDescription(Column column, List<CellAtRow> cellsAtRows) {
|
protected String createDescription(Column column, List<CellAtRow> cellsAtRows) {
|
||||||
|
@ -44,7 +44,11 @@ public class ColumnRemovalOperation implements AbstractOperation {
|
|||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
writer.object();
|
||||||
|
writer.key("op"); writer.value("remove-column");
|
||||||
|
writer.key("description"); writer.value("Remove column " + _columnName);
|
||||||
|
writer.key("columnName"); writer.value(_columnName);
|
||||||
|
writer.endObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,13 @@ public class DiscardReconOperation extends EngineDependentMassCellOperation {
|
|||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
|
writer.object();
|
||||||
|
writer.key("op"); writer.value("disapprove-recon");
|
||||||
|
writer.key("description"); writer.value("Discard recon judgments in column " + _columnName);
|
||||||
|
writer.key("engineConfig"); writer.value(_engineConfig);
|
||||||
|
writer.key("columnName"); writer.value(_columnName);
|
||||||
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String createDescription(Column column,
|
protected String createDescription(Column column,
|
||||||
|
@ -99,7 +99,7 @@ public class MultiValueCellJoinOperation implements AbstractOperation {
|
|||||||
r = r2 - 1; // r will be incremented by the for loop anyway
|
r = r2 - 1; // r will be incremented by the for loop anyway
|
||||||
}
|
}
|
||||||
|
|
||||||
String description = "Join multi-value cells in column " + column.getHeaderLabel();
|
String description = "Join multi-valued cells in column " + column.getHeaderLabel();
|
||||||
|
|
||||||
Change change = new MassRowChange(newRows);
|
Change change = new MassRowChange(newRows);
|
||||||
HistoryEntry historyEntry = new HistoryEntry(
|
HistoryEntry historyEntry = new HistoryEntry(
|
||||||
@ -110,7 +110,13 @@ public class MultiValueCellJoinOperation implements AbstractOperation {
|
|||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
writer.object();
|
||||||
|
writer.key("op"); writer.value("join-multivalued-cells");
|
||||||
|
writer.key("description"); writer.value("Join multi-valued cells in column " + _columnName);
|
||||||
|
writer.key("columnName"); writer.value(_columnName);
|
||||||
|
writer.key("keyColumnName"); writer.value(_keyColumnName);
|
||||||
|
writer.key("separator"); writer.value(_separator);
|
||||||
|
writer.endObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ public class MultiValueCellSplitOperation implements AbstractOperation {
|
|||||||
r = r2 - 1; // r will be incremented by the for loop anyway
|
r = r2 - 1; // r will be incremented by the for loop anyway
|
||||||
}
|
}
|
||||||
|
|
||||||
String description = "Split multi-value cells in column " + column.getHeaderLabel();
|
String description = "Split multi-valued cells in column " + column.getHeaderLabel();
|
||||||
|
|
||||||
Change change = new MassRowChange(newRows);
|
Change change = new MassRowChange(newRows);
|
||||||
HistoryEntry historyEntry = new HistoryEntry(
|
HistoryEntry historyEntry = new HistoryEntry(
|
||||||
@ -125,7 +125,14 @@ public class MultiValueCellSplitOperation implements AbstractOperation {
|
|||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
writer.object();
|
||||||
|
writer.key("op"); writer.value("split-multivalued-cells");
|
||||||
|
writer.key("description"); writer.value("Split multi-valued cells in column " + _columnName);
|
||||||
|
writer.key("columnName"); writer.value(_columnName);
|
||||||
|
writer.key("keyColumnName"); writer.value(_keyColumnName);
|
||||||
|
writer.key("separator"); writer.value(_separator);
|
||||||
|
writer.key("mode"); writer.value(_mode);
|
||||||
|
writer.endObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,8 +94,13 @@ public class ReconOperation extends EngineDependentOperation {
|
|||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
|
writer.object();
|
||||||
|
writer.key("op"); writer.value("recon");
|
||||||
|
writer.key("description"); writer.value("Reconcile cells in column " + _columnName + " to type " + _typeID);
|
||||||
|
writer.key("columnName"); writer.value(_columnName);
|
||||||
|
writer.key("typeID"); writer.value(_typeID);
|
||||||
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
static protected class ReconEntry {
|
static protected class ReconEntry {
|
||||||
|
@ -38,8 +38,12 @@ public class SaveProtographOperation implements AbstractOperation {
|
|||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
writer.object();
|
||||||
|
writer.key("op"); writer.value("save-protograph");
|
||||||
|
writer.key("description"); writer.value("Save protograph");
|
||||||
|
writer.key("protograph"); _protograph.write(writer, options);
|
||||||
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +29,14 @@ public class TextTransformOperation extends EngineDependentMassCellOperation {
|
|||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
writer.object();
|
||||||
|
writer.key("op"); writer.value("text-transform");
|
||||||
|
writer.key("description"); writer.value("Text transform on cells in column " + _columnName + " with expression " + _expression);
|
||||||
|
writer.key("engineConfig"); writer.value(_engineConfig);
|
||||||
|
writer.key("columnName"); writer.value(_columnName);
|
||||||
|
writer.key("expression"); writer.value(_expression);
|
||||||
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String createDescription(Column column,
|
protected String createDescription(Column column,
|
||||||
|
@ -63,6 +63,16 @@ HistoryWidget.prototype._render = function() {
|
|||||||
bodyDiv[0].scrollTop = divNow[0].offsetTop + divNow[0].offsetHeight - bodyDiv[0].offsetHeight;
|
bodyDiv[0].scrollTop = divNow[0].offsetTop + divNow[0].offsetHeight - bodyDiv[0].offsetHeight;
|
||||||
};
|
};
|
||||||
autoscroll();
|
autoscroll();
|
||||||
|
|
||||||
|
|
||||||
|
var footerDiv = $('<div></div>').addClass("history-panel-footer").appendTo(this._div);
|
||||||
|
$('<a href="javascript:{}"></a>').text("extract").appendTo(footerDiv).click(function() {
|
||||||
|
self._extractOperations();
|
||||||
|
});
|
||||||
|
$('<span> • </span>').appendTo(footerDiv);
|
||||||
|
$('<a href="javascript:{}"></a>').text("apply").appendTo(footerDiv).click(function() {
|
||||||
|
self._applyOperations();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
HistoryWidget.prototype._onClickHistoryEntry = function(evt, entry, lastDoneID) {
|
HistoryWidget.prototype._onClickHistoryEntry = function(evt, entry, lastDoneID) {
|
||||||
@ -81,3 +91,38 @@ HistoryWidget.prototype._onClickHistoryEntry = function(evt, entry, lastDoneID)
|
|||||||
"json"
|
"json"
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
HistoryWidget.prototype._extractOperations = function() {
|
||||||
|
var self = this;console.log("here");
|
||||||
|
$.getJSON(
|
||||||
|
"/command/get-operations?" + $.param({ project: theProject.id }),
|
||||||
|
null,
|
||||||
|
function(data) {
|
||||||
|
if ("operations" in data) {
|
||||||
|
self._showOperationsDialog(data.operations);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"jsonp"
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
HistoryWidget.prototype._showOperationsDialog = function(json) {
|
||||||
|
var self = this;
|
||||||
|
var frame = DialogSystem.createDialog();
|
||||||
|
frame.width("800px");
|
||||||
|
|
||||||
|
var header = $('<div></div>').addClass("dialog-header").text("Operations").appendTo(frame);
|
||||||
|
var body = $('<div></div>').addClass("dialog-body").appendTo(frame);
|
||||||
|
var footer = $('<div></div>').addClass("dialog-footer").appendTo(frame);
|
||||||
|
|
||||||
|
var textarea = $('<textarea />').attr("wrap", "hard").width("100%").height("400px").appendTo(body);
|
||||||
|
textarea.text(JSON.stringify(json, null, 2));
|
||||||
|
|
||||||
|
$('<button></button>').text("Done").click(function() {
|
||||||
|
DialogSystem.dismissUntil(level - 1);
|
||||||
|
}).appendTo(footer);
|
||||||
|
|
||||||
|
var level = DialogSystem.showDialog(frame);
|
||||||
|
|
||||||
|
textarea[0].focus();
|
||||||
|
};
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
border: 1px solid #666;
|
border: 1px solid #666;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
-moz-border-radius-bottomleft: 20px;
|
-moz-border-radius-bottomleft: 20px;
|
||||||
padding-bottom: 10px;
|
|
||||||
}
|
}
|
||||||
.history-panel h3 {
|
.history-panel h3 {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
@ -74,3 +73,16 @@ a.history-entry:hover {
|
|||||||
.history-future a.history-entry {
|
.history-future a.history-entry {
|
||||||
color: #888;
|
color: #888;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.history-panel-footer {
|
||||||
|
margin: 0;
|
||||||
|
padding: 3px;
|
||||||
|
background: #aaa;
|
||||||
|
color: #eee;
|
||||||
|
font-size: 80%;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.history-panel-footer a {
|
||||||
|
color: white;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user