summaryrefslogtreecommitdiff
path: root/views.rkt
diff options
context:
space:
mode:
authorMarius Peter <dev@marius-peter.com>2025-12-14 11:07:32 +0100
committerMarius Peter <dev@marius-peter.com>2025-12-14 11:07:32 +0100
commit1e98c940c5a133fc20a05ea9cd5b4a6cf561c349 (patch)
tree5dd74f222fec0cd0ae14193b2805eb234a7b53ec /views.rkt
parentbd7f884180efbe0b47aa6de64b86489d0a81be07 (diff)
Add crop requirement new/show/edit logic.
Diffstat (limited to 'views.rkt')
-rw-r--r--views.rkt36
1 files changed, 30 insertions, 6 deletions
diff --git a/views.rkt b/views.rkt
index 2ffce4c..e46843f 100644
--- a/views.rkt
+++ b/views.rkt
@@ -14,6 +14,9 @@
show-measurement-page
show-rotation-page
show-fertilizer-page
+ show-crop-requirement-page
+ new-crop-requirement-page
+ edit-crop-requirement-page
fallback-page)
(require gregor
@@ -206,6 +209,9 @@
(define (new-fertilizer-page)
(form-page-template "Nouvel intrant" "/ferti/fertilizers/create" (fertilizer-formlet)))
+(define (new-crop-requirement-page)
+ (form-page-template "Nouveau profil" "/ferti/crop-requirements/create" (crop-requirements-formlet)))
+
;; Edit
(define (edit-measurement-page nm)
@@ -216,12 +222,12 @@
(define (edit-fertilizer-page fp)
(form-page-template "Modifier intrant" "/ferti/fertilizers/update" (fertilizer-formlet #:value fp)))
-;; (define (new-crop-requirement-page)
-;; (page-template "Nouveau profil"
-;; `((h1 ((class "display-1 mb-3")) "Nouveau profil")
-;; (div ((class "mb-3") [style "max-width: 30em"])
-;; (form ([action "/ferti/crop-requirements/create"] [method "POST"])
-;; ,@(formlet-display (crop-requirement-formlet)))))))
+(define (edit-crop-requirement-page cr)
+ (form-page-template "Modifier profil"
+ "/ferti/crop-requirements/update"
+ (crop-requirements-formlet #:value cr)))
+
+;; Show
(define (show-measurement-page nm)
(define title (format "Relevé du ~a" (normal-date (nutrient-measurement-date nm))))
@@ -285,6 +291,24 @@
,button-group
,table)))
+(define (show-crop-requirement-page cr)
+ (define id (crop-requirement-id cr))
+ (define title (string-titlecase (crop-requirement-profile cr)))
+ (define table
+ `(table ((class "table") (style "max-width: 30em"))
+ (thead (tr (th "Nutriment") (th ((class "text-end")) "Concentration (mg/L)")))
+ (tbody ,@(for/list ([n (get-nutrients)])
+ (define nutrient-value (hash-ref (crop-requirement-values cr) n 0))
+ `(tr (td ,(nutrient-french-name n))
+ (td ((class "text-end font-monospace")) ,(round 2 nutrient-value)))))))
+ (define button-group
+ `(div ((class "btn-group"))
+ (a ((class "btn btn-primary") [href ,(format "/ferti/crop-requirements/~a/edit" id)])
+ "Modifier")
+ (a ((class "btn btn-danger") [href ,(format "/ferti/crop-requirements/~a/destroy" id)])
+ "Supprimer")))
+ (page-template title `((h1 ((class "display-1 mb-3")) ,title) ,button-group ,table)))
+
(define (index-page user)
(page-template
"Bienvenue à la FAPG"
Copyright 2019--2026 Marius PETER