diff options
| author | Marius Peter <dev@marius-peter.com> | 2025-12-13 17:01:24 +0100 |
|---|---|---|
| committer | Marius Peter <dev@marius-peter.com> | 2025-12-13 17:01:24 +0100 |
| commit | ad27abde5a5a45f4d1fb9290c8baf71cef7b516f (patch) | |
| tree | 1bc1a5c0f15f284b072ac3fd7d7cd86b702da079 | |
| parent | 89ea0330ef89b41998f069e5acdc9fb1fcceecce (diff) | |
Sort fertilizer product values by nutrient quantity.
| -rw-r--r-- | views.rkt | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -242,15 +242,15 @@ (define (show-fertilizer-page fp) (define product-name (fertilizer-product-name fp)) (define brand-name (fertilizer-brand-name fp)) - (define nutrient-values (fertilizer-product-values fp)) + (define positive-nutrient-values (hash-filter-values (fertilizer-product-values fp) positive?)) + (define sorted-nutrient-values (sort (hash->list positive-nutrient-values) > #:key cdr)) (define table `(table ((class "table")) (thead (tr (th "Nutriment") (th ((class "text-end")) "Apport (mg/L)"))) - (tbody ,@(for/list ([(nutrient quantity) (in-hash nutrient-values)] - #:when (not (zero? quantity))) - `(tr (td ,(nutrient-french-name nutrient)) - (td ((class "text-end font-monospace")) ,(round 2 quantity))))))) - + (tbody ,@(for/list ([nv-pair sorted-nutrient-values]) + (match-define (cons n v) nv-pair) + `(tr (td ,(nutrient-french-name n)) + (td ((class "text-end font-monospace")) ,(round 2 v))))))) (page-template product-name `((h1 ((class "display-1 mb-3")) ,(or brand-name "Intrant générique")) (h5 ((class "display-5 mb-3")) ,product-name) |