From c43615157b52a51f9d4a8a9f8a0a32490dbbb30d Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Fri, 15 May 2020 20:05:50 +0200 Subject: [PATCH] weblib: use some templates --- .../fanfix/library/WebLibraryServerHtml.java | 136 +++++++++--------- .../nikiroo/fanfix/library/web/bookline.html | 1 + .../nikiroo/fanfix/library/web/browser.html | 18 +++ .../fanfix/library/web/browser.select.html | 3 + 4 files changed, 92 insertions(+), 66 deletions(-) create mode 100644 src/be/nikiroo/fanfix/library/web/bookline.html create mode 100644 src/be/nikiroo/fanfix/library/web/browser.html create mode 100644 src/be/nikiroo/fanfix/library/web/browser.select.html diff --git a/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java b/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java index 1ec3b1fb..e530d3f0 100644 --- a/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java +++ b/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java @@ -371,45 +371,53 @@ abstract class WebLibraryServerHtml implements Runnable { // TODO: javascript in realtime, using visible=false + hide [submit] - builder.append("\t\t
\n"); - builder.append("\t\t\t\n"); + selects.append(selectTemplate // + .replace("${name}", "browser3") // + .replace("${value}", browser3) // + .replace("${options}", options.toString()) // + ); + } - // TODO: javascript in realtime, using visible=false + hide [submit] - builder.append("\t\t\t
\n"); - builder.append("\t\t\t\tFilter: \n"); - builder.append( - "\t\t\t\t\n"); - builder.append("\t\t\t\t\n"); - builder.append( - "\t\t\t\t\n"); - builder.append( - "\t\t\t\t\n"); - builder.append("\t\t\t
\n"); - builder.append("\t\t
\n"); + String sel = "selected='selected'"; + builder.append(getTemplate("browser") // + .replace("${sourcesSelected}", sourcesSel ? sel : "") // + .replace("${authorsSelected}", authorsSel ? sel : "") // + .replace("${tagsSelected}", tagsSel ? sel : "") // + .replace("${filter}", filter) // + .replace("${selects}", selects.toString()) // + ); builder.append("\t\t
\n"); for (MetaData meta : result.getMetas()) { @@ -481,34 +481,28 @@ abstract class WebLibraryServerHtml implements Runnable { continue; } - builder.append("\t\t\t\n"); + + builder.append(getTemplate("bookline") // + .replace("${href}", + WebLibraryUrls.getViewUrl(meta.getLuid(), null, + null)) // + .replace("${luid}", meta.getLuid()) // + .replace("${title}", meta.getTitle()) // + .replace("${author}", author) // + .replace("${cachedClass}", cachedClass) // + .replace("${cached}", cached) // + ); } builder.append("\t\t
\n"); @@ -900,4 +894,14 @@ abstract class WebLibraryServerHtml implements Runnable { builder.append(name); builder.append("\n"); } + + private String getTemplate(String template) throws IOException { + InputStream in = IOUtils.openResource(WebLibraryServerIndex.class, + template + ".html"); + try { + return IOUtils.readSmallStream(in); + } finally { + in.close(); + } + } } diff --git a/src/be/nikiroo/fanfix/library/web/bookline.html b/src/be/nikiroo/fanfix/library/web/bookline.html new file mode 100644 index 00000000..9b1a6b78 --- /dev/null +++ b/src/be/nikiroo/fanfix/library/web/bookline.html @@ -0,0 +1 @@ +
${cached}${luid}${title}${author}
diff --git a/src/be/nikiroo/fanfix/library/web/browser.html b/src/be/nikiroo/fanfix/library/web/browser.html new file mode 100644 index 00000000..f3f30478 --- /dev/null +++ b/src/be/nikiroo/fanfix/library/web/browser.html @@ -0,0 +1,18 @@ +
+ +
+ Filter: + + + + +
+
diff --git a/src/be/nikiroo/fanfix/library/web/browser.select.html b/src/be/nikiroo/fanfix/library/web/browser.select.html new file mode 100644 index 00000000..447d845a --- /dev/null +++ b/src/be/nikiroo/fanfix/library/web/browser.select.html @@ -0,0 +1,3 @@ + -- 2.27.0