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
|
// GetProject returns a project from the database
|
||||||
func GetProject(dbConn *sql.DB, url string) (Project, error) {
|
func GetProject(dbConn *sql.DB, url string) (Project, error) {
|
||||||
var p Project
|
|
||||||
projectDB, err := db.GetProject(dbConn, url)
|
projectDB, err := db.GetProject(dbConn, url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return p, err
|
return Project{}, err
|
||||||
}
|
}
|
||||||
p = Project{
|
if len(projectDB) == 0 {
|
||||||
|
return Project{}, nil
|
||||||
|
}
|
||||||
|
p := Project{
|
||||||
URL: projectDB["url"],
|
URL: projectDB["url"],
|
||||||
Name: projectDB["name"],
|
Name: projectDB["name"],
|
||||||
Forge: projectDB["forge"],
|
Forge: projectDB["forge"],
|
||||||
|
|
|
@ -24,8 +24,9 @@
|
||||||
<p>Which release of {{ .Name }} are you currently running?</p>
|
<p>Which release of {{ .Name }} are you currently running?</p>
|
||||||
{{- $url := .URL -}}
|
{{- $url := .URL -}}
|
||||||
{{- $forge := .Forge -}}
|
{{- $forge := .Forge -}}
|
||||||
|
{{- $running := .Running -}}
|
||||||
{{- range .Releases -}}
|
{{- 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 "" -}}
|
{{- if ne .URL "" -}}
|
||||||
<label for="{{ .Tag }}"><a href="{{ .URL }}">{{ .Tag }}</a></label><br>
|
<label for="{{ .Tag }}"><a href="{{ .URL }}">{{ .Tag }}</a></label><br>
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
|
@ -44,7 +45,7 @@
|
||||||
<input type="hidden" name="forge" value="{{ .Forge }}">
|
<input type="hidden" name="forge" value="{{ .Forge }}">
|
||||||
<input class="button" type="submit" formaction="/new" value="Track future releases">
|
<input class="button" type="submit" formaction="/new" value="Track future releases">
|
||||||
</form>
|
</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") -}}
|
{{- 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>
|
<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 -}}
|
{{- end -}}
|
||||||
|
|
18
ws/ws.go
18
ws/ws.go
|
@ -73,6 +73,17 @@ func (h Handler) NewHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
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"))
|
forge := bmStrict.Sanitize(params.Get("forge"))
|
||||||
if forge == "" {
|
if forge == "" {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
@ -93,7 +104,7 @@ func (h Handler) NewHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
proj := project.Project{
|
proj = project.Project{
|
||||||
URL: submittedURL,
|
URL: submittedURL,
|
||||||
Name: name,
|
Name: name,
|
||||||
Forge: forge,
|
Forge: forge,
|
||||||
|
@ -101,7 +112,9 @@ func (h Handler) NewHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
proj.URL = strings.TrimSuffix(proj.URL, ".git")
|
proj.URL = strings.TrimSuffix(proj.URL, ".git")
|
||||||
|
|
||||||
proj, err := project.GetReleases(h.DbConn, proj)
|
}
|
||||||
|
|
||||||
|
proj, err = project.GetReleases(h.DbConn, proj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
_, err := w.Write([]byte(fmt.Sprintf("Error getting releases: %s", err)))
|
_, 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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpl := template.Must(template.ParseFS(fs, "static/select-release.html"))
|
tmpl := template.Must(template.ParseFS(fs, "static/select-release.html"))
|
||||||
if err := tmpl.Execute(w, proj); err != nil {
|
if err := tmpl.Execute(w, proj); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|
Loading…
Reference in New Issue