diff --git a/src/main/java/com/metaweb/gridworks/GridworksServlet.java b/src/main/java/com/metaweb/gridworks/GridworksServlet.java index 379b017e1..d29a9582e 100644 --- a/src/main/java/com/metaweb/gridworks/GridworksServlet.java +++ b/src/main/java/com/metaweb/gridworks/GridworksServlet.java @@ -28,6 +28,7 @@ import com.metaweb.gridworks.commands.info.ExportRowsCommand; import com.metaweb.gridworks.commands.info.GetAllProjectMetadataCommand; import com.metaweb.gridworks.commands.info.GetModelsCommand; 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.GetProjectMetadataCommand; 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-processes", new GetProcessesCommand()); _commands.put("get-history", new GetHistoryCommand()); + _commands.put("get-operations", new GetOperationsCommand()); _commands.put("undo-redo", new UndoRedoCommand()); _commands.put("compute-facets", new ComputeFacetsCommand()); diff --git a/src/main/java/com/metaweb/gridworks/commands/info/GetOperationsCommand.java b/src/main/java/com/metaweb/gridworks/commands/info/GetOperationsCommand.java new file mode 100644 index 000000000..cca378d6c --- /dev/null +++ b/src/main/java/com/metaweb/gridworks/commands/info/GetOperationsCommand.java @@ -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); + } + } + +} diff --git a/src/main/java/com/metaweb/gridworks/history/History.java b/src/main/java/com/metaweb/gridworks/history/History.java index 2b174c35b..c5ac8e1f0 100644 --- a/src/main/java/com/metaweb/gridworks/history/History.java +++ b/src/main/java/com/metaweb/gridworks/history/History.java @@ -2,6 +2,7 @@ package com.metaweb.gridworks.history; import java.io.Serializable; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import java.util.Properties; @@ -42,7 +43,11 @@ public class History implements Serializable, Jsonizable { } public List getLastPastEntries(int count) { - return _pastEntries.subList(Math.max(_pastEntries.size() - count, 0), _pastEntries.size()); + if (count <= 0) { + return new LinkedList(_pastEntries); + } else { + return _pastEntries.subList(Math.max(_pastEntries.size() - count, 0), _pastEntries.size()); + } } public void undoRedo(long lastDoneEntryID) { diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ApproveNewReconOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ApproveNewReconOperation.java index c99699bae..766c791e8 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ApproveNewReconOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ApproveNewReconOperation.java @@ -27,6 +27,7 @@ public class ApproveNewReconOperation extends EngineDependentMassCellOperation { throws JSONException { writer.object(); + writer.key("op"); writer.value("approve-new-recon"); writer.key("description"); writer.value("Approve new topics in column " + _columnName); writer.key("engineConfig"); writer.value(_engineConfig); writer.key("columnName"); writer.value(_columnName); diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ApproveReconOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ApproveReconOperation.java index e677860c2..30f3fb1f3 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ApproveReconOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ApproveReconOperation.java @@ -24,8 +24,13 @@ public class ApproveReconOperation extends EngineDependentMassCellOperation { public void write(JSONWriter writer, Properties options) 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, diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ColumnAdditionOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ColumnAdditionOperation.java index bc2659154..215ad7736 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ColumnAdditionOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ColumnAdditionOperation.java @@ -76,8 +76,21 @@ public class ColumnAdditionOperation extends EngineDependentOperation { public void write(JSONWriter writer, Properties options) 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 cellsAtRows) { diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ColumnRemovalOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ColumnRemovalOperation.java index 7439699cd..efccced58 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ColumnRemovalOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ColumnRemovalOperation.java @@ -44,7 +44,11 @@ public class ColumnRemovalOperation implements AbstractOperation { public void write(JSONWriter writer, Properties options) 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(); } } diff --git a/src/main/java/com/metaweb/gridworks/model/operations/DiscardReconOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/DiscardReconOperation.java index 4bb5fd030..d2508abc0 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/DiscardReconOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/DiscardReconOperation.java @@ -23,8 +23,13 @@ public class DiscardReconOperation extends EngineDependentMassCellOperation { public void write(JSONWriter writer, Properties options) 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, diff --git a/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellJoinOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellJoinOperation.java index 7bcb2cd38..f4fca1cad 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellJoinOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellJoinOperation.java @@ -99,7 +99,7 @@ public class MultiValueCellJoinOperation implements AbstractOperation { 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); HistoryEntry historyEntry = new HistoryEntry( @@ -110,7 +110,13 @@ public class MultiValueCellJoinOperation implements AbstractOperation { public void write(JSONWriter writer, Properties options) 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(); } } diff --git a/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellSplitOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellSplitOperation.java index 76803dbc8..06ef2ba10 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellSplitOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellSplitOperation.java @@ -114,7 +114,7 @@ public class MultiValueCellSplitOperation implements AbstractOperation { 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); HistoryEntry historyEntry = new HistoryEntry( @@ -125,7 +125,14 @@ public class MultiValueCellSplitOperation implements AbstractOperation { public void write(JSONWriter writer, Properties options) 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(); } } diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java index bc49147d0..ee1681048 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java @@ -94,8 +94,13 @@ public class ReconOperation extends EngineDependentOperation { public void write(JSONWriter writer, Properties options) 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 { diff --git a/src/main/java/com/metaweb/gridworks/model/operations/SaveProtographOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/SaveProtographOperation.java index a057c12a3..409f0dd31 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/SaveProtographOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/SaveProtographOperation.java @@ -38,8 +38,12 @@ public class SaveProtographOperation implements AbstractOperation { public void write(JSONWriter writer, Properties options) 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(); } diff --git a/src/main/java/com/metaweb/gridworks/model/operations/TextTransformOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/TextTransformOperation.java index 06c2fa83a..5e3bee191 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/TextTransformOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/TextTransformOperation.java @@ -29,7 +29,14 @@ public class TextTransformOperation extends EngineDependentMassCellOperation { public void write(JSONWriter writer, Properties options) 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, diff --git a/src/main/webapp/scripts/project/history-widget.js b/src/main/webapp/scripts/project/history-widget.js index 09a9e2a91..3bdfb09d9 100644 --- a/src/main/webapp/scripts/project/history-widget.js +++ b/src/main/webapp/scripts/project/history-widget.js @@ -63,6 +63,16 @@ HistoryWidget.prototype._render = function() { bodyDiv[0].scrollTop = divNow[0].offsetTop + divNow[0].offsetHeight - bodyDiv[0].offsetHeight; }; autoscroll(); + + + var footerDiv = $('
').addClass("history-panel-footer").appendTo(this._div); + $('').text("extract").appendTo(footerDiv).click(function() { + self._extractOperations(); + }); + $('').appendTo(footerDiv); + $('').text("apply").appendTo(footerDiv).click(function() { + self._applyOperations(); + }); }; HistoryWidget.prototype._onClickHistoryEntry = function(evt, entry, lastDoneID) { @@ -81,3 +91,38 @@ HistoryWidget.prototype._onClickHistoryEntry = function(evt, entry, lastDoneID) "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 = $('
').addClass("dialog-header").text("Operations").appendTo(frame); + var body = $('
').addClass("dialog-body").appendTo(frame); + var footer = $('
').addClass("dialog-footer").appendTo(frame); + + var textarea = $('