Complete default individual list view in FreeMarker

This commit is contained in:
rjy7 2010-06-02 17:06:55 +00:00
parent b3ddf9e822
commit 037ff45736
9 changed files with 78 additions and 36 deletions

View file

@ -32,7 +32,7 @@ public class UrlBuilder {
SEARCH("/search"), SEARCH("/search"),
TERMS_OF_USE("/termsOfUse"), TERMS_OF_USE("/termsOfUse"),
// put under /admin // RY put these under /admin/
LOGIN("/siteAdmin"), LOGIN("/siteAdmin"),
LOGOUT("/login_process.jsp"), LOGOUT("/login_process.jsp"),
SITE_ADMIN("/siteAdmin"); SITE_ADMIN("/siteAdmin");

View file

@ -2,10 +2,14 @@
package edu.cornell.mannlib.vitro.webapp.view; package edu.cornell.mannlib.vitro.webapp.view;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.Link;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils; import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
import edu.cornell.mannlib.vitro.webapp.view.ViewFinder.ClassView; import edu.cornell.mannlib.vitro.webapp.view.ViewFinder.ClassView;
@ -46,21 +50,43 @@ public class IndividualView extends ViewObject {
} }
public String getSearchView() { public String getSearchView() {
return getView(ClassView.SEARCH);
ViewFinder vf = new ViewFinder(ClassView.SEARCH);
return vf.findView(individual, context);
} }
public String getCustomView() { public String getShortView() {
// see code currently in entityList.ftl return getView(ClassView.SHORT);
String customView = null;
return customView;
} }
public Object getProperty(String propertyName) { public String getDisplayView() {
return new Object(); return getView(ClassView.DISPLAY);
} }
private String getView(ClassView view) {
ViewFinder vf = new ViewFinder(view);
return vf.findClassView(individual, context);
}
public Link getPrimaryLink() {
Link primaryLink = null;
String anchor = individual.getAnchor();
String url = individual.getUrl();
if (anchor != null && url != null) {
primaryLink = new Link();
primaryLink.setAnchor(individual.getAnchor());
primaryLink.setUrl(individual.getUrl());
}
return primaryLink;
}
public List<Link> getLinks() {
List<Link> additionalLinks = individual.getLinksList();
List<Link> links = new ArrayList<Link>(additionalLinks.size()+1);
Link primaryLink = getPrimaryLink();
if (primaryLink != null) {
links.add(primaryLink);
}
links.addAll(additionalLinks);
return links;
}
} }

View file

