X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FWebLibraryServer.java;h=8a874010257072cc93018f92583c1d82620fedfd;hb=4c3426fbd8a0208c285fc10d8d51e92670996438;hp=4abd438b6046a31053d71f5f7e772afb825f1314;hpb=db9146bc53fcfd0912910f5bd21a6cc917018b36;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/library/WebLibraryServer.java b/src/be/nikiroo/fanfix/library/WebLibraryServer.java index 4abd438..8a87401 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"); @@ -620,7 +626,7 @@ public class WebLibraryServer implements Runnable { builder.append("
"); builder.append(""); @@ -707,6 +713,8 @@ public class WebLibraryServer implements Runnable { if (img != null) { in = img.newInputStream(); } + // TODO: get correct image type + mimeType = "image/png"; } else if ("metadata".equals(chapterStr)) { MetaData meta = meta(luid, whitelist); JSONObject json = JsonIO.toJson(meta); @@ -776,7 +784,7 @@ public class WebLibraryServer implements Runnable { String paragraphStr = cover.length < off + 4 ? null : cover[off + 3]; // 1-based (0 = desc) - int chapter = -1; + int chapter = 0; if (chapterStr != null) { try { chapter = Integer.parseInt(chapterStr); @@ -813,11 +821,9 @@ public class WebLibraryServer implements Runnable { StringBuilder builder = new StringBuilder(); appendPreHtml(builder, false); - // TODO: no desc page for images? + // For images documents, always go to the images if not chap 0 desc if (story.getMeta().isImageDocument()) { - if (chapter <= 0) - chapter = 1; - if (paragraph <= 0) + if (chapter > 0 && paragraph <= 0) paragraph = 1; } @@ -844,26 +850,29 @@ public class WebLibraryServer implements Runnable { String disabledZoomHeight = ""; if (paragraph <= 0) { - first = getViewUrl(luid, 1, null); - previous = getViewUrl(luid, (Math.max(chapter - 1, 1)), null); + 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); - // TODO StringBuilder desc = new StringBuilder(); if (chapter <= 0) { + desc.append("

"); + desc.append(story.getMeta().getTitle()); + desc.append("

\n"); desc.append("
\n"); desc.append("

Description

\n"); @@ -871,11 +880,14 @@ public class WebLibraryServer implements Runnable { content.append("
\n"); content.append(desc); - content.append( - new TextOutput(false).convert(chap, chapter > 0)); + String description = new TextOutput(false).convert(chap, + chapter > 0); + content.append(chap.getParagraphs().size() <= 0 + ? "No content provided." + : description); content.append("
\n"); - if (chapter <= 1) + if (chapter <= 0) disabledLeft = " disabled='disbaled'"; if (chapter >= story.getChapters().size()) disabledRight = " disabled='disbaled'"; @@ -892,6 +904,14 @@ public class WebLibraryServer implements Runnable { 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; + } + Paragraph para = null; try { para = chap.getParagraphs().get(paragraph - 1); @@ -920,27 +940,64 @@ public class WebLibraryServer implements Runnable { } } + String javascript = "document.getElementById(\"previous\").click(); return false;"; content.append(String.format("" // - + "
" + + "" + "" + "", // + javascript, // next, // zoomStyle, // getStoryUrl(luid, chapter, paragraph))); } else { - content.append(para.getContent()); + content.append(String.format("" // + + "
%s
", // + para.getContent())); } } builder.append(String.format("" // + "\n", // + + "\t<\n" // + + "\t
\n" // + + "\t\t
%d
\n" // + + "\t\t
\n", // disabledLeft, first, // disabledLeft, previous, // + paragraph > 0 ? paragraph : chapter // + )); + + // List of chap/para links + + appendItemA(builder, 3, getViewUrl(luid, 0, null), "Description", + paragraph == 0 && chapter == 0); + if (paragraph > 0) { + for (int i = 1; i <= chap.getParagraphs().size(); i++) { + appendItemA(builder, 3, getViewUrl(luid, chapter, i), + "Image " + i, paragraph == i); + } + } else { + int i = 1; + for (Chapter c : story.getChapters()) { + String chapName = "Chapter " + c.getNumber(); + if (c.getName() != null && !c.getName().isEmpty()) { + chapName += ": " + c.getName(); + } + + appendItemA(builder, 3, getViewUrl(luid, i, null), chapName, + chapter == i); + + i++; + } + } + + builder.append(String.format("" // + + "\t\t
\n" // + + "\t
\n" // + + "\t>\n" // + + "\t>>\n"// + + "
\n", // disabledRight, next, // disabledRight, last // )); @@ -1005,12 +1062,12 @@ public class WebLibraryServer implements Runnable { return ""; } - private String getViewUrl(String luid, int chap, Integer para) { + private String getViewUrl(String luid, Integer chap, Integer para) { return VIEWER_URL // .replace("{luid}", luid) // - .replace("{chap}", Integer.toString(chap)) // + .replace("/{chap}", chap == null ? "" : "/" + chap) // .replace("/{para}", - para == null ? "" : "/" + Integer.toString(para)); + (chap == null || para == null) ? "" : "/" + para); } private String getStoryUrl(String luid, int chap, Integer para) { @@ -1143,6 +1200,41 @@ public class WebLibraryServer implements Runnable { builder.append(">").append(name).append("\n"); } + private void appendTableRow(StringBuilder builder, int depth, + String... tds) { + for (int i = 0; i < depth; i++) { + builder.append("\t"); + } + + int col = 1; + builder.append(""); + for (String td : tds) { + builder.append(""); + builder.append(td); + builder.append(""); + } + builder.append("\n"); + } + + private void appendItemA(StringBuilder builder, int depth, String link, + String name, boolean selected) { + for (int i = 0; i < depth; i++) { + builder.append("\t"); + } + + builder.append(""); + builder.append(name); + builder.append("\n"); + } + public static void main(String[] args) throws IOException { Instance.init(); WebLibraryServer web = new WebLibraryServer(false);