NIHVIVO-1491 Display of overview and research areas on person profile page

This commit is contained in:
rjy7 2011-01-03 22:34:17 +00:00
parent fb7e71ab9d
commit 675adfab19
9 changed files with 102 additions and 66 deletions

View file

@ -325,6 +325,12 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
return map;
}
protected Map<String, Object> getMethods() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("url", new edu.cornell.mannlib.vitro.webapp.web.functions.IndividualProfileUrlMethod());
return map;
}
// Add variables that should be available only to the page's root map, not to the body.
// RY This is protected instead of private so FreeMarkerComponentGenerator can access.
// Once we don't need that (i.e., jsps have been eliminated) we can make it private.
@ -356,6 +362,7 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
map.put("currentPage", vreq.getServletPath().replaceFirst("/", ""));
map.putAll(getDirectives());
map.putAll(getMethods());
map.put("tabMenu", getTabMenu(vreq));
map.put("menu", getDisplayModelMenu(vreq));

View file

@ -129,7 +129,6 @@ public class IndividualController extends FreemarkerHttpServlet {
*/
body.put("individual", getNonDefaultBeansWrapper(BeansWrapper.EXPOSE_SAFE).wrap(ind));
body.put("url", new IndividualProfileUrlMethod());
body.put("localName", new IndividualLocalNameMethod());
String template = getIndividualTemplate(individual);

View file

@ -64,4 +64,10 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
return statements;
}
// Allows the template to display a data value for a single property, when there is expected to be
// only a single value for the property.
public String getValue() {
return statements.get(0).getValue();
}
}

View file

@ -30,7 +30,11 @@ import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
/*
public class GroupedPropertyList extends ArrayList<PropertyGroupTemplateModel> {
If this class extends a List type, Freemarker does not let the templates call methods
on it.
on it. Since the class must then contain a list rather than be a list, the template
syntax is less idiomatic: e.g., groups.all rather than simply groups. An alternative
is to make the get methods (getProperty and getPropertyAndRemoveFromList) methods
of the IndividualTemplateModel. Then this class doesn't need methods, and can extend
a List type.
*/
public class GroupedPropertyList extends BaseTemplateModel {
@ -386,42 +390,34 @@ public class GroupedPropertyList extends BaseTemplateModel {
public PropertyTemplateModel getProperty(String propertyUri) {
PropertyTemplateModel propertyTemplateModel = null;
groupLoop: for (PropertyGroupTemplateModel pgtm : groups) {
for (PropertyGroupTemplateModel pgtm : groups) {
List<PropertyTemplateModel> properties = pgtm.getProperties();
for (PropertyTemplateModel ptm : properties) {
if (propertyUri.equals(ptm.getUri())) {
propertyTemplateModel = ptm;
break groupLoop;
return ptm;
}
}
}
return propertyTemplateModel;
return null;
}
public PropertyTemplateModel getPropertyAndRemoveFromList(String propertyUri) {
PropertyTemplateModel propertyTemplateModel = null;
groupLoop: for (PropertyGroupTemplateModel pgtm : groups) {
for (PropertyGroupTemplateModel pgtm : groups) {
List<PropertyTemplateModel> properties = pgtm.getProperties();
for (PropertyTemplateModel ptm : properties) {
if (propertyUri.equals(ptm.getUri())) {
propertyTemplateModel = ptm;
// Remove the property from the group
properties.remove(ptm);
// If this is the only property in the group, remove the group as well
if (properties.size() == 0) {
groups.remove(pgtm);
}
break groupLoop;
return ptm;
}
}
}
return propertyTemplateModel;
return null;
}
}

View file

@ -31,6 +31,7 @@ public class IndividualTemplateModel extends BaseTemplateModel {
protected Individual individual;
protected VitroRequest vreq;
protected UrlBuilder urlBuilder;
protected GroupedPropertyList propertyList = null;
public IndividualTemplateModel(Individual individual, VitroRequest vreq) {
this.individual = individual;
@ -123,7 +124,10 @@ public class IndividualTemplateModel extends BaseTemplateModel {
}
public GroupedPropertyList getPropertyList() {
return new GroupedPropertyList(individual, vreq);
if (propertyList == null) {
propertyList = new GroupedPropertyList(individual, vreq);
}
return propertyList;
}
/* These methods simply forward to the methods of the wrapped individual. It would be desirable to

View file

@ -2,7 +2,11 @@
<#-- Template for individual profile page -->
<#-- RY This is actually the person profile page, but we cannot move it to its proper location until selection of template by
annotaiton has been implemented. -->
<#import "lib-list.ftl" as l>
<#import "lib-properties.ftl" as p>
<#assign editingClass>
<#if editStatus.showEditLinks>editing<#else></#if>
@ -70,15 +74,22 @@
</ul>
</header>
<p class="individual-overview">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est erat, tristique non bibendum eu, mollis non est. Cras vehicula velit quis elit porta vel molestie tellus blandit. Donec eget magna dolor. Phasellus faucibus mollis lorem at dapibus. Sed ultricies lobortis mauris in volutpat. Cras mattis neque ut sapien pellentesque fringilla. Mauris posuere dui quis massa mattis id mollis nibh accumsan. [+]</p>
<#-- Overview -->
<#assign overview = propertyGroups.getPropertyAndRemoveFromList("http://vivoweb.org/ontology/core#overview")>
<#if overview?has_content>
<p class="individual-overview">${overview.value}</p>
</#if>
<#-- Research Areas -->
<#assign researchAreas = propertyGroups.getPropertyAndRemoveFromList("http://vivoweb.org/ontology/core#hasResearchArea")>
<#if researchAreas?has_content>
<h2>Research Areas</h2>
<ul id="individual-areas" role="list">
<li role="listitem"><a href="#">Researcher (5)</a></li>
<li role="listitem"><a href="#">Principal Investigator (3)</a></li>
<li role="listitem"><a href="#">Teacher (2)</a></li>
<@p.objectProperty researchAreas />
</ul>
</#if>
</section>
</section>

View file

@ -2,6 +2,8 @@
<#-- Template for property listing on individual profile page -->
<#import "lib-properties.ftl" as p>
<#list propertyGroups.all as group>
<#assign groupname = group.name(nameForOtherGroup)>
@ -28,13 +30,13 @@
<ul class="property-list" role="list">
<#-- data property -->
<#if property.type == "data">
<@dataPropertyList property.statements />
<@p.dataPropertyList property.statements />
<#-- object property -->
<#elseif property.collatedBySubclass> <#-- collated -->
<@collatedObjectPropertyList property />
<@p.collatedObjectPropertyList property />
<#else> <#-- uncollated -->
<@objectPropertyList property.statements property.template />
<@p.objectPropertyList property.statements property.template />
</#if>
</ul>
</article> <!-- end property -->
@ -42,34 +44,3 @@
</section> <!-- end property-group -->
</#list>
<#-----------------------------------------------------------------------------
Macros for generating property lists
------------------------------------------------------------------------------>
<#macro dataPropertyList statements>
<#list statements as statement>
<@propertyListItem>${statement.value}</@propertyListItem>
</#list>
</#macro>
<#macro collatedObjectPropertyList property>
<#assign subclasses = property.subclasses>
<#list subclasses?keys as subclass>
<li class="subclass">
<h3>${subclass?lower_case}</h3>
<ul class="subclass-property-list">
<@objectPropertyList subclasses[subclass] property.template />
</ul>
</li>
</#list>
</#macro>
<#macro objectPropertyList statements template>
<#list statements as statement>
<@propertyListItem><#include "${template}"></@propertyListItem>
</#list>
</#macro>
<#macro propertyListItem>
<li role="listitem"><#nested></li>
</#macro>

View file

@ -0,0 +1,37 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#-----------------------------------------------------------------------------
Macros for generating property lists
------------------------------------------------------------------------------>
<#macro dataPropertyList statements>
<#list statements as statement>
<@propertyListItem>${statement.value}</@propertyListItem>
</#list>
</#macro>
<#macro collatedObjectPropertyList property>
<#assign subclasses = property.subclasses>
<#list subclasses?keys as subclass>
<li class="subclass">
<h3>${subclass?lower_case}</h3>
<ul class="subclass-property-list">
<@objectPropertyList subclasses[subclass] property.template />
</ul>
</li>
</#list>
</#macro>
<#macro objectProperty property>
<@objectPropertyList property.statements "propStatement-simple.ftl" />
</#macro>
<#macro objectPropertyList statements template>
<#list statements as statement>
<@propertyListItem><#include "${template}"></@propertyListItem>
</#list>
</#macro>
<#macro propertyListItem>
<li role="listitem"><#nested></li>
</#macro>

View file

@ -0,0 +1,5 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#-- Simple object property statement template -->
<a href="${url(statement.object)}">${statement.name!}</a>