X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FWebLibraryServer.java;h=982d224d03cc7f12c1415dbf4b0dd3324210139d;hb=6b89e45caaa566895d505b56c9ef272dd67f1d76;hp=4bd51f47e3a4a141b7fd4b45460a60ba60405ee1;hpb=3fbc084c1d4adb2176816692f722e8d5e8b4867e;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/library/WebLibraryServer.java b/src/be/nikiroo/fanfix/library/WebLibraryServer.java index 4bd51f4..982d224 100644 --- a/src/be/nikiroo/fanfix/library/WebLibraryServer.java +++ b/src/be/nikiroo/fanfix/library/WebLibraryServer.java @@ -242,8 +242,10 @@ public class WebLibraryServer implements Runnable { // set options String optionName = params.get("optionName"); if (optionName != null && !optionName.isEmpty()) { + String optionNo = params.get("optionNo"); String optionValue = params.get("optionValue"); - if (optionValue == null || optionValue.isEmpty()) { + if (optionNo != null || optionValue == null + || optionValue.isEmpty()) { session.getCookies().delete(optionName); cookies.remove(optionName); } else { @@ -491,12 +493,15 @@ public class WebLibraryServer implements Runnable { appendPreHtml(builder, true); + Map params = session.getParms(); + String filter = cookies.get("filter"); + if (params.get("optionNo") != null) + filter = null; if (filter == null) { filter = ""; } - Map params = session.getParms(); String browser = params.get("browser") == null ? "" : params.get("browser"); String browser2 = params.get("browser2") == null ? "" @@ -585,11 +590,12 @@ public class WebLibraryServer implements Runnable { // TODO: javascript in realtime, using visible=false + hide [submit] builder.append("
\n"); - builder.append("\tFilter: \n"); + builder.append("\tFilter: \n"); builder.append( "\t\n"); builder.append("\t\n"); + builder.append("\t"); builder.append( "\t\n"); builder.append("
\n"); @@ -813,145 +819,208 @@ public class WebLibraryServer implements Runnable { StringBuilder builder = new StringBuilder(); appendPreHtml(builder, false); - if (chapter < 0) { - builder.append(story); - } else { - if (chapter == 0) { - // TODO: description - chapter = 1; - } + // For images documents, always go to the images if not chap 0 desc + if (story.getMeta().isImageDocument()) { + if (chapter > 0 && paragraph <= 0) + paragraph = 1; + } - Chapter chap = null; + Chapter chap = null; + if (chapter <= 0) { + chap = story.getMeta().getResume(); + } else { try { chap = story.getChapters().get(chapter - 1); } catch (IndexOutOfBoundsException e) { return NanoHTTPD.newFixedLengthResponse(Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT, "Chapter not found"); } + } - if (story.getMeta().isImageDocument() && paragraph <= 0) { - paragraph = 1; + String first, previous, next, last; + + StringBuilder content = new StringBuilder(); + + String disabledLeft = ""; + String disabledRight = ""; + String disabledZoomReal = ""; + String disabledZoomWidth = ""; + String disabledZoomHeight = ""; + + if (paragraph <= 0) { + first = getViewUrl(luid, 0, null); + previous = getViewUrl(luid, (Math.max(chapter - 1, 0)), null); + next = getViewUrl(luid, + (Math.min(chapter + 1, story.getChapters().size())), + null); + last = getViewUrl(luid, story.getChapters().size(), null); + + StringBuilder desc = new StringBuilder(); + + if (chapter <= 0) { + desc.append("
\n"); + desc.append("\t
\n"); + desc.append("\t\t\n"); + desc.append("\t
\n"); + desc.append("\t\n"); + Map details = BasicLibrary + .getMetaDesc(story.getMeta()); + for (String key : details.keySet()) { + appendTableRow(desc, 2, key, details.get(key)); + } + desc.append("\t
\n"); + desc.append("
\n"); + desc.append("

Description

\n"); } - String first, previous, next, last; - String content; + content.append("
\n"); + content.append(desc); + String description = new TextOutput(false).convert(chap, + chapter > 0); + content.append( + description.isEmpty() ? "No description provided." + : description); + content.append("
\n"); + + if (chapter <= 0) + disabledLeft = " disabled='disbaled'"; + if (chapter >= story.getChapters().size()) + disabledRight = " disabled='disbaled'"; + } else { + first = getViewUrl(luid, chapter, 1); + previous = getViewUrl(luid, chapter, + (Math.max(paragraph - 1, 1))); + next = getViewUrl(luid, chapter, + (Math.min(paragraph + 1, chap.getParagraphs().size()))); + last = getViewUrl(luid, chapter, chap.getParagraphs().size()); + + if (paragraph <= 1) + disabledLeft = " disabled='disbaled'"; + if (paragraph >= chap.getParagraphs().size()) + disabledRight = " disabled='disbaled'"; + + // First -> previous *chapter* + if (chapter > 0) + disabledLeft = ""; + first = getViewUrl(luid, (Math.max(chapter - 1, 0)), null); + if (paragraph <= 1) { + previous = first; + } - String disabledLeft = ""; - String disabledRight = ""; - String disabledZoomReal = ""; - String disabledZoomWidth = ""; - String disabledZoomHeight = ""; + Paragraph para = null; + try { + para = chap.getParagraphs().get(paragraph - 1); + } catch (IndexOutOfBoundsException e) { + return NanoHTTPD.newFixedLengthResponse(Status.NOT_FOUND, + NanoHTTPD.MIME_PLAINTEXT, + "Paragraph " + paragraph + " not found"); + } - if (paragraph <= 0) { - first = getViewUrl(luid, 1, null); - previous = getViewUrl(luid, (Math.max(chapter - 1, 1)), - null); - next = getViewUrl(luid, - (Math.min(chapter + 1, story.getChapters().size())), - null); - last = getViewUrl(luid, story.getChapters().size(), null); - - content = "
\n" - + new TextOutput(false).convert(chap, true) - + "
\n"; - - if (chapter <= 1) - disabledLeft = " disabled='disbaled'"; - if (chapter >= story.getChapters().size()) - disabledRight = " disabled='disbaled'"; - } else { - first = getViewUrl(luid, chapter, 1); - previous = getViewUrl(luid, chapter, - (Math.max(paragraph - 1, 1))); - next = getViewUrl(luid, chapter, (Math.min(paragraph + 1, - chap.getParagraphs().size()))); - last = getViewUrl(luid, chapter, - chap.getParagraphs().size()); - - if (paragraph <= 1) - disabledLeft = " disabled='disbaled'"; - if (paragraph >= chap.getParagraphs().size()) - disabledRight = " disabled='disbaled'"; - - Paragraph para = null; - try { - para = chap.getParagraphs().get(paragraph - 1); - } catch (IndexOutOfBoundsException e) { - return NanoHTTPD.newFixedLengthResponse( - Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT, - "Paragraph not found"); + if (para.getType() == ParagraphType.IMAGE) { + String zoomStyle = "max-width: 100%;"; + disabledZoomWidth = " disabled='disabled'"; + String zoomOption = cookies.get("zoom"); + if (zoomOption != null && !zoomOption.isEmpty()) { + if (zoomOption.equals("real")) { + zoomStyle = ""; + disabledZoomWidth = ""; + disabledZoomReal = " disabled='disabled'"; + } else if (zoomOption.equals("width")) { + zoomStyle = "max-width: 100%;"; + } else if (zoomOption.equals("height")) { + // see height of navbar + optionbar + zoomStyle = "max-height: calc(100% - 128px);"; + disabledZoomWidth = ""; + disabledZoomHeight = " disabled='disabled'"; + } } - if (para.getType() == ParagraphType.IMAGE) { - String zoomStyle = "max-width: 100%;"; - disabledZoomWidth = " disabled='disabled'"; - String zoomOption = cookies.get("zoom"); - if (zoomOption != null && !zoomOption.isEmpty()) { - if (zoomOption.equals("real")) { - zoomStyle = ""; - disabledZoomWidth = ""; - disabledZoomReal = " disabled='disabled'"; - } else if (zoomOption.equals("width")) { - zoomStyle = "max-width: 100%;"; - } else if (zoomOption.equals("height")) { - // see height of navbar + optionbar - zoomStyle = "max-height: calc(100% - 128px);"; - disabledZoomWidth = ""; - disabledZoomHeight = " disabled='disabled'"; - } - } - content = String.format("" // - + "" // - + "" - + "", // - next, // - zoomStyle, // - getStoryUrl(luid, chapter, paragraph)); - } else { - content = para.getContent(); + content.append(String.format("" // + + "" + + "" + + "", // + next, // + zoomStyle, // + getStoryUrl(luid, chapter, paragraph))); + } else { + content.append(String.format("" // + + "
%s
", // + para.getContent())); + } + } + + builder.append(String.format("" // + + "\n", // + disabledRight, next, // + disabledRight, last // + )); + + builder.append(content); + + builder.append("
\n"); + builder.append(" BACK\n"); + if (paragraph > 0) { builder.append(String.format("" // - + "\n" // - + "%s", // - disabledLeft, first, // - disabledLeft, previous, // - disabledRight, next, // - disabledRight, last, // - content // + + "\tREAL\n"// + + "\tWIDTH\n"// + + "\tHEIGHT\n"// + + "
\n", // + disabledZoomReal, + uri + "?optionName=zoom&optionValue=real", // + disabledZoomWidth, + uri + "?optionName=zoom&optionValue=width", // + disabledZoomHeight, + uri + "?optionName=zoom&optionValue=height" // )); - - builder.append("
\n"); - builder.append( - " BACK\n"); - - if (paragraph > 0) { - builder.append(String.format("" // - + "\tREAL\n"// - + "\tWIDTH\n"// - + "\tHEIGHT\n"// - + "
\n", // - disabledZoomReal, - uri + "?optionName=zoom&optionValue=real", // - disabledZoomWidth, - uri + "?optionName=zoom&optionValue=width", // - disabledZoomHeight, - uri + "?optionName=zoom&optionValue=height" // - )); - } } appendPostHtml(builder); @@ -1023,7 +1092,8 @@ public class WebLibraryServer implements Runnable { throws IOException { MetaData meta = meta(luid, whitelist); if (meta != null) { - return meta.getCover(); + BasicLibrary lib = Instance.getInstance().getLibrary(); + return lib.getCover(meta.getLuid()); } return null; @@ -1098,7 +1168,7 @@ public class WebLibraryServer implements Runnable { if (banner) { builder.append("