Switch cell detail page to libremap rendering
This commit is contained in:
parent
9d0a4b4b88
commit
5b33b7ffcf
8 changed files with 295 additions and 200 deletions
102
sync/cell.go
Normal file
102
sync/cell.go
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
package sync
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/h3utils"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/html"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/uber/h3-go/v4"
|
||||
)
|
||||
|
||||
type contentCell struct {
|
||||
BreedingSources []BreedingSourceSummary
|
||||
CellBoundary h3.CellBoundary
|
||||
Inspections []Inspection
|
||||
MapData ComponentMap
|
||||
Traps []TrapSummary
|
||||
Treatments []Treatment
|
||||
URL ContentURL
|
||||
User User
|
||||
}
|
||||
|
||||
func getCellDetails(w http.ResponseWriter, r *http.Request, user *models.User) {
|
||||
cell_str := chi.URLParam(r, "cell")
|
||||
if cell_str == "" {
|
||||
respondError(w, "There should always be a cell", nil, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
c, err := HexToInt64(cell_str)
|
||||
if err != nil {
|
||||
respondError(w, "Cannot convert provided cell to uint64", err, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
ctx := r.Context()
|
||||
org, err := user.Organization().One(ctx, db.PGInstance.BobDB)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to get org", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
userContent, err := contentForUser(ctx, user)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to get user", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
center, err := h3.Cell(c).LatLng()
|
||||
if err != nil {
|
||||
respondError(w, "Failed to get center", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
boundary, err := h3.Cell(c).Boundary()
|
||||
if err != nil {
|
||||
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 by cell", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
geojson, err := h3utils.H3ToGeoJSON([]h3.Cell{h3.Cell(c)})
|
||||
if err != nil {
|
||||
respondError(w, "Failed to get boundaries", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
resolution := h3.Cell(c).Resolution()
|
||||
sources, err := breedingSourcesByCell(ctx, org, h3.Cell(c))
|
||||
if err != nil {
|
||||
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{
|
||||
BreedingSources: sources,
|
||||
CellBoundary: boundary,
|
||||
Inspections: inspections,
|
||||
MapData: ComponentMap{
|
||||
Center: h3.LatLng{
|
||||
Lat: center.Lat,
|
||||
Lng: center.Lng,
|
||||
},
|
||||
GeoJSON: geojson,
|
||||
Zoom: resolution + 5,
|
||||
},
|
||||
Traps: traps,
|
||||
Treatments: treatments,
|
||||
URL: newContentURL(),
|
||||
User: userContent,
|
||||
}
|
||||
html.RenderOrError(w, "sync/cell.html", &data)
|
||||
}
|
||||
93
sync/dash.go
93
sync/dash.go
|
|
@ -13,11 +13,9 @@ import (
|
|||
"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/h3utils"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/html"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/google/uuid"
|
||||
"github.com/uber/h3-go/v4"
|
||||
)
|
||||
|
||||
// Authenticated pages
|
||||
|
|
@ -41,15 +39,6 @@ type ContentTrap struct {
|
|||
Trap Trap
|
||||
User User
|
||||
}
|
||||
type ContentCell struct {
|
||||
BreedingSources []BreedingSourceSummary
|
||||
CellBoundary h3.CellBoundary
|
||||
Inspections []Inspection
|
||||
MapData ComponentMap
|
||||
Traps []TrapSummary
|
||||
Treatments []Treatment
|
||||
User User
|
||||
}
|
||||
type ContentDashboard struct {
|
||||
CountTraps int
|
||||
CountMosquitoSources int
|
||||
|
|
@ -70,20 +59,6 @@ type ContentDistrict struct {
|
|||
MapboxToken string
|
||||
}
|
||||
|
||||
func getCellDetails(w http.ResponseWriter, r *http.Request, user *models.User) {
|
||||
cell_str := chi.URLParam(r, "cell")
|
||||
if cell_str == "" {
|
||||
respondError(w, "There should always be a cell", nil, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
c, err := HexToInt64(cell_str)
|
||||
if err != nil {
|
||||
respondError(w, "Cannot convert provided cell to uint64", err, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
cell(r.Context(), w, user, c)
|
||||
}
|
||||
|
||||
func getDistrict(w http.ResponseWriter, r *http.Request) {
|
||||
context := ContentDistrict{
|
||||
MapboxToken: config.MapboxToken,
|
||||
|
|
@ -182,74 +157,6 @@ func getTrap(w http.ResponseWriter, r *http.Request, u *models.User) {
|
|||
trap(w, r, u, globalid)
|
||||
}
|
||||
|
||||
func cell(ctx context.Context, w http.ResponseWriter, user *models.User, c int64) {
|
||||
org, err := user.Organization().One(ctx, db.PGInstance.BobDB)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to get org", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
userContent, err := contentForUser(ctx, user)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to get user", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
center, err := h3.Cell(c).LatLng()
|
||||
if err != nil {
|
||||
respondError(w, "Failed to get center", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
boundary, err := h3.Cell(c).Boundary()
|
||||
if err != nil {
|
||||
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 by cell", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
geojson, err := h3utils.H3ToGeoJSON([]h3.Cell{h3.Cell(c)})
|
||||
if err != nil {
|
||||
respondError(w, "Failed to get boundaries", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
resolution := h3.Cell(c).Resolution()
|
||||
sources, err := breedingSourcesByCell(ctx, org, h3.Cell(c))
|
||||
if err != nil {
|
||||
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{
|
||||
BreedingSources: sources,
|
||||
CellBoundary: boundary,
|
||||
Inspections: inspections,
|
||||
MapData: ComponentMap{
|
||||
Center: h3.LatLng{
|
||||
Lat: center.Lat,
|
||||
Lng: center.Lng,
|
||||
},
|
||||
GeoJSON: geojson,
|
||||
MapboxToken: config.MapboxToken,
|
||||
Zoom: resolution + 5,
|
||||
},
|
||||
Traps: traps,
|
||||
Treatments: treatments,
|
||||
User: userContent,
|
||||
}
|
||||
html.RenderOrError(w, "sync/cell.html", &data)
|
||||
}
|
||||
|
||||
func dashboard(ctx context.Context, w http.ResponseWriter, user *models.User) {
|
||||
org, err := user.Organization().One(ctx, db.PGInstance.BobDB)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue