NIHVIVO-707 First draft of Manage Web Pages screen. JS not yet functional.

This commit is contained in:
ryounes 2011-07-11 21:13:05 +00:00
parent 2cb38eab37
commit e48271b1a4
5 changed files with 177 additions and 17 deletions

View file

@ -37,10 +37,10 @@ core:authorInAuthorship (Person : Authorship) - inverse of linkedAuthor
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.JavaScript" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Css" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ page import="org.json.JSONObject" %>
<%@ page import="org.apache.commons.logging.Log" %>
<%@ page import="org.apache.commons.logging.LogFactory" %>
@ -308,8 +308,6 @@ SPARQL queries for existing values. --%>
int maxRank = 0;
int authorshipCount = authorships.size();
// for ( ObjectPropertyStatement stmt : authorshipStmts) {
// Individual authorship = stmt.getObject();
%>
<script type="text/javascript">
var authorshipData = [];

View file

@ -46,17 +46,6 @@ core:rank
<%!
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.addEditWebpageForm.jsp");
/* Note on ordering by rank in sparql: if there is a non-integer value on a link, that will be returned,
* since it's ranked highest. Preventing that would require getting all the ranks and sorting in Java,
* throwing out non-int values.
*/
public static String RANK_QUERY = ""
+ "PREFIX core: <http://vivoweb.org/ontology/core#> \n"
+ "SELECT DISTINCT ?rank WHERE { \n"
+ " ?subject core:webpage ?link . \n"
+ " ?link core:rank ?rank .\n"
+ "} ORDER BY DESC(?rank) LIMIT 1";
%>
<%
@ -264,6 +253,18 @@ core:rank
<jsp:include page="${postForm}"/>
<%!
/* Note on ordering by rank in sparql: if there is a non-integer value on a link, that will be returned,
* since it's ranked highest. Preventing that would require getting all the ranks and sorting in Java,
* throwing out non-int values.
*/
private static String RANK_QUERY = ""
+ "PREFIX core: <http://vivoweb.org/ontology/core#> \n"
+ "SELECT DISTINCT ?rank WHERE { \n"
+ " ?subject core:webpage ?link . \n"
+ " ?link core:rank ?rank .\n"
+ "} ORDER BY DESC(?rank) LIMIT 1";
private int getMaxRank(String objectUri, String subjectUri, VitroRequest vreq) {
int maxRank = 0; // default value

View file

@ -0,0 +1,55 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
#manageWebpages {
margin-left: 0;
}
#manageWebpages li {
list-style: none;
margin-bottom: .75em;
}
/* Use class dd rather than jQuery UI's class ui-sortable, so that we can remove
the class if there's fewer than one author. We don't want to remove the ui-sortable
class, in case we want to re-enable DD without a page reload. */
#manageWebpages.dd li {
padding-left: 1em;
background: url("../images/sortable_icon.png") no-repeat left center;
cursor: move;
}
#manageWebpages .webpageName {
display: inline-block;
width: 15em;
}
#showAddForm span.or {
display: none;
}
#showAddForm a.cancel {
margin-left: 2em;
}
#manageWebpages a:link.remove,
#manageWebpages a:visited.remove,
#manageWebpages a:link.undo,
#manageWebpages a:visited.undo,
#manageWebpages a:hover.remove,
#manageWebpages a:hover.undo,
#showAddForm a:hover.cancel {
color: #fff;
background: #f70;
}
#manageWebpages a:hover.remove,
#manageWebpages a:hover.undo,
#showAddForm a:hover.cancel {
color: #fff;
background: #f70;
}
#manageWebpages a.undo {
margin-left: 1em;
}

View file

