NIHVIVO-2343 Use the specialized AJAX handlers instead of the SparqlQueryAjaxController -- fixes issues with placeholder images.
This commit is contained in:
parent
2704ce3c78
commit
57c28c183f
7 changed files with 49 additions and 248 deletions
|
@ -70,6 +70,7 @@ function itemElement(template, uri, label, classLabel, imageUrl, removeInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* proxyAutoComplete
|
||||
|
@ -77,8 +78,7 @@ function itemElement(template, uri, label, classLabel, imageUrl, removeInfo) {
|
|||
* Attach the autocomplete funcionality that we like in proxy panels.
|
||||
*
|
||||
* You provide:
|
||||
* parms -- a map containing the URL of the AJAX controller, the query, and
|
||||
* the model selector.
|
||||
* parms -- a map containing the URL and the action code needed for the AJAX call.
|
||||
* excludedUris -- these URIs are always filtered out of the results.
|
||||
* getProxyInfos -- a function that will return an array of itemElements
|
||||
* that are already present in the list and so should be filtered out of
|
||||
|
@ -90,8 +90,7 @@ function itemElement(template, uri, label, classLabel, imageUrl, removeInfo) {
|
|||
* will accept the length of the search term and the number of results,
|
||||
* and will display it in some way.
|
||||
* ----------------------------------------------------------------------------
|
||||
* Before executing the AJAX request, the query from the parms map will be modified,
|
||||
* replacing "%term%" with the current search term.
|
||||
* The AJAX request will include a "term" parameter, set to the current search term.
|
||||
* ----------------------------------------------------------------------------
|
||||
* The functionality includes:
|
||||
* -- fetching data for the autocomplete list.
|
||||
|
@ -137,14 +136,13 @@ function proxyAutocomplete(parms, excludedUris, getProxyInfos, addProxyInfo, rep
|
|||
url: parms.url,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
model: parms.model,
|
||||
query: parms.query.replace("%term%", request.term)
|
||||
action: parms.action,
|
||||
term: request.term
|
||||
},
|
||||
complete: function(xhr, status) {
|
||||
var results = $.parseJSON(xhr.responseText);
|
||||
var parsed = sparqlUtils.parseSparqlResults(results);
|
||||
cache[request.term] = parsed;
|
||||
sendResponse(request, response, filterResults(parsed));
|
||||
cache[request.term] = results;
|
||||
sendResponse(request, response, filterResults(results));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -154,6 +152,4 @@ function proxyAutocomplete(parms, excludedUris, getProxyInfos, addProxyInfo, rep
|
|||
event.preventDefault();
|
||||
event.target.value = '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -58,24 +58,35 @@ function proxyItemsPanel(panel, contextInfo) {
|
|||
}
|
||||
|
||||
this.addItemData = function(selection) {
|
||||
var imageUrl = contextInfo.defaultImageUrl;
|
||||
if (selection.imageUrl) {
|
||||
imageUrl = contextInfo.baseUrl + selection.imageUrl;
|
||||
}
|
||||
|
||||
var classLabel = selection.classLabel ? selection.classLabel : "";
|
||||
|
||||
var info = new itemElement(self.templateHtml, selection.uri, selection.label, classLabel,
|
||||
imageUrl, self.removeItem);
|
||||
var info = new itemElement(self.templateHtml, selection.uri, selection.label,
|
||||
selection.classLabel, selection.imageUrl, self.removeItem);
|
||||
self.itemData.unshift(info);
|
||||
self.displayItemData();
|
||||
self.getAdditionalData(self, info, selection.externalAuthId)
|
||||
}
|
||||
|
||||
this.getAdditionalData = function(parent, info, externalAuthId) {
|
||||
// For the plain vanilla panel, this need not do anything. For the
|
||||
// proxy panel, this will be replaced by a function that does another
|
||||
// AJAX call to get the classLabel and imageUrl.
|
||||
data = info
|
||||
$.ajax({
|
||||
url: contextInfo.ajaxUrl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: contextInfo.moreInfoAction,
|
||||
uri: info.uri
|
||||
},
|
||||
complete: function(xhr, status) {
|
||||
var results = $.parseJSON(xhr.responseText);
|
||||
if (results.length > 0) {
|
||||
if ("classLabel" in results[0]) {
|
||||
info.classLabel = results[0].classLabel;
|
||||
}
|
||||
if ("imageUrl" in results[0]) {
|
||||
info.imageUrl = results[0].imageUrl;
|
||||
}
|
||||
self.displayItemData();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var parseOriginalData = function() {
|
||||
|
@ -95,10 +106,9 @@ function proxyItemsPanel(panel, contextInfo) {
|
|||
|
||||
var setupAutoCompleteFields = function() {
|
||||
var parms = {
|
||||
query: contextInfo.query,
|
||||
model: contextInfo.model,
|
||||
url: contextInfo.sparqlQueryUrl
|
||||
};
|
||||
url: contextInfo.ajaxUrl,
|
||||
action: contextInfo.basicInfoAction
|
||||
}
|
||||
var updateStatus = new statusFieldUpdater(searchStatusField, 3).setText;
|
||||
var autocompleteInfo = new proxyAutocomplete(parms, excludedUris, getItemData, self.addItemData, updateStatus)
|
||||
autoCompleteField.autocomplete(autocompleteInfo);
|
||||
|
@ -126,152 +136,6 @@ function statusFieldUpdater(element, minLength) {
|
|||
}
|
||||
}
|
||||
|
||||
var profileQuery = ""
|
||||
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"
|
||||
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
|
||||
+ "\n"
|
||||
+ "SELECT DISTINCT ?uri ?label ?classLabel ?imageUrl \n"
|
||||
+ "WHERE { \n"
|
||||
+ " %typesUnion% \n"
|
||||
+ " ?uri rdfs:label ?label ; \n"
|
||||
+ " FILTER (REGEX(str(?label), '^%term%', 'i')) \n"
|
||||
+ "} \n"
|
||||
+ "ORDER BY ASC(?label) \n"
|
||||
+ "LIMIT 25 \n";
|
||||
|
||||
var profileMoreInfoQuery = ""
|
||||
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"
|
||||
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
|
||||
+ "PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n"
|
||||
+ "PREFIX vpublic: <http://vitro.mannlib.cornell.edu/ns/vitro/public#> \n"
|
||||
+ "\n"
|
||||
+ "SELECT DISTINCT ?classLabel ?imageUrl \n"
|
||||
+ "WHERE { \n"
|
||||
+ " OPTIONAL { \n"
|
||||
+ " <%uri%> vitro:mostSpecificType ?type. \n"
|
||||
+ " ?type rdfs:label ?classLabel \n"
|
||||
+ " } \n"
|
||||
+ " OPTIONAL { \n"
|
||||
+ " <%uri%> vpublic:mainImage ?imageUri. \n"
|
||||
+ " ?imageUri vpublic:thumbnailImage ?thumbUri. \n"
|
||||
+ " ?thumbUri vpublic:downloadLocation ?thumbstreamUri. \n"
|
||||
+ " ?thumbstreamUri vpublic:directDownloadUrl ?imageUrl. \n"
|
||||
+ " } \n"
|
||||
+ "} \n"
|
||||
+ "ORDER BY ASC(?label) \n"
|
||||
+ "LIMIT 25 \n";
|
||||
|
||||
var proxyQuery = ""
|
||||
+ "PREFIX fn: <http://www.w3.org/2005/xpath-functions#> \n"
|
||||
+ "PREFIX auth: <http://vitro.mannlib.cornell.edu/ns/vitro/authorization#> \n"
|
||||
+ "\n"
|
||||
+ "SELECT DISTINCT ?uri ?label ?externalAuthId \n"
|
||||
+ "WHERE { \n"
|
||||
+ " ?uri a auth:UserAccount ; \n"
|
||||
+ " auth:firstName ?firstName ; \n"
|
||||
+ " auth:lastName ?lastName . \n"
|
||||
+ " LET ( ?label := fn:concat(?lastName, ', ', ?firstName) )"
|
||||
+ " OPTIONAL { ?uri auth:externalAuthId ?externalAuthId } \n"
|
||||
+ " FILTER (REGEX(?label, '^%term%', 'i')) \n"
|
||||
+ "} \n"
|
||||
+ "ORDER BY ASC(?lastName) ASC(?firstName) \n"
|
||||
+ "LIMIT 25 \n";
|
||||
|
||||
var proxyMoreInfoQuery = ""
|
||||
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
|
||||
+ "PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n"
|
||||
+ "PREFIX p.1: <http://vitro.mannlib.cornell.edu/ns/vitro/public#> \n"
|
||||
+ " \n"
|
||||
+ "SELECT ?uri ?classLabel ?imageUrl \n"
|
||||
+ "WHERE \n"
|
||||
+ "{ \n"
|
||||
+ " ?uri <%matchingProperty%> '%externalAuthId%'. \n"
|
||||
+ " \n"
|
||||
+ " OPTIONAL { \n"
|
||||
+ " ?uri vitro:mostSpecificType ?type. \n"
|
||||
+ " ?type rdfs:label ?classLabel \n"
|
||||
+ " } \n"
|
||||
+ " \n"
|
||||
+ " OPTIONAL { \n"
|
||||
+ " ?uri p.1:mainImage ?imageUri. \n"
|
||||
+ " ?imageUri p.1:thumbnailImage ?thumbUri. \n"
|
||||
+ " ?thumbUri p.1:downloadLocation ?thumbstreamUri. \n"
|
||||
+ " ?thumbstreamUri p.1:directDownloadUrl ?imageUrl. \n"
|
||||
+ " } \n"
|
||||
+ "} \n"
|
||||
+ "LIMIT 1 \n";
|
||||
|
||||
/*
|
||||
* This function will allow a proxy panel to execute another query for each proxy.
|
||||
*/
|
||||
var getAdditionalProxyInfo = function(parent, info, externalAuthId) {
|
||||
$.ajax({
|
||||
url: proxyContextInfo.sparqlQueryUrl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
query: proxyMoreInfoQuery.replace(/%matchingProperty%/g, proxyContextInfo.matchingProperty)
|
||||
.replace(/%externalAuthId%/g, externalAuthId)
|
||||
},
|
||||
complete: function(xhr, status) {
|
||||
var results = $.parseJSON(xhr.responseText);
|
||||
var parsed = sparqlUtils.parseSparqlResults(results);
|
||||
if (parsed.length > 0) {
|
||||
if ("classLabel" in parsed[0]) {
|
||||
info.classLabel = parsed[0].classLabel;
|
||||
}
|
||||
if ("imageUrl" in parsed[0]) {
|
||||
info.imageUrl = proxyContextInfo.baseUrl + parsed[0].imageUrl;
|
||||
}
|
||||
parent.displayItemData();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* The profileTypes context string must have one or more type URIs, separated by commas.
|
||||
*/
|
||||
var applyProfileTypes = function(rawQuery) {
|
||||
var typeClause = '';
|
||||
var types = proxyContextInfo.profileTypes.split(',');
|
||||
|
||||
for (var i = 0; i < types.length; i++) {
|
||||
typeClause += '{ ?uri rdf:type <' + types[i].trim() + '> }';
|
||||
if (i + 1 < types.length) {
|
||||
typeClause += ' UNION ';
|
||||
} else {
|
||||
typeClause += ' .';
|
||||
}
|
||||
}
|
||||
return rawQuery.replace(/%typesUnion%/g, typeClause);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function will allow a profile panel to execute another query for each profile.
|
||||
*/
|
||||
var getAdditionalProfileInfo = function(parent, info) {
|
||||
$.ajax({
|
||||
url: proxyContextInfo.sparqlQueryUrl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
query: profileMoreInfoQuery.replace(/%uri%/g, info.uri)
|
||||
},
|
||||
complete: function(xhr, status) {
|
||||
var results = $.parseJSON(xhr.responseText);
|
||||
var parsed = sparqlUtils.parseSparqlResults(results);
|
||||
if (parsed.length > 0) {
|
||||
if ("classLabel" in parsed[0]) {
|
||||
info.classLabel = parsed[0].classLabel;
|
||||
}
|
||||
if ("imageUrl" in parsed[0]) {
|
||||
info.imageUrl = proxyContextInfo.baseUrl + parsed[0].imageUrl;
|
||||
}
|
||||
parent.displayItemData();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Execute this when the page loads.
|
||||
*/
|
||||
|
@ -295,42 +159,25 @@ $(document).ready(function() {
|
|||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* For each proxyProfilesPanel, modify the profile query to restrict it
|
||||
* to the permitted types, then create a plain vanilla panel using the
|
||||
* profile query against the main model.
|
||||
*/
|
||||
$("div[name='proxyProfilesPanel']").each(function(i) {
|
||||
var query = applyProfileTypes(profileQuery);
|
||||
var context = {
|
||||
excludedUris: [],
|
||||
baseUrl: proxyContextInfo.baseUrl,
|
||||
sparqlQueryUrl: proxyContextInfo.sparqlQueryUrl,
|
||||
defaultImageUrl: proxyContextInfo.defaultImageUrl,
|
||||
query: query,
|
||||
model: ''
|
||||
ajaxUrl: proxyContextInfo.ajaxUrl,
|
||||
basicInfoAction: "getAvailableProfiles",
|
||||
moreInfoAction: "moreProfileInfo"
|
||||
}
|
||||
var pip = new proxyItemsPanel(this, context);
|
||||
pip.getAdditionalData = getAdditionalProfileInfo;
|
||||
this["proxyItemsPanel"] = pip;
|
||||
this["proxyItemsPanel"] = new proxyItemsPanel(this, context);
|
||||
});
|
||||
|
||||
/*
|
||||
* For each proxyProxiesPanel, we start with a plain panel using the proxy
|
||||
* query against the user accounts model. Then we augment it with a method
|
||||
* that will fetch more info from the main model for each proxy.
|
||||
*/
|
||||
$("div[name='proxyProxiesPanel']").each(function(i) {
|
||||
var context = {
|
||||
excludedUris: [],
|
||||
baseUrl: proxyContextInfo.baseUrl,
|
||||
sparqlQueryUrl: proxyContextInfo.sparqlQueryUrl,
|
||||
defaultImageUrl: proxyContextInfo.defaultImageUrl,
|
||||
query: proxyQuery,
|
||||
model: 'userAccounts'
|
||||
ajaxUrl: proxyContextInfo.ajaxUrl,
|
||||
basicInfoAction: "getAvailableProxies",
|
||||
moreInfoAction: "moreProxyInfo"
|
||||
}
|
||||
var pip = new proxyItemsPanel(this, context);
|
||||
pip.getAdditionalData = getAdditionalProxyInfo;
|
||||
this["proxyItemsPanel"] = pip;
|
||||
this["proxyItemsPanel"] = new proxyItemsPanel(this, context);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue