Property suggest and type suggest widgets in standard recon service panel now use the service's suggest settings, including custom service URLs.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@1049 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-06-28 22:42:53 +00:00
parent 0e4781cb58
commit 59fe9e35bd
7 changed files with 48 additions and 117 deletions

View File

@ -27,6 +27,8 @@ function init() {
"externals/imgareaselect/jquery.imgareaselect.js",
"externals/date.js",
"scripts/project.js",
"scripts/util/misc.js",
"scripts/util/url.js",
"scripts/util/string.js",
@ -43,7 +45,6 @@ function init() {
"scripts/widgets/histogram-widget.js",
"scripts/widgets/slider-widget.js",
"scripts/project.js",
"scripts/project/menu-bar.js",
"scripts/project/browsing-engine.js",
"scripts/project/scripting.js",

View File

@ -39,7 +39,7 @@ ExtendDataPreviewDialog.getAllProperties = function(typeID, onDone) {
var done = false;
$.getJSON(
Gridworks.gridworksHelperService + "get_properties_of_type?type=" + typeID + "&callback=?",
Gridworks.gridworksHelperService + "/get_properties_of_type?type=" + typeID + "&callback=?",
null,
function(data) {
if (done) return;
@ -109,7 +109,7 @@ ExtendDataPreviewDialog.prototype._show = function(properties) {
type: '/type/property'
};
if ("reconConfig" in this._column && "type" in this._column.reconConfig) {
suggestConfig.schema = this._column.reconConfig.type.id;
suggestConfig.ac_param = { schema: this._column.reconConfig.type.id };
}
this._elmts.addPropertyInput.suggestP(suggestConfig).bind("fb-select", function(evt, data) {

View File

@ -2,7 +2,7 @@ var theProject;
var ui = {};
var Gridworks = {
gridworksHelperService: "http://1-0.gridworks-helper.dfhuynh.user.dev.freebaseapps.com/"
gridworksHelperService: "http://6.gridworks-helper.dfhuynh.user.dev.freebaseapps.com"
};
Gridworks.reportException = function(e) {

View File

@ -141,7 +141,7 @@ SchemaAlignmentDialog.UILink._getPropertiesOfType = function(typeID, targetTypeI
}
$.getJSON(
Gridworks.gridworksHelperService + "get_properties_of_type?" + $.param(params) + "&callback=?",
Gridworks.gridworksHelperService + "/get_properties_of_type?" + $.param(params) + "&callback=?",
null,
function(data) {
if (done) return;
@ -246,7 +246,7 @@ SchemaAlignmentDialog.UILink.prototype._showPropertySuggestPopup = function(elmt
} else {
var sourceTypeID = this._parentUINode.getExpectedType();
if (sourceTypeID !== null) {
suggestOptions.schema = sourceTypeID;
suggestOptions.ac_param = { schema: sourceTypeID };
}
}
input.suggestP(suggestOptions).bind("fb-select", function(e, data) { commitProperty(data); });

View File

@ -34,10 +34,12 @@ ReconciliationManager.registerService = function(service) {
};
ReconciliationManager.registerStandardService = function(url, f) {
$.ajax({
async: false,
url: url + (url.contains("?") ? "&" : "?") + "callback=?",
success: function(data) {
var dismissBusy = DialogSystem.showBusy();
$.getJSON(
url + (url.contains("?") ? "&" : "?") + "callback=?",
null,
function(data) {
data.url = url;
data.ui = { "handler" : "ReconStandardServicePanel" };
@ -49,12 +51,14 @@ ReconciliationManager.registerStandardService = function(url, f) {
ReconciliationManager.save();
dismissBusy();
if (f) {
f(index);
}
},
dataType: "jsonp"
});
"jsonp"
);
};
ReconciliationManager.unregisterService = function(service, f) {

View File

@ -131,7 +131,7 @@ ReconStandardServicePanel.prototype._populatePanel = function() {
.find('input[name="type-choice"][value=""]')
.attr("checked", "true");
this._panel.typeInput.focus();
this._elmts.typeInput.focus();
}
/*
@ -197,16 +197,18 @@ ReconStandardServicePanel.prototype._rewirePropertySuggests = function(type) {
.find('input[name="property"]')
.unbind();
if ("property" in this._service && "property" in this._service.suggest) {
if ("suggest" in this._service && "property" in this._service.suggest) {
var suggestOptions = $.extend({}, this._service.suggest.property);
if (type) {
suggestOptions.schema = typeof type == "string" ? type : type.id;
suggestOptions.ac_param = { schema: typeof type == "string" ? type : type.id };
}
inputs.suggestP(suggestOptions);
} else if (this._isInFreebaseSchemaSpace()) {
inputs.suggestP({
type: '/type/property',
schema: (type) ? (typeof type == "string" ? type : type.id) : "/common/topic"
ac_param: {
schema: (type) ? (typeof type == "string" ? type : type.id) : "/common/topic"
}
});
}
};

View File

@ -1,40 +1,4 @@
(function() {
var oldResponse = $.suggest.suggest.prototype.response;
var typeToIncludedTypes = {};
var resortByType = function(data, type) {
var schemaPrefixes = [ type + "/" ];
var includedTypes = typeToIncludedTypes[type];
for (var i = 0; i < includedTypes.length; i++) {
schemaPrefixes.push(includedTypes[i] + "/");
}
var results = "result" in data ? data.result : [];
var entries1 = [];
var entries2 = [];
for (var i = 0; i < results.length; i++) {
var result = results[i];
var matched = false;
for (var j = 0; j < schemaPrefixes.length; j++) {
var schemaPrefix = schemaPrefixes[j];
if (result.id.substring(0, schemaPrefix.length) == schemaPrefix) {
matched = true;
break;
}
}
if (matched) {
entries1.push(result);
} else {
entries2.push(result);
}
}
data.result = entries1.concat(entries2);
};
/*
* Property suggest
*/
@ -45,80 +9,24 @@
{},
$.suggest.suggest.prototype,
{
request: function(val, start) {
if (this.ac_xhr) {
this.ac_xhr.abort();
this.ac_xhr = null;
}
var self = this;
var o = this.options;
var data = {
query: val
};
if (start) {
data.start = start;
}
if ("schema" in o) {
data.schema = o.schema;
}
$.extend(data, o.ac_param);
var baseUrl = Gridworks.gridworksHelperService + "suggest_property";
var url = baseUrl + "?" + $.param(data),
cached = $.suggest.cache[url];
if (cached) {
this.response(cached, start ? start : -1, true);
return;
}
clearTimeout(this.request.timeout);
this.request.timeout =
setTimeout(function() {
self.ac_xhr = $.ajax({
url: baseUrl,
data: data,
beforeSend: function() {
var calls = self.input.data("request.count.suggest") || 0;
if (!calls) {
self.trackEvent(self.name, "start_session");
}
calls += 1;
self.trackEvent(self.name, "request", "count", calls);
self.input.data("request.count.suggest", calls);
},
success: function(data) {
self.response(data, start ? start : -1);
},
error: function(xhr) {
self.trackEvent(self.name, "request", "error", {url:this.url, response: xhr ? xhr.responseText : ''});
},
complete: function(xhr) {
if (xhr) {
self.trackEvent(self.name, "request", "tid", xhr.getResponseHeader("X-Metaweb-TID"));
}
},
dataType: "jsonp",
cache: true
});
}, o.xhr_delay);
},
create_item: function(data, response_data) {
var css = this.options.css;
var li = $("<li>").addClass(css.item);
var name = $("<div>")
.addClass(css.item_name)
.append(
$("<label>").append($.suggest.strongify(data.name || data.guid, response_data.prefix)));
$("<label>").append(
$.suggest.strongify(
data.name || data.guid, response_data.prefix
)
)
);
data.name = name.text(); // this converts html escaped strings like "&amp;" back to "&"
li.append(name);
name.prepend($("<div>").addClass(css.item_type).text(data.id));
return li;
@ -127,6 +35,19 @@
)
);
var originalSuggestP = $.suggest.suggestP;
$.suggest.suggestP = function(input, options) {
originalSuggestP.call(this, input, options);
if ("ac_param" in options) {
var ac_param = options.ac_param;
if ("schema" in ac_param) {
this.options.ac_param.schema = ac_param.schema;
}
}
};
$.suggest.suggestP.prototype = originalSuggestP.prototype;
$.extend(
$.suggest.suggestP,
{
@ -134,6 +55,9 @@
true,
{},
$.suggest.suggest.defaults, {
service_url: Gridworks.gridworksHelperService,
service_path: "/suggest_property",
flyout_service_url: "http://www.freebase.com",
css: { pane: "fbs-pane fbs-pane-property" }
}
)