@ -27,6 +27,7 @@ public class ViewFinder {
public enum ClassView { public enum ClassView {
DISPLAY("getCustomDisplayView", "/view/display"), DISPLAY("getCustomDisplayView", "/view/display"),
// NB this is not the value currently used for custom forms - we use the value on the object property
FORM("getCustomEntryForm", "/form"), FORM("getCustomEntryForm", "/form"),
SEARCH("getCustomSearchView", "/view/search"), SEARCH("getCustomSearchView", "/view/search"),
SHORT("getCustomShortView", "/view/short"); SHORT("getCustomShortView", "/view/short");
@ -64,9 +65,8 @@ public class ViewFinder {
this.view = view; this.view = view;
} }
public String findView(Individual individual, ServletContext context) { public String findClassView(Individual individual, ServletContext context) {
String viewName = "default.ftl"; String viewName = "default.ftl";
// For now, all custom views are attached to classes.
List<VClass> vclasses = individual.getVClasses(); List<VClass> vclasses = individual.getVClasses();
Method method = view.getMethod(); Method method = view.getMethod();
/* RY The logic here is incorrect. The vclasses are /* RY The logic here is incorrect. The vclasses are

View file

@ -16,6 +16,7 @@
<ul> <ul>
<#list individuals as individual> <#list individuals as individual>
<li> <li>
<#-- Currently we just use the search view here; there's no custom list view defined. -->
<#include "partials/class/view/search/${individual.searchView}"> <#include "partials/class/view/search/${individual.searchView}">
</li> </li>
</#list> </#list>

View file

@ -1,3 +1,15 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> <#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<a href="${individual.profileUrl}">${individual.name}</a> ${individual.tagline} <#-- Default individual search view -->
<#import "/macros/list.ftl" as l>
<a href="${individual.profileUrl}">${individual.name}</a>
<ul class="individualData">
<@l.firstLastList>
<li>${individual.tagline}</li>,
<#list individual.links as link>
<li><a class="externalLink" href="${link.url}">${link.anchor}</a></li>,
</#list>
</@l.firstLastList>
</ul>

View file

@ -1,6 +1,8 @@
<#-- <#--
Macro: firstLastList
Output a sequence of <li> elements, adding classes "first" and "last" to first and last list elements, respectively. Output a sequence of <li> elements, adding classes "first" and "last" to first and last list elements, respectively.
It is helpful when the list elements are generated conditionally, to avoid complex tests for the presence/absence Especially useful when the list elements are generated conditionally, to avoid complex tests for the presence/absence
of other list elements in order to assign these classes. of other list elements in order to assign these classes.
Input should be a series of <li> elements separated by some delimiter. Default delimiter value is ",". Input should be a series of <li> elements separated by some delimiter. Default delimiter value is ",".
@ -8,27 +10,27 @@
Tolerates a delimiter following the last <li> element. Tolerates a delimiter following the last <li> element.
Usage: Usage:
<@makeList> <@firstLastList>
<li>apples</li>, <li>apples</li>,
<li>bananas</li>, <li>bananas</li>,
<li>oranges</li> <li>oranges</li>
<@makeList> <@firstLastList>
<@makeList delim="??"> <@firstLastList delim="??">
<li>apples, oranges</li>?? <li>apples, oranges</li>??
<li>bananas, lemons</li>?? <li>bananas, lemons</li>??
<li>grapefruit, limes</li> <li>grapefruit, limes</li>
<@makeList> <@firstLastList>
RY Consider rewriting in Java. Probably designers won't want to modify this. RY Consider rewriting in Java. Probably designers won't want to modify this.
--> -->
<#macro makeList delim=","> <#macro firstLastList delim=",">
<#assign text> <#assign text>
<#nested> <#nested>
</#assign> </#assign>
<#-- Strip out a list-final delimiter, else (unlike most languages) it results in an empty final array item. --> <#-- Strip out a list-final delimiter, else (unlike most languages) it results in an empty final array item. -->
<#assign text = text?replace("${delim}$", "", "r")> <#assign text = text?replace("${delim}\\s*$", "", "r")>
<#assign items = text?split(delim)> <#assign items = text?split(delim)>
@ -45,13 +47,9 @@
<#assign newItem = newItem?replace(m?groups[1], "")> <#assign newItem = newItem?replace(m?groups[1], "")>
</#list> </#list>
<#-- Test indices, rather than comparing content, on the remote chance
that there are two list items with the same content. -->
<#-- <#if item == arr?first> -->
<#if item_index == 0> <#if item_index == 0>
<#assign classVal = "${classVal} first"> <#assign classVal = "${classVal} first">
</#if> </#if>
<#-- <#if item == arr?last> -->
<#if !item_has_next> <#if !item_has_next>
<#assign classVal = "${classVal} last"> <#assign classVal = "${classVal} last">
</#if> </#if>
@ -66,3 +64,5 @@
</#macro> </#macro>
<#-----------------------------------------------------------------------------> <#----------------------------------------------------------------------------->

View file

@ -10,12 +10,12 @@
<div class="footerLinks"> <div class="footerLinks">
<ul class="otherNav"> <ul class="otherNav">
<@l.makeList> <@l.firstLastList>
<li><a href="${urls.about}" title="more about this web site">About</a></li>, <li><a href="${urls.about}" title="more about this web site">About</a></li>,
<#if urls.contact??> <#if urls.contact??>
<li><a href="${urls.contact}" title="feedback form">Contact Us</a></li> <li><a href="${urls.contact}" title="feedback form">Contact Us</a></li>
</#if> </#if>
</@l.makeList> </@l.firstLastList>
</ul> </ul>
</div> </div>

View file

@ -11,7 +11,7 @@
</#if> </#if>
<ul id="otherMenu"> <ul id="otherMenu">
<@l.makeList> <@l.firstLastList>
<#if loginName??> <#if loginName??>
<li> <li>
Logged in as <strong>${loginName}</strong> (<a href="${urls.logout}">Log out</a>) Logged in as <strong>${loginName}</strong> (<a href="${urls.logout}">Log out</a>)
@ -25,6 +25,6 @@
<#if urls.contact??> <#if urls.contact??>
<li><a href="${urls.contact}">Contact Us</a></li> <li><a href="${urls.contact}">Contact Us</a></li>
</#if> </#if>
</@l.makeList> </@l.firstLastList>
</ul> </ul>
</div> </div>

View file

@ -16,6 +16,7 @@
request.parameters: request.parameters:
None yet. None yet.
********************************************* */ ********************************************* */
if (request.getAttribute("beans") == null) { if (request.getAttribute("beans") == null) {
String e = "searchBaisc.jsp expects that request attribute " + String e = "searchBaisc.jsp expects that request attribute " +
"'beans' be set to a List of Individuals to display."; "'beans' be set to a List of Individuals to display.";
@ -24,6 +25,8 @@
Portal portal = (Portal) request.getAttribute("portalBean"); Portal portal = (Portal) request.getAttribute("portalBean");
String portalParm = "&amp;home=" + portal.getPortalId(); String portalParm = "&amp;home=" + portal.getPortalId();
%> %>
<div id='content'><!-- searchPaged.jsp --> <div id='content'><!-- searchPaged.jsp -->
<h2>Search Results for '<c:out value="${querytext}"></c:out>' <h2>Search Results for '<c:out value="${querytext}"></c:out>'