From bcceb1200980351e2d9e326f1b78541042c908b2 Mon Sep 17 00:00:00 2001 From: bouncepaw Date: Mon, 31 Aug 2020 23:16:22 +0500 Subject: [PATCH] Make a better /list page --- main.go | 23 ++----- templates/http_stuff.qtpl | 23 +++++-- templates/http_stuff.qtpl.go | 124 +++++++++++++++++++++++++++-------- 3 files changed, 119 insertions(+), 51 deletions(-) diff --git a/main.go b/main.go index cf567eb..dfa1089 100644 --- a/main.go +++ b/main.go @@ -44,23 +44,14 @@ func HttpErr(w http.ResponseWriter, status int, name, title, errMsg string) { // Show all hyphae func handlerList(w http.ResponseWriter, rq *http.Request) { log.Println(rq.URL) - var tbody string - // It should be moved to templates too, right? - for name, data := range HyphaStorage { - tbody += fmt.Sprintf(` - - %s - %s - %d - %s - %d - `, - name, name, - util.ShorterPath(data.textPath), data.textType, - util.ShorterPath(data.binaryPath), data.binaryType, - ) + var ( + tbody string + pageCount = len(HyphaStorage) + ) + for hyphaName, data := range HyphaStorage { + tbody += templates.HyphaListRowHTML(hyphaName, data.binaryType.Mime(), data.binaryPath != "") } - util.HTTP200Page(w, base("List of pages", templates.PageListHTML(tbody))) + util.HTTP200Page(w, base("List of pages", templates.HyphaListHTML(tbody, pageCount))) } // This part is present in all html documents. diff --git a/templates/http_stuff.qtpl b/templates/http_stuff.qtpl index 63a3a4e..9bacf51 100644 --- a/templates/http_stuff.qtpl +++ b/templates/http_stuff.qtpl @@ -12,17 +12,15 @@ {% endfunc %} -{% func PageListHTML(tbody string) %} +{% func HyphaListHTML(tbody string, pageCount int) %}
-

List of pages

+

List of hyphae

+

This wiki has {%d pageCount %} hyphae.

- - - - - + + @@ -31,3 +29,14 @@
NameText pathText typeBinary pathBinary typeFull nameBinary part type
{% endfunc %} + +{% func HyphaListRowHTML(hyphaName, binaryMime string, binaryPresent bool) %} + + {%s hyphaName %} + {% if binaryPresent %} + {%s binaryMime %} + {% else %} + + {% endif %} + +{% endfunc %} diff --git a/templates/http_stuff.qtpl.go b/templates/http_stuff.qtpl.go index 89d322c..8fa0096 100644 --- a/templates/http_stuff.qtpl.go +++ b/templates/http_stuff.qtpl.go @@ -71,56 +71,124 @@ func BaseHTML(title, body string) string { } //line templates/http_stuff.qtpl:15 -func StreamPageListHTML(qw422016 *qt422016.Writer, tbody string) { +func StreamHyphaListHTML(qw422016 *qt422016.Writer, tbody string, pageCount int) { //line templates/http_stuff.qtpl:15 qw422016.N().S(`
-

List of pages

+

List of hyphae

+

This wiki has `) +//line templates/http_stuff.qtpl:18 + qw422016.N().D(pageCount) +//line templates/http_stuff.qtpl:18 + qw422016.N().S(` hyphae.

- - - - - + + `) -//line templates/http_stuff.qtpl:29 +//line templates/http_stuff.qtpl:27 qw422016.N().S(tbody) -//line templates/http_stuff.qtpl:29 +//line templates/http_stuff.qtpl:27 qw422016.N().S(`
NameText pathText typeBinary pathBinary typeFull nameBinary part type
`) -//line templates/http_stuff.qtpl:33 +//line templates/http_stuff.qtpl:31 } -//line templates/http_stuff.qtpl:33 -func WritePageListHTML(qq422016 qtio422016.Writer, tbody string) { -//line templates/http_stuff.qtpl:33 +//line templates/http_stuff.qtpl:31 +func WriteHyphaListHTML(qq422016 qtio422016.Writer, tbody string, pageCount int) { +//line templates/http_stuff.qtpl:31 qw422016 := qt422016.AcquireWriter(qq422016) -//line templates/http_stuff.qtpl:33 - StreamPageListHTML(qw422016, tbody) -//line templates/http_stuff.qtpl:33 +//line templates/http_stuff.qtpl:31 + StreamHyphaListHTML(qw422016, tbody, pageCount) +//line templates/http_stuff.qtpl:31 qt422016.ReleaseWriter(qw422016) -//line templates/http_stuff.qtpl:33 +//line templates/http_stuff.qtpl:31 +} + +//line templates/http_stuff.qtpl:31 +func HyphaListHTML(tbody string, pageCount int) string { +//line templates/http_stuff.qtpl:31 + qb422016 := qt422016.AcquireByteBuffer() +//line templates/http_stuff.qtpl:31 + WriteHyphaListHTML(qb422016, tbody, pageCount) +//line templates/http_stuff.qtpl:31 + qs422016 := string(qb422016.B) +//line templates/http_stuff.qtpl:31 + qt422016.ReleaseByteBuffer(qb422016) +//line templates/http_stuff.qtpl:31 + return qs422016 +//line templates/http_stuff.qtpl:31 } //line templates/http_stuff.qtpl:33 -func PageListHTML(tbody string) string { -//line templates/http_stuff.qtpl:33 - qb422016 := qt422016.AcquireByteBuffer() -//line templates/http_stuff.qtpl:33 - WritePageListHTML(qb422016, tbody) -//line templates/http_stuff.qtpl:33 - qs422016 := string(qb422016.B) -//line templates/http_stuff.qtpl:33 - qt422016.ReleaseByteBuffer(qb422016) -//line templates/http_stuff.qtpl:33 - return qs422016 +func StreamHyphaListRowHTML(qw422016 *qt422016.Writer, hyphaName, binaryMime string, binaryPresent bool) { //line templates/http_stuff.qtpl:33 + qw422016.N().S(` + + `) +//line templates/http_stuff.qtpl:35 + qw422016.E().S(hyphaName) +//line templates/http_stuff.qtpl:35 + qw422016.N().S(` + `) +//line templates/http_stuff.qtpl:36 + if binaryPresent { +//line templates/http_stuff.qtpl:36 + qw422016.N().S(` + `) +//line templates/http_stuff.qtpl:37 + qw422016.E().S(binaryMime) +//line templates/http_stuff.qtpl:37 + qw422016.N().S(` + `) +//line templates/http_stuff.qtpl:38 + } else { +//line templates/http_stuff.qtpl:38 + qw422016.N().S(` + + `) +//line templates/http_stuff.qtpl:40 + } +//line templates/http_stuff.qtpl:40 + qw422016.N().S(` + +`) +//line templates/http_stuff.qtpl:42 +} + +//line templates/http_stuff.qtpl:42 +func WriteHyphaListRowHTML(qq422016 qtio422016.Writer, hyphaName, binaryMime string, binaryPresent bool) { +//line templates/http_stuff.qtpl:42 + qw422016 := qt422016.AcquireWriter(qq422016) +//line templates/http_stuff.qtpl:42 + StreamHyphaListRowHTML(qw422016, hyphaName, binaryMime, binaryPresent) +//line templates/http_stuff.qtpl:42 + qt422016.ReleaseWriter(qw422016) +//line templates/http_stuff.qtpl:42 +} + +//line templates/http_stuff.qtpl:42 +func HyphaListRowHTML(hyphaName, binaryMime string, binaryPresent bool) string { +//line templates/http_stuff.qtpl:42 + qb422016 := qt422016.AcquireByteBuffer() +//line templates/http_stuff.qtpl:42 + WriteHyphaListRowHTML(qb422016, hyphaName, binaryMime, binaryPresent) +//line templates/http_stuff.qtpl:42 + qs422016 := string(qb422016.B) +//line templates/http_stuff.qtpl:42 + qt422016.ReleaseByteBuffer(qb422016) +//line templates/http_stuff.qtpl:42 + return qs422016 +//line templates/http_stuff.qtpl:42 }