2010-02-07 04:36:40 +01:00
|
|
|
var SchemaAlignment = {};
|
|
|
|
|
|
|
|
SchemaAlignment.autoAlign = function() {
|
|
|
|
var protograph = {};
|
|
|
|
|
|
|
|
var columns = theProject.columnModel.columns;
|
|
|
|
|
2010-02-09 00:57:37 +01:00
|
|
|
var typedCandidates = [];
|
2010-02-07 04:36:40 +01:00
|
|
|
var candidates = [];
|
|
|
|
|
|
|
|
for (var c = 0; c < columns.length; c++) {
|
|
|
|
var column = columns[c];
|
2010-02-09 00:57:37 +01:00
|
|
|
var typed = "reconConfig" in column && column.reconConfig != null;
|
|
|
|
var candidate = {
|
2010-02-07 04:36:40 +01:00
|
|
|
status: "unbound",
|
2010-02-09 00:57:37 +01:00
|
|
|
typed: typed,
|
2010-02-07 04:36:40 +01:00
|
|
|
index: c,
|
|
|
|
column: column
|
2010-02-09 00:57:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
candidates.push(candidate);
|
|
|
|
if (typed) {
|
|
|
|
typedCandidates.push(candidate);
|
|
|
|
}
|
2010-02-07 04:36:40 +01:00
|
|
|
}
|
|
|
|
|
2010-02-09 00:57:37 +01:00
|
|
|
if (typedCandidates.length > 0) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
var queries = {};
|
|
|
|
for (var i = 0; i < candidates.length; i++) {
|
|
|
|
var candidate = candidates[i];
|
|
|
|
var name = SchemaAlignment._cleanName(candidate.column.headerLabel);
|
|
|
|
var key = "t" + i + ":search";
|
|
|
|
queries[key] = {
|
|
|
|
"query" : name,
|
|
|
|
"limit" : 10,
|
|
|
|
"type" : "/type/type,/type/property",
|
|
|
|
"type_strict" : "any"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
SchemaAlignment._batchSearch(queries, function(result) {
|
|
|
|
console.log(result);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignment._batchSearch = function(queries, onDone) {
|
|
|
|
var keys = [];
|
|
|
|
for (var n in queries) {
|
|
|
|
if (queries.hasOwnProperty(n)) {
|
|
|
|
keys.push(n);
|
|
|
|
}
|
|
|
|
}
|
2010-02-07 04:36:40 +01:00
|
|
|
|
2010-02-09 00:57:37 +01:00
|
|
|
var result = {};
|
|
|
|
var args = [];
|
|
|
|
var makeBatch = function(keyBatch) {
|
|
|
|
var batch = {};
|
|
|
|
for (var k = 0; k < keyBatch.length; k++) {
|
|
|
|
var key = keyBatch[k];
|
|
|
|
batch[key] = queries[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
args.push("http://api.freebase.com/api/service/search?" +
|
|
|
|
$.param({ "queries" : JSON.stringify(batch) }) + "&callback=?");
|
|
|
|
|
|
|
|
args.push(null); // no data
|
|
|
|
args.push(function(data) {
|
|
|
|
for (var k = 0; k < keyBatch.length; k++) {
|
|
|
|
var key = keyBatch[k];
|
|
|
|
result[key] = data[key];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 0; i < keys.length; i += 10) {
|
|
|
|
makeBatch(keys.slice(i, i + 10));
|
|
|
|
}
|
|
|
|
|
|
|
|
args.push(function() {
|
|
|
|
onDone(result);
|
|
|
|
})
|
|
|
|
|
|
|
|
Ajax.chainGetJSON.apply(null, args);
|
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignment._cleanName = function(s) {
|
|
|
|
return s.replace(/\W/g, " ").replace(/\s+/g, " ").toLowerCase();
|
2010-02-09 01:45:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function SchemaAlignmentDialog(protograph) {
|
2010-02-09 07:46:40 +01:00
|
|
|
this._originalProtograph = {
|
2010-02-09 01:45:54 +01:00
|
|
|
rootNodes: [
|
|
|
|
{
|
2010-02-09 07:46:40 +01:00
|
|
|
nodeType: "cell-as-topic",
|
2010-02-09 01:45:54 +01:00
|
|
|
column: "name",
|
|
|
|
linkages: [
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this._createDialog();
|
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.prototype._createDialog = function() {
|
|
|
|
var self = this;
|
|
|
|
var frame = DialogSystem.createDialog();
|
|
|
|
|
|
|
|
frame.width("1000px");
|
|
|
|
|
|
|
|
var header = $('<div></div>').addClass("dialog-header").text("Schema Alignment").appendTo(frame);
|
|
|
|
var body = $('<div></div>').addClass("dialog-body").appendTo(frame);
|
|
|
|
var footer = $('<div></div>').addClass("dialog-footer").appendTo(frame);
|
|
|
|
|
|
|
|
this._renderFooter(footer);
|
|
|
|
this._renderBody(body);
|
|
|
|
|
|
|
|
this._level = DialogSystem.showDialog(frame);
|
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.prototype._renderFooter = function(footer) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$('<button></button>').html(" OK ").click(function() {
|
|
|
|
DialogSystem.dismissUntil(self._level - 1);
|
|
|
|
self._onDone(self._getNewProtograph());
|
|
|
|
}).appendTo(footer);
|
|
|
|
|
|
|
|
$('<button></button>').text("Cancel").click(function() {
|
|
|
|
DialogSystem.dismissUntil(self._level - 1);
|
|
|
|
}).appendTo(footer);
|
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.prototype._renderBody = function(body) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this._canvas = $('<div></div>').addClass("schema-alignment-dialog-canvas").appendTo(body);
|
2010-02-09 07:46:40 +01:00
|
|
|
this._nodeTable = $('<table></table>').appendTo(this._canvas)[0];
|
|
|
|
|
|
|
|
for (var i = 0; i < this._originalProtograph.rootNodes.length; i++) {
|
|
|
|
new SchemaAlignmentDialog.UINode(
|
|
|
|
this._originalProtograph.rootNodes[i],
|
|
|
|
this._nodeTable,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.UINode = function(node, table, expanded) {
|
|
|
|
this._originalNode = node;
|
|
|
|
this._newNode = {
|
|
|
|
nodeType: node.nodeType
|
|
|
|
};
|
|
|
|
this._detailsRendered = false;
|
|
|
|
|
|
|
|
this._tr = table.insertRow(table.rows.length);
|
|
|
|
this._tdMain = this._tr.insertCell(0);
|
|
|
|
this._tdToggle = this._tr.insertCell(1);
|
|
|
|
this._tdDetails = this._tr.insertCell(2);
|
|
|
|
|
|
|
|
$(this._tdMain).addClass("schema-alignment-node-main").attr("width", "250");
|
|
|
|
$(this._tdToggle).addClass("schema-alignment-node-toggle").attr("width", "1%").hide();
|
|
|
|
$(this._tdDetails).addClass("schema-alignment-node-details").attr("width", "90%").hide();
|
|
|
|
|
|
|
|
this._renderMain();
|
|
|
|
|
|
|
|
this._expanded = expanded;
|
|
|
|
if (this._isExpandable()) {
|
|
|
|
this._showExpandable();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.UINode.prototype._isExpandable = function() {
|
|
|
|
return this._newNode.nodeType != "existing-content" && this._newNode.nodeType != "cell-as-content";
|
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.UINode.prototype._renderMain = function() {
|
|
|
|
$(this._tdMain).empty().html(this._newNode.nodeType);
|
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.UINode.prototype._showExpandable = function() {
|
|
|
|
$(this._tdToggle).show();
|
|
|
|
$(this._tdDetails).show();
|
|
|
|
|
|
|
|
if (this._detailsRendered) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._detailsRendered = true;
|
|
|
|
|
|
|
|
this._collapsedDetailDiv = $('<div></div>').appendTo(this._tdDetails).html("...");
|
|
|
|
this._expandedDetailDiv = $('<div></div>').appendTo(this._tdDetails).html("details");
|
|
|
|
|
|
|
|
this._renderDetails();
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
var show = function() {
|
|
|
|
if (self._expanded) {
|
|
|
|
self._collapsedDetailDiv.hide();
|
|
|
|
self._expandedDetailDiv.show();
|
|
|
|
} else {
|
|
|
|
self._collapsedDetailDiv.show();
|
|
|
|
self._expandedDetailDiv.hide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
show();
|
|
|
|
|
|
|
|
$(this._tdToggle).html(" ");
|
|
|
|
|
|
|
|
$('<img />')
|
|
|
|
.attr("src", this._expanded ? "images/down-arrow.png" : "images/right-arrow.png")
|
|
|
|
.appendTo(this._tdToggle)
|
|
|
|
.click(function() {
|
|
|
|
self._expanded = !self._expanded;
|
|
|
|
|
|
|
|
$(this).attr("src", self._expanded ? "images/down-arrow.png" : "images/right-arrow.png");
|
|
|
|
|
|
|
|
show();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.UINode.prototype._hideExpandable = function() {
|
|
|
|
$(this._tdToggle).hide();
|
|
|
|
$(this._tdDetails).hide();
|
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.UINode.prototype._renderDetails = function() {
|
|
|
|
var tableDetails = $('<table></table>').appendTo(this._tdDetails)[0];
|
2010-02-09 01:45:54 +01:00
|
|
|
};
|