More work on the extend data preview dialog. It's starting to render some results.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@290 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
f34577ec85
commit
99ae7dea29
@ -70,6 +70,7 @@ public class PreviewExtendDataCommand extends Command {
|
|||||||
|
|
||||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||||
writer.object();
|
writer.object();
|
||||||
|
writer.key("code"); writer.value("ok");
|
||||||
writer.key("columns");
|
writer.key("columns");
|
||||||
writer.array();
|
writer.array();
|
||||||
for (String name : job.columnNames) {
|
for (String name : job.columnNames) {
|
||||||
|
@ -76,7 +76,7 @@ public class FreebaseDataExtensionJob {
|
|||||||
protected FreebaseDataExtensionJob.DataExtension collectResult(JSONObject obj) throws JSONException {
|
protected FreebaseDataExtensionJob.DataExtension collectResult(JSONObject obj) throws JSONException {
|
||||||
List<Object[]> rows = new ArrayList<Object[]>();
|
List<Object[]> rows = new ArrayList<Object[]>();
|
||||||
|
|
||||||
collectResult(rows, extension, obj, 0, 0);
|
collectResult(rows, extension.getJSONArray("properties"), obj, 0, 0);
|
||||||
|
|
||||||
Object[][] data = new Object[rows.size()][columnCount];
|
Object[][] data = new Object[rows.size()][columnCount];
|
||||||
rows.toArray(data);
|
rows.toArray(data);
|
||||||
@ -157,16 +157,18 @@ public class FreebaseDataExtensionJob {
|
|||||||
storeCell(rows, startRowIndex2++, startColumnIndex2++, o);
|
storeCell(rows, startRowIndex2++, startColumnIndex2++, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
int[] rowcol = collectResult(
|
if (hasSubProperties) {
|
||||||
rows,
|
int[] rowcol = collectResult(
|
||||||
extNode.getJSONArray("properties"),
|
rows,
|
||||||
o,
|
extNode.getJSONArray("properties"),
|
||||||
startRowIndex,
|
o,
|
||||||
startColumnIndex2
|
startRowIndex,
|
||||||
);
|
startColumnIndex2
|
||||||
|
);
|
||||||
startRowIndex = rowcol[0];
|
|
||||||
maxColIndex = Math.max(maxColIndex, rowcol[1]);
|
startRowIndex = rowcol[0];
|
||||||
|
maxColIndex = Math.max(maxColIndex, rowcol[1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new int[] { startRowIndex, maxColIndex };
|
return new int[] { startRowIndex, maxColIndex };
|
||||||
@ -210,6 +212,7 @@ static protected InputStream doPost(URL url, String name, String load) throws IO
|
|||||||
URLConnection connection = url.openConnection();
|
URLConnection connection = url.openConnection();
|
||||||
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||||
connection.setConnectTimeout(5000);
|
connection.setConnectTimeout(5000);
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
|
||||||
DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
|
DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
|
||||||
try {
|
try {
|
||||||
@ -242,7 +245,7 @@ static protected void formulateQuery(Set<String> guids, JSONObject node, Writer
|
|||||||
}
|
}
|
||||||
jsonWriter.endArray();
|
jsonWriter.endArray();
|
||||||
|
|
||||||
formulateQueryNode(node, jsonWriter);
|
formulateQueryNode(node.getJSONArray("properties"), jsonWriter);
|
||||||
|
|
||||||
jsonWriter.endObject();
|
jsonWriter.endObject();
|
||||||
jsonWriter.endArray();
|
jsonWriter.endArray();
|
||||||
@ -270,12 +273,7 @@ static protected void formulateQueryNode(JSONObject node, JSONWriter writer) thr
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hasSubProperties) {
|
if (hasSubProperties) {
|
||||||
JSONArray a = node.getJSONArray("properties");
|
formulateQueryNode(node.getJSONArray("properties"), writer);
|
||||||
int l = a.length();
|
|
||||||
|
|
||||||
for (int i = 0; i < l; i++) {
|
|
||||||
formulateQueryNode(a.getJSONObject(i), writer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
@ -284,6 +282,14 @@ static protected void formulateQueryNode(JSONObject node, JSONWriter writer) thr
|
|||||||
writer.endArray();
|
writer.endArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static protected void formulateQueryNode(JSONArray propertiesA, JSONWriter writer) throws JSONException {
|
||||||
|
int l = propertiesA.length();
|
||||||
|
|
||||||
|
for (int i = 0; i < l; i++) {
|
||||||
|
formulateQueryNode(propertiesA.getJSONObject(i), writer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static protected int countColumns(JSONObject obj, List<String> columnNames) throws JSONException {
|
static protected int countColumns(JSONObject obj, List<String> columnNames) throws JSONException {
|
||||||
if (obj.has("properties") && !obj.isNull("properties")) {
|
if (obj.has("properties") && !obj.isNull("properties")) {
|
||||||
boolean included = (obj.has("included") && obj.getBoolean("included"));
|
boolean included = (obj.has("included") && obj.getBoolean("included"));
|
||||||
|
@ -1,21 +1,25 @@
|
|||||||
function ExtendDataPreviewDialog(columnName, rowIndices, onDone) {
|
function ExtendDataPreviewDialog(column, rowIndices, onDone) {
|
||||||
|
this._column = column;
|
||||||
|
this._rowIndices = rowIndices;
|
||||||
this._onDone = onDone;
|
this._onDone = onDone;
|
||||||
|
this._extension = { properties: [] };
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var frame = DialogSystem.createDialog();
|
var frame = DialogSystem.createDialog();
|
||||||
frame.width("900px").addClass("extend-data-preview-dialog");
|
frame.width("900px").addClass("extend-data-preview-dialog");
|
||||||
|
|
||||||
var header = $('<div></div>').addClass("dialog-header").text("Add Columns from Freebase Based on Column " + columnName).appendTo(frame);
|
var header = $('<div></div>').addClass("dialog-header").text("Add Columns from Freebase Based on Column " + column.name).appendTo(frame);
|
||||||
var body = $('<div></div>').addClass("dialog-body").appendTo(frame);
|
var body = $('<div></div>').addClass("dialog-body").appendTo(frame);
|
||||||
var footer = $('<div></div>').addClass("dialog-footer").appendTo(frame);
|
var footer = $('<div></div>').addClass("dialog-footer").appendTo(frame);
|
||||||
var html = $(
|
var html = $(
|
||||||
'<div class="grid-layout layout-normal layout-full"><table style="height: 600px">' +
|
'<div class="grid-layout layout-normal layout-full"><table style="height: 600px">' +
|
||||||
'<tr>' +
|
'<tr>' +
|
||||||
'<td width="150" height="1">Add Property</td>' +
|
'<td width="150" height="1">Add Property</td>' +
|
||||||
'<td height="100%" rowspan="4"><div class="preview-container" bind="previewDiv"></div></td>' +
|
'<td height="1">Preview</td>' +
|
||||||
'</tr>' +
|
'</tr>' +
|
||||||
'<tr>' +
|
'<tr>' +
|
||||||
'<td height="1"><div class="input-container"><input /></div></td>' +
|
'<td height="1"><div class="input-container"><input bind="addPropertyInput" /></div></td>' +
|
||||||
|
'<td height="100%" rowspan="3"><div class="preview-container" bind="previewContainer"></div></td>' +
|
||||||
'</tr>' +
|
'</tr>' +
|
||||||
'<tr>' +
|
'<tr>' +
|
||||||
'<td height="1">Suggested Properties</td>' +
|
'<td height="1">Suggested Properties</td>' +
|
||||||
@ -38,8 +42,74 @@ function ExtendDataPreviewDialog(columnName, rowIndices, onDone) {
|
|||||||
}).appendTo(footer);
|
}).appendTo(footer);
|
||||||
|
|
||||||
this._level = DialogSystem.showDialog(frame);
|
this._level = DialogSystem.showDialog(frame);
|
||||||
|
|
||||||
|
var suggestConfig = {
|
||||||
|
type: '/type/property'
|
||||||
|
};
|
||||||
|
if ("reconConfig" in column) {
|
||||||
|
suggestConfig.schema = column.reconConfig.type.id;
|
||||||
|
}
|
||||||
|
this._elmts.addPropertyInput.suggestP(suggestConfig).bind("fb-select", function(evt, data) {
|
||||||
|
self._addProperty(data);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ExtendDataPreviewDialog.prototype.update = function() {
|
ExtendDataPreviewDialog.prototype._update = function() {
|
||||||
|
this._elmts.previewContainer.empty().text("Querying Freebase ...");
|
||||||
|
|
||||||
};
|
var self = this;
|
||||||
|
var params = {
|
||||||
|
project: theProject.id,
|
||||||
|
columnName: this._column.name
|
||||||
|
};
|
||||||
|
|
||||||
|
$.post(
|
||||||
|
"/command/preview-extend-data?" + $.param(params),
|
||||||
|
{
|
||||||
|
rowIndices: JSON.stringify(this._rowIndices),
|
||||||
|
extension: JSON.stringify(this._extension)
|
||||||
|
},
|
||||||
|
function(data) {
|
||||||
|
self._renderPreview(data)
|
||||||
|
},
|
||||||
|
"json"
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
ExtendDataPreviewDialog.prototype._addProperty = function(p) {
|
||||||
|
this._extension.properties.push({
|
||||||
|
id : p.id,
|
||||||
|
name: p.name,
|
||||||
|
expected: p["/type/property/expected_type"]
|
||||||
|
});
|
||||||
|
this._update();
|
||||||
|
};
|
||||||
|
|
||||||
|
ExtendDataPreviewDialog.prototype._renderPreview = function(data) {
|
||||||
|
var container = this._elmts.previewContainer.empty();
|
||||||
|
if (data.code == "error") {
|
||||||
|
container.text("Error.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var table = $('<table>')[0];
|
||||||
|
|
||||||
|
for (var r = 0; r < data.rows.length; r++) {
|
||||||
|
var tr = table.insertRow(table.rows.length);
|
||||||
|
var row = data.rows[r];
|
||||||
|
|
||||||
|
for (var c = 0; c < row.length; c++) {
|
||||||
|
var td = tr.insertCell(tr.cells.length);
|
||||||
|
var cell = row[c];
|
||||||
|
if (cell != null) {
|
||||||
|
if ($.isPlainObject(cell)) {
|
||||||
|
$('<a>').attr("href", "http://www.freebase.com/view" + cell.id).text(cell.name).appendTo(td);
|
||||||
|
} else {
|
||||||
|
$('<span>').text(cell).appendTo(td);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
container.append(table);
|
||||||
|
}
|
@ -66,7 +66,8 @@
|
|||||||
"id" : val,
|
"id" : val,
|
||||||
"name" : null,
|
"name" : null,
|
||||||
"guid" : null,
|
"guid" : null,
|
||||||
"x:type" : "/type/property"
|
"x:type" : "/type/property",
|
||||||
|
"/type/property/expected_type" : null
|
||||||
}];
|
}];
|
||||||
var data = {
|
var data = {
|
||||||
query: JSON.stringify({ query: query })
|
query: JSON.stringify({ query: query })
|
||||||
@ -122,7 +123,12 @@
|
|||||||
var o = this.options;
|
var o = this.options;
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
query: val
|
query: val,
|
||||||
|
mql_output: JSON.stringify([{
|
||||||
|
"id" : null,
|
||||||
|
"name" : null,
|
||||||
|
"/type/property/expected_type" : null
|
||||||
|
}])
|
||||||
};
|
};
|
||||||
if (start) {
|
if (start) {
|
||||||
data.start = start;
|
data.start = start;
|
||||||
|
@ -822,7 +822,7 @@ DataTableColumnHeaderUI.prototype._doAddColumnFromFreebase = function() {
|
|||||||
var o = DataTableView.sampleVisibleRows(this._column);
|
var o = DataTableView.sampleVisibleRows(this._column);
|
||||||
|
|
||||||
new ExtendDataPreviewDialog(
|
new ExtendDataPreviewDialog(
|
||||||
this._column.name,
|
this._column,
|
||||||
o.rowIndices,
|
o.rowIndices,
|
||||||
function() {}
|
function() {}
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user