Add feature to site data
This commit is contained in:
parent
5a35c1d1f8
commit
74e24b7de3
6 changed files with 97 additions and 5 deletions
42
platform/feature.go
Normal file
42
platform/feature.go
Normal file
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
7
platform/types/feature.go
Normal file
7
platform/types/feature.go
Normal file
|
|
@ -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"`
|
||||
}
|
||||
|
|
@ -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"`
|
||||
|
|
|
|||
|
|
@ -1,11 +1,36 @@
|
|||
<template>
|
||||
<p>loading</p>
|
||||
<h5 class="mb-4">Actions</h5>
|
||||
<template v-if="!selectedSite">
|
||||
<p>select a site to see actions</p>
|
||||
</template>
|
||||
<template v-if="selectedSite">
|
||||
<button
|
||||
class="btn btn-success action-btn"
|
||||
@click="emit('doRequestComplianceMailer', selectedSite?.id ?? 0)"
|
||||
:disabled="!selectedSite || submitting"
|
||||
>
|
||||
<span v-if="!submitting">
|
||||
<i class="bi bi-check-circle"></i> Send Compliance Mailer
|
||||
</span>
|
||||
<span v-else>
|
||||
<span class="spinner-border spinner-border-sm" role="status"></span>
|
||||
Submitting...
|
||||
</span>
|
||||
</button>
|
||||
</template>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { Site } from "@/type/api";
|
||||
|
||||
interface Emits {
|
||||
(e: "doSelectTask", id: number): void;
|
||||
(e: "doRequestComplianceMailer", id: number): void;
|
||||
}
|
||||
interface Props {
|
||||
selectedSite: Site | undefined;
|
||||
submitting?: boolean;
|
||||
}
|
||||
interface Props {}
|
||||
const emit = defineEmits<Emits>();
|
||||
const props = withDefaults(defineProps<Props>(), {});
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
submitting: false,
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -43,7 +43,10 @@ body {
|
|||
/>
|
||||
</template>
|
||||
<template #right>
|
||||
<ReviewSiteColumnAction />
|
||||
<ReviewSiteColumnAction
|
||||
:selectedSite="selectedSite"
|
||||
:submitting="submitting"
|
||||
/>
|
||||
</template>
|
||||
</ThreeColumn>
|
||||
</template>
|
||||
|
|
@ -71,6 +74,7 @@ const props = withDefaults(defineProps<Props>(), {});
|
|||
const mapFlyoverCamera = ref<Camera>(new Camera());
|
||||
const storeSite = useStoreSite();
|
||||
const selectedSiteID = ref<number>(0);
|
||||
const submitting = ref<boolean>(false);
|
||||
const selectedSite = computed((): Site | undefined => {
|
||||
if (!selectedSiteID.value) {
|
||||
return undefined;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue