diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ListPropertyGroupsController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ListPropertyGroupsController.java new file mode 100644 index 000000000..2f147fcd8 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ListPropertyGroupsController.java @@ -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 body = new HashMap(); + try { + + body.put("displayOption", "group"); + body.put("pageTitle", "Property Groups"); + + PropertyGroupDao dao = vreq.getFullWebappDaoFactory().getPropertyGroupDao(); + + List groups = dao.getPublicGroups(WITH_PROPERTIES); + +// Comparator 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\": \""+publicName+"\", "; + } catch (Exception e) { + json += "{ \"name\": \"" + publicName + "\", "; + } + Integer t; + + json += "\"data\": { \"displayRank\": \"" + (((t = Integer.valueOf(pg.getDisplayRank())) != -1) ? t.toString() : "") + "\"}, "; + + List propertyList = pg.getPropertyList(); + if (propertyList != null && propertyList.size()>0) { + json += "\"children\": ["; + Iterator 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\": \""+ nameStr +"\", "; + } 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 { + + 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(); + } + } + } +*/ +} diff --git a/webapp/web/WEB-INF/web.xml b/webapp/web/WEB-INF/web.xml index 4a9f1492c..ab2683642 100644 --- a/webapp/web/WEB-INF/web.xml +++ b/webapp/web/WEB-INF/web.xml @@ -616,11 +616,11 @@ - PropertyGroupsListingController - edu.cornell.mannlib.vitro.webapp.controller.edit.listing.PropertyGroupsListingController + ListPropertyGroupsController + edu.cornell.mannlib.vitro.webapp.controller.freemarker.ListPropertyGroupsController - PropertyGroupsListingController + ListPropertyGroupsController /listPropertyGroups diff --git a/webapp/web/js/siteAdmin/objectPropertyHierarchyUtils.js b/webapp/web/js/siteAdmin/objectPropertyHierarchyUtils.js index de0b96db8..413dc548c 100644 --- a/webapp/web/js/siteAdmin/objectPropertyHierarchyUtils.js +++ b/webapp/web/js/siteAdmin/objectPropertyHierarchyUtils.js @@ -6,6 +6,7 @@ this.propType = type; this.initObjects(); this.expandAll.hide(); +// this.toggleDiv.hide(); this.checkJsonTree(); if ( noProps ) { @@ -14,14 +15,20 @@ else if ( displayOption == "all" ) { this.buildAllPropsHtml(); } + else if ( displayOption == "group" ) { + this.buildPropertyGroupHtml(); + } else { this.buildPropertyHierarchyHtml(); this.wireExpandLink(); } - if ( displayOption == "hierarchy" ) { + if ( displayOption == "hierarchy" || displayOption == "group") { this.expandAll.show(); } +// else if ( displayOption == "group" ) { +// this.toggleDiv.show(); +// } this.bindEventListeners(); }, @@ -34,18 +41,24 @@ this.form = $('form#classHierarchyForm'); this.select = $('select#displayOption'); this.addProperty = $('input#addProperty'); +// this.toggleDiv = $('div#propsToggleDiv'); +// this.toggleSpan = $('span#propsToggle'); +// this.toggleLink = $('span#propsToggle').find('a'); noProps = new Boolean; }, bindEventListeners: function() { if ( this.propType == "object" ) { this.select.change(function() { - if ( objectPropHierarchyUtils.select.val() == "all") { + if ( objectPropHierarchyUtils.select.val() == "all" ) { objectPropHierarchyUtils.form.attr("action", "listPropertyWebapps"); } - else { + else if ( objectPropHierarchyUtils.select.val() == "hierarchy") { objectPropHierarchyUtils.form.attr("action", "showObjectPropertyHierarchy"); } + else { + objectPropHierarchyUtils.form.attr("action", "listPropertyGroups"); + } objectPropHierarchyUtils.form.submit(); }); @@ -54,14 +67,17 @@ objectPropHierarchyUtils.form.submit(); }); } - else { + else { this.select.change(function() { - if ( objectPropHierarchyUtils.select.val() == "all") { + if ( objectPropHierarchyUtils.select.val() == "all" ) { objectPropHierarchyUtils.form.attr("action", "listDatatypeProperties"); } - else { + else if ( objectPropHierarchyUtils.select.val() == "hierarchy" ) { objectPropHierarchyUtils.form.attr("action", "showDataPropertyHierarchy"); } + else { + objectPropHierarchyUtils.form.attr("action", "listPropertyGroups"); + } objectPropHierarchyUtils.form.submit(); }); @@ -70,6 +86,19 @@ 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() { @@ -289,5 +318,50 @@ $newClassSection.appendTo($('section#container')); objectPropHierarchyUtils.classHtml = ""; }); + }, + + buildPropertyGroupHtml: function() { + + $.each(json, function() { + $newClassSection = jQuery("
", { + id: "classContainer" + objectPropHierarchyUtils.classCounter + }); + var descendants = ""; + + if ( this.children.length ) { + var ctr = 0; + $.each(this.children, function() { + if ( ctr == 0 ) { + descendants += "Properties:"; + ctr = ctr + 1; + } + else { + descendants += "" ; + } + + descendants += "" + this.name + ""; +// descendants += "
" + this.data.shortDef + "
"; + + }); + descendants += ""; + } + + objectPropHierarchyUtils.classHtml += "
" + this.name + "
" + "" ; + + if ( this.data.displayRank.length > 0 ) { + objectPropHierarchyUtils.classHtml += "" + } + + objectPropHierarchyUtils.classHtml += descendants; + + objectPropHierarchyUtils.classHtml += "
Display Rank:" + this.data.displayRank + "
"; + // alert(objectPropHierarchyUtils.classHtml); + $newClassSection.html(objectPropHierarchyUtils.classHtml); + $newClassSection.appendTo($('section#container')); + objectPropHierarchyUtils.classHtml = ""; + objectPropHierarchyUtils.classCounter += 1; + }); } + } diff --git a/webapp/web/templates/freemarker/body/siteAdmin/siteAdmin-objectPropHierarchy.ftl b/webapp/web/templates/freemarker/body/siteAdmin/siteAdmin-objectPropHierarchy.ftl index 6b838a5dc..a28f9bdcb 100644 --- a/webapp/web/templates/freemarker/body/siteAdmin/siteAdmin-objectPropHierarchy.ftl +++ b/webapp/web/templates/freemarker/body/siteAdmin/siteAdmin-objectPropHierarchy.ftl @@ -5,6 +5,11 @@ separate controllers for those. Also used to display lists of "all" object and data properties, though there are separate controllers for those, too. --> + <#if propertyType??> + <#assign propType = propertyType> +<#else> + <#assign propType = "group"> +
@@ -15,16 +20,24 @@ <#assign displayOption = "hierarchy"> -
Object<#else>DataPropertyHierarchy" method="post" role="classHierarchy"> - - - object<#else>data property"/> -
- - + <#if propType == "group"> +
+ + +
+ + <#else> +
Object<#else>DataPropertyHierarchy" method="post" role="classHierarchy"> + + + object<#else>data property"/> +
+ +
@@ -37,7 +50,7 @@