From 7919b374533145dc63bf6b0685f445fd0d07d2a2 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Fri, 9 Jan 2026 20:08:29 +0000 Subject: [PATCH] Add mock status page --- htmlpage/html.go | 8 + public-report/endpoint.go | 7 - public-report/page.go | 2 - public-report/routes.go | 1 + public-report/status.go | 145 ++++++++++++++++++ .../template/nuisance-submit-complete.html | 4 +- .../template/pool-submit-complete.html | 4 +- .../template/quick-submit-complete.html | 4 +- .../register-notifications-complete.html | 4 +- public-report/template/status-by-id.html | 139 +++++++++++++++++ 10 files changed, 301 insertions(+), 17 deletions(-) create mode 100644 public-report/status.go create mode 100644 public-report/template/status-by-id.html diff --git a/htmlpage/html.go b/htmlpage/html.go index a34d8197..0fa93df0 100644 --- a/htmlpage/html.go +++ b/htmlpage/html.go @@ -112,6 +112,7 @@ func makeFuncMap() template.FuncMap { "bigNumber": bigNumber, "GISStatement": gisStatement, "latLngDisplay": latLngDisplay, + "publicReportID": publicReportID, "timeAsRelativeDate": timeAsRelativeDate, "timeDelta": timeDelta, "timeElapsed": timeElapsed, @@ -145,6 +146,13 @@ func parseFromDisk(files []string) (*template.Template, error) { return templ, nil } +func publicReportID(s string) string { + if len(s) != 12 { + return s + } + return s[0:4] + "-" + s[4:8] + "-" + s[8:12] +} + func timeAsRelativeDate(d time.Time) string { return d.Format("01-02") } diff --git a/public-report/endpoint.go b/public-report/endpoint.go index 2b4bd6d2..0eb77bb7 100644 --- a/public-report/endpoint.go +++ b/public-report/endpoint.go @@ -29,13 +29,6 @@ func getRegisterNotificationsComplete(w http.ResponseWriter, r *http.Request) { }, ) } -func getStatus(w http.ResponseWriter, r *http.Request) { - htmlpage.RenderOrError( - w, - Status, - ContextStatus{}, - ) -} func postRegisterNotifications(w http.ResponseWriter, r *http.Request) { err := r.ParseForm() if err != nil { diff --git a/public-report/page.go b/public-report/page.go index 3791ceff..1f03ef15 100644 --- a/public-report/page.go +++ b/public-report/page.go @@ -17,12 +17,10 @@ type ContextRegisterNotificationsComplete struct { ReportID string } type ContextRoot struct{} -type ContextStatus struct{} var ( RegisterNotificationsComplete = buildTemplate("register-notifications-complete", "base") Root = buildTemplate("root", "base") - Status = buildTemplate("status", "base") ) var components = [...]string{"footer", "location-geocode", "location-geocode-header", "photo-upload", "photo-upload-header"} diff --git a/public-report/routes.go b/public-report/routes.go index 3bdd6b32..a0a55bb6 100644 --- a/public-report/routes.go +++ b/public-report/routes.go @@ -22,6 +22,7 @@ func Router() chi.Router { r.Post("/register-notifications", postRegisterNotifications) r.Get("/register-notifications-complete", getRegisterNotificationsComplete) r.Get("/status", getStatus) + r.Get("/status/{report_id}", getStatusByID) localFS := http.Dir("./static") htmlpage.FileServer(r, "/static", localFS, EmbeddedStaticFS, "static") return r diff --git a/public-report/status.go b/public-report/status.go new file mode 100644 index 00000000..7b14a371 --- /dev/null +++ b/public-report/status.go @@ -0,0 +1,145 @@ +package publicreport + +import ( + "net/http" + + "github.com/Gleipnir-Technology/nidus-sync/htmlpage" + "github.com/go-chi/chi/v5" + /* + "fmt" + "strconv" + "time" + + "github.com/Gleipnir-Technology/nidus-sync/db" + "github.com/Gleipnir-Technology/nidus-sync/db/models" + "github.com/Gleipnir-Technology/nidus-sync/h3utils" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/rs/zerolog/log" + "github.com/stephenafamo/bob/dialect/psql" + "github.com/stephenafamo/bob/dialect/psql/um" + */) + +type Report struct { + ID string +} + +type ContextStatus struct{} +type ContextStatusByID struct { + Report Report +} + +var ( + Status = buildTemplate("status", "base") + StatusByID = buildTemplate("status-by-id", "base") +) + +func getStatus(w http.ResponseWriter, r *http.Request) { + htmlpage.RenderOrError( + w, + Status, + ContextStatus{}, + ) +} +func getStatusByID(w http.ResponseWriter, r *http.Request) { + report_id := chi.URLParam(r, "report_id") + htmlpage.RenderOrError( + w, + StatusByID, + ContextStatusByID{ + Report: Report{ + ID: report_id, + }, + }, + ) +} + +/* +func getQuick(w http.ResponseWriter, r *http.Request) { + htmlpage.RenderOrError( + w, + Quick, + ContextQuick{}, + ) +} +func getQuickSubmitComplete(w http.ResponseWriter, r *http.Request) { + report := r.URL.Query().Get("report") + htmlpage.RenderOrError( + w, + QuickSubmitComplete, + ContextQuickSubmitComplete{ + ReportID: report, + }, + ) +} +func postQuick(w http.ResponseWriter, r *http.Request) { + err := r.ParseMultipartForm(32 << 10) // 32 MB buffer + if err != nil { + respondError(w, "Failed to parse form", err, http.StatusBadRequest) + return + } + lat := r.FormValue("latitude") + lng := r.FormValue("longitude") + comments := r.FormValue("comments") + //photos := r.FormValue("photos") + + latitude, err := strconv.ParseFloat(lat, 64) + if err != nil { + respondError(w, "Failed to create parse latitude", err, http.StatusBadRequest) + return + } + longitude, err := strconv.ParseFloat(lng, 64) + if err != nil { + respondError(w, "Failed to create parse longitude", err, http.StatusBadRequest) + return + } + u, err := GenerateReportID() + if err != nil { + respondError(w, "Failed to create quick report public ID", err, http.StatusInternalServerError) + return + } + c, err := h3utils.GetCell(longitude, latitude, 15) + setter := models.PublicreportQuickSetter{ + Created: omit.From(time.Now()), + Comments: omit.From(comments), + //Location: omitnull.From(fmt.Sprintf("ST_GeometryFromText(Point(%s %s))", longitude, latitude)), + H3cell: omitnull.From(c.String()), + PublicID: omit.From(u), + ReporterEmail: omit.From(""), + ReporterPhone: omit.From(""), + } + quick, err := models.PublicreportQuicks.Insert(&setter).One(r.Context(), db.PGInstance.BobDB) + if err != nil { + respondError(w, "Failed to create database record", err, http.StatusInternalServerError) + return + } + _, err = psql.Update( + um.Table("publicreport.quick"), + um.SetCol("location").To(fmt.Sprintf("ST_GeometryFromText('Point(%f %f)')", longitude, latitude)), + um.Where(psql.Quote("id").EQ(psql.Arg(quick.ID))), + ).Exec(r.Context(), db.PGInstance.BobDB) + if err != nil { + respondError(w, "Failed to insert publicreport", err, http.StatusInternalServerError) + return + } + log.Info().Float64("latitude", latitude).Float64("longitude", longitude).Msg("Got upload") + photoSetters := make([]*models.PublicreportQuickPhotoSetter, 0) + uploads, err := extractPhotoUploads(r) + if err != nil { + respondError(w, "Failed to extract photo uploads", err, http.StatusInternalServerError) + return + } + for _, u := range uploads { + photoSetters = append(photoSetters, &models.PublicreportQuickPhotoSetter{ + Filename: omit.From(u.Filename), + Size: omit.From(u.Size), + UUID: omit.From(u.UUID), + }) + } + err = quick.InsertQuickPhotos(r.Context(), db.PGInstance.BobDB, photoSetters...) + if err != nil { + respondError(w, "Failed to create photo records", err, http.StatusInternalServerError) + return + } + http.Redirect(w, r, fmt.Sprintf("/quick-submit-complete?report=%s", u), http.StatusFound) +}*/ diff --git a/public-report/template/nuisance-submit-complete.html b/public-report/template/nuisance-submit-complete.html index 6cf6efcf..1e6c6237 100644 --- a/public-report/template/nuisance-submit-complete.html +++ b/public-report/template/nuisance-submit-complete.html @@ -32,7 +32,7 @@

Your report has been successfully submitted.

Report ID: - {{.ReportID}} + {{.ReportID|publicReportID}}
@@ -80,7 +80,7 @@
- + diff --git a/public-report/template/pool-submit-complete.html b/public-report/template/pool-submit-complete.html index 700d6791..f5882051 100644 --- a/public-report/template/pool-submit-complete.html +++ b/public-report/template/pool-submit-complete.html @@ -32,7 +32,7 @@

Your report has been successfully submitted.

Report ID: - {{.ReportID}} + {{.ReportID|publicReportID}}
@@ -80,7 +80,7 @@
- + diff --git a/public-report/template/quick-submit-complete.html b/public-report/template/quick-submit-complete.html index 6021768f..35dc6673 100644 --- a/public-report/template/quick-submit-complete.html +++ b/public-report/template/quick-submit-complete.html @@ -26,7 +26,7 @@

Thank you for helping us control mosquito populations in your area!

Your Report ID: - {{.ReportID}} + {{.ReportID|publicReportID}}

Please save this ID for your reference.

@@ -42,7 +42,7 @@ Check Your Report Status

You can check the status of your report at any time using your Report ID.

-
+ Check Status diff --git a/public-report/template/register-notifications-complete.html b/public-report/template/register-notifications-complete.html index 1ebd1791..44123252 100644 --- a/public-report/template/register-notifications-complete.html +++ b/public-report/template/register-notifications-complete.html @@ -32,7 +32,7 @@

Your contact information has been successfully registered for report updates.

Report ID: - {{.ReportID}} + {{.ReportID|publicReportID}}
@@ -80,7 +80,7 @@
- + diff --git a/public-report/template/status-by-id.html b/public-report/template/status-by-id.html new file mode 100644 index 00000000..73bf8dac --- /dev/null +++ b/public-report/template/status-by-id.html @@ -0,0 +1,139 @@ +{{template "base.html" .}} + +{{define "title"}}Status of report {{.Report.ID|publicReportID}}{{end}} +{{define "extraheader"}} + +{{end}} +{{define "content"}} + +
+
+
Report {{.Report.ID|publicReportID}}
+ Scheduled +
+
+
+
+ Created: + July 15, 2023 - 9:30 AM +
+
+ Last Updated: + July 17, 2023 - 2:45 PM +
+
+ Next Step: + July 19, 2023 (Estimated) +
+
+
+
+ + +
+
+
+
+
Reporter Information
+
+
+

Name: Jane Doe

+

Phone: (555) 123-4567

+

Address: 123 Main Street, Anytown, USA 12345

+
+
+
+
+
+
+
Nuisance Property Information
+
+
+

Owner: John Smith

+

Address: 456 Elm Street, Anytown, USA 12345

+

Description: Standing water in abandoned pool

+
+
+
+
+ + +
+
+
Location Map
+
+
+
+ + +
+
+
+ + +
+
+
Request History
+
+
+
+
+
July 17, 2023 - 2:45 PM
+
Scheduled for Treatment
+

Site visit scheduled for July 19. Technician: Michael Johnson

+
+
+
July 16, 2023 - 10:30 AM
+
Assessment Complete
+

Initial assessment completed. Property requires treatment for mosquito larvae.

+
+
+
July 15, 2023 - 1:15 PM
+
In Review
+

Report assigned to field supervisor for initial assessment.

+
+
+
July 15, 2023 - 9:30 AM
+
Report Created
+

New mosquito nuisance report submitted by Jane Doe.

+
+
+
+
+{{end}}