Ignore:
Timestamp:
Feb 13, 2015, 5:10:11 PM (9 years ago)
Author:
casties
Branch:
default
Message:

make admin ui view of all annotations scale better.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsResource.java

    r99 r101  
    2929import java.util.logging.Logger;
    3030
     31import org.restlet.data.Form;
    3132import org.restlet.data.MediaType;
    3233import org.restlet.data.Reference;
     
    3940import de.mpiwg.itgroup.annotations.Annotation;
    4041import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
     42import de.mpiwg.itgroup.annotations.restlet.AnnotatorResourceImpl;
    4143import de.mpiwg.itgroup.annotations.restlet.BaseRestlet;
    4244
     
    7072    @Get("html")
    7173    public Representation doGetHTML(Representation entity) {
    72         String result = null;
     74        Form form = getRequest().getResourceRef().getQueryAsForm();
     75        int limit = AnnotatorResourceImpl.getInt(form.getFirstValue("limit", "100"));
     76        int offset = AnnotatorResourceImpl.getInt(form.getFirstValue("offset", "0"));
     77        int max = offset + limit;
     78        int numannots = store.getAnnotationCount();
     79        String baseUrl = this.getReference().getHierarchicalPart();
     80        StringBuilder result = null;
    7381        // list all annotations
    74         result = "<html><body>\n<h1>Annotations</h1>\n<table>";
    75         result += "<tr><th>uri</th><th>text</th><th>target</th><th>fragment</th><th>creator</th></tr>";
    76         List<Annotation> annotations = store.getAnnotations("id", "*");
     82        result = new StringBuilder("<html><body>\n<h1>Annotations</h1>\n");
     83        result.append("<p>");
     84        if (offset > 0) {
     85            result.append(String.format(" <a href=\"%s?offset=%s&limit=%s\">prev</a> ", baseUrl, Math.max(offset - limit, 0), limit));
     86        }
     87        result.append(String.format("| %s - %s of %s annotations |", offset, (offset + limit), numannots));
     88        if (max < numannots) {
     89            result.append(String.format(" <a href=\"%s?offset=%s&limit=%s\">next</a>", baseUrl, Math.min(max, numannots), limit));
     90        }
     91        result.append("</p>\n");
     92        result.append("<table>");
     93        result.append("<tr><th>uri</th><th>text</th><th>target</th><th>fragment</th><th>creator</th></tr>");
     94        List<Annotation> annotations = store.getAnnotations("id", "*", limit, offset);
    7795        for (Annotation annotation : annotations) {
    7896            Reference url = this.getReference().clone();
    7997            url.addSegment(annotation.getUrlId());
    80             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,
     98            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,
    8199                    annotation.getUri(), annotation.getBodyText(), annotation.getTargetBaseUri(), annotation.getTargetBaseUri(),
    82                     annotation.getTargetFragment(), annotation.getCreatorName());
     100                    annotation.getTargetFragment(), annotation.getCreatorName()));
    83101        }
    84         result += "</table>\n";
    85         result += "</body>\n</html>";
     102        result.append("</table>\n");
     103        result.append("</body>\n</html>");
    86104        return new StringRepresentation(result, MediaType.TEXT_HTML);
    87105    }
Note: See TracChangeset for help on using the changeset viewer.