Add inspections to cell page
This commit is contained in:
parent
7b13b4b1ad
commit
aab9bd0c44
2 changed files with 57 additions and 16 deletions
43
html.go
43
html.go
|
|
@ -82,6 +82,7 @@ type ContentAuthenticatedPlaceholder struct {
|
|||
type ContentCell struct {
|
||||
BreedingSources []BreedingSource
|
||||
CellBoundary h3.CellBoundary
|
||||
Inspections []Inspection
|
||||
MapData ComponentMap
|
||||
Treatments []Treatment
|
||||
User User
|
||||
|
|
@ -117,6 +118,13 @@ type LatLng struct {
|
|||
Lat float64
|
||||
Lng float64
|
||||
}
|
||||
type Inspection struct {
|
||||
Action string
|
||||
Date time.Time
|
||||
Notes string
|
||||
Location string
|
||||
LocationID string
|
||||
}
|
||||
type Link struct {
|
||||
Href 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)
|
||||
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)})
|
||||
if err != nil {
|
||||
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{
|
||||
BreedingSources: sources,
|
||||
CellBoundary: boundary,
|
||||
Inspections: inspections,
|
||||
MapData: ComponentMap{
|
||||
Center: LatLng{
|
||||
Lat: center.Lat,
|
||||
|
|
@ -612,6 +626,8 @@ func treatmentsByCell(ctx context.Context, org *models.Organization, c h3.Cell)
|
|||
sm.Where(
|
||||
psql.F("ST_Within", "geom", geom_query),
|
||||
),
|
||||
sm.OrderBy("pointlocid"),
|
||||
sm.OrderBy("enddatetime"),
|
||||
).All(ctx, PGInstance.BobDB)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
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) {
|
||||
var results []BreedingSource
|
||||
|
||||
|
|
|
|||
|
|
@ -118,31 +118,28 @@
|
|||
<table class="table table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Approximate Address</th>
|
||||
<th>Inspection Date</th>
|
||||
<th>Technician Comments</th>
|
||||
<th>LocationID</th>
|
||||
<th>Location</th>
|
||||
<th>Date</th>
|
||||
<th>Action</th>
|
||||
<th>Notes</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range .Inspections }}
|
||||
<tr>
|
||||
<td>123 Main St</td>
|
||||
<td>04/15/2023</td>
|
||||
<td>Found larvae in standing water near gutter downspout.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<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>
|
||||
<td>{{.LocationID|uuidShort}}</td>
|
||||
<td>{{.Location}}</td>
|
||||
<td>{{.Date|timeSince}}</td>
|
||||
<td>{{.Action}}</td>
|
||||
<td>{{.Notes}}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
<nav aria-label="Inspections pagination">
|
||||
<ul class="pagination justify-content-center">
|
||||
<li class="page-item disabled">
|
||||
|
|
@ -156,6 +153,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
-->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue