converted prperty groups listing to new design, like class groups and class hierarchy
This commit is contained in:
parent
1f1adb31cc
commit
de276020aa
4 changed files with 270 additions and 20 deletions
|
@ -0,0 +1,163 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||||
|
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.servlet.RequestDispatcher;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||||
|
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;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
|
||||||
|
|
||||||
|
public class ListPropertyGroupsController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static final Log log = LogFactory.getLog(ListPropertyGroupsController.class);
|
||||||
|
private static final boolean WITH_PROPERTIES = true;
|
||||||
|
private static final String TEMPLATE_NAME = "siteAdmin-objectPropHierarchy.ftl";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Actions requiredActions(VitroRequest vreq) {
|
||||||
|
return SimplePermission.EDIT_ONTOLOGY.ACTIONS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
|
||||||
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
|
try {
|
||||||
|
|
||||||
|
body.put("displayOption", "group");
|
||||||
|
body.put("pageTitle", "Property Groups");
|
||||||
|
|
||||||
|
PropertyGroupDao dao = vreq.getFullWebappDaoFactory().getPropertyGroupDao();
|
||||||
|
|
||||||
|
List<PropertyGroup> groups = dao.getPublicGroups(WITH_PROPERTIES);
|
||||||
|
|
||||||
|
// Comparator<Property> comparator = new PropertySorter();
|
||||||
|
|
||||||
|
String json = new String();
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
if (groups != null) {
|
||||||
|
for(PropertyGroup pg: groups) {
|
||||||
|
if ( counter > 0 ) {
|
||||||
|
json += ", ";
|
||||||
|
}
|
||||||
|
String publicName = pg.getName();
|
||||||
|
if ( StringUtils.isBlank(publicName) ) {
|
||||||
|
publicName = "(unnamed group)";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
json += "{ \"name\": \"<a href='./editForm?uri="+URLEncoder.encode(pg.getURI(),"UTF-8")+"&controller=Classgroup'>"+publicName+"</a>\", ";
|
||||||
|
} catch (Exception e) {
|
||||||
|
json += "{ \"name\": \"" + publicName + "\", ";
|
||||||
|
}
|
||||||
|
Integer t;
|
||||||
|
|
||||||
|
json += "\"data\": { \"displayRank\": \"" + (((t = Integer.valueOf(pg.getDisplayRank())) != -1) ? t.toString() : "") + "\"}, ";
|
||||||
|
|
||||||
|
List<Property> propertyList = pg.getPropertyList();
|
||||||
|
if (propertyList != null && propertyList.size()>0) {
|
||||||
|
json += "\"children\": [";
|
||||||
|
Iterator<Property> propIt = propertyList.iterator();
|
||||||
|
while (propIt.hasNext()) {
|
||||||
|
Property prop = propIt.next();
|
||||||
|
String controllerStr = "propertyEdit";
|
||||||
|
String nameStr =
|
||||||
|
(prop.getLabel() == null)
|
||||||
|
? ""
|
||||||
|
: prop.getLabel();
|
||||||
|
if (prop instanceof ObjectProperty) {
|
||||||
|
nameStr = ((ObjectProperty) prop).getDomainPublic();
|
||||||
|
} else if (prop instanceof DataProperty) {
|
||||||
|
controllerStr = "datapropEdit";
|
||||||
|
nameStr = ((DataProperty) prop).getName();
|
||||||
|
}
|
||||||
|
if (prop.getURI() != null) {
|
||||||
|
try {
|
||||||
|
json += "{ \"name\": \"<a href='" + controllerStr
|
||||||
|
+ "?uri="+URLEncoder.encode(prop.getURI(),"UTF-8")+"'>"+ nameStr +"</a>\", ";
|
||||||
|
} catch (Exception e) {
|
||||||
|
json += "\"" + nameStr + "\", ";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
json += "\"\", ";
|
||||||
|
}
|
||||||
|
|
||||||
|
json += "\"data\": { \"shortDef\": \"\"}, \"children\": [] ";
|
||||||
|
if (propIt.hasNext())
|
||||||
|
json += "} , ";
|
||||||
|
else
|
||||||
|
json += "}] ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
json += "\"children\": [] ";
|
||||||
|
}
|
||||||
|
json += "} ";
|
||||||
|
counter += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
body.put("jsonTree",json);
|
||||||
|
log.debug("json = " + json);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TemplateResponseValues(TEMPLATE_NAME, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
private class PropertySorter implements Comparator<Property> {
|
||||||
|
|
||||||
|
private Collator coll = Collator.getInstance();
|
||||||
|
|
||||||
|
public int compare(Property p1, Property p2) {
|
||||||
|
String name1 = getName(p1);
|
||||||
|
String name2 = getName(p2);
|
||||||
|
if (name1 == null && name2 != null) {
|
||||||
|
return 1;
|
||||||
|
} else if (name2 == null && name1 != null) {
|
||||||
|
return -1;
|
||||||
|
} else if (name1 == null && name2 == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return coll.compare(name1, name2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getName(Property prop) {
|
||||||
|
if (prop instanceof ObjectProperty) {
|
||||||
|
return ((ObjectProperty) prop).getDomainPublic();
|
||||||
|
} else if (prop instanceof DataProperty) {
|
||||||
|
return ((DataProperty) prop).getName();
|
||||||
|
} else {
|
||||||
|
return prop.getLabel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
|
@ -616,11 +616,11 @@
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>PropertyGroupsListingController</servlet-name>
|
<servlet-name>ListPropertyGroupsController</servlet-name>
|
||||||
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.edit.listing.PropertyGroupsListingController</servlet-class>
|
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.ListPropertyGroupsController</servlet-class>
|
||||||
</servlet>
|
</servlet>
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>PropertyGroupsListingController</servlet-name>
|
<servlet-name>ListPropertyGroupsController</servlet-name>
|
||||||
<url-pattern>/listPropertyGroups</url-pattern>
|
<url-pattern>/listPropertyGroups</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
this.propType = type;
|
this.propType = type;
|
||||||
this.initObjects();
|
this.initObjects();
|
||||||
this.expandAll.hide();
|
this.expandAll.hide();
|
||||||
|
// this.toggleDiv.hide();
|
||||||
this.checkJsonTree();
|
this.checkJsonTree();
|
||||||
|
|
||||||
if ( noProps ) {
|
if ( noProps ) {
|
||||||
|
@ -14,14 +15,20 @@
|
||||||
else if ( displayOption == "all" ) {
|
else if ( displayOption == "all" ) {
|
||||||
this.buildAllPropsHtml();
|
this.buildAllPropsHtml();
|
||||||
}
|
}
|
||||||
|
else if ( displayOption == "group" ) {
|
||||||
|
this.buildPropertyGroupHtml();
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
this.buildPropertyHierarchyHtml();
|
this.buildPropertyHierarchyHtml();
|
||||||
this.wireExpandLink();
|
this.wireExpandLink();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( displayOption == "hierarchy" ) {
|
if ( displayOption == "hierarchy" || displayOption == "group") {
|
||||||
this.expandAll.show();
|
this.expandAll.show();
|
||||||
}
|
}
|
||||||
|
// else if ( displayOption == "group" ) {
|
||||||
|
// this.toggleDiv.show();
|
||||||
|
// }
|
||||||
this.bindEventListeners();
|
this.bindEventListeners();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -34,18 +41,24 @@
|
||||||
this.form = $('form#classHierarchyForm');
|
this.form = $('form#classHierarchyForm');
|
||||||
this.select = $('select#displayOption');
|
this.select = $('select#displayOption');
|
||||||
this.addProperty = $('input#addProperty');
|
this.addProperty = $('input#addProperty');
|
||||||
|
// this.toggleDiv = $('div#propsToggleDiv');
|
||||||
|
// this.toggleSpan = $('span#propsToggle');
|
||||||
|
// this.toggleLink = $('span#propsToggle').find('a');
|
||||||
noProps = new Boolean;
|
noProps = new Boolean;
|
||||||
},
|
},
|
||||||
|
|
||||||
bindEventListeners: function() {
|
bindEventListeners: function() {
|
||||||
if ( this.propType == "object" ) {
|
if ( this.propType == "object" ) {
|
||||||
this.select.change(function() {
|
this.select.change(function() {
|
||||||
if ( objectPropHierarchyUtils.select.val() == "all") {
|
if ( objectPropHierarchyUtils.select.val() == "all" ) {
|
||||||
objectPropHierarchyUtils.form.attr("action", "listPropertyWebapps");
|
objectPropHierarchyUtils.form.attr("action", "listPropertyWebapps");
|
||||||
}
|
}
|
||||||
else {
|
else if ( objectPropHierarchyUtils.select.val() == "hierarchy") {
|
||||||
objectPropHierarchyUtils.form.attr("action", "showObjectPropertyHierarchy");
|
objectPropHierarchyUtils.form.attr("action", "showObjectPropertyHierarchy");
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
objectPropHierarchyUtils.form.attr("action", "listPropertyGroups");
|
||||||
|
}
|
||||||
objectPropHierarchyUtils.form.submit();
|
objectPropHierarchyUtils.form.submit();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -54,14 +67,17 @@
|
||||||
objectPropHierarchyUtils.form.submit();
|
objectPropHierarchyUtils.form.submit();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.select.change(function() {
|
this.select.change(function() {
|
||||||
if ( objectPropHierarchyUtils.select.val() == "all") {
|
if ( objectPropHierarchyUtils.select.val() == "all" ) {
|
||||||
objectPropHierarchyUtils.form.attr("action", "listDatatypeProperties");
|
objectPropHierarchyUtils.form.attr("action", "listDatatypeProperties");
|
||||||
}
|
}
|
||||||
else {
|
else if ( objectPropHierarchyUtils.select.val() == "hierarchy" ) {
|
||||||
objectPropHierarchyUtils.form.attr("action", "showDataPropertyHierarchy");
|
objectPropHierarchyUtils.form.attr("action", "showDataPropertyHierarchy");
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
objectPropHierarchyUtils.form.attr("action", "listPropertyGroups");
|
||||||
|
}
|
||||||
objectPropHierarchyUtils.form.submit();
|
objectPropHierarchyUtils.form.submit();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -70,6 +86,19 @@
|
||||||
objectPropHierarchyUtils.form.submit();
|
objectPropHierarchyUtils.form.submit();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if ( this.propType == "group" ) {
|
||||||
|
this.expandAll.click(function() {
|
||||||
|
|
||||||
|
if ( objectPropHierarchyUtils.expandAll.text() == "hide properties" ) {
|
||||||
|
$('td.subclassCell').parent('tr').hide();
|
||||||
|
objectPropHierarchyUtils.expandAll.text("show properties");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$('td.subclassCell').parent('tr').show();
|
||||||
|
objectPropHierarchyUtils.expandAll.text("hide properties");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
checkJsonTree: function() {
|
checkJsonTree: function() {
|
||||||
|
@ -289,5 +318,50 @@
|
||||||
$newClassSection.appendTo($('section#container'));
|
$newClassSection.appendTo($('section#container'));
|
||||||
objectPropHierarchyUtils.classHtml = "";
|
objectPropHierarchyUtils.classHtml = "";
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
buildPropertyGroupHtml: function() {
|
||||||
|
|
||||||
|
$.each(json, function() {
|
||||||
|
$newClassSection = jQuery("<section></section>", {
|
||||||
|
id: "classContainer" + objectPropHierarchyUtils.classCounter
|
||||||
|
});
|
||||||
|
var descendants = "";
|
||||||
|
|
||||||
|
if ( this.children.length ) {
|
||||||
|
var ctr = 0;
|
||||||
|
$.each(this.children, function() {
|
||||||
|
if ( ctr == 0 ) {
|
||||||
|
descendants += "<tr><td class='classDetail'>Properties:</td>";
|
||||||
|
ctr = ctr + 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
descendants += "<tr><td></td>" ;
|
||||||
|
}
|
||||||
|
|
||||||
|
descendants += "<td class='subclassCell'>" + this.name + "</td></tr>";
|
||||||
|
// descendants += "<tr><td></td><td><table class='innerDefinition'><tr><td>" + this.data.shortDef + "</td></tr></table></td></tr>";
|
||||||
|
|
||||||
|
});
|
||||||
|
descendants += "</table></td></tr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
objectPropHierarchyUtils.classHtml += "<div>" + this.name + "</div>" + "<table class='classHierarchy' id='classHierarchy"
|
||||||
|
+ objectPropHierarchyUtils.classCounter + "'>" ;
|
||||||
|
|
||||||
|
if ( this.data.displayRank.length > 0 ) {
|
||||||
|
objectPropHierarchyUtils.classHtml += "<tr><td class='classDetail'>Display Rank:</td><td>" + this.data.displayRank + "</td></tr>"
|
||||||
|
}
|
||||||
|
|
||||||
|
objectPropHierarchyUtils.classHtml += descendants;
|
||||||
|
|
||||||
|
objectPropHierarchyUtils.classHtml += "</table>";
|
||||||
|
// alert(objectPropHierarchyUtils.classHtml);
|
||||||
|
$newClassSection.html(objectPropHierarchyUtils.classHtml);
|
||||||
|
$newClassSection.appendTo($('section#container'));
|
||||||
|
objectPropHierarchyUtils.classHtml = "";
|
||||||
|
objectPropHierarchyUtils.classCounter += 1;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,11 @@
|
||||||
separate controllers for those. Also used to display lists of "all" object and
|
separate controllers for those. Also used to display lists of "all" object and
|
||||||
data properties, though there are separate controllers for those, too.
|
data properties, though there are separate controllers for those, too.
|
||||||
-->
|
-->
|
||||||
|
<#if propertyType??>
|
||||||
|
<#assign propType = propertyType>
|
||||||
|
<#else>
|
||||||
|
<#assign propType = "group">
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
|
||||||
<section role="region">
|
<section role="region">
|
||||||
|
@ -15,16 +20,24 @@
|
||||||
<#assign displayOption = "hierarchy">
|
<#assign displayOption = "hierarchy">
|
||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
<form name="classHierarchyForm" id="classHierarchyForm" action="show<#if propertyType == "object">Object<#else>Data</#if>PropertyHierarchy" method="post" role="classHierarchy">
|
<#if propType == "group">
|
||||||
<label id="displayOptionLabel" class="inline">Display Options</label>
|
<form action="editForm" method="get">
|
||||||
<select id="displayOption" name="displayOption">
|
<input type="submit" class="form-button" id="addProperty" value="Add new property group"/>
|
||||||
<option value="hierarchy" <#if displayOption == "asserted">selected</#if> >Property Hierarchy</option>
|
<input type="hidden" name="controller" value="PropertyGroup"/>
|
||||||
<option value="all" <#if displayOption == "all">selected</#if> >All Properties</option>
|
</form>
|
||||||
</select>
|
<div id="expandLink"><span id="expandAll" ><a href="javascript:" title="hide/show properties">hide properties</a></span></div>
|
||||||
<input type="submit" class="form-button" id="addProperty" value="Add new <#if propertyType == "object">object<#else>data</#if> property"/>
|
<#else>
|
||||||
</form>
|
<form name="classHierarchyForm" id="classHierarchyForm" action="show<#if propType == "object">Object<#else>Data</#if>PropertyHierarchy" method="post" role="classHierarchy">
|
||||||
|
<label id="displayOptionLabel" class="inline">Display Options</label>
|
||||||
<div id="expandLink"><span id="expandAll" ><a href="#" title="expand all">expand all</a></span></div>
|
<select id="displayOption" name="displayOption">
|
||||||
|
<option value="hierarchy" <#if displayOption == "asserted">selected</#if> >${propType?capitalize} Property Hierarchy</option>
|
||||||
|
<option value="all" <#if displayOption == "all">selected</#if> >All ${propType?capitalize} Properties</option>
|
||||||
|
<option value="group" <#if displayOption == "group">selected</#if> >Property Groups</option>
|
||||||
|
</select>
|
||||||
|
<input type="submit" class="form-button" id="addProperty" value="Add new <#if propType == "object">object<#else>data</#if> property"/>
|
||||||
|
</form>
|
||||||
|
<div id="expandLink"><span id="expandAll" ><a href="#" title="expand all">expand all</a></span></div>
|
||||||
|
</#if>
|
||||||
|
|
||||||
<section id="container">
|
<section id="container">
|
||||||
</section>
|
</section>
|
||||||
|
@ -37,7 +50,7 @@
|
||||||
|
|
||||||
<script language="javascript" type="text/javascript" >
|
<script language="javascript" type="text/javascript" >
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
objectPropHierarchyUtils.onLoad("${urls.base!}","${displayOption!}","${propertyType}");
|
objectPropHierarchyUtils.onLoad("${urls.base!}","${displayOption!}","${propType}");
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue