diff options
author | Brian Picciano <mediocregopher@gmail.com> | 2024-05-18 15:55:59 +0200 |
---|---|---|
committer | Brian Picciano <mediocregopher@gmail.com> | 2024-05-18 15:55:59 +0200 |
commit | 93a8843e2e3391459fd333aef9e5c7617608c2b3 (patch) | |
tree | 2e5615cd22d1b39c7d5f870b88e3f29b5c24a223 /src/http/tpl | |
parent | 8d7e708d98a3a46ba3ba08f9c8deeb4838bb8ca5 (diff) |
Remove most rendering related querying from go http handlers
Diffstat (limited to 'src/http/tpl')
-rw-r--r-- | src/http/tpl/draft-posts-manage.html | 26 | ||||
-rw-r--r-- | src/http/tpl/post-assets-manage.html | 6 | ||||
-rw-r--r-- | src/http/tpl/post-edit.html | 34 | ||||
-rw-r--r-- | src/http/tpl/posts-manage.html | 14 | ||||
-rw-r--r-- | src/http/tpl/posts.html | 15 |
5 files changed, 61 insertions, 34 deletions
diff --git a/src/http/tpl/draft-posts-manage.html b/src/http/tpl/draft-posts-manage.html index 5454f24..b1b4362 100644 --- a/src/http/tpl/draft-posts-manage.html +++ b/src/http/tpl/draft-posts-manage.html @@ -1,5 +1,15 @@ {{ define "body" }} + {{ $page := .GetQueryIntValue "p" 0 -}} + {{ $getPostsRes := .GetDraftPosts $page 20 -}} + + <script> + function confirmDelete(event) { + if (!confirm("Are you sure you want to delete this draft?")) + event.preventDefault(); + } + </script> + <p> <a href="{{ BlogURL "admin" }}">Back to Admin</a> </p> @@ -10,15 +20,15 @@ <a href="{{ BlogURL "drafts" }}?method=edit">New Draft</a> </p> - {{ if ge .Payload.PrevPage 0 }} + {{ if gt $page 0 }} <p> - <a href="?method=manage&p={{ .Payload.PrevPage}}">< < Previous Page</a> + <a href="?method=manage&p={{ .Add $page -1 }}">< < Previous Page</a> </p> {{ end }} <table> - {{ range .Payload.Posts }} + {{ range $getPostsRes.Posts }} <tr> <td>{{ .Title }}</td> <td> @@ -31,7 +41,11 @@ action="{{ DraftURL .ID }}?method=delete" method="POST" > - <input type="submit" value="Delete" /> + <input + type="submit" + value="Delete" + onclick="confirmDelete(event)" + /> </form> </td> </tr> @@ -39,9 +53,9 @@ </table> - {{ if ge .Payload.NextPage 0 }} + {{ if $getPostsRes.HasMore }} <p> - <a href="?method=manage&p={{ .Payload.NextPage}}">Next Page > ></a> + <a href="?method=manage&p={{ .Add $page 1 }}">Next Page > ></a> </p> {{ end }} diff --git a/src/http/tpl/post-assets-manage.html b/src/http/tpl/post-assets-manage.html index f21717a..a0b0da0 100644 --- a/src/http/tpl/post-assets-manage.html +++ b/src/http/tpl/post-assets-manage.html @@ -1,5 +1,7 @@ {{ define "body" }} +{{ $assetIDs := .GetPostAssetIDs }} + <p> <a href="{{ BlogURL "admin" }}">Back to Admin</a> </p> @@ -27,13 +29,13 @@ </div> </form> -{{ if gt (len .Payload.IDs) 0 }} +{{ if $assetIDs }} <h2>Existing Assets</h2> <table> - {{ range .Payload.IDs }} + {{ range $assetIDs }} <tr> <td><a href="{{ AssetURL . }}">{{ . }}</a></td> <td> diff --git a/src/http/tpl/post-edit.html b/src/http/tpl/post-edit.html index c66b60a..28dcd0e 100644 --- a/src/http/tpl/post-edit.html +++ b/src/http/tpl/post-edit.html @@ -1,5 +1,9 @@ {{ define "body" }} +{{ $tags := .GetTags }} + +{{ $post := (or (and .Payload.IsDraft .GetThisDraftPost) .GetThisPost) }} + <p> {{ if .Payload.IsDraft }} <a href="{{ BlogURL "drafts?method=manage" }}"> @@ -21,19 +25,19 @@ Unique ID </td> <td> - {{ if eq .Payload.Post.ID "" }} + {{ if eq $post.ID "" }} <input name="id" type="text" required placeholder="e.g. how-to-fly-a-kite" - value="{{ .Payload.Post.ID }}" /> + value="{{ $post.ID }}" /> {{ else if .Payload.IsDraft }} - {{ .Payload.Post.ID }} - <input name="id" type="hidden" value="{{ .Payload.Post.ID }}" /> + {{ $post.ID }} + <input name="id" type="hidden" value="{{ $post.ID }}" /> {{ else }} - <a href="{{ PostURL .Payload.Post.ID }}">{{ .Payload.Post.ID }}</a> - <input name="id" type="hidden" value="{{ .Payload.Post.ID }}" /> + <a href="{{ PostURL $post.ID }}">{{ $post.ID }}</a> + <input name="id" type="hidden" value="{{ $post.ID }}" /> {{ end }} </td> </tr> @@ -45,15 +49,15 @@ name="tags" type="text" required - value="{{- range $i, $tag := .Payload.Post.Tags -}} + value="{{- range $i, $tag := $post.Tags -}} {{- if ne $i 0 }} {{ end }}{{ $tag -}} {{- end -}} "/> - {{ if gt (len .Payload.Tags) 0 }} + {{ if $tags }} <em> Existing tags: - {{ range $i, $tag := .Payload.Tags }} + {{ range $i, $tag := $tags }} {{ if ne $i 0 }} {{ end }}{{ $tag }} {{ end }} </em> @@ -67,7 +71,7 @@ <input name="series" type="text" - value="{{ .Payload.Post.Series }}" /> + value="{{ $post.Series }}" /> </td> </tr> @@ -78,7 +82,7 @@ name="title" type="text" required - value="{{ .Payload.Post.Title }}" /> + value="{{ $post.Title }}" /> </td> </tr> @@ -88,7 +92,7 @@ <input name="description" type="text" - value="{{ .Payload.Post.Description }}" /> + value="{{ $post.Description }}" /> </td> </tr> @@ -98,7 +102,7 @@ <select name="format" required> <option value=""></option> - {{ $format := .Payload.Post.Format }} + {{ $format := $post.Format }} {{ range .Payload.Formats -}} <option {{- if eq . $format }} @@ -122,7 +126,7 @@ placeholder="Post body" style="width:100%;height: 75vh;" > - {{- .Payload.Post.Body -}} + {{- $post.Body -}} </textarea> </p> @@ -131,7 +135,7 @@ <input type="submit" value="Preview" - formaction="{{ BlogURL "posts/" }}{{ .Payload.Post.ID }}?method=preview" + formaction="{{ BlogURL "posts/" }}{{ $post.ID }}?method=preview" formtarget="_blank" /> diff --git a/src/http/tpl/posts-manage.html b/src/http/tpl/posts-manage.html index 96b30ca..f9adbc1 100644 --- a/src/http/tpl/posts-manage.html +++ b/src/http/tpl/posts-manage.html @@ -1,4 +1,8 @@ {{ define "body" }} + + {{ $page := .GetQueryIntValue "p" 0 -}} + {{ $getPostsRes := .GetPosts $page 20 -}} + <script> function confirmDelete(event) { if (!confirm("Are you sure you want to delete this post?")) @@ -12,9 +16,9 @@ <h1>Posts</h1> - {{ if ge .Payload.PrevPage 0 }} + {{ if gt $page 0 }} <p> - <a href="?method=manage&p={{ .Payload.PrevPage}}">< < Previous Page</a> + <a href="?method=manage&p={{ .Add $page -1 }}">< < Previous Page</a> </p> {{ end }} @@ -26,7 +30,7 @@ <col span="1" style="width: auto;"> </colgroup> - {{ range .Payload.Posts }} + {{ range $getPostsRes.Posts }} <tr> <td>{{ .PublishedAt.Local.Format "2006-01-02 15:04:05 MST" }}</td> <td><a href="{{ PostURL .ID }}">{{ .Title }}</a></td> @@ -52,9 +56,9 @@ </table> - {{ if ge .Payload.NextPage 0 }} + {{ if $getPostsRes.HasMore }} <p> - <a href="?method=manage&p={{ .Payload.NextPage}}">Next Page > ></a> + <a href="?method=manage&p={{ .Add $page 1 }}">Next Page > ></a> </p> {{ end }} diff --git a/src/http/tpl/posts.html b/src/http/tpl/posts.html index 0701459..2fa336d 100644 --- a/src/http/tpl/posts.html +++ b/src/http/tpl/posts.html @@ -1,8 +1,11 @@ {{ define "body" }} - {{ if ge .Payload.PrevPage 0 }} + {{ $page := .GetQueryIntValue "p" 0 -}} + {{ $getPostsRes := .GetPosts $page 20 -}} + + {{ if gt $page 0 }} <p> - <a href="?p={{ .Payload.PrevPage}}">< < Previous Page</a> + <a href="?p={{ .Add $page -1 }}">< < Previous Page</a> </p> {{ else }} <p> @@ -12,10 +15,10 @@ {{ end }} <ul> - {{ range .Payload.Posts }} + {{ range $getPostsRes.Posts }} <li> <strong><a href="{{ PostURL .ID }}"> - {{ DateTimeFormat .PublishedAt }} / {{ .Title }} + {{ .PublishedAt.Format "2006-01-02" }} - {{ .Title }} </a></strong> {{ if .Description }} <br/><em>{{ .Description }}</em> @@ -24,9 +27,9 @@ {{ end }} </ul> - {{ if ge .Payload.NextPage 0 }} + {{ if $getPostsRes.HasMore }} <p> - <a href="?p={{ .Payload.NextPage}}">Next Page > ></a> + <a href="?p={{ .Add $page 1 }}">Next Page > ></a> </p> {{ end }} |