Add inspections to cell page

This commit is contained in:
Eli Ribble 2025-11-19 22:30:01 +00:00
parent 7b13b4b1ad
commit aab9bd0c44
No known key found for this signature in database
2 changed files with 57 additions and 16 deletions

43
html.go
View file

@ -82,6 +82,7 @@ type ContentAuthenticatedPlaceholder struct {
type ContentCell struct { type ContentCell struct {
BreedingSources []BreedingSource BreedingSources []BreedingSource
CellBoundary h3.CellBoundary CellBoundary h3.CellBoundary
Inspections []Inspection
MapData ComponentMap MapData ComponentMap
Treatments []Treatment Treatments []Treatment
User User User User
@ -117,6 +118,13 @@ type LatLng struct {
Lat float64 Lat float64
Lng float64 Lng float64
} }
type Inspection struct {
Action string
Date time.Time
Notes string
Location string
LocationID string
}
type Link struct { type Link struct {
Href string Href string
Title string Title string
@ -219,6 +227,11 @@ func htmlCell(ctx context.Context, w http.ResponseWriter, user *models.User, c i
respondError(w, "Failed to get boundary", err, http.StatusInternalServerError) respondError(w, "Failed to get boundary", err, http.StatusInternalServerError)
return return
} }
inspections, err := inspectionsByCell(ctx, org, h3.Cell(c))
if err != nil {
respondError(w, "Failed to get inspections", err, http.StatusInternalServerError)
return
}
geojson, err := h3ToGeoJSON([]h3.Cell{h3.Cell(c)}) geojson, err := h3ToGeoJSON([]h3.Cell{h3.Cell(c)})
if err != nil { if err != nil {
respondError(w, "Failed to get boundaries", err, http.StatusInternalServerError) respondError(w, "Failed to get boundaries", err, http.StatusInternalServerError)
@ -238,6 +251,7 @@ func htmlCell(ctx context.Context, w http.ResponseWriter, user *models.User, c i
data := ContentCell{ data := ContentCell{
BreedingSources: sources, BreedingSources: sources,
CellBoundary: boundary, CellBoundary: boundary,
Inspections: inspections,
MapData: ComponentMap{ MapData: ComponentMap{
Center: LatLng{ Center: LatLng{
Lat: center.Lat, Lat: center.Lat,
@ -612,6 +626,8 @@ func treatmentsByCell(ctx context.Context, org *models.Organization, c h3.Cell)
sm.Where( sm.Where(
psql.F("ST_Within", "geom", geom_query), psql.F("ST_Within", "geom", geom_query),
), ),
sm.OrderBy("pointlocid"),
sm.OrderBy("enddatetime"),
).All(ctx, PGInstance.BobDB) ).All(ctx, PGInstance.BobDB)
if err != nil { if err != nil {
return results, fmt.Errorf("Failed to query rows: %w", err) return results, fmt.Errorf("Failed to query rows: %w", err)
@ -626,6 +642,33 @@ func treatmentsByCell(ctx context.Context, org *models.Organization, c h3.Cell)
} }
return results, nil return results, nil
} }
func inspectionsByCell(ctx context.Context, org *models.Organization, c h3.Cell) ([]Inspection, error) {
var results []Inspection
boundary, err := c.Boundary()
if err != nil {
return results, fmt.Errorf("Failed to get cell boundary: %w", err)
}
geom_query := gisStatement(boundary)
rows, err := org.FSMosquitoinspections(
sm.Where(
psql.F("ST_Within", "geom", geom_query),
),
).All(ctx, PGInstance.BobDB)
if err != nil {
return results, fmt.Errorf("Failed to query rows: %w", err)
}
for _, r := range rows {
results = append(results, Inspection{
Action: r.Actiontaken.GetOr("none"),
Date: *fsTimestampToTime(r.Enddatetime),
Notes: r.Comments.GetOr("none"),
Location: r.Locationname.GetOr("none"),
LocationID: r.Pointlocid.GetOr(""),
})
}
return results, nil
}
func breedingSourcesByCell(ctx context.Context, org *models.Organization, c h3.Cell) ([]BreedingSource, error) { func breedingSourcesByCell(ctx context.Context, org *models.Organization, c h3.Cell) ([]BreedingSource, error) {
var results []BreedingSource var results []BreedingSource

View file

@ -118,31 +118,28 @@
<table class="table table-striped table-hover"> <table class="table table-striped table-hover">
<thead> <thead>
<tr> <tr>
<th>Approximate Address</th> <th>LocationID</th>
<th>Inspection Date</th> <th>Location</th>
<th>Technician Comments</th> <th>Date</th>
<th>Action</th>
<th>Notes</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{{ range .Inspections }}
<tr> <tr>
<td>123 Main St</td> <td>{{.LocationID|uuidShort}}</td>
<td>04/15/2023</td> <td>{{.Location}}</td>
<td>Found larvae in standing water near gutter downspout.</td> <td>{{.Date|timeSince}}</td>
</tr> <td>{{.Action}}</td>
<tr> <td>{{.Notes}}</td>
<td>125 Main St</td>
<td>04/15/2023</td>
<td>Catch basin had moderate larvae activity.</td>
</tr>
<tr>
<td>130 Main St</td>
<td>04/14/2023</td>
<td>Drainage ditch showing signs of mosquito breeding.</td>
</tr> </tr>
{{ end }}
</tbody> </tbody>
</table> </table>
</div> </div>
<!--
<nav aria-label="Inspections pagination"> <nav aria-label="Inspections pagination">
<ul class="pagination justify-content-center"> <ul class="pagination justify-content-center">
<li class="page-item disabled"> <li class="page-item disabled">
@ -156,6 +153,7 @@
</li> </li>
</ul> </ul>
</nav> </nav>
-->
</div> </div>
</div> </div>
</div> </div>