diff --git a/platform/feature.go b/platform/feature.go new file mode 100644 index 00000000..2a36372e --- /dev/null +++ b/platform/feature.go @@ -0,0 +1,42 @@ +package platform + +import ( + "context" + "fmt" + + //"github.com/aarondl/opt/omit" + //"github.com/aarondl/opt/omitnull" + //"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/db" + "github.com/Gleipnir-Technology/nidus-sync/db/models" + //"github.com/Gleipnir-Technology/nidus-sync/platform/geocode" + "github.com/Gleipnir-Technology/nidus-sync/platform/types" + //"github.com/stephenafamo/scan" +) + +func featuresBySiteID(ctx context.Context, site_ids []int32) (map[int32][]types.Feature, error) { + rows, err := models.Features.Query( + sm.Where(models.Features.Columns.SiteID.EQ(psql.Any(site_ids))), + ).All(ctx, db.PGInstance.BobDB) + if err != nil { + return nil, fmt.Errorf("query features: %w", err) + } + results := make(map[int32][]types.Feature, len(site_ids)) + for _, site_id := range site_ids { + results[site_id] = make([]types.Feature, 0) + } + for _, row := range rows { + features, ok := results[row.SiteID] + if !ok { + return nil, fmt.Errorf("impossible") + } + features = append(features, types.Feature{ + ID: row.ID, + Type: "pool", + }) + results[row.SiteID] = features + } + return results, nil +} diff --git a/platform/site.go b/platform/site.go index 5e321279..a2fae236 100644 --- a/platform/site.go +++ b/platform/site.go @@ -100,9 +100,22 @@ func SiteList(ctx context.Context, user User, limit int) ([]*types.Site, error) if err != nil { return nil, fmt.Errorf("query sites: %w", err) } + site_ids := make([]int32, len(rows)) results := make([]*types.Site, len(rows)) for i, row := range rows { results[i] = &row + site_ids[i] = row.ID + } + features_by_site_id, err := featuresBySiteID(ctx, site_ids) + if err != nil { + return nil, fmt.Errorf("query features for sites: %w", err) + } + for _, result := range results { + features, ok := features_by_site_id[result.ID] + if !ok { + return nil, fmt.Errorf("impossible") + } + result.Features = features } return results, nil } diff --git a/platform/types/feature.go b/platform/types/feature.go new file mode 100644 index 00000000..91e483f4 --- /dev/null +++ b/platform/types/feature.go @@ -0,0 +1,7 @@ +package types + +type Feature struct { + ID int32 `db:"id" json:"id"` + Location Location `db:"location" json:"location"` + Type string `db:"-" json:"type"` +} diff --git a/platform/types/site.go b/platform/types/site.go index 894e51c9..c1d53b82 100644 --- a/platform/types/site.go +++ b/platform/types/site.go @@ -10,6 +10,7 @@ type Site struct { Address Address `db:"address" json:"address"` Created time.Time `db:"created" json:"created"` CreatorID int32 `db:"creator_id" json:"creator_id"` + Features []Feature `db:"-" json:"features"` FileID int32 `db:"file_id" json:"file_id"` ID int32 `db:"id" json:"id"` Notes string `db:"notes" json:"notes"` diff --git a/ts/components/ReviewSiteColumnAction.vue b/ts/components/ReviewSiteColumnAction.vue index 3c0673de..b6d0366f 100644 --- a/ts/components/ReviewSiteColumnAction.vue +++ b/ts/components/ReviewSiteColumnAction.vue @@ -1,11 +1,36 @@ - loading + Actions + + select a site to see actions + + + + + Send Compliance Mailer + + + + Submitting... + + + diff --git a/ts/view/review/Site.vue b/ts/view/review/Site.vue index fc01f760..34361ddb 100644 --- a/ts/view/review/Site.vue +++ b/ts/view/review/Site.vue @@ -43,7 +43,10 @@ body { /> - + @@ -71,6 +74,7 @@ const props = withDefaults(defineProps(), {}); const mapFlyoverCamera = ref(new Camera()); const storeSite = useStoreSite(); const selectedSiteID = ref(0); +const submitting = ref(false); const selectedSite = computed((): Site | undefined => { if (!selectedSiteID.value) { return undefined;
loading
select a site to see actions