summaryrefslogtreecommitdiff
path: root/views.rkt
diff options
context:
space:
mode:
Diffstat (limited to 'views.rkt')
-rw-r--r--views.rkt90
1 files changed, 44 insertions, 46 deletions
diff --git a/views.rkt b/views.rkt
index 00af4b6..f319879 100644
--- a/views.rkt
+++ b/views.rkt
@@ -68,33 +68,31 @@
;; Pages
(define (ferti-page fertilizer-recipe latest-measurement-hash latest-target-hash measurements)
- (page-template
- "Ferti"
- `((h1 ((class "display-1 mb-3")) "Ferti")
- ,ferti-actions
- ,@(ferti-recipe fertilizer-recipe)
- ,@(ferti-targets latest-measurement-hash latest-target-hash)
- ,@(ferti-measurements measurements)
- ,@(ferti-fertilizers))))
+ (page-template "Ferti"
+ `((h1 ((class "display-1 mb-3")) "Ferti") ,ferti-actions
+ ,@(ferti-recipe fertilizer-recipe)
+ ,@(ferti-targets latest-measurement-hash
+ latest-target-hash)
+ ,@(ferti-measurements measurements)
+ ,@(ferti-fertilizers))))
(define ferti-actions
`(div ((class "btn-group mb-3"))
(a ((class "btn btn-outline-primary") [href "/target/new"]) "Créer une cible")
(a ((class "btn btn-outline-primary") [href "/measurement/new"]) "Ajouter un relevé")
(a ((class "btn btn-outline-primary") [href "/fertilizer/new"]) "Ajouter un intrant")))
-
(define (ferti-recipe ferti-recipe)
- `((h2 () "Recette")
- ,(if (ormap (λ (pair) (not (zero? (cdr pair)))) ferti-recipe)
- `(table ((class "table"))
- (tr (th "Intrant") (th ((class "text-end")) "Quantité (g/L)"))
- ,@(for/list ([fertilizer-amount ferti-recipe]
- #:when (not (zero? (cdr fertilizer-amount))))
- (match-define (cons fertilizer amount) fertilizer-amount)
- `(tr (td () ,(fertilizer-name fertilizer))
- (td ((class "text-end font-monospace")) ,(round 2 amount)))))
- `(p "La recette Ferti requiert au moins un relevé et une cible."))))
+ `((h2 () "Recette") ,(if (ormap (λ (pair) (not (zero? (cdr pair)))) ferti-recipe)
+ `(table ((class "table"))
+ (tr (th "Intrant") (th ((class "text-end")) "Quantité (g/L)"))
+ ,@(for/list ([fertilizer-amount ferti-recipe]
+ #:when (not (zero? (cdr fertilizer-amount))))
+ (match-define (cons fertilizer amount) fertilizer-amount)
+ `(tr (td () ,(fertilizer-name fertilizer))
+ (td ((class "text-end font-monospace"))
+ ,(round 2 amount)))))
+ `(p "La recette Ferti requiert au moins un relevé et une cible."))))
(define (ferti-targets latest-measurement-hash latest-target-hash)
`((h2 () "Dernière Cible")
@@ -128,35 +126,35 @@
"—")))))))
(define (ferti-measurements measurements)
- `((h2 () "Relevés")
- (table ((class "table table-striped"))
- (tr (th "Date")
- (th ((class "text-end")) "N")
- (th ((class "text-end")) "P")
- (th ((class "text-end")) "K"))
- ,@(for/list ([m measurements])
- (define measured-on (nutrient-measurement-date m))
- (define-values (n p k)
- (apply values
- (for/list ([nutrient '("Nitrate Nitrogen" "Phosphorus" "Potassium")])
- (define n (get-nutrient #:name nutrient))
- (define mnv (get-nutrient-measurement-value m n))
- (if (real? mnv)
- (round 2 mnv)
- "—"))))
- `(tr (td ,measured-on)
- (td ((class "text-end font-monospace")) ,n)
- (td ((class "text-end font-monospace")) ,p)
- (td ((class "text-end font-monospace")) ,k))))))
+ `((h2 () "Relevés") (table ((class "table table-striped"))
+ (tr (th "Date")
+ (th ((class "text-end")) "N")
+ (th ((class "text-end")) "P")
+ (th ((class "text-end")) "K"))
+ ,@(for/list ([m measurements])
+ (define measured-on (nutrient-measurement-date m))
+ ;; TODO: use new nutrient-value hash, available
+ ;; immediately in this context.
+ (define-values (n p k)
+ (apply values
+ (for/list ([nutrient '("Nitrate Nitrogen" "Phosphorus"
+ "Potassium")])
+ (define n (get-nutrient #:name nutrient))
+ (define mnv (get-nutrient-measurement-value m n))
+ (if (real? mnv)
+ (round 2 mnv)
+ "—"))))
+ `(tr (td ,measured-on)
+ (td ((class "text-end font-monospace")) ,n)
+ (td ((class "text-end font-monospace")) ,p)
+ (td ((class "text-end font-monospace")) ,k))))))
(define (ferti-fertilizers)
- `((h2 () "Intrants")
- (table ((class "table table-striped"))
- (tr (th () "Nom de référence")
- (th () "Nom de marque"))
- ,@(for/list ([fertilizer (get-fertilizer-products)])
- `(tr (td ,(fertilizer-name fertilizer))
- (td ,(or (fertilizer-brand-name fertilizer) "—")))))))
+ `((h2 () "Intrants") (table ((class "table table-striped"))
+ (tr (th () "Nom de référence") (th () "Nom de marque"))
+ ,@(for/list ([fertilizer (get-fertilizer-products)])
+ `(tr (td ,(fertilizer-name fertilizer))
+ (td ,(or (fertilizer-brand-name fertilizer) "—")))))))
(define (new-measurement-page)
(page-template "Nouveau relevé"
Copyright 2019--2026 Marius PETER