Pre-select current $running when modifying it
Implements: https://todo.sr.ht/~amolith/willow/25
This commit is contained in:
parent
61c551ade4
commit
8ca0376243
|
@ -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"],
|
||||
|
|
|
@ -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 -}}
|
||||
|
|
18
ws/ws.go
18
ws/ws.go
|
@ -73,6 +73,17 @@ func (h Handler) NewHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
proj, err := project.GetProject(h.DbConn, submittedURL)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
_, err := w.Write([]byte(fmt.Sprintf("Error getting project: %s", err)))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if proj.Running == "" {
|
||||
forge := bmStrict.Sanitize(params.Get("forge"))
|
||||
if forge == "" {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
|
@ -93,7 +104,7 @@ func (h Handler) NewHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
proj := project.Project{
|
||||
proj = project.Project{
|
||||
URL: submittedURL,
|
||||
Name: name,
|
||||
Forge: forge,
|
||||
|
@ -101,7 +112,9 @@ func (h Handler) NewHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue