Add link from root upload page to upload pool detail page.
This commit is contained in:
parent
a776c83557
commit
c8f5408f27
8 changed files with 20 additions and 85 deletions
|
|
@ -61,6 +61,10 @@ func bigNumber(n int) string {
|
|||
}
|
||||
func displayUploadStatus(s string) string {
|
||||
switch s {
|
||||
case "committed":
|
||||
return "committed"
|
||||
case "discarded":
|
||||
return "Discarded"
|
||||
case "error":
|
||||
return "Bad upload"
|
||||
case "parsed":
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
{{ template "sync/layout/authenticated.html" . }}
|
||||
|
||||
{{ define "title" }}Pool List{{ end }}
|
||||
{{ define "extraheader" }}
|
||||
<script>
|
||||
function onLoaded() {
|
||||
document.querySelectorAll("tr.clickable-row").forEach((el) => {
|
||||
el.addEventListener("click", (e) => {
|
||||
let element = e.target;
|
||||
while (element.nodeName != "TR") {
|
||||
element = element.parentElement;
|
||||
}
|
||||
let uploadId = element.dataset.uploadId;
|
||||
window.location = "/pool/upload/" + uploadId;
|
||||
});
|
||||
});
|
||||
}
|
||||
document.addEventListener("DOMContentLoaded", onLoaded);
|
||||
</script>
|
||||
{{ end }}
|
||||
{{ define "content" }}
|
||||
<div class="container-fluid py-3">
|
||||
<div class="col-12">
|
||||
<div class="row">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header">
|
||||
<h1>Pool CSV Uploads</h1>
|
||||
</div>
|
||||
<div class="card-body py-2">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-bordered table-hover">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Status</th>
|
||||
<th>Uploaded</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range .C.Uploads }}
|
||||
<tr class="clickable-row" data-upload-id="{{ .ID }}">
|
||||
<td>{{ .Status }}</td>
|
||||
<td>{{ .Created|timeRelative }}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<a class="btn btn-primary" href="{{ .URL.PoolCSVUpload }}"
|
||||
>Do an upload</a
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
|
@ -133,7 +133,7 @@
|
|||
</div>
|
||||
<div class="card-body">
|
||||
<form
|
||||
action="{{ .URL.PoolCSVUpload }}"
|
||||
action="{{ .URL.UploadCSVPool }}"
|
||||
method="POST"
|
||||
enctype="multipart/form-data"
|
||||
>
|
||||
|
|
@ -36,16 +36,9 @@
|
|||
Upload spreadsheets with addresses and contact information of
|
||||
unmaintained pools that may breed mosquitoes.
|
||||
</p>
|
||||
<p class="text-muted small">Supported formats: .xlsx, .csv, .xls</p>
|
||||
<div class="mb-3">
|
||||
<label for="greenPoolFile" class="form-label"
|
||||
>Select file to import</label
|
||||
>
|
||||
<input class="form-control" type="file" id="greenPoolFile" />
|
||||
</div>
|
||||
<button type="button" class="btn btn-success">
|
||||
<i class="bi bi-upload me-2"></i>Upload Green Pool Data
|
||||
</button>
|
||||
<a class="btn btn-primary" href="{{ .URL.UploadCSVPool }}">
|
||||
<i class="bi bi-upload me-2"></i>Upload Green Pool Data</a
|
||||
>
|
||||
</div>
|
||||
<div class="card-footer bg-white text-muted">
|
||||
<small><i class="bi bi-clock"></i> Last import: 02/15/2023</small>
|
||||
|
|
|
|||
|
|
@ -79,6 +79,14 @@ func ProcessJob(ctx context.Context, file_id int32) error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("parse file: %w", err)
|
||||
}
|
||||
_, err = psql.Update(
|
||||
um.Table("fileupload.csv"),
|
||||
um.SetCol("rowcount").ToArg(len(pools)),
|
||||
um.Where(psql.Quote("id").EQ(psql.Arg(file_id))),
|
||||
).Exec(ctx, txn)
|
||||
if err != nil {
|
||||
return fmt.Errorf("update csv row: %w", err)
|
||||
}
|
||||
err = bulkGeocode(ctx, txn, *file, pools)
|
||||
if err != nil {
|
||||
return fmt.Errorf("bulk geocode: %w", err)
|
||||
|
|
|
|||
|
|
@ -74,8 +74,7 @@ func Router() chi.Router {
|
|||
r.Method("GET", "/trap/{globalid}", authenticatedHandler(getTrap))
|
||||
r.Method("GET", "/text/{destination}", authenticatedHandler(getTextMessages))
|
||||
r.Method("GET", "/upload", authenticatedHandler(getUploadList))
|
||||
r.Method("GET", "/upload/pool", authenticatedHandler(getUploadPoolList))
|
||||
r.Method("GET", "/upload/pool/create", authenticatedHandler(getUploadPoolCreate))
|
||||
r.Method("GET", "/upload/pool", authenticatedHandler(getUploadPoolCreate))
|
||||
r.Method("POST", "/upload/pool/create", authenticatedHandlerPostMultipart(postUploadPoolCreate))
|
||||
r.Method("GET", "/upload/{id}", authenticatedHandler(getUploadByID))
|
||||
r.Method("POST", "/upload/{id}/discard", authenticatedHandlerPost(postUploadDiscard))
|
||||
|
|
|
|||
|
|
@ -47,20 +47,9 @@ type contentUploadPoolList struct {
|
|||
}
|
||||
type contentUploadPoolCreate struct{}
|
||||
|
||||
func getUploadPoolList(ctx context.Context, r *http.Request, org *models.Organization, u *models.User) (*response[contentUploadPoolList], *errorWithStatus) {
|
||||
uploads, err := platform.PoolUploadList(ctx, u.OrganizationID)
|
||||
if err != nil {
|
||||
return nil, newError("Failed to get uploads: %w", err)
|
||||
}
|
||||
data := contentUploadPoolList{
|
||||
Uploads: uploads,
|
||||
}
|
||||
return newResponse("sync/pool-list.html", data), nil
|
||||
}
|
||||
|
||||
func getUploadPoolCreate(ctx context.Context, r *http.Request, org *models.Organization, u *models.User) (*response[contentUploadPoolCreate], *errorWithStatus) {
|
||||
data := contentUploadPoolCreate{}
|
||||
return newResponse("sync/pool-csv-upload.html", data), nil
|
||||
return newResponse("sync/upload-csv-pool.html", data), nil
|
||||
}
|
||||
func getUploadByID(ctx context.Context, r *http.Request, org *models.Organization, u *models.User) (*response[contentUploadDetail], *errorWithStatus) {
|
||||
file_id_str := chi.URLParam(r, "id")
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
type ContentURL struct {
|
||||
OAuthRefreshArcGIS string
|
||||
PoolCSVUpload string
|
||||
Root string
|
||||
Route string
|
||||
SamplePoolCSV string
|
||||
|
|
@ -18,12 +17,12 @@ type ContentURL struct {
|
|||
SettingUser string
|
||||
SettingUserAdd string
|
||||
Tegola string
|
||||
UploadCSVPool string
|
||||
}
|
||||
|
||||
func newContentURL() ContentURL {
|
||||
return ContentURL{
|
||||
OAuthRefreshArcGIS: config.MakeURLNidus("/arcgis/oauth/begin"),
|
||||
PoolCSVUpload: config.MakeURLNidus("/pool/upload"),
|
||||
Root: config.MakeURLNidus("/"),
|
||||
Route: config.MakeURLNidus("/route"),
|
||||
SamplePoolCSV: config.MakeURLNidus("/static/file/sample-pool.csv"),
|
||||
|
|
@ -35,5 +34,6 @@ func newContentURL() ContentURL {
|
|||
SettingUser: config.MakeURLNidus("/setting/user"),
|
||||
SettingUserAdd: config.MakeURLNidus("/setting/user/add"),
|
||||
Tegola: config.MakeURLTegola("/"),
|
||||
UploadCSVPool: config.MakeURLNidus("/upload/pool"),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue