aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-02-13 10:54:01 +0800
committerRunxi Yu <me@runxiyu.org>2025-02-13 10:54:01 +0800
commitd8cfbf4d10788ef0f3bf730d824734c496602b0c (patch)
tree9b8a1d14db8022a83921c3de89a98b085d23b52d
parentrepo_log: Scrollable view (diff)
downloadforge-d8cfbf4d10788ef0f3bf730d824734c496602b0c.tar.gz
forge-d8cfbf4d10788ef0f3bf730d824734c496602b0c.tar.zst
forge-d8cfbf4d10788ef0f3bf730d824734c496602b0c.zip
group_index: Use table list
-rw-r--r--http_handle_group_index.go25
-rw-r--r--templates/group_repos.html.tmpl23
2 files changed, 36 insertions, 12 deletions
diff --git a/http_handle_group_index.go b/http_handle_group_index.go
index c694914..cd71101 100644
--- a/http_handle_group_index.go
+++ b/http_handle_group_index.go
@@ -7,16 +7,33 @@ import (
func handle_group_repos(w http.ResponseWriter, r *http.Request, params map[string]any) {
group_name := params["group_name"]
- names, err := query_list[string](r.Context(), "SELECT r.name FROM repos r JOIN groups g ON r.group_id = g.id WHERE g.name = $1;", group_name)
+ rows, err := database.Query(r.Context(), "SELECT r.name, COALESCE(r.description, '') FROM repos r JOIN groups g ON r.group_id = g.id WHERE g.name = $1;", group_name)
if err != nil {
- http.Error(w, "Error getting groups:: "+err.Error(), http.StatusInternalServerError)
+ http.Error(w, "Error getting groups: "+err.Error(), http.StatusInternalServerError)
return
}
- params["repos"] = names
+ defer rows.Close()
+
+ repos := []struct {
+ Name string
+ Description string
+ }{}
+ for rows.Next() {
+ var repoName, repoDescription string
+ if err := rows.Scan(&repoName, &repoDescription); err != nil {
+ http.Error(w, "Error scanning repo: "+err.Error(), http.StatusInternalServerError)
+ return
+ }
+ repos = append(repos, struct {
+ Name string
+ Description string
+ }{repoName, repoDescription})
+ }
+ params["repos"] = repos
err = templates.ExecuteTemplate(w, "group_repos", params)
if err != nil {
- http.Error(w, "Error rendering template:: "+err.Error(), http.StatusInternalServerError)
+ http.Error(w, "Error rendering template: "+err.Error(), http.StatusInternalServerError)
return
}
}
diff --git a/templates/group_repos.html.tmpl b/templates/group_repos.html.tmpl
index c9c12fd..3166565 100644
--- a/templates/group_repos.html.tmpl
+++ b/templates/group_repos.html.tmpl
@@ -8,16 +8,23 @@
<body class="group-repos">
{{ template "header" . }}
<div class="padding-wrapper">
- <h1>
- Repos in {{ .group_name }}
- </h1>
- <ul>
+ <table class="wide">
+ <thead>
+ <tr>
+ <th colspan="2" class="title-row">Repos in {{ .group_name }}</th>
+ </tr>
+ </thead>
+ <tbody>
{{- range .repos }}
- <li>
- <a href="{{ . }}/">{{ . }}</a>
- </li>
+ <td>
+ <a href="{{ .Name }}/">{{ .Name }}</a>
+ </td>
+ <td>
+ {{ .Description }}
+ </td>
{{- end }}
- </ul>
+ </tbody>
+ </table>
</div>
<footer>
{{ template "footer" . }}