Pre-select current $running when modifying it

Implements: https://todo.sr.ht/~amolith/willow/25
This commit is contained in:
Amolith 2023-11-28 20:01:26 -05:00
parent 61c551ade4
commit 8ca0376243
Signed by: Amolith
GPG Key ID: 8AE30347CE28D101
3 changed files with 41 additions and 24 deletions

View File

@ -196,12 +196,14 @@ func RefreshLoop(dbConn *sql.DB, interval int, manualRefresh, req *chan struct{}
// GetProject returns a project from the database
func GetProject(dbConn *sql.DB, url string) (Project, error) {
var p Project
projectDB, err := db.GetProject(dbConn, url)
if err != nil {
return p, err
return Project{}, err
}
p = Project{
if len(projectDB) == 0 {
return Project{}, nil
}
p := Project{
URL: projectDB["url"],
Name: projectDB["name"],
Forge: projectDB["forge"],

View File

@ -24,8 +24,9 @@
<p>Which release of {{ .Name }} are you currently running?</p>
{{- $url := .URL -}}
{{- $forge := .Forge -}}
{{- $running := .Running -}}
{{- range .Releases -}}
<input type="radio" id="{{ .Tag }}" name="release" value="{{ .Tag }}">
<input type="radio" id="{{ .Tag }}" name="release" value="{{ .Tag }}" {{- if eq $running .Tag }} checked {{- end -}}>
{{- if ne .URL "" -}}
<label for="{{ .Tag }}"><a href="{{ .URL }}">{{ .Tag }}</a></label><br>
{{- else -}}
@ -44,7 +45,7 @@
<input type="hidden" name="forge" value="{{ .Forge }}">
<input class="button" type="submit" formaction="/new" value="Track future releases">
</form>
<!-- Append these if they ever start limited RSS entries: `(eq $forge "gitea") (eq $forge "forgejo")` -->
<!-- Append these if they ever start limiting RSS entries: `(eq $forge "gitea") (eq $forge "forgejo")` -->
{{- if or (eq $forge "github") -}}
<small>Some RSS feeds (notably GitHub's) include a limited number of releases. If you don't see your version, please change the forge type to "Other".</small>
{{- end -}}

View File

@ -73,35 +73,48 @@ func (h Handler) NewHandler(w http.ResponseWriter, r *http.Request) {
return
}
forge := bmStrict.Sanitize(params.Get("forge"))
if forge == "" {
proj, err := project.GetProject(h.DbConn, submittedURL)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
_, err := w.Write([]byte("No forge provided"))
_, err := w.Write([]byte(fmt.Sprintf("Error getting project: %s", err)))
if err != nil {
fmt.Println(err)
}
return
}
name := bmStrict.Sanitize(params.Get("name"))
if name == "" {
w.WriteHeader(http.StatusBadRequest)
_, err := w.Write([]byte("No name provided"))
if err != nil {
fmt.Println(err)
if proj.Running == "" {
forge := bmStrict.Sanitize(params.Get("forge"))
if forge == "" {
w.WriteHeader(http.StatusBadRequest)
_, err := w.Write([]byte("No forge provided"))
if err != nil {
fmt.Println(err)
}
return
}
return
name := bmStrict.Sanitize(params.Get("name"))
if name == "" {
w.WriteHeader(http.StatusBadRequest)
_, err := w.Write([]byte("No name provided"))
if err != nil {
fmt.Println(err)
}
return
}
proj = project.Project{
URL: submittedURL,
Name: name,
Forge: forge,
}
proj.URL = strings.TrimSuffix(proj.URL, ".git")
}
proj := project.Project{
URL: submittedURL,
Name: name,
Forge: forge,
}
proj.URL = strings.TrimSuffix(proj.URL, ".git")
proj, err := project.GetReleases(h.DbConn, proj)
proj, err = project.GetReleases(h.DbConn, proj)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
_, err := w.Write([]byte(fmt.Sprintf("Error getting releases: %s", err)))
@ -110,6 +123,7 @@ func (h Handler) NewHandler(w http.ResponseWriter, r *http.Request) {
}
return
}
tmpl := template.Must(template.ParseFS(fs, "static/select-release.html"))
if err := tmpl.Execute(w, proj); err != nil {
fmt.Println(err)