Added support for specifying number of initial rows to skip when creating a new project.
Fixed the height of the histogram images in range facets to eliminate jitters. git-svn-id: http://google-refine.googlecode.com/svn/trunk@135 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
254853b51d
commit
bb83dcda1c
@ -90,6 +90,8 @@ public class CreateProjectCommand extends Command {
|
||||
String url = null;
|
||||
|
||||
int limit = -1;
|
||||
int skip = 0;
|
||||
|
||||
if (options.containsKey("limit")) {
|
||||
String s = options.getProperty("limit");
|
||||
try {
|
||||
@ -97,6 +99,13 @@ public class CreateProjectCommand extends Command {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
if (options.containsKey("skip")) {
|
||||
String s = options.getProperty("skip");
|
||||
try {
|
||||
skip = Integer.parseInt(s);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
while ((part = parser.readNextPart()) != null) {
|
||||
|
||||
@ -108,14 +117,14 @@ public class CreateProjectCommand extends Command {
|
||||
if (importer.takesReader()) {
|
||||
Reader reader = new InputStreamReader(filePart.getInputStream());
|
||||
try {
|
||||
importer.read(reader, project, options, limit);
|
||||
importer.read(reader, project, options, skip, limit);
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
} else {
|
||||
InputStream inputStream = filePart.getInputStream();
|
||||
try {
|
||||
importer.read(inputStream, project, options, limit);
|
||||
importer.read(inputStream, project, options, skip, limit);
|
||||
} finally {
|
||||
inputStream.close();
|
||||
}
|
||||
@ -126,7 +135,7 @@ public class CreateProjectCommand extends Command {
|
||||
if (paramName.equals("raw-text")) {
|
||||
StringReader reader = new StringReader(paramPart.getStringValue());
|
||||
try {
|
||||
new TsvCsvImporter().read(reader, project, options, limit);
|
||||
new TsvCsvImporter().read(reader, project, options, skip, limit);
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
@ -139,7 +148,7 @@ public class CreateProjectCommand extends Command {
|
||||
}
|
||||
|
||||
if (url != null && url.length() > 0) {
|
||||
internalImportURL(request, project, options, url, limit);
|
||||
internalImportURL(request, project, options, url, skip, limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -149,6 +158,7 @@ public class CreateProjectCommand extends Command {
|
||||
Project project,
|
||||
Properties options,
|
||||
String urlString,
|
||||
int skip,
|
||||
int limit
|
||||
) throws Exception {
|
||||
URL url = new URL(urlString);
|
||||
@ -182,9 +192,9 @@ public class CreateProjectCommand extends Command {
|
||||
Reader reader = new InputStreamReader(
|
||||
inputStream, (encoding == null) ? "ISO-8859-1" : encoding);
|
||||
|
||||
importer.read(reader, project, options, limit);
|
||||
importer.read(reader, project, options, skip, limit);
|
||||
} else {
|
||||
importer.read(inputStream, project, options, limit);
|
||||
importer.read(inputStream, project, options, skip, limit);
|
||||
}
|
||||
} finally {
|
||||
inputStream.close();
|
||||
|
@ -29,14 +29,14 @@ public class ExcelImporter implements Importer {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void read(Reader reader, Project project, Properties options, int limit)
|
||||
public void read(Reader reader, Project project, Properties options, int skip, int limit)
|
||||
throws Exception {
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void read(InputStream inputStream, Project project,
|
||||
Properties options, int limit) throws Exception {
|
||||
Properties options, int skip, int limit) throws Exception {
|
||||
|
||||
Workbook wb = _xmlBased ?
|
||||
new XSSFWorkbook(inputStream) :
|
||||
@ -99,6 +99,7 @@ public class ExcelImporter implements Importer {
|
||||
/*
|
||||
* Now process the data rows
|
||||
*/
|
||||
int rowsWithData = 0;
|
||||
for (; r <= lastRow; r++) {
|
||||
org.apache.poi.ss.usermodel.Row row = sheet.getRow(r);
|
||||
if (row == null) {
|
||||
@ -149,10 +150,14 @@ public class ExcelImporter implements Importer {
|
||||
}
|
||||
|
||||
if (hasData) {
|
||||
project.rows.add(newRow);
|
||||
if (limit > 0 && project.rows.size() >= limit) {
|
||||
break;
|
||||
}
|
||||
rowsWithData++;
|
||||
|
||||
if (skip <= 0 || rowsWithData > skip) {
|
||||
project.rows.add(newRow);
|
||||
if (limit > 0 && project.rows.size() >= limit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,6 @@ import com.metaweb.gridworks.model.Project;
|
||||
public interface Importer {
|
||||
public boolean takesReader();
|
||||
|
||||
public void read(Reader reader, Project project, Properties options, int limit) throws Exception;
|
||||
public void read(InputStream inputStream, Project project, Properties options, int limit) throws Exception;
|
||||
public void read(Reader reader, Project project, Properties options, int skip, int limit) throws Exception;
|
||||
public void read(InputStream inputStream, Project project, Properties options, int skip, int limit) throws Exception;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import com.metaweb.gridworks.model.Row;
|
||||
|
||||
public class TsvCsvImporter implements Importer {
|
||||
|
||||
public void read(Reader reader, Project project, Properties options, int limit)
|
||||
public void read(Reader reader, Project project, Properties options, int skip, int limit)
|
||||
throws Exception {
|
||||
|
||||
LineNumberReader lnReader = new LineNumberReader(reader);
|
||||
@ -23,6 +23,7 @@ public class TsvCsvImporter implements Importer {
|
||||
boolean first = true;
|
||||
int cellCount = 1;
|
||||
|
||||
int rowsWithData = 0;
|
||||
while ((line = lnReader.readLine()) != null) {
|
||||
if (line.trim().length() == 0) {
|
||||
continue;
|
||||
@ -57,12 +58,16 @@ public class TsvCsvImporter implements Importer {
|
||||
Row row = new Row(cellCount);
|
||||
|
||||
if ((sep.charAt(0) == ',') ? ImporterUtilities.parseCSVIntoRow(row, line) : ImporterUtilities.parseTSVIntoRow(row, line)) {
|
||||
project.rows.add(row);
|
||||
project.columnModel.setMaxCellIndex(Math.max(project.columnModel.getMaxCellIndex(), row.cells.size()));
|
||||
rowsWithData++;
|
||||
|
||||
if (limit > 0 && project.rows.size() >= limit) {
|
||||
break;
|
||||
}
|
||||
if (skip <= 0 || rowsWithData > skip) {
|
||||
project.rows.add(row);
|
||||
project.columnModel.setMaxCellIndex(Math.max(project.columnModel.getMaxCellIndex(), row.cells.size()));
|
||||
|
||||
if (limit > 0 && project.rows.size() >= limit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -72,7 +77,7 @@ public class TsvCsvImporter implements Importer {
|
||||
}
|
||||
|
||||
public void read(InputStream inputStream, Project project,
|
||||
Properties options, int limit) throws Exception {
|
||||
Properties options, int skip, int limit) throws Exception {
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -1,3 +1 @@
|
||||
<html>
<head>
<title>Gridworks</title>
<link rel="stylesheet" href="/styles/common.css" />
<link rel="stylesheet" href="/styles/index.css" />
<script type="text/javascript" src="externals/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="externals/date.js"></script>
|
||||
|
||||
<script type="text/javascript" src="scripts/util/string.js"></script>
<script type="text/javascript" src="scripts/index.js"></script>
</head>
<body>
<div id="header">
<h1>Gridworks</h1>
</div>
<div id="body">
<div id="projects"></div>
<h2>New Project</h2>
<p>Create a new project by uploading a tab-separated value or comma-separated value file.</p>
<form id="file-upload-form" method="post" enctype="multipart/form-data" action="/command/create-project-from-upload">
<table cellspacing="5">
<tr><td>Project Name:</td><td><input type="text" size="30" id="project-name-input" name="project-name" /></td></tr>
<tr style="display: none;"><td>Project Password:</td><td><input type="password" size="30" id="project-password-input" name="project-password" /><br/>optional, not protected, so use some password you don't care to reveal</td></tr>
<tr><td>Upload File:</td><td>
<input type="file" id="project-file-input" name="project-file" size="50" />
</td></tr>
<tr><td>Load up to:</td><td>
<input id="limit-input" name="limit" size="5" /> rows
</td></tr>
<tr><td></td><td id="submit-container">
<input type="submit" value="Create Project" id="upload-file-button" />
</td></tr>
</table>
</form>
</div>
</body>
</html>
|
||||
<html>
<head>
<title>Gridworks</title>
<link rel="stylesheet" href="/styles/common.css" />
<link rel="stylesheet" href="/styles/index.css" />
<script type="text/javascript" src="externals/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="externals/date.js"></script>
<script type="text/javascript" src="scripts/util/string.js"></script>
<script type="text/javascript" src="scripts/index.js"></script>
</head>
<body>
<div id="header">
<h1>Gridworks</h1>
</div>
<div id="body">
<div id="projects"></div>
<h2>New Project</h2>
<p>Create a new project by uploading a tab-separated value or comma-separated value file.</p>
<form id="file-upload-form" method="post" enctype="multipart/form-data" action="/command/create-project-from-upload">
<table cellspacing="5">
<tr><td>Project Name:</td><td><input type="text" size="30" id="project-name-input" name="project-name" /></td></tr>
<tr style="display: none;"><td>Project Password:</td><td><input type="password" size="30" id="project-password-input" name="project-password" /><br/>optional, not protected, so use some password you don't care to reveal</td></tr>
<tr><td>Upload File:</td><td>
<input type="file" id="project-file-input" name="project-file" size="50" />
</td></tr>
<tr><td>Skip:</td><td>
<input id="skip-input" name="skip" size="5" /> initial data rows
</td></tr>
<tr><td>Load up to:</td><td>
<input id="limit-input" name="limit" size="5" /> data rows
</td></tr>
<tr><td></td><td id="submit-container">
<input type="submit" value="Create Project" id="upload-file-button" />
</td></tr>
</table>
</form>
</div>
</body>
</html>
|
@ -19,19 +19,15 @@ function onClickUploadFileButton(evt) {
|
||||
evt.preventDefault();
|
||||
return false;
|
||||
} else {
|
||||
$("#file-upload-form").attr("action", "/command/create-project-from-upload?limit=" + $("#limit-input")[0].value);
|
||||
$("#file-upload-form").attr("action",
|
||||
"/command/create-project-from-upload?" + [
|
||||
"skip=" + $("#skip-input")[0].value,
|
||||
"limit=" + $("#limit-input")[0].value
|
||||
].join("&"));
|
||||
}
|
||||
}
|
||||
|
||||
function renderProjects(data) {
|
||||
var container = $("#projects").empty();
|
||||
|
||||
$('<h2></h2>').text("Projects").appendTo(container);
|
||||
|
||||
var table = $('<table><tr><td></td><td>last modified</td></tr></table>')
|
||||
.attr("cellspacing", "5")
|
||||
.appendTo(container)[0];
|
||||
|
||||
var projects = [];
|
||||
for (var n in data.projects) {
|
||||
if (data.projects.hasOwnProperty(n)) {
|
||||
@ -41,16 +37,27 @@ function renderProjects(data) {
|
||||
projects.push(project);
|
||||
}
|
||||
}
|
||||
projects.sort(function(a, b) { return b.date.getTime() - a.date.getTime(); });
|
||||
|
||||
for (var i = 0; i < projects.length; i++) {
|
||||
var project = projects[i];
|
||||
var tr = table.insertRow(table.rows.length);
|
||||
var td0 = tr.insertCell(0);
|
||||
var td1 = tr.insertCell(1);
|
||||
if (projects.length > 0) {
|
||||
projects.sort(function(a, b) { return b.date.getTime() - a.date.getTime(); });
|
||||
|
||||
$('<a></a>').text(project.name).attr("href", "/project.html?project=" + project.id).appendTo(td0);
|
||||
$('<span></span>').text(formatDate(project.date)).appendTo(td1);
|
||||
var container = $("#projects").empty().show();
|
||||
|
||||
$('<h2></h2>').text("Projects").appendTo(container);
|
||||
|
||||
var table = $('<table><tr><td></td><td>last modified</td></tr></table>')
|
||||
.attr("cellspacing", "5")
|
||||
.appendTo(container)[0];
|
||||
|
||||
for (var i = 0; i < projects.length; i++) {
|
||||
var project = projects[i];
|
||||
var tr = table.insertRow(table.rows.length);
|
||||
var td0 = tr.insertCell(0);
|
||||
var td1 = tr.insertCell(1);
|
||||
|
||||
$('<a></a>').text(project.name).attr("href", "/project.html?project=" + project.id).appendTo(td0);
|
||||
$('<span></span>').text(formatDate(project.date)).appendTo(td1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,6 +76,7 @@ a.facet-choice-link:hover {
|
||||
overflow: hidden;
|
||||
}
|
||||
.facet-range-histogram img {
|
||||
height: 50px;
|
||||
position: relative;
|
||||
left: -2px;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
border: 1px solid #ccc;
|
||||
background: #fffee0;
|
||||
padding: 20px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
#file-upload-form > table > tbody > tr > td {
|
||||
|
Loading…
Reference in New Issue
Block a user