WIP filling out report status page
This commit is contained in:
parent
aa3d7ab6b7
commit
13cbf71c0f
2 changed files with 143 additions and 37 deletions
|
|
@ -1,38 +1,54 @@
|
|||
package publicreport
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/sql"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/htmlpage"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/stephenafamo/bob/dialect/psql"
|
||||
"github.com/stephenafamo/bob/dialect/psql/sm"
|
||||
"github.com/stephenafamo/scan"
|
||||
/*
|
||||
"strconv"
|
||||
"time"
|
||||
"strconv"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/h3utils"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
"github.com/stephenafamo/bob/dialect/psql"
|
||||
"github.com/stephenafamo/bob/dialect/psql/um"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/h3utils"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
*/)
|
||||
|
||||
type Contact struct {
|
||||
Email string
|
||||
Name string
|
||||
Phone string
|
||||
}
|
||||
type Report struct {
|
||||
ID string
|
||||
Address string
|
||||
Created time.Time
|
||||
ID string
|
||||
Location string // GeoJSON
|
||||
Reporter Contact
|
||||
SiteOwner Contact
|
||||
Updated time.Time
|
||||
}
|
||||
|
||||
type ContextStatus struct {
|
||||
type ContentStatus struct {
|
||||
Error string
|
||||
ReportID string
|
||||
}
|
||||
type ContextStatusByID struct {
|
||||
Report Report
|
||||
type ContentStatusByID struct {
|
||||
MapboxToken string
|
||||
Report Report
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -66,7 +82,7 @@ func getStatus(w http.ResponseWriter, r *http.Request) {
|
|||
htmlpage.RenderOrError(
|
||||
w,
|
||||
Status,
|
||||
ContextStatus{
|
||||
ContentStatus{
|
||||
Error: "",
|
||||
ReportID: "",
|
||||
},
|
||||
|
|
@ -85,7 +101,7 @@ func getStatus(w http.ResponseWriter, r *http.Request) {
|
|||
htmlpage.RenderOrError(
|
||||
w,
|
||||
Status,
|
||||
ContextStatus{
|
||||
ContentStatus{
|
||||
Error: "Sorry, server's confused",
|
||||
ReportID: report_id_str,
|
||||
},
|
||||
|
|
@ -99,22 +115,103 @@ func getStatus(w http.ResponseWriter, r *http.Request) {
|
|||
htmlpage.RenderOrError(
|
||||
w,
|
||||
Status,
|
||||
ContextStatus{
|
||||
ContentStatus{
|
||||
Error: "Sorry, we can't find that report",
|
||||
ReportID: report_id_str,
|
||||
},
|
||||
)
|
||||
}
|
||||
func contentFromNuisance(ctx context.Context, report_id string) (result ContentStatusByID, err error) {
|
||||
nuisance, err := models.PublicreportNuisances.Query(
|
||||
models.SelectWhere.PublicreportNuisances.PublicID.EQ(report_id),
|
||||
).One(ctx, db.PGInstance.BobDB)
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("Failed to query nuisance %s: %w", report_id, err)
|
||||
}
|
||||
result.Report.ID = report_id
|
||||
result.Report.Address = nuisance.Address
|
||||
result.Report.Created = nuisance.Created
|
||||
result.Report.Updated = nuisance.Created
|
||||
result.Report.Reporter.Email = nuisance.ReporterEmail
|
||||
result.Report.Reporter.Name = nuisance.ReporterName
|
||||
result.Report.Reporter.Phone = nuisance.ReporterPhone
|
||||
|
||||
type LocationGeoJSON struct {
|
||||
Location string
|
||||
}
|
||||
row, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select(
|
||||
sm.From(
|
||||
psql.F("ST_AsGeoJSON", "location"),
|
||||
).As("location"),
|
||||
sm.Where(psql.Quote("public_id").EQ(psql.Arg(report_id))),
|
||||
), scan.StructMapper[LocationGeoJSON]())
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("Failed to query nuisance %s: %w", report_id, err)
|
||||
}
|
||||
result.Report.Location = row.Location
|
||||
|
||||
return result, err
|
||||
}
|
||||
func contentFromPool(ctx context.Context, report_id string) (result ContentStatusByID, err error) {
|
||||
return result, err
|
||||
}
|
||||
func contentFromQuick(ctx context.Context, report_id string) (result ContentStatusByID, err error) {
|
||||
quick, err := models.PublicreportQuicks.Query(
|
||||
models.SelectWhere.PublicreportQuicks.PublicID.EQ(report_id),
|
||||
).One(ctx, db.PGInstance.BobDB)
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("Failed to query nuisance %s: %w", report_id, err)
|
||||
}
|
||||
result.Report.ID = report_id
|
||||
result.Report.Address = quick.Address
|
||||
result.Report.Created = quick.Created
|
||||
result.Report.Updated = quick.Created
|
||||
result.Report.Reporter.Email = quick.ReporterEmail
|
||||
result.Report.Reporter.Name = "-"
|
||||
result.Report.Reporter.Phone = quick.ReporterPhone
|
||||
|
||||
type LocationGeoJSON struct {
|
||||
Location string
|
||||
}
|
||||
row, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select(
|
||||
sm.Columns(
|
||||
psql.F("ST_AsGeoJSON", "location"),
|
||||
),
|
||||
sm.From("publicreport.quick"),
|
||||
sm.Where(psql.Quote("public_id").EQ(psql.Arg(report_id))),
|
||||
), scan.StructMapper[LocationGeoJSON]())
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("Failed to query nuisance %s: %w", report_id, err)
|
||||
}
|
||||
result.Report.Location = row.Location
|
||||
|
||||
return result, err
|
||||
}
|
||||
func getStatusByID(w http.ResponseWriter, r *http.Request) {
|
||||
report_id := chi.URLParam(r, "report_id")
|
||||
ctx := r.Context()
|
||||
|
||||
location, err := models.PublicreportReportLocations.Query(
|
||||
models.SelectWhere.PublicreportReportLocations.PublicID.EQ(report_id),
|
||||
).One(ctx, db.PGInstance.BobDB)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to find report", err, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
var content ContentStatusByID
|
||||
switch location.TableName.MustGet() {
|
||||
case "nuisance":
|
||||
content, err = contentFromNuisance(ctx, report_id)
|
||||
case "pool":
|
||||
content, err = contentFromPool(ctx, report_id)
|
||||
case "quick":
|
||||
content, err = contentFromQuick(ctx, report_id)
|
||||
}
|
||||
content.MapboxToken = config.MapboxToken
|
||||
htmlpage.RenderOrError(
|
||||
w,
|
||||
StatusByID,
|
||||
ContextStatusByID{
|
||||
Report: Report{
|
||||
ID: report_id,
|
||||
},
|
||||
},
|
||||
content,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +220,7 @@ func getStatusByID(w http.ResponseWriter, r *http.Request) {
|
|||
htmlpage.RenderOrError(
|
||||
w,
|
||||
Quick,
|
||||
ContextQuick{},
|
||||
ContentQuick{},
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +229,7 @@ func getStatusByID(w http.ResponseWriter, r *http.Request) {
|
|||
htmlpage.RenderOrError(
|
||||
w,
|
||||
QuickSubmitComplete,
|
||||
ContextQuickSubmitComplete{
|
||||
ContentQuickSubmitComplete{
|
||||
ReportID: report,
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
{{define "title"}}Status of report {{.Report.ID|publicReportID}}{{end}}
|
||||
{{define "extraheader"}}
|
||||
<script src="/static/js/map-single-point.js"></script>
|
||||
<style>
|
||||
.timeline {
|
||||
border-left: 3px solid #dee2e6;
|
||||
|
|
@ -51,7 +52,7 @@
|
|||
<div class="row">
|
||||
<div class="col-md-4 mb-3">
|
||||
<strong><i class="fas fa-calendar-plus me-2"></i>Created:</strong>
|
||||
<span>July 15, 2023 - 9:30 AM</span>
|
||||
<span>{{.Report.Created|timeSince}}</span>
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<strong><i class="fas fa-sync me-2"></i>Last Updated:</strong>
|
||||
|
|
@ -73,37 +74,45 @@
|
|||
<h5 class="mb-0"><i class="fas fa-user me-2"></i>Reporter Information</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p><strong>Name:</strong> Jane Doe</p>
|
||||
<p><strong>Phone:</strong> (555) 123-4567</p>
|
||||
<p><strong>Address:</strong> 123 Main Street, Anytown, USA 12345</p>
|
||||
<p><strong>Name:</strong>{{.Report.Reporter.Name}}</p>
|
||||
<p><strong>Phone:</strong>{{.Report.Reporter.Phone}}</p>
|
||||
<p><strong>Email:</strong>{{.Report.Reporter.Email}}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="card h-100">
|
||||
<div class="card-header bg-secondary text-white">
|
||||
<h5 class="mb-0"><i class="fas fa-home me-2"></i>Nuisance Property Information</h5>
|
||||
<h5 class="mb-0"><i class="fas fa-home me-2"></i>Reported Location</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p><strong>Owner:</strong> John Smith</p>
|
||||
<p><strong>Address:</strong> 456 Elm Street, Anytown, USA 12345</p>
|
||||
<p><strong>Description:</strong> Standing water in abandoned pool</p>
|
||||
<p><strong>Site Contact Name:</strong>{{.Report.SiteOwner.Name}}</p>
|
||||
<p><strong>Site Contact Phone:</strong>{{.Report.SiteOwner.Phone}}</p>
|
||||
<p><strong>Site Contact Email:</strong>{{.Report.SiteOwner.Email}}</p>
|
||||
<p><strong>Address:</strong>{{.Report.Address}}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Report Information -->
|
||||
<div class="row mb-4">
|
||||
<div class="card-header bg-success text-white">
|
||||
<h5 class="mb-0"><i class="fas fa-history me-2"></i>Report Detail</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p><strong>Foo:</strong>Bar</p>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Map Section -->
|
||||
<div class="card mb-4">
|
||||
<div class="card-header bg-info text-white">
|
||||
<h5 class="mb-0"><i class="fas fa-map-marked-alt me-2"></i>Location Map</h5>
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<div class="map-container">
|
||||
<!-- Replace with actual map embed code -->
|
||||
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3000!2d-122.4194!3d37.7749!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0x0!2zMzfCsDQ2JzI5LjYiTiAxMjLCsDI1JzEwLjAiVw!5e0!3m2!1sen!2sus!4v1627309456789!5m2!1sen!2sus"
|
||||
width="100%" height="100%" style="border:0;" allowfullscreen="" loading="lazy"></iframe>
|
||||
</div>
|
||||
<map-single-point
|
||||
api-key="{{ .MapboxToken }}"
|
||||
geojson="{{ .Report.Location }}"
|
||||
zoom="14"></map-single-point>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue