diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/UserAccountsPage.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/UserAccountsPage.java index 22b3c667c..b6f837279 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/UserAccountsPage.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/UserAccountsPage.java @@ -104,7 +104,7 @@ public abstract class UserAccountsPage extends AbstractPageHandler { map.put("firstTimeExternal", UrlBuilder.getUrl("/accounts/firstTimeExternal")); map.put("accountsAjax", UrlBuilder.getUrl("/accountsAjax")); - map.put("sparqlQueryAjax", UrlBuilder.getUrl("/ajax/sparqlQuery")); + map.put("proxyAjax", UrlBuilder.getUrl("/proxiesAjax")); map.put("defaultImageUrl", DEFAULT_IMAGE_URL); return map; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ManageProxiesListPage.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ManageProxiesListPage.java index 30f7f3825..09be9877e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ManageProxiesListPage.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ManageProxiesListPage.java @@ -37,11 +37,6 @@ public class ManageProxiesListPage extends AbstractPageHandler { private static final String TEMPLATE_NAME = "manageProxies-list.ftl"; - private static final String PROPERTY_PROFILE_TYPES = "proxy.eligibleTypeList"; - - private static final String DEFAULT_IMAGE_URL = UrlBuilder - .getUrl("/images/placeholders/person.thumbnail.jpg"); - private final Context selectorContext; private ProxyRelationshipSelectionCriteria criteria = ProxyRelationshipSelectionCriteria.DEFAULT_CRITERIA; @@ -80,6 +75,8 @@ public class ManageProxiesListPage extends AbstractPageHandler { public ResponseValues showPage() { ProxyRelationshipSelection selection = ProxyRelationshipSelector .select(selectorContext, criteria); + log.debug("Selection: " + selection); + Map body = buildTemplateBodyMap(selection); return new TemplateResponseValues(TEMPLATE_NAME, body); } @@ -97,9 +94,6 @@ public class ManageProxiesListPage extends AbstractPageHandler { body.put("total", selection.getTotalResultCount()); body.put("page", buildPageMap(selection)); - body.put("matchingProperty", getMatchingProperty()); - body.put("profileTypes", buildProfileTypesString()); - body.put("formUrls", buildUrlsMap()); applyMessage(vreq, body); @@ -108,11 +102,6 @@ public class ManageProxiesListPage extends AbstractPageHandler { return body; } - private String buildProfileTypesString() { - return ConfigurationProperties.getBean(vreq).getProperty( - PROPERTY_PROFILE_TYPES, "http://www.w3.org/2002/07/owl#Thing"); - } - private List wrapProxyRelationships( ProxyRelationshipSelection selection) { List wrapped = new ArrayList(); @@ -153,8 +142,8 @@ public class ManageProxiesListPage extends AbstractPageHandler { private ProxyItemInfo wrapProfileItem(ProxyItemInfo item) { String imagePath = item.getImageUrl(); if (imagePath.isEmpty()) { - imagePath = ImageUtil - .getPlaceholderImagePathForIndividual(vreq, item.getUri()); + imagePath = ImageUtil.getPlaceholderImagePathForIndividual(vreq, + item.getUri()); } return new ProfileItemWrapper(item.getUri(), item.getLabel(), @@ -191,8 +180,7 @@ public class ManageProxiesListPage extends AbstractPageHandler { map.put("list", UrlBuilder.getUrl("/manageProxies/list")); map.put("edit", UrlBuilder.getUrl("/manageProxies/edit")); map.put("create", UrlBuilder.getUrl("/manageProxies/create")); - map.put("sparqlQueryAjax", UrlBuilder.getUrl("/ajax/sparqlQuery")); - map.put("defaultImageUrl", DEFAULT_IMAGE_URL); + map.put("ajax", UrlBuilder.getUrl("/proxiesAjax")); return map; } diff --git a/webapp/web/js/account/accountProxyCommon.js b/webapp/web/js/account/accountProxyCommon.js index 19be955be..06af6469f 100644 --- a/webapp/web/js/account/accountProxyCommon.js +++ b/webapp/web/js/account/accountProxyCommon.js @@ -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 = ''; } - } - diff --git a/webapp/web/js/account/accountProxyItemsPanel.js b/webapp/web/js/account/accountProxyItemsPanel.js index 5d81a23a6..c490b14a9 100644 --- a/webapp/web/js/account/accountProxyItemsPanel.js +++ b/webapp/web/js/account/accountProxyItemsPanel.js @@ -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: \n" - + "PREFIX rdfs: \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: \n" - + "PREFIX rdfs: \n" - + "PREFIX vitro: \n" - + "PREFIX vpublic: \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: \n" - + "PREFIX auth: \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: \n" - + "PREFIX vitro: \n" - + "PREFIX p.1: \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); }); }); diff --git a/webapp/web/js/sparqlUtils.js b/webapp/web/js/sparqlUtils.js deleted file mode 100644 index d77a2403d..000000000 --- a/webapp/web/js/sparqlUtils.js +++ /dev/null @@ -1,22 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -/* - * Parse the results that we got from the SparqlQueryAjaxController. - * - * The input is a complex structure from the controller. The output is an array - * of maps where each map represents a result row, populated with key-value pairs. - */ -sparqlUtils = { - parseSparqlResults: function(data) { - var parsed = []; - $.each(data.results.bindings, function() { - var row = {}; - for (var i in this) { - row[i] = this[i].value; - } - parsed.push(row); - }); - return parsed; - } -}; - diff --git a/webapp/web/templates/freemarker/body/accounts/userAccounts-myProxiesPanel.ftl b/webapp/web/templates/freemarker/body/accounts/userAccounts-myProxiesPanel.ftl index fd92b62b8..080fd5e4b 100644 --- a/webapp/web/templates/freemarker/body/accounts/userAccounts-myProxiesPanel.ftl +++ b/webapp/web/templates/freemarker/body/accounts/userAccounts-myProxiesPanel.ftl @@ -51,15 +51,11 @@ ${stylesheets.add(' var proxyContextInfo = { baseUrl: '${urls.base}', - sparqlQueryUrl: '${formUrls.sparqlQueryAjax}', - defaultImageUrl: '${formUrls.defaultImageUrl}', - matchingProperty: '${matchingProperty}', - profileTypes: '${profileTypes}' + ajaxUrl: '${formUrls.proxyAjax}' }; ${scripts.add('', - '', '', '', '')} \ No newline at end of file diff --git a/webapp/web/templates/freemarker/body/manageproxies/manageProxies-list.ftl b/webapp/web/templates/freemarker/body/manageproxies/manageProxies-list.ftl index a07bc554c..dd6cf52de 100644 --- a/webapp/web/templates/freemarker/body/manageproxies/manageProxies-list.ftl +++ b/webapp/web/templates/freemarker/body/manageproxies/manageProxies-list.ftl @@ -220,16 +220,12 @@ ${stylesheets.add(' var proxyContextInfo = { baseUrl: '${urls.base}', - sparqlQueryUrl: '${formUrls.sparqlQueryAjax}', - defaultImageUrl: '${formUrls.defaultImageUrl}', - matchingProperty: '${matchingProperty}', - profileTypes: '${profileTypes}' + ajaxUrl: '${formUrls.ajax}' }; ${scripts.add('', '')} ${scripts.add('', - '', '', '')}