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;
|
String url = null;
|
||||||
|
|
||||||
int limit = -1;
|
int limit = -1;
|
||||||
|
int skip = 0;
|
||||||
|
|
||||||
if (options.containsKey("limit")) {
|
if (options.containsKey("limit")) {
|
||||||
String s = options.getProperty("limit");
|
String s = options.getProperty("limit");
|
||||||
try {
|
try {
|
||||||
@ -97,6 +99,13 @@ public class CreateProjectCommand extends Command {
|
|||||||
} catch (Exception e) {
|
} 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) {
|
while ((part = parser.readNextPart()) != null) {
|
||||||
|
|
||||||
@ -108,14 +117,14 @@ public class CreateProjectCommand extends Command {
|
|||||||
if (importer.takesReader()) {
|
if (importer.takesReader()) {
|
||||||
Reader reader = new InputStreamReader(filePart.getInputStream());
|
Reader reader = new InputStreamReader(filePart.getInputStream());
|
||||||
try {
|
try {
|
||||||
importer.read(reader, project, options, limit);
|
importer.read(reader, project, options, skip, limit);
|
||||||
} finally {
|
} finally {
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
InputStream inputStream = filePart.getInputStream();
|
InputStream inputStream = filePart.getInputStream();
|
||||||
try {
|
try {
|
||||||
importer.read(inputStream, project, options, limit);
|
importer.read(inputStream, project, options, skip, limit);
|
||||||
} finally {
|
} finally {
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
}
|
}
|
||||||
@ -126,7 +135,7 @@ public class CreateProjectCommand extends Command {
|
|||||||
if (paramName.equals("raw-text")) {
|
if (paramName.equals("raw-text")) {
|
||||||
StringReader reader = new StringReader(paramPart.getStringValue());
|
StringReader reader = new StringReader(paramPart.getStringValue());
|
||||||
try {
|
try {
|
||||||
new TsvCsvImporter().read(reader, project, options, limit);
|
new TsvCsvImporter().read(reader, project, options, skip, limit);
|
||||||
} finally {
|
} finally {
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
}
|
||||||
@ -139,7 +148,7 @@ public class CreateProjectCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (url != null && url.length() > 0) {
|
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,
|
Project project,
|
||||||
Properties options,
|
Properties options,
|
||||||
String urlString,
|
String urlString,
|
||||||
|
int skip,
|
||||||
int limit
|
int limit
|
||||||
) throws Exception {
|
) throws Exception {
|
||||||
URL url = new URL(urlString);
|
URL url = new URL(urlString);
|
||||||
@ -182,9 +192,9 @@ public class CreateProjectCommand extends Command {
|
|||||||
Reader reader = new InputStreamReader(
|
Reader reader = new InputStreamReader(
|
||||||
inputStream, (encoding == null) ? "ISO-8859-1" : encoding);
|
inputStream, (encoding == null) ? "ISO-8859-1" : encoding);
|
||||||
|
|
||||||
importer.read(reader, project, options, limit);
|
importer.read(reader, project, options, skip, limit);
|
||||||
} else {
|
} else {
|
||||||
importer.read(inputStream, project, options, limit);
|
importer.read(inputStream, project, options, skip, limit);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
|
@ -29,14 +29,14 @@ public class ExcelImporter implements Importer {
|
|||||||
return false;
|
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 {
|
throws Exception {
|
||||||
|
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read(InputStream inputStream, Project project,
|
public void read(InputStream inputStream, Project project,
|
||||||
Properties options, int limit) throws Exception {
|
Properties options, int skip, int limit) throws Exception {
|
||||||
|
|
||||||
Workbook wb = _xmlBased ?
|
Workbook wb = _xmlBased ?
|
||||||
new XSSFWorkbook(inputStream) :
|
new XSSFWorkbook(inputStream) :
|
||||||
@ -99,6 +99,7 @@ public class ExcelImporter implements Importer {
|
|||||||
/*
|
/*
|
||||||
* Now process the data rows
|
* Now process the data rows
|
||||||
*/
|
*/
|
||||||
|
int rowsWithData = 0;
|
||||||
for (; r <= lastRow; r++) {
|
for (; r <= lastRow; r++) {
|
||||||
org.apache.poi.ss.usermodel.Row row = sheet.getRow(r);
|
org.apache.poi.ss.usermodel.Row row = sheet.getRow(r);
|
||||||
if (row == null) {
|
if (row == null) {
|
||||||
@ -149,6 +150,9 @@ public class ExcelImporter implements Importer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hasData) {
|
if (hasData) {
|
||||||
|
rowsWithData++;
|
||||||
|
|
||||||
|
if (skip <= 0 || rowsWithData > skip) {
|
||||||
project.rows.add(newRow);
|
project.rows.add(newRow);
|
||||||
if (limit > 0 && project.rows.size() >= limit) {
|
if (limit > 0 && project.rows.size() >= limit) {
|
||||||
break;
|
break;
|
||||||
@ -158,3 +162,4 @@ public class ExcelImporter implements Importer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -9,6 +9,6 @@ import com.metaweb.gridworks.model.Project;
|
|||||||
public interface Importer {
|
public interface Importer {
|
||||||
public boolean takesReader();
|
public boolean takesReader();
|
||||||
|
|
||||||
public void read(Reader reader, 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 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 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 {
|
throws Exception {
|
||||||
|
|
||||||
LineNumberReader lnReader = new LineNumberReader(reader);
|
LineNumberReader lnReader = new LineNumberReader(reader);
|
||||||
@ -23,6 +23,7 @@ public class TsvCsvImporter implements Importer {
|
|||||||
boolean first = true;
|
boolean first = true;
|
||||||
int cellCount = 1;
|
int cellCount = 1;
|
||||||
|
|
||||||
|
int rowsWithData = 0;
|
||||||
while ((line = lnReader.readLine()) != null) {
|
while ((line = lnReader.readLine()) != null) {
|
||||||
if (line.trim().length() == 0) {
|
if (line.trim().length() == 0) {
|
||||||
continue;
|
continue;
|
||||||
@ -57,6 +58,9 @@ public class TsvCsvImporter implements Importer {
|
|||||||
Row row = new Row(cellCount);
|
Row row = new Row(cellCount);
|
||||||
|
|
||||||
if ((sep.charAt(0) == ',') ? ImporterUtilities.parseCSVIntoRow(row, line) : ImporterUtilities.parseTSVIntoRow(row, line)) {
|
if ((sep.charAt(0) == ',') ? ImporterUtilities.parseCSVIntoRow(row, line) : ImporterUtilities.parseTSVIntoRow(row, line)) {
|
||||||
|
rowsWithData++;
|
||||||
|
|
||||||
|
if (skip <= 0 || rowsWithData > skip) {
|
||||||
project.rows.add(row);
|
project.rows.add(row);
|
||||||
project.columnModel.setMaxCellIndex(Math.max(project.columnModel.getMaxCellIndex(), row.cells.size()));
|
project.columnModel.setMaxCellIndex(Math.max(project.columnModel.getMaxCellIndex(), row.cells.size()));
|
||||||
|
|
||||||
@ -66,13 +70,14 @@ public class TsvCsvImporter implements Importer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
lnReader.close();
|
lnReader.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read(InputStream inputStream, Project project,
|
public void read(InputStream inputStream, Project project,
|
||||||
Properties options, int limit) throws Exception {
|
Properties options, int skip, int limit) throws Exception {
|
||||||
|
|
||||||
throw new NotImplementedException();
|
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>
|
<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>
|
||||||
|
|
||||||
<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>
|
|
@ -19,19 +19,15 @@ function onClickUploadFileButton(evt) {
|
|||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} 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) {
|
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 = [];
|
var projects = [];
|
||||||
for (var n in data.projects) {
|
for (var n in data.projects) {
|
||||||
if (data.projects.hasOwnProperty(n)) {
|
if (data.projects.hasOwnProperty(n)) {
|
||||||
@ -41,8 +37,18 @@ function renderProjects(data) {
|
|||||||
projects.push(project);
|
projects.push(project);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (projects.length > 0) {
|
||||||
projects.sort(function(a, b) { return b.date.getTime() - a.date.getTime(); });
|
projects.sort(function(a, b) { return b.date.getTime() - a.date.getTime(); });
|
||||||
|
|
||||||
|
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++) {
|
for (var i = 0; i < projects.length; i++) {
|
||||||
var project = projects[i];
|
var project = projects[i];
|
||||||
var tr = table.insertRow(table.rows.length);
|
var tr = table.insertRow(table.rows.length);
|
||||||
@ -53,6 +59,7 @@ function renderProjects(data) {
|
|||||||
$('<span></span>').text(formatDate(project.date)).appendTo(td1);
|
$('<span></span>').text(formatDate(project.date)).appendTo(td1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function formatDate(d) {
|
function formatDate(d) {
|
||||||
var yesterday = Date.today().add({ days: -1 });
|
var yesterday = Date.today().add({ days: -1 });
|
||||||
|
@ -76,6 +76,7 @@ a.facet-choice-link:hover {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
.facet-range-histogram img {
|
.facet-range-histogram img {
|
||||||
|
height: 50px;
|
||||||
position: relative;
|
position: relative;
|
||||||
left: -2px;
|
left: -2px;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
background: #fffee0;
|
background: #fffee0;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
#file-upload-form > table > tbody > tr > td {
|
#file-upload-form > table > tbody > tr > td {
|
||||||
|
Loading…
Reference in New Issue
Block a user