aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkg/app/handler/packages/search.go7
-rw-r--r--pkg/app/handler/packages/search.templ61
-rw-r--r--pkg/app/handler/packages/utils.go15
-rw-r--r--web/templates/packages/search.tmpl73
4 files changed, 63 insertions, 93 deletions
diff --git a/pkg/app/handler/packages/search.go b/pkg/app/handler/packages/search.go
index 6562916..ade3982 100644
--- a/pkg/app/handler/packages/search.go
+++ b/pkg/app/handler/packages/search.go
@@ -6,6 +6,7 @@ import (
"encoding/json"
"net/http"
"soko/pkg/app/handler/feeds"
+ "soko/pkg/app/layout"
"soko/pkg/database"
"soko/pkg/models"
"strings"
@@ -65,11 +66,7 @@ func Search(w http.ResponseWriter, r *http.Request) {
return
}
- renderPackageTemplate("search",
- "search",
- GetFuncMap(),
- getSearchData(packages, searchTerm),
- w)
+ layout.Layout(searchTerm, "packages", search(searchTerm, packages)).Render(r.Context(), w)
}
// Search renders a template containing a list of search results
diff --git a/pkg/app/handler/packages/search.templ b/pkg/app/handler/packages/search.templ
new file mode 100644
index 0000000..a42e5b3
--- /dev/null
+++ b/pkg/app/handler/packages/search.templ
@@ -0,0 +1,61 @@
+package packages
+
+import "strconv"
+import "soko/pkg/models"
+
+templ search(query string, packages []models.Package) {
+ <div class="container mb-5">
+ <div class="row">
+ <div class="col-12">
+ <h1 class="first-header">
+ Search Results <small>{ "for " + query }</small>
+ <a title="Atom feed" href={ templ.URL("/packages/search.atom?q=" + query) } class="kk-feed-icon">
+ <span class="fa fa-fw fa-rss-square"></span>
+ </a>
+ </h1>
+ if len(packages) > 0 {
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ Results 1—{ strconv.Itoa(len(packages)) } of { strconv.Itoa(len(packages)) }
+ </div>
+ <div class="list-group">
+ for _, pkg := range packages {
+ <a class="list-group-item list-group-item-action" href={ templ.URL("/packages/" + pkg.Atom) }>
+ <h3 class="kk-search-result-header"><span class="text-muted">{ pkg.Category }/</span>{ pkg.Name }</h3>
+ { pkg.Versions[0].Description }
+ </a>
+ }
+ </div>
+ // TODO paging
+ // <div class="panel-footer">
+ // <div class="btn-group" role="group" aria-label="Result navigation">
+ // <%= link_to '< Prev', search_packages_path(q: params[:q], o: [@offset - PackageRepository.default_search_size, 0].max), class: 'btn btn-default' + (@offset > 0 ? '' : ' disabled') %>
+ // <%= link_to 'Next >', search_packages_path(q: params[:q], o: @offset + PackageRepository.default_search_size), class: 'btn btn-default ' + ((@offset + PackageRepository.default_search_size) > @packages.total ? 'disabled' : '') %>
+ // </div>
+ // </div>
+ </div>
+ // TODO in head: alternate_feed_link(search_packages_url(format: :atom, params: request.query_parameters), t(:atom_feed))
+ } else {
+ <div class="jumbotron">
+ <h2 class="site-welcome stick-top">Nothing found. :( Try again?</h2>
+ <form action="/packages/search" method="get">
+ <div class="typeahead__container">
+ <div class="typeahead__field">
+ <span class="typeahead__query">
+ <input id="q" name="q" type="search" autocomplete="off" placeholder="Find Packages" aria-label="Find Packages" autofocus/>
+ </span>
+ <span class="typeahead__button">
+ <button type="submit" title="Find" aria-label="Find">
+ <span class="typeahead__search-icon"></span><span class="sr-only">Find</span>
+ </button>
+ </span>
+ </div>
+ </div>
+ </form>
+ </div>
+ <script src="/assets/index.js"></script>
+ }
+ </div>
+ </div>
+ </div>
+}
diff --git a/pkg/app/handler/packages/utils.go b/pkg/app/handler/packages/utils.go
index 1195ea4..d169e93 100644
--- a/pkg/app/handler/packages/utils.go
+++ b/pkg/app/handler/packages/utils.go
@@ -142,21 +142,6 @@ func getAtom(r *http.Request) string {
return atom
}
-// getSearchData returns the data used in search templates
-func getSearchData(packages []models.Package, search string) interface{} {
- return struct {
- Header models.Header
- Search string
- Packages []models.Package
- Application models.Application
- }{
- Header: models.Header{Title: search + " – ", Tab: "packages"},
- Search: search,
- Packages: packages,
- Application: utils.GetApplicationData(),
- }
-}
-
// GetFuncMap returns the FuncMap used in templates
func GetFuncMap() template.FuncMap {
return template.FuncMap{
diff --git a/web/templates/packages/search.tmpl b/web/templates/packages/search.tmpl
deleted file mode 100644
index 894d372..0000000
--- a/web/templates/packages/search.tmpl
+++ /dev/null
@@ -1,73 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-{{template "head" .Header}}
-<body>
-{{template "header" .Header}}
-
-<div class="container mb-5">
- <div class="row">
- <div class="col-12">
-
-
- <h1 class="first-header">Search Results <small>for {{.Search}}</small>
- <a title="Atom feed" href="/packages/search.atom?q={{.Search}}" class="kk-feed-icon"><span class="fa fa-fw fa-rss-square"></span></a></h1>
-
- {{ if .Packages }}
- <div class="panel panel-default">
- <div class="panel-heading">
- Results 1—{{len .Packages}} of {{len .Packages}}
- </div>
- <div class="list-group">
- {{range .Packages}}
- <a class="list-group-item list-group-item-action" href="/packages/{{.Atom}}">
- <h3 class="kk-search-result-header"><span class="text-muted">{{.Category}}/</span>{{.Name}}</h3>
- {{ (index .Versions 0).Description}}
- </a>
- {{end}}
- </div>
- <!-- TODO paging
- <div class="panel-footer">
- <div class="btn-group" role="group" aria-label="Result navigation">
- <%= link_to '< Prev', search_packages_path(q: params[:q], o: [@offset - PackageRepository.default_search_size, 0].max), class: 'btn btn-default' + (@offset > 0 ? '' : ' disabled') %>
- <%= link_to 'Next >', search_packages_path(q: params[:q], o: @offset + PackageRepository.default_search_size), class: 'btn btn-default ' + ((@offset + PackageRepository.default_search_size) > @packages.total ? 'disabled' : '') %>
- </div>
- </div>
- -->
-
- </div>
-
- <!-- TODO in head: alternate_feed_link(search_packages_url(format: :atom, params: request.query_parameters), t(:atom_feed)) -->
- {{ else }}
- <div class="jumbotron">
- <h2 class="site-welcome stick-top">Nothing found. :( Try again?</h2>
-
- <form action="/packages/search" method="get">
- <div class="typeahead__container">
- <div class="typeahead__field">
- <span class="typeahead__query">
- <input id="q" name="q" type="search" autocomplete="off" placeholder="Find Packages" aria-label="Find Packages" autofocus>
- </span>
-
- <span class="typeahead__button">
- <button type="submit" title="Find" aria-label="Find">
- <span class="typeahead__search-icon"></span><span class="sr-only">Find</span>
- </button>
- </span>
- </div>
- </div>
- </form>
- </div>
- {{end}}
-
-
- </div>
- </div>
-</div>
-
-
-{{template "footer" .Application }}
-
-<script src="/assets/index.js"></script>
-
-</body>
-</html>