Mercurial > hg > AnnotationManagerN4J
diff src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsResource.java @ 101:7268c3ca025b
make admin ui view of all annotations scale better.
author | casties |
---|---|
date | Fri, 13 Feb 2015 18:10:11 +0100 |
parents | 199143c669e4 |
children |
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsResource.java Wed Feb 11 20:02:56 2015 +0100 +++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsResource.java Fri Feb 13 18:10:11 2015 +0100 @@ -28,6 +28,7 @@ import java.util.List; import java.util.logging.Logger; +import org.restlet.data.Form; import org.restlet.data.MediaType; import org.restlet.data.Reference; import org.restlet.representation.Representation; @@ -38,6 +39,7 @@ import de.mpiwg.itgroup.annotations.Annotation; import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; +import de.mpiwg.itgroup.annotations.restlet.AnnotatorResourceImpl; import de.mpiwg.itgroup.annotations.restlet.BaseRestlet; /** @@ -69,20 +71,36 @@ */ @Get("html") public Representation doGetHTML(Representation entity) { - String result = null; + Form form = getRequest().getResourceRef().getQueryAsForm(); + int limit = AnnotatorResourceImpl.getInt(form.getFirstValue("limit", "100")); + int offset = AnnotatorResourceImpl.getInt(form.getFirstValue("offset", "0")); + int max = offset + limit; + int numannots = store.getAnnotationCount(); + String baseUrl = this.getReference().getHierarchicalPart(); + StringBuilder result = null; // list all annotations - result = "<html><body>\n<h1>Annotations</h1>\n<table>"; - result += "<tr><th>uri</th><th>text</th><th>target</th><th>fragment</th><th>creator</th></tr>"; - List<Annotation> annotations = store.getAnnotations("id", "*"); + result = new StringBuilder("<html><body>\n<h1>Annotations</h1>\n"); + result.append("<p>"); + if (offset > 0) { + result.append(String.format(" <a href=\"%s?offset=%s&limit=%s\">prev</a> ", baseUrl, Math.max(offset - limit, 0), limit)); + } + result.append(String.format("| %s - %s of %s annotations |", offset, (offset + limit), numannots)); + if (max < numannots) { + result.append(String.format(" <a href=\"%s?offset=%s&limit=%s\">next</a>", baseUrl, Math.min(max, numannots), limit)); + } + result.append("</p>\n"); + result.append("<table>"); + result.append("<tr><th>uri</th><th>text</th><th>target</th><th>fragment</th><th>creator</th></tr>"); + List<Annotation> annotations = store.getAnnotations("id", "*", limit, offset); for (Annotation annotation : annotations) { Reference url = this.getReference().clone(); url.addSegment(annotation.getUrlId()); - result += String.format("<tr><td><a href=\"%s\">%s</a></td><td>%s</td><td><a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, + result.append(String.format("<tr><td><a href=\"%s\">%s</a></td><td>%s</td><td><a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, annotation.getUri(), annotation.getBodyText(), annotation.getTargetBaseUri(), annotation.getTargetBaseUri(), - annotation.getTargetFragment(), annotation.getCreatorName()); + annotation.getTargetFragment(), annotation.getCreatorName())); } - result += "</table>\n"; - result += "</body>\n</html>"; + result.append("</table>\n"); + result.append("</body>\n</html>"); return new StringRepresentation(result, MediaType.TEXT_HTML); }