Skip to content

Commit

Permalink
Merge pull request #17 from blackfyre/figure-captions-and-other-metas
Browse files Browse the repository at this point in the history
Figure captions and other metas
  • Loading branch information
blackfyre authored Oct 11, 2023
2 parents 5d694aa + 5b805ff commit e0fe9cb
Show file tree
Hide file tree
Showing 7 changed files with 322 additions and 87 deletions.
2 changes: 1 addition & 1 deletion assets/public/css/style.css

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions assets/views/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<link rel="mask-icon" href="/assets/images/safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#ff0000">
<meta name="theme-color" content="#ffffff">
{{block "head" .}}
{{end}}
</head>

<body>
Expand Down Expand Up @@ -42,6 +44,8 @@
<script src="/assets/js/viewer.min.js"></script>
<script src="/assets/js/htmx.min.js"></script>
<script src="/assets/js/site.js"></script>
{{block "scripts" .}}
{{end}}
</body>

</html>
Expand Down
7 changes: 3 additions & 4 deletions assets/views/pages/artist.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{define "title"}}
Page 1
{{ .Name }} - Web Gallery of Art
{{end}}

{{define "body"}}
Expand All @@ -19,8 +19,6 @@ <h1 class="is-size-1">
({{.BioExcerpt}})
</div>
</div>


</div>
</div>
<div class="container">
Expand All @@ -44,13 +42,14 @@ <h1 class="is-size-1">
<div class="column is-one-third-tablet is-one-quarter-desktop">
<article class="card is-art-card">
<div class="card-image">
<figure class="image is-4by3">
<figure class="image is-4by3 hidden-caption">
<picture>
<source media="(max-width: 768px)" srcset="{{.Thumb}}">
<source media="(min-width: 769px)" srcset="{{.Thumb}}">
<source media="(min-width: 1024px)" srcset="{{.Thumb}}">
<img src="{{.Image}}" alt="{{ .Title}}">
</picture>
<figcaption>{{.Title}} - {{ .Technique }}</figcaption>
</figure>
</div>
<div class="card-content">
Expand Down
156 changes: 77 additions & 79 deletions assets/views/pages/artists.html
Original file line number Diff line number Diff line change
@@ -1,93 +1,91 @@
{{define "title"}}
Artists
Artists - Web Gallery of Art
{{end}}

{{define "body"}}
{{block "artists:content" .}}
<section class="section">

<div class="container">
<div class="box table-container">

<table class="table is-hoverable has-sticky-header">
<thead>
<tr>
<th>
ARTIST
</th>
<th>
BORN-DIED
</th>
<th>
School(s)
</th>
<th>
Profession
</th>

</tr>
</thead>
<tbody>
<div class="box">
<nav class="level">
<div class="level-left">
<div class="level-item">
<p class="subtitle is-5">
<strong>{{.Count}}</strong> artists
</p>
</div>
<div class="level-item">
<div class="field has-addons">
<p class="control">
<input class="input" type="search" name="q" placeholder="Find an artist"
hx-get="/artists" hx-trigger="keyup changed delay:500ms, search"
hx-target="#search-results">
</p>
</div>
</div>
</div>
</nav>
<div id="search-results">
{{block "artists:search-results" .}}
<div class="table-container">
<table class="table is-hoverable is-fullwidth">
<thead>
<tr>
<th>
ARTIST
</th>
<th>
BORN-DIED
</th>
<th>
School(s)
</th>
<th>
Profession
</th>

{{range .Content}}
<tr>
<td><a href="{{.Url}}" hx-get="{{.Url}}" hx-target="#mc-area"><b>{{.Name}}</b></a></td>
<td>{{.BornDied}}</td>
<td>{{.Schools}}</td>
<td>{{.Profession}}</td>
</tr>
{{else}}
<tr>
<td colspan="4">meh</td>
</tr>
{{end}}
</tr>
</thead>
<tbody>

