From 5e7c5476707972e4ffab1af06f815a74437ebb1d Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Wed, 11 Mar 2026 14:59:04 +0000 Subject: [PATCH] Fix map display on RMO status-by-id page This involves rebuilding the "publicreport.report_location" view after making a bunch of changes to making publicreport.water the consistent name (over pool) throughout RMA tables. --- db/dbinfo/publicreport.report_location.bob.go | 20 +++---- .../00099_publicreport_location_water.sql | 60 +++++++++++++++++++ db/models/publicreport.report_location.bob.go | 48 +++++++-------- html/static/js/map-locator-ro.js | 1 - html/template/rmo/status-by-id.html | 39 +++++------- html/template/rmo/status.html | 18 +++--- rmo/status.go | 7 +-- scss/rmo/mailer.scss | 4 -- 8 files changed, 121 insertions(+), 76 deletions(-) create mode 100644 db/migrations/00099_publicreport_location_water.sql diff --git a/db/dbinfo/publicreport.report_location.bob.go b/db/dbinfo/publicreport.report_location.bob.go index dce9982b..f61aa376 100644 --- a/db/dbinfo/publicreport.report_location.bob.go +++ b/db/dbinfo/publicreport.report_location.bob.go @@ -31,8 +31,8 @@ var PublicreportReportLocations = Table[ Generated: false, AutoIncr: false, }, - Address: column{ - Name: "address", + AddressRaw: column{ + Name: "address_raw", DBType: "text", Default: "NULL", Comment: "", @@ -82,18 +82,18 @@ var PublicreportReportLocations = Table[ } type publicreportReportLocationColumns struct { - ID column - TableName column - Address column - Created column - Location column - PublicID column - Status column + ID column + TableName column + AddressRaw column + Created column + Location column + PublicID column + Status column } func (c publicreportReportLocationColumns) AsSlice() []column { return []column{ - c.ID, c.TableName, c.Address, c.Created, c.Location, c.PublicID, c.Status, + c.ID, c.TableName, c.AddressRaw, c.Created, c.Location, c.PublicID, c.Status, } } diff --git a/db/migrations/00099_publicreport_location_water.sql b/db/migrations/00099_publicreport_location_water.sql new file mode 100644 index 00000000..0e274fa5 --- /dev/null +++ b/db/migrations/00099_publicreport_location_water.sql @@ -0,0 +1,60 @@ +-- +goose Up +DROP VIEW publicreport.report_location; +CREATE VIEW publicreport.report_location AS +SELECT + ROW_NUMBER() OVER (ORDER BY table_name, public_id) AS id, + table_name, + address_raw, + created, + location, + public_id, + status +FROM ( + SELECT + 'nuisance' AS table_name, + address_raw, + created, + location, + public_id, + status + FROM publicreport.nuisance + UNION + SELECT + 'water' AS table_name, + address_raw, + created, + location, + public_id, + status + FROM publicreport.water +) AS combined_data; +-- +goose Down +DROP VIEW publicreport.report_location; +CREATE VIEW publicreport.report_location AS +SELECT + ROW_NUMBER() OVER (ORDER BY table_name, public_id) AS id, + table_name, + address_raw, + created, + location, + public_id, + status +FROM ( + SELECT + 'nuisance' AS table_name, + address_raw, + created, + location, + public_id, + status + FROM publicreport.nuisance + UNION + SELECT + 'pool' AS table_name, + address_raw, + created, + location, + public_id, + status + FROM publicreport.water +) AS combined_data; diff --git a/db/models/publicreport.report_location.bob.go b/db/models/publicreport.report_location.bob.go index 04348b85..a2512c1f 100644 --- a/db/models/publicreport.report_location.bob.go +++ b/db/models/publicreport.report_location.bob.go @@ -16,13 +16,13 @@ import ( // PublicreportReportLocation is an object representing the database table. type PublicreportReportLocation struct { - ID null.Val[int64] `db:"id" ` - TableName null.Val[string] `db:"table_name" ` - Address null.Val[string] `db:"address" ` - Created null.Val[time.Time] `db:"created" ` - Location null.Val[string] `db:"location" ` - PublicID null.Val[string] `db:"public_id" ` - Status null.Val[enums.PublicreportReportstatustype] `db:"status" ` + ID null.Val[int64] `db:"id" ` + TableName null.Val[string] `db:"table_name" ` + AddressRaw null.Val[string] `db:"address_raw" ` + Created null.Val[time.Time] `db:"created" ` + Location null.Val[string] `db:"location" ` + PublicID null.Val[string] `db:"public_id" ` + Status null.Val[enums.PublicreportReportstatustype] `db:"status" ` } // PublicreportReportLocationSlice is an alias for a slice of pointers to PublicreportReportLocation. @@ -38,12 +38,12 @@ type PublicreportReportLocationsQuery = *psql.ViewQuery[*PublicreportReportLocat func buildPublicreportReportLocationColumns(alias string) publicreportReportLocationColumns { return publicreportReportLocationColumns{ ColumnsExpr: expr.NewColumnsExpr( - "id", "table_name", "address", "created", "location", "public_id", "status", + "id", "table_name", "address_raw", "created", "location", "public_id", "status", ).WithParent("publicreport.report_location"), tableAlias: alias, ID: psql.Quote(alias, "id"), TableName: psql.Quote(alias, "table_name"), - Address: psql.Quote(alias, "address"), + AddressRaw: psql.Quote(alias, "address_raw"), Created: psql.Quote(alias, "created"), Location: psql.Quote(alias, "location"), PublicID: psql.Quote(alias, "public_id"), @@ -56,7 +56,7 @@ type publicreportReportLocationColumns struct { tableAlias string ID psql.Expression TableName psql.Expression - Address psql.Expression + AddressRaw psql.Expression Created psql.Expression Location psql.Expression PublicID psql.Expression @@ -96,13 +96,13 @@ func (o PublicreportReportLocationSlice) AfterQueryHook(ctx context.Context, exe } type publicreportReportLocationWhere[Q psql.Filterable] struct { - ID psql.WhereNullMod[Q, int64] - TableName psql.WhereNullMod[Q, string] - Address psql.WhereNullMod[Q, string] - Created psql.WhereNullMod[Q, time.Time] - Location psql.WhereNullMod[Q, string] - PublicID psql.WhereNullMod[Q, string] - Status psql.WhereNullMod[Q, enums.PublicreportReportstatustype] + ID psql.WhereNullMod[Q, int64] + TableName psql.WhereNullMod[Q, string] + AddressRaw psql.WhereNullMod[Q, string] + Created psql.WhereNullMod[Q, time.Time] + Location psql.WhereNullMod[Q, string] + PublicID psql.WhereNullMod[Q, string] + Status psql.WhereNullMod[Q, enums.PublicreportReportstatustype] } func (publicreportReportLocationWhere[Q]) AliasedAs(alias string) publicreportReportLocationWhere[Q] { @@ -111,12 +111,12 @@ func (publicreportReportLocationWhere[Q]) AliasedAs(alias string) publicreportRe func buildPublicreportReportLocationWhere[Q psql.Filterable](cols publicreportReportLocationColumns) publicreportReportLocationWhere[Q] { return publicreportReportLocationWhere[Q]{ - ID: psql.WhereNull[Q, int64](cols.ID), - TableName: psql.WhereNull[Q, string](cols.TableName), - Address: psql.WhereNull[Q, string](cols.Address), - Created: psql.WhereNull[Q, time.Time](cols.Created), - Location: psql.WhereNull[Q, string](cols.Location), - PublicID: psql.WhereNull[Q, string](cols.PublicID), - Status: psql.WhereNull[Q, enums.PublicreportReportstatustype](cols.Status), + ID: psql.WhereNull[Q, int64](cols.ID), + TableName: psql.WhereNull[Q, string](cols.TableName), + AddressRaw: psql.WhereNull[Q, string](cols.AddressRaw), + Created: psql.WhereNull[Q, time.Time](cols.Created), + Location: psql.WhereNull[Q, string](cols.Location), + PublicID: psql.WhereNull[Q, string](cols.PublicID), + Status: psql.WhereNull[Q, enums.PublicreportReportstatustype](cols.Status), } } diff --git a/html/static/js/map-locator-ro.js b/html/static/js/map-locator-ro.js index 21a2a9db..6380f1d7 100644 --- a/html/static/js/map-locator-ro.js +++ b/html/static/js/map-locator-ro.js @@ -47,7 +47,6 @@ class MapLocatorReadOnly extends HTMLElement { }) .setLngLat(marker.coordinates) .addTo(this._map); - this.dispatchEvent(markerDraggedEvent); this.dispatchEvent( new CustomEvent("load", { bubbles: true, diff --git a/html/template/rmo/status-by-id.html b/html/template/rmo/status-by-id.html index 10c8b72d..03b148b7 100644 --- a/html/template/rmo/status-by-id.html +++ b/html/template/rmo/status-by-id.html @@ -2,8 +2,12 @@ {{ define "title" }}Status of report {{ .Report.ID|publicReportID }}{{ end }} {{ define "extraheader" }} + - + - + {{ end }} {{ define "content" }} {{ if (eq .District nil) }} @@ -133,7 +119,12 @@ document.addEventListener("DOMContentLoaded", onLoad);
- +
+ +
diff --git a/html/template/rmo/status.html b/html/template/rmo/status.html index d9232a16..988ae9c4 100644 --- a/html/template/rmo/status.html +++ b/html/template/rmo/status.html @@ -19,7 +19,7 @@ var markers = []; // Because features come from tiled vector data, feature geometries may be split // or duplicated across tile boundaries. As a result, features may appear // multiple times in query results. -function getUniqueFeatures(nuisances, pools, comparatorProperty) { +function getUniqueFeatures(nuisances, waters, comparatorProperty) { const uniqueIds = new Set(); const uniqueFeatures = []; for (const feature of nuisances) { @@ -31,12 +31,12 @@ function getUniqueFeatures(nuisances, pools, comparatorProperty) { uniqueFeatures.push(f); } } - for (const feature of pools) { + for (const feature of waters) { const id = feature.properties[comparatorProperty]; if (!uniqueIds.has(id)) { uniqueIds.add(id); let f = structuredClone(feature); - f.type = "pool"; + f.type = "water"; uniqueFeatures.push(f); } } @@ -88,9 +88,9 @@ function onLoad() { } }); map.addLayer({ - 'id': 'pool', + 'id': 'water', 'source': 'tegola', - 'source-layer': 'pool_location', + 'source-layer': 'water_location', 'type': 'circle', 'paint': { 'circle-color': "#0D6EfD", @@ -110,16 +110,16 @@ function onLoad() { } } _addCheckboxClick(checkboxNuisance, "nuisance"); - _addCheckboxClick(checkboxWater, "pool"); + _addCheckboxClick(checkboxWater, "water"); checkboxNuisance.onclick() checkboxWater.onclick() }); function _updateReports() { const nuisances = map.queryRenderedFeatures({target: {layerId: 'nuisance'}}); - const pools = map.queryRenderedFeatures({target: {layerId: 'pool'}}); + const waters = map.queryRenderedFeatures({target: {layerId: 'water'}}); const nidus_nuisances = nuisances.filter((feature) => feature.source == "tegola"); - const nidus_pools = pools.filter((feature) => feature.source == "tegola"); - const uniqueFeatures = getUniqueFeatures(nidus_nuisances, nidus_pools, 'public_id'); + const nidus_waters = waters.filter((feature) => feature.source == "tegola"); + const uniqueFeatures = getUniqueFeatures(nidus_nuisances, nidus_waters, 'public_id'); // Populate features for the listing overlay. renderReports(uniqueFeatures); } diff --git a/rmo/status.go b/rmo/status.go index cf8e57aa..25610f15 100644 --- a/rmo/status.go +++ b/rmo/status.go @@ -16,7 +16,7 @@ import ( "github.com/Gleipnir-Technology/nidus-sync/db/sql" "github.com/Gleipnir-Technology/nidus-sync/html" "github.com/go-chi/chi/v5" - "github.com/rs/zerolog/log" + //"github.com/rs/zerolog/log" "github.com/stephenafamo/scan" /* "github.com/Gleipnir-Technology/nidus-sync/db" @@ -266,9 +266,6 @@ func contentFromWater(ctx context.Context, report_id string) (result ContentStat Title: "Created", }, } - type LocationGeoJSON struct { - Location string - } location, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select( sm.Columns( psql.F("ST_AsGeoJSON", "location"), @@ -301,6 +298,8 @@ func getStatusByID(w http.ResponseWriter, r *http.Request) { content, err = contentFromNuisance(ctx, report_id) case "water": content, err = contentFromWater(ctx, report_id) + default: + err = fmt.Errorf("table name %s not in switch", location.TableName.MustGet()) } if err != nil { respondError(w, "Failed to generate report content", err, http.StatusInternalServerError) diff --git a/scss/rmo/mailer.scss b/scss/rmo/mailer.scss index 33e3a428..fad8de37 100644 --- a/scss/rmo/mailer.scss +++ b/scss/rmo/mailer.scss @@ -31,10 +31,6 @@ body { position: relative; overflow: hidden; } -#map { - width: 510px; - height: 300px; -} .address-container { background-color: #f8f9fa; border-radius: 10px;