Added export row feature.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@43 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
93f0dfd63a
commit
62c8c72dc4
@ -21,6 +21,7 @@ import com.metaweb.gridworks.commands.edit.DoTextTransformCommand;
|
|||||||
import com.metaweb.gridworks.commands.edit.RemoveColumnCommand;
|
import com.metaweb.gridworks.commands.edit.RemoveColumnCommand;
|
||||||
import com.metaweb.gridworks.commands.edit.UndoRedoCommand;
|
import com.metaweb.gridworks.commands.edit.UndoRedoCommand;
|
||||||
import com.metaweb.gridworks.commands.info.ComputeFacetsCommand;
|
import com.metaweb.gridworks.commands.info.ComputeFacetsCommand;
|
||||||
|
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.GetColumnModelCommand;
|
import com.metaweb.gridworks.commands.info.GetColumnModelCommand;
|
||||||
import com.metaweb.gridworks.commands.info.GetHistoryCommand;
|
import com.metaweb.gridworks.commands.info.GetHistoryCommand;
|
||||||
@ -40,6 +41,7 @@ public class GridworksServlet extends HttpServlet {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
_commands.put("create-project-from-upload", new CreateProjectFromUploadCommand());
|
_commands.put("create-project-from-upload", new CreateProjectFromUploadCommand());
|
||||||
|
_commands.put("export-rows", new ExportRowsCommand());
|
||||||
|
|
||||||
_commands.put("get-project-metadata", new GetProjectMetadataCommand());
|
_commands.put("get-project-metadata", new GetProjectMetadataCommand());
|
||||||
_commands.put("get-all-project-metadata", new GetAllProjectMetadataCommand());
|
_commands.put("get-all-project-metadata", new GetAllProjectMetadataCommand());
|
||||||
|
@ -0,0 +1,111 @@
|
|||||||
|
package com.metaweb.gridworks.commands.info;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.browsing.Engine;
|
||||||
|
import com.metaweb.gridworks.browsing.FilteredRows;
|
||||||
|
import com.metaweb.gridworks.browsing.RowVisitor;
|
||||||
|
import com.metaweb.gridworks.commands.Command;
|
||||||
|
import com.metaweb.gridworks.model.Cell;
|
||||||
|
import com.metaweb.gridworks.model.Column;
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
import com.metaweb.gridworks.model.Row;
|
||||||
|
|
||||||
|
public class ExportRowsCommand extends Command {
|
||||||
|
@Override
|
||||||
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Project project = getProject(request);
|
||||||
|
Engine engine = getEngine(request, project);
|
||||||
|
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setHeader("Content-Type", "text/plain");
|
||||||
|
|
||||||
|
PrintWriter writer = response.getWriter();
|
||||||
|
|
||||||
|
boolean first = true;
|
||||||
|
for (Column column : project.columnModel.columns) {
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
writer.print("\t");
|
||||||
|
}
|
||||||
|
writer.print(column.getHeaderLabel());
|
||||||
|
}
|
||||||
|
writer.print("\n");
|
||||||
|
|
||||||
|
{
|
||||||
|
RowVisitor visitor = new RowVisitor() {
|
||||||
|
PrintWriter writer;
|
||||||
|
|
||||||
|
public RowVisitor init(PrintWriter writer) {
|
||||||
|
this.writer = writer;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visit(Project project, int rowIndex, Row row) {
|
||||||
|
boolean first = true;
|
||||||
|
for (Column column : project.columnModel.columns) {
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
writer.print("\t");
|
||||||
|
}
|
||||||
|
|
||||||
|
int cellIndex = column.getCellIndex();
|
||||||
|
if (cellIndex < row.cells.size()) {
|
||||||
|
Cell cell = row.cells.get(cellIndex);
|
||||||
|
if (cell != null && cell.value != null) {
|
||||||
|
writer.print(cell.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writer.print("\n");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}.init(writer);
|
||||||
|
|
||||||
|
FilteredRows filteredRows = engine.getAllFilteredRows();
|
||||||
|
filteredRows.accept(project, visitor);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
respondException(response, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static protected class RowAccumulator implements RowVisitor {
|
||||||
|
final public int start;
|
||||||
|
final public int limit;
|
||||||
|
|
||||||
|
public int total;
|
||||||
|
|
||||||
|
public RowAccumulator(int start, int limit) {
|
||||||
|
this.start = start;
|
||||||
|
this.limit = limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visit(Project project, int rowIndex, Row row) {
|
||||||
|
boolean r = false;
|
||||||
|
|
||||||
|
if (total >= start && total < start + limit) {
|
||||||
|
r = internalVisit(rowIndex, row);
|
||||||
|
}
|
||||||
|
total++;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean internalVisit(int rowIndex, Row row) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -320,6 +320,11 @@ DataTableView.prototype._createMenuForAllColumns = function(elmt) {
|
|||||||
}
|
}
|
||||||
self.render();
|
self.render();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
label: "Export Filtered Rows",
|
||||||
|
click: function() { self._doExportRows(); }
|
||||||
}
|
}
|
||||||
], elmt);
|
], elmt);
|
||||||
};
|
};
|
||||||
@ -776,3 +781,23 @@ DataTableView.prototype._doRemoveColumn = function(column, index) {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DataTableView.prototype._doExportRows = function() {
|
||||||
|
var form = document.createElement("form");
|
||||||
|
$(form)
|
||||||
|
.css("display", "none")
|
||||||
|
.attr("method", "post")
|
||||||
|
.attr("action", "/command/export-rows?project=" + theProject.id)
|
||||||
|
.attr("target", "gridworks-export");
|
||||||
|
|
||||||
|
$('<input />')
|
||||||
|
.attr("name", "engine")
|
||||||
|
.attr("value", JSON.stringify(ui.browsingEngine.getJSON()))
|
||||||
|
.appendTo(form);
|
||||||
|
|
||||||
|
document.body.appendChild(form);
|
||||||
|
|
||||||
|
window.open("about:blank", "gridworks-export");
|
||||||
|
form.submit();
|
||||||
|
|
||||||
|
document.body.removeChild(form);
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user