changes for the home page redesign
This commit is contained in:
parent
556af80432
commit
1ca0904911
13 changed files with 270 additions and 51 deletions
|
@ -9,6 +9,7 @@ import java.util.List;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||
|
@ -48,6 +49,7 @@ public class HomePageController extends FreemarkerHttpServlet {
|
|||
}
|
||||
}*/
|
||||
body.put("dataServiceUrlVClassesForVClassGroup", UrlBuilder.getUrl("/dataservice?getVClassesForVClassGroup=1&classgroupUri="));
|
||||
body.put("geoFocusMapsEnabled", getGeoFocusMapsFlag(vreq));
|
||||
|
||||
return new TemplateResponseValues(BODY_TEMPLATE, body);
|
||||
}
|
||||
|
@ -61,4 +63,11 @@ public class HomePageController extends FreemarkerHttpServlet {
|
|||
protected String getPageTemplateName() {
|
||||
return PAGE_TEMPLATE;
|
||||
}
|
||||
|
||||
private boolean getGeoFocusMapsFlag(VitroRequest vreq) {
|
||||
String property = ConfigurationProperties.getBean(vreq).getProperty(
|
||||
"homePage.geoFocusMaps");
|
||||
return "enabled".equals(property);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -182,8 +182,19 @@ public class IndividualListController extends FreemarkerHttpServlet {
|
|||
}
|
||||
return rvMap;
|
||||
}
|
||||
|
||||
|
||||
public static Map<String,Object> getRandomResultsForVClass(String vclassURI, int page, int pageSize, IndividualDao indDao, ServletContext context) {
|
||||
Map<String,Object> rvMap = new HashMap<String,Object>();
|
||||
try{
|
||||
List<String> classUris = Collections.singletonList(vclassURI);
|
||||
IndividualListQueryResults results = SolrQueryUtils.buildAndExecuteRandomVClassQuery(classUris, page, pageSize, context, indDao);
|
||||
rvMap = getResultsForVClassQuery(results, page, pageSize, "");
|
||||
} catch(Throwable th) {
|
||||
log.error("An error occurred retrieving random results for vclass query", th);
|
||||
}
|
||||
return rvMap;
|
||||
}
|
||||
|
||||
//TODO: Get rid of this method and utilize SolrQueryUtils - currently appears to be referenced
|
||||
//only within DataGetterUtils
|
||||
public static long getIndividualCount(List<String> vclassUris, IndividualDao indDao, ServletContext context) {
|
||||
|
|
|
@ -180,7 +180,7 @@ class IndividualResponseBuilder {
|
|||
|
||||
private boolean getprofilePageTypesFlag() {
|
||||
String property = ConfigurationProperties.getBean(vreq).getProperty(
|
||||
"MultiViews.profilePageTypes");
|
||||
"multiViews.profilePageTypes");
|
||||
return "enabled".equals(property);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.json;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewService;
|
||||
import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewService.ShortViewContext;
|
||||
import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewServiceSetup;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
||||
|
||||
/**
|
||||
* Does a Solr search for individuals, and uses the short view to render each of
|
||||
* the results.
|
||||
*/
|
||||
public class GetRandomSolrIndividualsByVClass extends GetSolrIndividualsByVClass {
|
||||
private static final Log log = LogFactory
|
||||
.getLog(GetRandomSolrIndividualsByVClass.class);
|
||||
|
||||
protected GetRandomSolrIndividualsByVClass(VitroRequest vreq) {
|
||||
super(vreq);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for individuals by VClass.
|
||||
*/
|
||||
@Override
|
||||
protected JSONObject process() throws Exception {
|
||||
JSONObject rObj = null;
|
||||
|
||||
//This gets the first vclass value and sets that as display type.
|
||||
List<String> vclassIds = super.getVclassIds(vreq);
|
||||
String vclassId = vclassIds.get(0);
|
||||
vreq.setAttribute("queryType", "random");
|
||||
// vreq.setAttribute("displayType", vclassId);
|
||||
|
||||
//This will get all the solr individuals by VClass (if one value) or the intersection
|
||||
//i.e. individuals that have all the types for the different vclasses entered
|
||||
rObj = super.process();
|
||||
addShortViewRenderings(rObj);
|
||||
return rObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look through the return object. For each individual, render the short
|
||||
* view and insert the resulting HTML into the object.
|
||||
*/
|
||||
private void addShortViewRenderings(JSONObject rObj) throws JSONException {
|
||||
JSONArray individuals = rObj.getJSONArray("individuals");
|
||||
String vclassName = rObj.getJSONObject("vclass").getString("name");
|
||||
for (int i = 0; i < individuals.length(); i++) {
|
||||
JSONObject individual = individuals.getJSONObject(i);
|
||||
individual.put("shortViewHtml",
|
||||
renderShortView(individual.getString("URI"), vclassName));
|
||||
}
|
||||
}
|
||||
|
||||
private String renderShortView(String individualUri, String vclassName) {
|
||||
IndividualDao iDao = vreq.getWebappDaoFactory().getIndividualDao();
|
||||
Individual individual = iDao.getIndividualByURI(individualUri);
|
||||
|
||||
Map<String, Object> modelMap = new HashMap<String, Object>();
|
||||
modelMap.put("individual",
|
||||
new IndividualTemplateModel(individual, vreq));
|
||||
modelMap.put("vclass", vclassName);
|
||||
|
||||
ShortViewService svs = ShortViewServiceSetup.getService(ctx);
|
||||
return svs.renderShortView(individual, ShortViewContext.BROWSE,
|
||||
modelMap, vreq);
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ public class GetSolrIndividualsByVClass extends JsonObjectProducer {
|
|||
protected JSONObject process() throws Exception {
|
||||
VClass vclass=null;
|
||||
|
||||
String queryType = (String) vreq.getAttribute("queryType");
|
||||
String vitroClassIdStr = vreq.getParameter("vclassId");
|
||||
if ( vitroClassIdStr != null && !vitroClassIdStr.isEmpty()){
|
||||
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vitroClassIdStr);
|
||||
|
@ -35,8 +36,13 @@ public class GetSolrIndividualsByVClass extends JsonObjectProducer {
|
|||
log.debug("parameter vclassId URI parameter expected ");
|
||||
throw new Exception("parameter vclassId URI parameter expected ");
|
||||
}
|
||||
|
||||
vreq.setAttribute("displayType", vitroClassIdStr);
|
||||
return JsonServlet.getSolrIndividualsByVClass(vclass.getURI(), vreq, ctx);
|
||||
if ( queryType != null && queryType.equals("random")){
|
||||
return JsonServlet.getRandomSolrIndividualsByVClass(vclass.getURI(), vreq, ctx);
|
||||
} else {
|
||||
return JsonServlet.getSolrIndividualsByVClass(vclass.getURI(), vreq, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -72,7 +72,10 @@ public class JsonServlet extends VitroHttpServlet {
|
|||
new GetDataForPage(vreq).process(resp);
|
||||
}else if( vreq.getParameter("getRenderedSolrIndividualsByVClass") != null ){
|
||||
new GetRenderedSolrIndividualsByVClass(vreq).process(resp);
|
||||
}else if( vreq.getParameter("getRandomSolrIndividualsByVClass") != null ){
|
||||
new GetRandomSolrIndividualsByVClass(vreq).process(resp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -135,7 +138,35 @@ public class JsonServlet extends VitroHttpServlet {
|
|||
return value;
|
||||
}
|
||||
|
||||
public static JSONObject getRandomSolrIndividualsByVClass(String vclassURI, HttpServletRequest req, ServletContext context) throws Exception {
|
||||
VitroRequest vreq = new VitroRequest(req);
|
||||
|
||||
Map<String, Object> map = getRandomSolrVClassResults(vclassURI, vreq, context);
|
||||
//last parameter indicates single vclass instead of multiple vclasses
|
||||
return processVClassResults(map, vreq, context, false);
|
||||
}
|
||||
|
||||
//Including version for Random Solr query for Vclass Intersections
|
||||
private static Map<String,Object> getRandomSolrVClassResults(String vclassURI, VitroRequest vreq, ServletContext context){
|
||||
log.debug("Retrieving random Solr intersection results for " + vclassURI);
|
||||
|
||||
int page = IndividualListController.getPageParameter(vreq);
|
||||
int pageSize = Integer.parseInt(vreq.getParameter("pageSize"));
|
||||
log.debug("page and pageSize parameters = " + page + " and " + pageSize);
|
||||
Map<String,Object> map = null;
|
||||
try {
|
||||
map = IndividualListController.getRandomResultsForVClass(
|
||||
vclassURI,
|
||||
page,
|
||||
pageSize,
|
||||
vreq.getWebappDaoFactory().getIndividualDao(),
|
||||
context);
|
||||
} catch(Exception ex) {
|
||||
log.error("Error in retrieval of search results for VClass " + vclassURI, ex);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -211,7 +211,8 @@ public class PagedSearchController extends FreemarkerHttpServlet {
|
|||
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
|
||||
String classGroupParam = vreq.getParameter(PARAM_CLASSGROUP);
|
||||
String classGroupParam = vreq.getParameter(PARAM_CLASSGROUP);
|
||||
log.debug("Query text is \""+ classGroupParam + "\"");
|
||||
boolean classGroupFilterRequested = false;
|
||||
if (!StringUtils.isEmpty(classGroupParam)) {
|
||||
VClassGroup grp = grpDao.getGroupByURI(classGroupParam);
|
||||
|
|
|
@ -190,6 +190,26 @@ public class SolrQueryUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static SolrQuery getRandomQuery(List<String> vclassUris, int page, int pageSize){
|
||||
String queryText = "";
|
||||
|
||||
try {
|
||||
queryText = makeMultiClassQuery(vclassUris);
|
||||
log.debug("queryText is " + queryText);
|
||||
SolrQuery query = new SolrQuery(queryText);
|
||||
|
||||
//page count starts at 1, row count starts at 0
|
||||
query.setStart( page ).setRows( pageSize );
|
||||
|
||||
log.debug("Query is " + query.toString());
|
||||
return query;
|
||||
|
||||
} catch (Exception ex){
|
||||
log.error("Could not make the Solr query",ex);
|
||||
return new SolrQuery();
|
||||
}
|
||||
}
|
||||
|
||||
public static String makeMultiClassQuery( List<String> vclassUris){
|
||||
List<String> queryTypes = new ArrayList<String>();
|
||||
try {
|
||||
|
@ -217,4 +237,16 @@ public class SolrQueryUtils {
|
|||
return results;
|
||||
}
|
||||
|
||||
public static IndividualListQueryResults buildAndExecuteRandomVClassQuery(
|
||||
List<String> vclassURIs, int page, int pageSize,
|
||||
ServletContext context, IndividualDao indDao)
|
||||
throws SolrServerException {
|
||||
SolrQuery query = SolrQueryUtils.getRandomQuery(vclassURIs, page, pageSize);
|
||||
IndividualListQueryResults results = IndividualListQueryResults.runQuery(query, indDao, context);
|
||||
log.debug("Executed solr query for " + vclassURIs);
|
||||
if (results.getIndividuals().isEmpty()) {
|
||||
log.debug("entities list is null for vclass " + vclassURIs);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<@widget name="login" include="assets" />
|
||||
<#include "browse-classgroups.ftl">
|
||||
<#import "lib-home-page.ftl" as lh>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
@ -36,17 +36,14 @@
|
|||
<div id="search-home-field">
|
||||
<input type="text" name="querytext" class="search-homepage" value="${querytext!}" autocapitalize="off" />
|
||||
<input type="submit" value="Search" class="search" />
|
||||
<input type="hidden" name="classgroup" class="search-homepage" value="" autocapitalize="off" />
|
||||
</div>
|
||||
|
||||
<a class="filter-search filter-default" href="#" title="Filter search"><span class="displace">filter search</span></a>
|
||||
|
||||
<ul id="filter-search-nav">
|
||||
<li><a class="active" href="">All</a></li>
|
||||
<li><a href="">People</a></li>
|
||||
<li><a href="">Organizations</a></li>
|
||||
<li><a href="">Research</a></li>
|
||||
<li><a href="">Events</a></li>
|
||||
<li><a href="">Topics</a></li>
|
||||
<@lh.allClassGroupNames vClassGroups! />
|
||||
</ul>
|
||||
</form>
|
||||
</fieldset>
|
||||
|
@ -57,19 +54,12 @@
|
|||
|
||||
|
||||
<@widget name="login" />
|
||||
|
||||
<#--<@allClassGroups vClassGroups! />-->
|
||||
|
||||
<section id="home-stats">
|
||||
<h4>Stats</h4>
|
||||
|
||||
<section id="home-stats" class="home-sections" >
|
||||
<h4>Statistics</h4>
|
||||
|
||||
<ul id="stats">
|
||||
<li><a href="#"><p class="stats-count">19<span>k</span></p><p class="stats-type">People</p></a></li>
|
||||
<li><a href="#"><p class="stats-count">128<span>k</span></p><p class="stats-type">Research</p></a></li>
|
||||
<li><a href="#"><p class="stats-count">22<span>k</span></p><p class="stats-type">Organizations</p></a></li>
|
||||
<li><a href="#"><p class="stats-count">29<span>k</span></p><p class="stats-type">Events</p></a></li>
|
||||
<li><a href="#"><p class="stats-count">1.9<span>k</span></p><p class="stats-type">Topics</p></a></li>
|
||||
<li><a href="#"><p class="stats-count">6.5<span>k</span></p><p class="stats-type">Activities</p></a></li>
|
||||
<@lh.allClassGroups vClassGroups! />
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
|
|
|
@ -341,11 +341,10 @@ a.filter-search {
|
|||
margin-top: 1em;
|
||||
width: 921px;
|
||||
height: 213px;
|
||||
float: left;
|
||||
clear: both;
|
||||
}
|
||||
#home-stats h4 {
|
||||
.home-sections h4 {
|
||||
margin-top: 0;
|
||||
width: 64px;
|
||||
height: 34px;
|
||||
font-size: 18px;
|
||||
text-align: center;
|
||||
|
@ -353,6 +352,9 @@ a.filter-search {
|
|||
padding: 0;
|
||||
line-height: 35px;
|
||||
}
|
||||
#home-stats h4 {
|
||||
width: 102px;
|
||||
}
|
||||
#stats {
|
||||
margin: 0 auto;
|
||||
width: 875px;
|
||||
|
|
29
webapp/web/js/vitroUtils.js
Executable file → Normal file
29
webapp/web/js/vitroUtils.js
Executable file → Normal file
|
@ -10,15 +10,10 @@ $(document).ready(function(){
|
|||
// fade in flash-message when user logs out
|
||||
jQuery('section#flash-message').css('display', 'none').fadeIn(1500);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Home search fiter
|
||||
// Toggle filter select list
|
||||
|
||||
var $searchFilterList = $('#filter-search-nav');
|
||||
var $selectedFilter;
|
||||
var $queryToSend;
|
||||
var $queryToSendAll = true;
|
||||
var $isFilterOpen = false;
|
||||
|
||||
console.log("Filter is open = " + $isFilterOpen);
|
||||
|
@ -63,15 +58,14 @@ $(document).ready(function(){
|
|||
ev.preventDefault();
|
||||
|
||||
if ($(this).text() == 'All') {
|
||||
$queryToSendAll = true;
|
||||
//Selected filter feedback
|
||||
$('.search-filter-selected').text('');
|
||||
$('input[name="classgroup"]').val('');
|
||||
console.log("ALL");
|
||||
} else {
|
||||
|
||||
//Selected filter feedback
|
||||
$('.search-filter-selected').text($(this).text()).fadeIn('slow');
|
||||
$queryToSendAll = false;
|
||||
$('input[name="classgroup"]').val($(this).children("a").attr("title"));
|
||||
}
|
||||
|
||||
//Hide filter select list
|
||||
|
@ -82,10 +76,7 @@ $(document).ready(function(){
|
|||
$('a.filter-search').removeClass('filter-active');
|
||||
$('a.filter-search').addClass('filter-default');
|
||||
|
||||
|
||||
$selectedFilter = $(this).text();
|
||||
$isFilterOpen = false;
|
||||
console.log("$queryToSend " + $selectedFilter);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -118,18 +109,4 @@ $(document).ready(function(){
|
|||
|
||||
console.log("HIDE input value ") ;
|
||||
});
|
||||
|
||||
$('#search-homepage').submit(function(){
|
||||
|
||||
if ($queryToSendAll) {
|
||||
$filterType = '';
|
||||
}else {
|
||||
$filterType = '&classgroup=http://vivoweb.org/ontology/vitroClassGroup' + $selectedFilter;
|
||||
}
|
||||
|
||||
$queryToSend = 'querytext=' + $('input.search-homepage').val() + $filterType;
|
||||
console.log("Query to send: " + $queryToSend);
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,4 +2,7 @@
|
|||
|
||||
<#-- Main template for the login page -->
|
||||
|
||||
<@widget name="login" />
|
||||
<@widget name="login" />
|
||||
<script>
|
||||
$('div.vivoAccount').show();
|
||||
</script>
|
73
webapp/web/templates/freemarker/lib/lib-home-page.ftl
Normal file
73
webapp/web/templates/freemarker/lib/lib-home-page.ftl
Normal file
|
@ -0,0 +1,73 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<#-- Macros used to build the statistical information on the home page -->
|
||||
|
||||
<#-- Get the classgroups so they can be used to qualify searches -->
|
||||
<#macro allClassGroupNames classGroups>
|
||||
<#list classGroups as group>
|
||||
<#-- Only display populated class groups -->
|
||||
<#if (group.individualCount > 0)>
|
||||
<li role="listitem"><a href="" title="${group.uri}">${group.displayName?capitalize}</a></li>
|
||||
</#if>
|
||||
</#list>
|
||||
</#macro>
|
||||
|
||||
<#-- builds the "stats" section of the home page, i.e., class group counts -->
|
||||
<#macro allClassGroups classGroups>
|
||||
<#-- Loop through classGroups first so we can account for situations when all class groups are empty -->
|
||||
<#assign selected = 'class="selected" ' />
|
||||
<#assign classGroupList>
|
||||
<#list classGroups as group>
|
||||
<#-- Only display populated class groups -->
|
||||
<#if (group.individualCount > 0)>
|
||||
<#-- Catch the first populated class group. Will be used later as the default selected class group -->
|
||||
<#if !firstPopulatedClassGroup??>
|
||||
<#assign firstPopulatedClassGroup = group />
|
||||
</#if>
|
||||
<#-- Determine the active (selected) group -->
|
||||
<#assign activeGroup = "" />
|
||||
<#if !classGroup??>
|
||||
<#if group_index == 0>
|
||||
<#assign activeGroup = selected />
|
||||
</#if>
|
||||
<#elseif classGroup.uri == group.uri>
|
||||
<#assign activeGroup = selected />
|
||||
</#if>
|
||||
<#if group.displayName != "equipment" && group.displayName != "locations" && group.displayName != "courses" >
|
||||
<li>
|
||||
<a href="#">
|
||||
<p class="stats-count">
|
||||
<#if (group.individualCount > 10000) >
|
||||
<#assign overTen = group.individualCount/1000>
|
||||
${overTen?round}<span>k</span>
|
||||
<#elseif (group.individualCount > 1000)>
|
||||
<#assign underTen = group.individualCount/1000>
|
||||
${underTen?string("0.#")}<span>k</span>
|
||||
<#else>
|
||||
${group.individualCount}<span> </span>
|
||||
</#if>
|
||||
</p>
|
||||
<p class="stats-type">${group.displayName?capitalize}</p>
|
||||
</a>
|
||||
</li>
|
||||
</#if>
|
||||
</#if>
|
||||
</#list>
|
||||
</#assign>
|
||||
|
||||
<#-- Display the class group browse only if we have at least one populated class group -->
|
||||
<#if firstPopulatedClassGroup??>
|
||||
${classGroupList}
|
||||
<#else>
|
||||
<h3>There is currently no content in the system, or you need to create class groups and assign your classes to them.</h3>
|
||||
|
||||
<#if user.loggedIn>
|
||||
<#if user.hasSiteAdminAccess>
|
||||
<p>You can <a href="${urls.siteAdmin}" title="Manage content">add content and manage this site</a> from the Site Administration page.</p>
|
||||
</#if>
|
||||
<#else>
|
||||
<p>Please <a href="${urls.login}" title="log in to manage this site">log in</a> to manage content.</p>
|
||||
</#if>
|
||||
</#if>
|
||||
|
||||
</#macro>
|
Loading…
Add table
Add a link
Reference in a new issue