From 1e98c940c5a133fc20a05ea9cd5b4a6cf561c349 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Sun, 14 Dec 2025 11:07:32 +0100 Subject: Add crop requirement new/show/edit logic. --- formlets.rkt | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'formlets.rkt') diff --git a/formlets.rkt b/formlets.rkt index c35e882..c2923ad 100644 --- a/formlets.rkt +++ b/formlets.rkt @@ -2,7 +2,8 @@ (provide measurements-formlet rotation-formlet - fertilizer-formlet) + fertilizer-formlet + crop-requirements-formlet) (require gregor web-server/formlets @@ -82,10 +83,43 @@ (let ([id (string->number (first id*))] [canonical-name (first canonical-name*)] [brand-name (first brand-name*)] - [nutrient-values (for/hash ([nv nutrient-values*]) - (values (car nv) (cdr nv)))]) + [nutrient-values (make-immutable-hash nutrient-values*)]) (fertilizer-product id canonical-name brand-name nutrient-values)))) +(define (crop-requirements-formlet #:value [cr #f]) + (formlet* (#%# (=>* (to-string (required (hidden (if cr + (number->string (crop-requirement-id cr)) + "")))) + id*) + `(div ((class "mb-3")) + (h5 "Profil de culture") + ,(=>* (required-string-input #:value (if cr + (crop-requirement-profile cr) + "")) + profile*)) + `(div ((class "mb-3")) + (h5 "Culture associƩe") + ,(=>* (select-input (cons (crop #f "") (get-crops)) + #:attributes '((class "form-select")) + #:display crop-name) + crop*)) + `(div ((class "mb-3")) + (h5 "Valeurs du profil") + ,@(for/list ([n (get-nutrients)]) + (define v + (if cr + (crop-requirement-value cr n) + 0)) + (=>* (nutrient-value-formlet n v) nutrient-values*))) + (=>* (submit (string-join (list (if cr "Modifier" "Enregistrer") "l'intrant")) + #:attributes '((class "btn btn-primary"))) + _)) + (let ([id (string->number (first id*))] + [profile (first profile*)] + [crop-id (crop-id (first crop*))] + [nutrient-values (make-immutable-hash nutrient-values*)]) + (crop-requirement id profile crop-id nutrient-values)))) + (define (crop-requirement-formlet requirement) (define id (number->string (crop-requirement-id requirement))) (define profile (crop-requirement-profile requirement)) -- cgit v1.2.3