@ -11,10 +11,14 @@
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Arrays" %>
<%@ page import="java.util.Map" %>
<%@ page import="com.hp.hpl.jena.rdf.model.Literal" %>
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
<%@ page import="com.hp.hpl.jena.vocabulary.XSD" %>
<%@ page import="com.hp.hpl.jena.query.ResultSet" %>
<%@ page import="com.hp.hpl.jena.rdf.model.RDFNode" %>
<%@ page import="com.hp.hpl.jena.query.QuerySolution" %>
<%@ page import="com.hp.hpl.jena.query.Dataset" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
@ -27,12 +31,15 @@
<%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.JavaScript" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Css" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ page import="org.apache.commons.logging.Log" %>
<%@ page import="org.apache.commons.logging.LogFactory" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
<%!
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.manageWebpagesForIndividual.jsp");
%>
@ -40,7 +47,6 @@
<%
String objectUri = (String) request.getAttribute("objectUri");
String view = request.getParameter("view");
if ( "form".equals(view) || // the url specifies form view
@ -48,21 +54,118 @@
%> <jsp:forward page="addEditWebpageForm.jsp" /> <%
} // else stay here for manage view
} // else stay here to manage webpages
VitroRequest vreq = new VitroRequest(request);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
vreq.setAttribute("defaultNamespace", wdf.getDefaultNamespace());
String subjectName = ((Individual)request.getAttribute("subject")).getName();
String subjectUri = (String) request.getAttribute("subjectUri");
List<Map<String, String>> webpages = getWebpages(subjectUri, vreq);
vreq.setAttribute("webpages", webpages);
String ulClass = "";
List<String> ulClasses = new ArrayList<String>();
if (webpages.size() > 1) {
// This class triggers application of dd styles. Don't wait for js to add
// the ui-sortable class, because then the page flashes as the styles are updated.
ulClasses.add("dd");
}
if (ulClasses.size() > 0) {
ulClass="class=\"" + StringUtils.join(ulClasses, " ") + "\"";
}
List<String> customJs = new ArrayList<String>(Arrays.asList(JavaScript.JQUERY_UI.path(),
JavaScript.CUSTOM_FORM_UTILS.path(),
//"/js/browserUtils.js",
"/edit/forms/js/manageWebpagesForIndividual.js"
));
request.setAttribute("customJs", customJs);
List<String> customCss = new ArrayList<String>(Arrays.asList(Css.JQUERY_UI.path(),
Css.CUSTOM_FORM.path(),
"/edit/forms/css/manageWebpagesForIndividual.css"
));
request.setAttribute("customCss", customCss);
%>
<c:url var="deleteWebpageHref" value="/edit/primitiveDelete" />
<jsp:include page="${preForm}"/>
<h2><em><%= subjectName %></em></h2>
<h3>Manage Web Pages</h3>
<script type="text/javascript">
var webpageData = [];
</script>
<ul id="manageWebpages" <%= ulClass %>>
<c:if test="${ empty webpages }">
<p>This individual currently has no web pages specified. Add a new web page by clicking on the button below.</p>
</c:if>
<c:forEach var="webpage" items="${webpages}">
<li class="webpage">
<c:set var="anchor">${ empty webpage.anchor ? webpage.url : webpage.anchor }</c:set>
<span class="webpageName">
<a href="${webpage.url}">${anchor}</a>
</span>
<span class="editingLinks">
<a href="" class="edit">Edit</a> |
<a href="${deleteWebpageHref}" class="remove">Delete</a>
</span>
</li>
<script type="text/javascript">
webpageData.push({
"webpageUri": "${webpage.link}"
});
</script>
</c:forEach>
</ul>
<div id="showAddForm">
</div>
<jsp:include page="${postForm}"/>
<%!
private static String WEBPAGE_QUERY = ""
+ "PREFIX core: <http://vivoweb.org/ontology/core#> \n"
+ "SELECT DISTINCT ?link ?url ?anchor ?rank WHERE { \n"
+ " ?subject core:webpage ?link . \n"
+ " OPTIONAL { ?link core:linkURI ?url } \n"
+ " OPTIONAL { ?link core:linkAnchorText ?anchor } \n"
+ " OPTIONAL { ?link core:rank ?rank } \n"
+ "} ORDER BY ?rank";
private List<Map<String, String>> getWebpages(String subjectUri, VitroRequest vreq) {
String queryStr = QueryUtils.subUriForQueryVar(WEBPAGE_QUERY, "subject", subjectUri);
log.debug("Query string is: " + queryStr);
List<Map<String, String>> webpages = new ArrayList<Map<String, String>>();
try {
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
while (results.hasNext()) {
QuerySolution soln = results.nextSolution();
RDFNode node = soln.get("link");
if (node.isURIResource()) {
webpages.add(QueryUtils.querySolutionToStringValueMap(soln));
}
}
} catch (Exception e) {
log.error(e, e);
}
return webpages;
}
%>

View file

@ -201,6 +201,7 @@ form textarea {
width: 100%;
}
#authorships a.remove:link,
#manageWebpages a.remove:link,
#showAddForm a.cancel:link,
form a:link.cancel,
form a:visited.cancel {
@ -211,6 +212,8 @@ form a:visited.cancel {
}
#authorships a.remove:hover,
#authorships a.remove:active,
#manageWebpages a.remove:hover,
#manageWebpages a.remove:active,
#showAddForm a.cancel:hover,
#showAddForm a.cancel:active,
form a:hover.cancel,