aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-02-13 10:29:57 +0800
committerRunxi Yu <me@runxiyu.org>2025-02-13 10:31:31 +0800
commitac956e5521b4ad1cce1f978cc1aef51e6aeb9480 (patch)
tree75a907b803a83452a5e0e8f5315458fa302059e8
parentdatabase.go: query_list[T any] (diff)
downloadforge-ac956e5521b4ad1cce1f978cc1aef51e6aeb9480.tar.gz
forge-ac956e5521b4ad1cce1f978cc1aef51e6aeb9480.tar.zst
forge-ac956e5521b4ad1cce1f978cc1aef51e6aeb9480.zip
index: Reformat the page
-rw-r--r--database.go1
-rw-r--r--http_handle_group_index.go4
-rw-r--r--http_handle_index.go24
-rw-r--r--schema.sql3
-rw-r--r--templates/index.html.tmpl44
5 files changed, 49 insertions, 27 deletions
diff --git a/database.go b/database.go
index cf4f4ba..a583211 100644
--- a/database.go
+++ b/database.go
@@ -26,4 +26,3 @@ func query_list[T any](ctx context.Context, query string, args ...any) ([]T, err
return result, nil
}
-
diff --git a/http_handle_group_index.go b/http_handle_group_index.go
index 834c0da..c694914 100644
--- a/http_handle_group_index.go
+++ b/http_handle_group_index.go
@@ -9,8 +9,8 @@ func handle_group_repos(w http.ResponseWriter, r *http.Request, params map[strin
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)
if err != nil {
- http.Error(w, "Error getting groups:: "+err.Error(), http.StatusInternalServerError)
- return
+ http.Error(w, "Error getting groups:: "+err.Error(), http.StatusInternalServerError)
+ return
}
params["repos"] = names
diff --git a/http_handle_index.go b/http_handle_index.go
index 8066a03..e36332d 100644
--- a/http_handle_index.go
+++ b/http_handle_index.go
@@ -5,25 +5,31 @@ import (
)
func handle_index(w http.ResponseWriter, r *http.Request, params map[string]any) {
- rows, err := database.Query(r.Context(), "SELECT name FROM groups")
+ rows, err := database.Query(r.Context(), "SELECT name, COALESCE(description, '') FROM groups")
if err != nil {
- http.Error(w, "Error querying groups: : "+err.Error(), http.StatusInternalServerError)
+ http.Error(w, "Error querying groups: "+err.Error(), http.StatusInternalServerError)
return
}
defer rows.Close()
- groups := []string{}
+ groups := []struct {
+ Name string
+ Description string
+ }{}
for rows.Next() {
- var groupName string
- if err := rows.Scan(&groupName); err != nil {
- http.Error(w, "Error scanning group name: : "+err.Error(), http.StatusInternalServerError)
+ var groupName, groupDescription string
+ if err := rows.Scan(&groupName, &groupDescription); err != nil {
+ http.Error(w, "Error scanning group: "+err.Error(), http.StatusInternalServerError)
return
}
- groups = append(groups, groupName)
+ groups = append(groups, struct {
+ Name string
+ Description string
+ }{groupName, groupDescription})
}
if err := rows.Err(); err != nil {
- http.Error(w, "Error iterating over rows: : "+err.Error(), http.StatusInternalServerError)
+ http.Error(w, "Error iterating over rows: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -31,7 +37,7 @@ func handle_index(w http.ResponseWriter, r *http.Request, params map[string]any)
err = templates.ExecuteTemplate(w, "index", 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/schema.sql b/schema.sql
index aa5e38e..0aaebd8 100644
--- a/schema.sql
+++ b/schema.sql
@@ -1,6 +1,7 @@
CREATE TABLE groups (
id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
- name TEXT NOT NULL UNIQUE
+ name TEXT NOT NULL UNIQUE,
+ description TEXT
);
CREATE TABLE repos (
diff --git a/templates/index.html.tmpl b/templates/index.html.tmpl
index 50cd489..c725948 100644
--- a/templates/index.html.tmpl
+++ b/templates/index.html.tmpl
@@ -8,21 +8,37 @@
<body class="index">
{{ template "header" . }}
<div class="padding-wrapper">
- <h1>Lindenii Forge</h1>
- <h2>
- Groups
- </h2>
- <ul>
- {{- range .groups }}
- <li>
- <a href="{{ . }}/:/repos/">{{ . }}</a>
- </li>
- {{- end }}
- </ul>
- <h2>
- Info
- </h2>
<table class="wide">
+ <thead>
+ <tr>
+ <th colspan="2" class="title-row">
+ Groups
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ {{- range .groups }}
+ <tr>
+ <td>
+ <a href="{{ .Name }}/:/repos/">{{ .Name }}</a>
+ </td>
+ <td>
+ {{ .Description }}
+ </td>
+ </tr>
+ {{- end }}
+ </tbody>
+ </table>
+ </div>
+ <div class="padding-wrapper">
+ <table class="wide">
+ <thead>
+ <tr>
+ <th colspan="2" class="title-row">
+ Info
+ </th>
+ </tr>
+ </thead>
<tbody>
<tr>
<th scope="row">SSH Public Key</th>