Add district list to report mosquitoes online
Makes it easier at a conference to find the district we're talking to
This commit is contained in:
parent
b77d9aa80a
commit
7ee2f72b8e
3 changed files with 65 additions and 0 deletions
|
|
@ -3,17 +3,28 @@ package rmo
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/html"
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
type ContentDistrict struct {
|
||||
Name string
|
||||
URLLogo string
|
||||
URLRMO string
|
||||
URLWebsite string
|
||||
}
|
||||
type ContentDistrictList struct {
|
||||
Districts []ContentDistrict
|
||||
URL ContentURL
|
||||
}
|
||||
|
||||
var (
|
||||
DistrictListT = buildTemplate("district-list", "base")
|
||||
)
|
||||
|
||||
func districtBySlug(r *http.Request) (*models.Organization, error) {
|
||||
slug := chi.URLParam(r, "slug")
|
||||
|
|
@ -22,6 +33,30 @@ func districtBySlug(r *http.Request) (*models.Organization, error) {
|
|||
).One(r.Context(), db.PGInstance.BobDB)
|
||||
return district, err
|
||||
}
|
||||
func getDistrictList(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
rows, err := models.Organizations.Query(
|
||||
models.SelectWhere.Organizations.ImportDistrictGid.IsNotNull(),
|
||||
sm.OrderBy("name"),
|
||||
).All(ctx, db.PGInstance.BobDB)
|
||||
if err != nil {
|
||||
respondError(w, "failed to query for districts", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
districts := make([]ContentDistrict, 0)
|
||||
for _, row := range rows {
|
||||
districts = append(districts, *newContentDistrict(row))
|
||||
}
|
||||
html.RenderOrError(
|
||||
w,
|
||||
DistrictListT,
|
||||
ContentDistrictList{
|
||||
Districts: districts,
|
||||
URL: makeContentURL(nil),
|
||||
},
|
||||
)
|
||||
|
||||
}
|
||||
func newContentDistrict(d *models.Organization) *ContentDistrict {
|
||||
if d == nil {
|
||||
return nil
|
||||
|
|
@ -29,6 +64,7 @@ func newContentDistrict(d *models.Organization) *ContentDistrict {
|
|||
return &ContentDistrict{
|
||||
Name: d.Name,
|
||||
URLLogo: config.MakeURLNidus("/api/district/%s/logo", d.Slug.GetOr("unset")),
|
||||
URLRMO: config.MakeURLReport("/district/%s", d.Slug.GetOr("unset")),
|
||||
URLWebsite: d.Website.GetOr(""),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ func Router() chi.Router {
|
|||
r.Get("/water", getWater)
|
||||
r.Post("/water", postWater)
|
||||
|
||||
r.Get("/district", getDistrictList)
|
||||
r.Get("/district/{slug}", getRootDistrict)
|
||||
r.Get("/district/{slug}/nuisance", getNuisanceDistrict)
|
||||
//r.Get("/district/{slug}/nuisance-submit-complete", renderMock(mockNuisanceSubmitCompleteT))
|
||||
|
|
|
|||
28
rmo/template/district-list.html
Normal file
28
rmo/template/district-list.html
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{{template "base.html" .}}
|
||||
|
||||
{{define "title"}}Districts{{end}}
|
||||
{{define "extraheader"}}
|
||||
{{end}}
|
||||
{{define "content"}}
|
||||
<!-- Main Content -->
|
||||
<main>
|
||||
<h1>District List</h1>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Logo</th>
|
||||
<th>Name</th>
|
||||
<th>URL</th>
|
||||
</tr>
|
||||
{{ range .Districts }}
|
||||
<tr>
|
||||
<td><a href="{{.URLWebsite}}"><img src="{{.URLLogo}}"></img></a></td>
|
||||
<td>{{.Name}}</td>
|
||||
<td><a href="{{.URLRMO}}">{{.URLRMO}}</a></td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</main>
|
||||
|
||||
{{end}}
|
||||
Loading…
Add table
Add a link
Reference in a new issue