diff --git a/htmlpage/static/js/map-aggregate.js b/htmlpage/static/js/map-aggregate.js index 6c912eb0..11175360 100644 --- a/htmlpage/static/js/map-aggregate.js +++ b/htmlpage/static/js/map-aggregate.js @@ -132,14 +132,13 @@ class MapAggregate extends HTMLElement { 'fill-color': '#0dcaf0' } }); - var self = this; map.addInteraction("tegola-click-interaction", { type: "click", target: { layerId: "mosquito_source" }, handler: (e) => { const coordinates = e.feature.geometry.coordinates.slice(); const properties = e.feature.properties; - self.dispatchEvent(new CustomEvent("cell-click", { + this.dispatchEvent(new CustomEvent("cell-click", { bubbles: true, composed: true, // Allows event to cross shadow DOM boundary detail: { diff --git a/sync/dash.go b/sync/dash.go index 66e1f1f6..04b464ac 100644 --- a/sync/dash.go +++ b/sync/dash.go @@ -33,6 +33,15 @@ type Config struct { URLTegola string } +type ContextCell struct { + BreedingSources []BreedingSourceSummary + CellBoundary h3.CellBoundary + Inspections []Inspection + MapData ComponentMap + Traps []Trap + Treatments []Treatment + User User +} type ContextDashboard struct { Config Config CountTraps int @@ -161,12 +170,18 @@ func cell(ctx context.Context, w http.ResponseWriter, user *models.User, c int64 respondError(w, "Failed to get sources", err, http.StatusInternalServerError) return } + traps, err := trapsByCell(ctx, org, h3.Cell(c)) + if err != nil { + respondError(w, "Failed to get traps", err, http.StatusInternalServerError) + return + } + treatments, err := treatmentsByCell(ctx, org, h3.Cell(c)) if err != nil { respondError(w, "Failed to get treatments", err, http.StatusInternalServerError) return } - data := ContentCell{ + data := ContextCell{ BreedingSources: sources, CellBoundary: boundary, Inspections: inspections, @@ -179,6 +194,7 @@ func cell(ctx context.Context, w http.ResponseWriter, user *models.User, c int64 MapboxToken: config.MapboxToken, Zoom: resolution + 5, }, + Traps: traps, Treatments: treatments, User: userContent, } diff --git a/sync/model_conversion.go b/sync/model_conversion.go index 6f07ec8a..31156274 100644 --- a/sync/model_conversion.go +++ b/sync/model_conversion.go @@ -154,6 +154,13 @@ type TrapData struct { Comments string `json:"comments"` } +type Trap struct { + Active bool + Comments string + Description string + GlobalID uuid.UUID +} + type Treatment struct { CadenceDelta time.Duration Date *time.Time @@ -162,7 +169,18 @@ type Treatment struct { Product string } -func toTemplateTraps(locations []sql.TrapLocationBySourceIDRow, trap_data []sql.TrapDataByLocationIDRecentRow, counts []sql.TrapCountByLocationIDRow) ([]TrapNearby, error) { +func toTemplateTrap(traps models.FieldseekerTraplocationSlice) (results []Trap, err error) { + for _, t := range traps { + results = append(results, Trap{ + Active: toBool16Or(t.Active, false), + Comments: t.Comments.GetOr(""), + Description: t.Description.GetOr(""), + GlobalID: t.Globalid, + }) + } + return results, err +} +func toTemplateTrapsNearby(locations []sql.TrapLocationBySourceIDRow, trap_data []sql.TrapDataByLocationIDRecentRow, counts []sql.TrapCountByLocationIDRow) ([]TrapNearby, error) { results := make([]TrapNearby, 0) count_by_trap_data_id := make(map[uuid.UUID]*sql.TrapCountByLocationIDRow) for _, c := range counts { @@ -409,3 +427,17 @@ func getTimeOrNull(v null.Val[time.Time]) *time.Time { val := v.MustGet() return &val } + +func toBool16Or(t null.Val[int16], def bool) bool { + if t.IsNull() { + return def + } + val := t.MustGet() + var b bool + if val == 0 { + b = false + } else { + b = true + } + return b +} diff --git a/sync/template/cell.html b/sync/template/cell.html index 96d716fb..82a9162a 100644 --- a/sync/template/cell.html +++ b/sync/template/cell.html @@ -160,6 +160,36 @@
| ID | +Active | +Comments | +
|---|---|---|
| {{.GlobalID|uuidShort}} | +{{.Active}} | +{{.Comments}} | +
No traps
+ {{ end }} +