Complete default individual list view in FreeMarker
This commit is contained in:
parent
b3ddf9e822
commit
037ff45736
9 changed files with 78 additions and 36 deletions
|
@ -32,7 +32,7 @@ public class UrlBuilder {
|
|||
SEARCH("/search"),
|
||||
TERMS_OF_USE("/termsOfUse"),
|
||||
|
||||
// put under /admin
|
||||
// RY put these under /admin/
|
||||
LOGIN("/siteAdmin"),
|
||||
LOGOUT("/login_process.jsp"),
|
||||
SITE_ADMIN("/siteAdmin");
|
||||
|
|
|
@ -2,10 +2,14 @@
|
|||
|
||||
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.LogFactory;
|
||||
|
||||
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.utils.StringUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.view.ViewFinder.ClassView;
|
||||
|
@ -46,21 +50,43 @@ public class IndividualView extends ViewObject {
|
|||
}
|
||||
|
||||
public String getSearchView() {
|
||||
|
||||
ViewFinder vf = new ViewFinder(ClassView.SEARCH);
|
||||
return vf.findView(individual, context);
|
||||
return getView(ClassView.SEARCH);
|
||||
}
|
||||
|
||||
public String getCustomView() {
|
||||
// see code currently in entityList.ftl
|
||||
String customView = null;
|
||||
|
||||
return customView;
|
||||
public String getShortView() {
|
||||
return getView(ClassView.SHORT);
|
||||
}
|
||||
|
||||
public Object getProperty(String propertyName) {
|
||||
return new Object();
|
||||
public String getDisplayView() {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ public class ViewFinder {
|
|||
|
||||
public enum ClassView {
|
||||
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"),
|
||||
SEARCH("getCustomSearchView", "/view/search"),
|
||||
SHORT("getCustomShortView", "/view/short");
|
||||
|
@ -64,9 +65,8 @@ public class ViewFinder {
|
|||
this.view = view;
|
||||
}
|
||||
|
||||
public String findView(Individual individual, ServletContext context) {
|
||||
public String findClassView(Individual individual, ServletContext context) {
|
||||
String viewName = "default.ftl";
|
||||
// For now, all custom views are attached to classes.
|
||||
List<VClass> vclasses = individual.getVClasses();
|
||||
Method method = view.getMethod();
|
||||
/* RY The logic here is incorrect. The vclasses are
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
<ul>
|
||||
<#list individuals as individual>
|
||||
<li>
|
||||
<#-- Currently we just use the search view here; there's no custom list view defined. -->
|
||||
<#include "partials/class/view/search/${individual.searchView}">
|
||||
</li>
|
||||
</#list>
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
<#-- $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>
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<#--
|
||||
Macro: firstLastList
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
Usage:
|
||||
<@makeList>
|
||||
<@firstLastList>
|
||||
<li>apples</li>,
|
||||
<li>bananas</li>,
|
||||
<li>oranges</li>
|
||||
<@makeList>
|
||||
<@firstLastList>
|
||||
|
||||
<@makeList delim="??">
|
||||
<@firstLastList delim="??">
|
||||
<li>apples, oranges</li>??
|
||||
<li>bananas, lemons</li>??
|
||||
<li>grapefruit, limes</li>
|
||||
<@makeList>
|
||||
<@firstLastList>
|
||||
|
||||
RY Consider rewriting in Java. Probably designers won't want to modify this.
|
||||
-->
|
||||
<#macro makeList delim=",">
|
||||
<#macro firstLastList delim=",">
|
||||
<#assign text>
|
||||
<#nested>
|
||||
</#assign>
|
||||
|
||||
<#-- 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)>
|
||||
|
||||
|
@ -45,13 +47,9 @@
|
|||
<#assign newItem = newItem?replace(m?groups[1], "")>
|
||||
</#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>
|
||||
<#assign classVal = "${classVal} first">
|
||||
</#if>
|
||||
<#-- <#if item == arr?last> -->
|
||||
<#if !item_has_next>
|
||||
<#assign classVal = "${classVal} last">
|
||||
</#if>
|
||||
|
@ -66,3 +64,5 @@
|
|||
</#macro>
|
||||
|
||||
<#----------------------------------------------------------------------------->
|
||||
|
||||
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
|
||||
<div class="footerLinks">
|
||||
<ul class="otherNav">
|
||||
<@l.makeList>
|
||||
<@l.firstLastList>
|
||||
<li><a href="${urls.about}" title="more about this web site">About</a></li>,
|
||||
<#if urls.contact??>
|
||||
<li><a href="${urls.contact}" title="feedback form">Contact Us</a></li>
|
||||
</#if>
|
||||
</@l.makeList>
|
||||
</@l.firstLastList>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
</#if>
|
||||
|
||||
<ul id="otherMenu">
|
||||
<@l.makeList>
|
||||
<@l.firstLastList>
|
||||
<#if loginName??>
|
||||
<li>
|
||||
Logged in as <strong>${loginName}</strong> (<a href="${urls.logout}">Log out</a>)
|
||||
|
@ -25,6 +25,6 @@
|
|||
<#if urls.contact??>
|
||||
<li><a href="${urls.contact}">Contact Us</a></li>
|
||||
</#if>
|
||||
</@l.makeList>
|
||||
</@l.firstLastList>
|
||||
</ul>
|
||||
</div>
|
|
@ -16,6 +16,7 @@
|
|||
request.parameters:
|
||||
None yet.
|
||||
********************************************* */
|
||||
|
||||
if (request.getAttribute("beans") == null) {
|
||||
String e = "searchBaisc.jsp expects that request attribute " +
|
||||
"'beans' be set to a List of Individuals to display.";
|
||||
|
@ -24,6 +25,8 @@
|
|||
Portal portal = (Portal) request.getAttribute("portalBean");
|
||||
String portalParm = "&home=" + portal.getPortalId();
|
||||
|
||||
|
||||
|
||||
%>
|
||||
<div id='content'><!-- searchPaged.jsp -->
|
||||
<h2>Search Results for '<c:out value="${querytext}"></c:out>'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue