diff options
Diffstat (limited to 'formlets.rkt')
| -rw-r--r-- | formlets.rkt | 40 |
1 files changed, 37 insertions, 3 deletions
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 "<aucune>") (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)) |