Move data out of import.district and in to organization

Then get the organization settings page to work again.

Tons of other stuff is broken now.
This commit is contained in:
Eli Ribble 2026-02-17 05:33:12 +00:00
parent b786c88f52
commit 5a7c9fd090
No known key found for this signature in database
31 changed files with 2001 additions and 4340 deletions

View file

@ -89,7 +89,7 @@ func getRoot(w http.ResponseWriter, r *http.Request) {
}
if user == nil {
errorCode := r.URL.Query().Get("error")
signin(w, errorCode)
signin(w, errorCode, "/")
return
} else {
has, err := background.HasFieldseekerConnection(r.Context(), user)

View file

@ -56,7 +56,7 @@ func Router() chi.Router {
r.Method("POST", "/pool/upload", auth.NewEnsureAuth(postPoolUpload))
r.Method("GET", "/radar", auth.NewEnsureAuth(getRadar))
r.Method("GET", "/setting", auth.NewEnsureAuth(getSetting))
r.Method("GET", "/setting/district", auth.NewEnsureAuth(getSettingDistrict))
r.Method("GET", "/setting/organization", auth.NewEnsureAuth(getSettingOrganization))
r.Method("GET", "/setting/integration", auth.NewEnsureAuth(getSettingIntegration))
r.Method("GET", "/setting/pesticide", authenticatedHandler(getSettingPesticide))
r.Method("GET", "/setting/pesticide/add", authenticatedHandler(getSettingPesticideAdd))

View file

@ -4,42 +4,17 @@ import (
"context"
"net/http"
"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
"github.com/Gleipnir-Technology/nidus-sync/arcgis"
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/Gleipnir-Technology/nidus-sync/html"
//"github.com/rs/zerolog/log"
"github.com/stephenafamo/scan"
)
type contentDistrict struct {
Address string `db:"address"`
Agency string `db:"agency"`
Centroid string `db:"st_asgeojson"`
Contact string `db:"contact"`
City1 string `db:"city1"`
City2 string `db:"city2"`
Fax string `db:"fax1"`
GID int32 `db:"gid"`
Phone1 string `db:"phone1"`
Phone2 string `db:"phone2"`
GeneralManager string `db:"general_mg"`
PostalCode string `db:"postal_c_1"`
ShapeArea string `db:"shape_area"`
SurfaceAreaMetersSquare string `db:"area_4326_sqm"`
Website string `db:"website"`
XMin float32 `db:"st_xmin"`
XMax float32 `db:"st_xmax"`
YMin float32 `db:"st_ymin"`
YMax float32 `db:"st_ymax"`
}
type contentSettingDistrict struct {
District contentDistrict
URL ContentURL
User User
type contentSettingOrganization struct {
Organization *models.Organization
URL ContentURL
User User
}
type contentSettingIntegration struct {
@ -60,7 +35,7 @@ func getSetting(w http.ResponseWriter, r *http.Request, u *models.User) {
}
html.RenderOrError(w, "sync/settings.html", data)
}
func getSettingDistrict(w http.ResponseWriter, r *http.Request, u *models.User) {
func getSettingOrganization(w http.ResponseWriter, r *http.Request, u *models.User) {
ctx := r.Context()
userContent, err := contentForUser(ctx, u)
if err != nil {
@ -68,10 +43,8 @@ func getSettingDistrict(w http.ResponseWriter, r *http.Request, u *models.User)
return
}
org, err := u.Organization().One(ctx, db.PGInstance.BobDB)
var district contentDistrict
gid := int32(0)
if org.ImportDistrictGid.IsValue() {
gid = org.ImportDistrictGid.MustGet()
/*
var district contentDistrict
district, err = bob.One[contentDistrict](ctx, db.PGInstance.BobDB, psql.Select(
sm.From("import.district"),
sm.Columns(
@ -100,13 +73,13 @@ func getSettingDistrict(w http.ResponseWriter, r *http.Request, u *models.User)
respondError(w, "Failed to get extents", err, http.StatusInternalServerError)
return
}
*/
data := contentSettingOrganization{
Organization: org,
URL: newContentURL(),
User: userContent,
}
data := contentSettingDistrict{
District: district,
URL: newContentURL(),
User: userContent,
}
html.RenderOrError(w, "sync/setting-district.html", data)
html.RenderOrError(w, "sync/setting-organization.html", data)
}
func getSettingIntegration(w http.ResponseWriter, r *http.Request, u *models.User) {
ctx := r.Context()

View file

@ -6,14 +6,22 @@ import (
"strings"
"github.com/Gleipnir-Technology/nidus-sync/auth"
"github.com/Gleipnir-Technology/nidus-sync/config"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/Gleipnir-Technology/nidus-sync/html"
"github.com/rs/zerolog/log"
)
type ContentSignin struct {
InvalidCredentials bool
Next string
}
type ContentSignup struct{}
func getSignin(w http.ResponseWriter, r *http.Request) {
errorCode := r.URL.Query().Get("error")
signin(w, errorCode)
next := r.URL.Query().Get("next")
signin(w, errorCode, next)
}
func getSignout(w http.ResponseWriter, r *http.Request, user *models.User) {
@ -31,10 +39,11 @@ func postSignin(w http.ResponseWriter, r *http.Request) {
return
}
next := r.FormValue("next")
username := r.FormValue("username")
password := r.FormValue("password")
log.Info().Str("username", username).Msg("HTML Signin")
log.Info().Str("username", username).Str("next", next).Msg("HTML Signin")
_, err := auth.SigninUser(r, username, password)
if err != nil {
@ -49,8 +58,11 @@ func postSignin(w http.ResponseWriter, r *http.Request) {
respondError(w, "Failed to signin user", err, http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/", http.StatusFound)
if next == "" {
next = "/"
}
location := config.MakeURLNidus(next)
http.Redirect(w, r, location, http.StatusFound)
}
func postSignup(w http.ResponseWriter, r *http.Request) {
@ -83,9 +95,13 @@ func postSignup(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", http.StatusFound)
}
func signin(w http.ResponseWriter, errorCode string) {
func signin(w http.ResponseWriter, errorCode string, next string) {
if next == "" {
next = "/"
}
data := ContentSignin{
InvalidCredentials: errorCode == "invalid-credentials",
Next: next,
}
html.RenderOrError(w, "sync/signin.html", data)
}

View file

@ -60,10 +60,6 @@ type ContentDashboardLoading struct {
User User
}
type ContentSignin struct {
InvalidCredentials bool
}
type ContentSignup struct{}
type Inspection struct {
Action string
Date *time.Time

View file

@ -9,8 +9,8 @@ type ContentURL struct {
PoolCSVUpload string
SamplePoolCSV string
Setting string
SettingDistrict string
SettingIntegration string
SettingOrganization string
SettingPesticide string
SettingPesticideAdd string
SettingUser string
@ -24,8 +24,8 @@ func newContentURL() ContentURL {
PoolCSVUpload: config.MakeURLNidus("/pool/upload"),
SamplePoolCSV: config.MakeURLNidus("/static/file/sample-pool.csv"),
Setting: config.MakeURLNidus("/setting"),
SettingDistrict: config.MakeURLNidus("/setting/district"),
SettingIntegration: config.MakeURLNidus("/setting/integration"),
SettingOrganization: config.MakeURLNidus("/setting/organization"),
SettingPesticide: config.MakeURLNidus("/setting/pesticide"),
SettingPesticideAdd: config.MakeURLNidus("/setting/pesticide/add"),
SettingUser: config.MakeURLNidus("/setting/user"),