- private Response root(IHTTPSession session, Map<String, String> cookies,
- List<String> whitelist) throws IOException {
- BasicLibrary lib = Instance.getInstance().getLibrary();
- MetaResultList result = lib.getList();
- result = new MetaResultList(result.filter(whitelist, null, null));
- StringBuilder builder = new StringBuilder();
-
-
- appendPreHtml(builder, true);
-
- Map<String, String> params = session.getParms();
-
- String filter = cookies.get("filter");
- if (params.get("clear") != null)
- filter = null;
- if (filter == null) {
- filter = "";
- }
-
- String browser = params.get("browser") == null ? "" : params
- .get("browser");
- String browser2 = params.get("browser2") == null ? "" : params
- .get("browser2");
- String browser3 = params.get("browser3") == null ? "" : params
- .get("browser3");
-
- String filterSource = null;
- String filterAuthor = null;
- String filterTag = null;
-
- // TODO: javascript in realtime, using visible=false + hide [submit]
-
- builder.append("<form class='browser'>\n");
- builder.append("<div class='breadcrumbs'>\n");
-
- builder.append("\t<select name='browser'>");
- appendOption(builder, 2, "", "", browser);
- appendOption(builder, 2, "Sources", "sources", browser);
- appendOption(builder, 2, "Authors", "authors", browser);
- appendOption(builder, 2, "Tags", "tags", browser);
- builder.append("\t</select>\n");
-
- if (!browser.isEmpty()) {
- builder.append("\t<select name='browser2'>");
- if (browser.equals("sources")) {
- filterSource = browser2.isEmpty() ? filterSource : browser2;
- // TODO: if 1 group -> no group
- appendOption(builder, 2, "", "", browser2);
- Map<String, List<String>> sources = result.getSourcesGrouped();
- for (String source : sources.keySet()) {
- appendOption(builder, 2, source, source, browser2);
- }
- } else if (browser.equals("authors")) {
- filterAuthor = browser2.isEmpty() ? filterAuthor : browser2;
- // TODO: if 1 group -> no group
- appendOption(builder, 2, "", "", browser2);
- Map<String, List<String>> authors = result.getAuthorsGrouped();
- for (String author : authors.keySet()) {
- appendOption(builder, 2, author, author, browser2);
- }
- } else if (browser.equals("tags")) {
- filterTag = browser2.isEmpty() ? filterTag : browser2;
- appendOption(builder, 2, "", "", browser2);
- for (String tag : result.getTags()) {
- appendOption(builder, 2, tag, tag, browser2);
- }
- }
- builder.append("\t</select>\n");
- }
-
- if (!browser2.isEmpty()) {
- if (browser.equals("sources")) {
- filterSource = browser3.isEmpty() ? filterSource : browser3;
- Map<String, List<String>> sourcesGrouped = result
- .getSourcesGrouped();
- List<String> sources = sourcesGrouped.get(browser2);
- if (sources != null && !sources.isEmpty()) {
- // TODO: single empty value
- builder.append("\t<select name='browser3'>");
- appendOption(builder, 2, "", "", browser3);
- for (String source : sources) {
- appendOption(builder, 2, source, source, browser3);
- }
- builder.append("\t</select>\n");
- }
- } else if (browser.equals("authors")) {
- filterAuthor = browser3.isEmpty() ? filterAuthor : browser3;
- Map<String, List<String>> authorsGrouped = result
- .getAuthorsGrouped();
- List<String> authors = authorsGrouped.get(browser2);
- if (authors != null && !authors.isEmpty()) {
- // TODO: single empty value
- builder.append("\t<select name='browser3'>");
- appendOption(builder, 2, "", "", browser3);
- for (String author : authors) {
- appendOption(builder, 2, author, author, browser3);
- }
- builder.append("\t</select>\n");
- }
- }
- }
-
- builder.append("\t<input type='submit' value='Select'/>\n");
- builder.append("</div>\n");
-
- // TODO: javascript in realtime, using visible=false + hide [submit]
- builder.append("<div class='filter'>\n");
- builder.append("\tFilter: \n");
- builder.append("\t<input name='optionName' type='hidden' value='filter' />\n");
- builder.append("\t<input name='optionValue' type='text' value='"
- + filter + "' place-holder='...' />\n");
- builder.append("\t<input name='clear' type='submit' value='x' />");
- builder.append("\t<input name='submit' type='submit' value='Filter' />\n");
- builder.append("</div>\n");
- builder.append("</form>\n");
-
- builder.append("\t<div class='books'>");
- for (MetaData meta : result.getMetas()) {
- if (!filter.isEmpty()
- && !meta.getTitle().toLowerCase()
- .contains(filter.toLowerCase())) {
- continue;
- }
-
- // TODO Sub sources
- if (filterSource != null && !filterSource.equals(meta.getSource())) {
- continue;
- }
-
- // TODO: sub authors
- if (filterAuthor != null && !filterAuthor.equals(meta.getAuthor())) {
- continue;
- }
-
- if (filterTag != null && !meta.getTags().contains(filterTag)) {
- continue;
- }
-
- builder.append("<div class='book_line'>");
- builder.append("<a href='");
- builder.append(getViewUrl(meta.getLuid(), 0, null));
- builder.append("'");
- builder.append(" class='link'>");
-
- if (lib.isCached(meta.getLuid())) {
- // â—‰ = ◉
- builder.append("<span class='cache_icon cached'>◉</span>");
- } else {
- // â—‹ = ○
- builder.append("<span class='cache_icon uncached'>○</span>");
- }
- builder.append("<span class='luid'>");
- builder.append(meta.getLuid());
- builder.append("</span>");
- builder.append("<span class='title'>");
- builder.append(meta.getTitle());
- builder.append("</span>");
- builder.append("<span class='author'>");
- if (meta.getAuthor() != null && !meta.getAuthor().isEmpty()) {
- builder.append("(").append(meta.getAuthor()).append(")");
- }
- builder.append("</span>");
- builder.append("</a></div>\n");
- }
- builder.append("</div>");
-
- appendPostHtml(builder);
- return NanoHTTPD.newFixedLengthResponse(builder.toString());
- }
-