</tbody>
<tfoot>
<tr>
<th>
ARTIST
</th>
<th>
BORN-DIED
</th>
<th>
PERIOD
</th>
<th>
SCHOOL
</th>
</tr>
</tfoot>
</table>
{{range .Content}}
<tr>
<td><a href="{{.Url}}" hx-get="{{.Url}}" hx-target="#mc-area"><b>{{.Name}}</b></a></td>
<td>{{.BornDied}}</td>
<td>{{.Schools}}</td>
<td>{{.Profession}}</td>
</tr>
{{else}}
<tr>
<td colspan="4">meh</td>
</tr>
{{end}}
</tbody>
<tfoot>
<tr>
<th>
ARTIST
</th>
<th>
BORN-DIED
</th>
<th>
PERIOD
</th>
<th>
SCHOOL
</th>
</tr>
</tfoot>
</table>
</div>

<nav class="pagination" role="navigation" aria-label="pagination">
<a class="pagination-previous">Previous</a>
<a class="pagination-next">Next page</a>
<ul class="pagination-list">
<li>
<a class="pagination-link" aria-label="Goto page 1">1</a>
</li>
<li>
<span class="pagination-ellipsis">&hellip;</span>
</li>
<li>
<a class="pagination-link" aria-label="Goto page 45">45</a>
</li>
<li>
<a class="pagination-link is-current" aria-label="Page 46" aria-current="page">46</a>
</li>
<li>
<a class="pagination-link" aria-label="Goto page 47">47</a>
</li>
<li>
<span class="pagination-ellipsis">&hellip;</span>
</li>
<li>
<a class="pagination-link" aria-label="Goto page 86">86</a>
</li>
</ul>
</nav>
<nav class="pagination" role="navigation" aria-label="pagination">
{{.Pagination}}
</nav>
{{end}}
</div>
</div>
</div>

Expand Down
57 changes: 54 additions & 3 deletions handlers/artists.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"strconv"
"strings"

"blackfyre.ninja/wga/utils"
"github.com/labstack/echo/v5"
"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/apis"
"github.com/pocketbase/pocketbase/core"
Expand All @@ -20,6 +22,8 @@ func registerArtists(app *pocketbase.PocketBase) {

limit := 30
page := 1
searchExpression := ""
searchExpressionPresent := false

if c.QueryParam("page") != "" {
err := error(nil)
Expand All @@ -30,24 +34,58 @@ func registerArtists(app *pocketbase.PocketBase) {
}
}

if c.QueryParam("q") != "" {
searchExpression = c.QueryParam("q")
}

if c.QueryParams().Has("q") {
searchExpressionPresent = true
}

offset := (page - 1) * limit

data := map[string]any{
"Content": "",
}

filter := "published = true"

if searchExpression != "" {
filter = filter + " && name ~ {:searchExpression}"
}

records, err := app.Dao().FindRecordsByFilter(
"artists",
"published = true",
filter,
"+name",
limit,
offset,
dbx.Params{
"searchExpression": searchExpression,
},
)

if err != nil {
return apis.NewBadRequestError("Invalid page", err)
}

totalRecords, err := app.Dao().FindRecordsByFilter(
"artists",
filter,
"+name",
0,
0,
dbx.Params{
"searchExpression": searchExpression,
},
)

if err != nil {
return apis.NewBadRequestError("Invalid page", err)
}

recordsCount := len(totalRecords)

preRendered := []map[string]string{}

for _, m := range records {
Expand Down Expand Up @@ -82,11 +120,22 @@ func registerArtists(app *pocketbase.PocketBase) {
}

data["Content"] = preRendered
data["Count"] = recordsCount

pagination := utils.NewPagination(recordsCount, limit, page, "/artists?q="+searchExpression)

data["Pagination"] = pagination.Render()

html := ""

if isHtmxRequest(c) {
html, err = renderBlock("artists:content", data)
blockToRender := "artists:content"

if searchExpression != "" || searchExpressionPresent {
blockToRender = "artists:search-results"
}

html, err = renderBlock(blockToRender, data)
} else {
html, err = renderPage("artists", data)
}
Expand All @@ -96,7 +145,9 @@ func registerArtists(app *pocketbase.PocketBase) {
return apis.NewNotFoundError("", err)
}

c.Response().Header().Set("HX-Push-Url", "/artists")
currentUrl := c.Request().URL.String()

c.Response().Header().Set("HX-Push-Url", currentUrl)

return c.HTML(http.StatusOK, html)
})
Expand Down
Loading

0 comments on commit e0fe9cb

Please sign in to comment.