summaryrefslogtreecommitdiff
path: root/views.rkt
diff options
context:
space:
mode:
Diffstat (limited to 'views.rkt')
-rw-r--r--views.rkt63
1 files changed, 52 insertions, 11 deletions
diff --git a/views.rkt b/views.rkt
index b988fef..adcf59b 100644
--- a/views.rkt
+++ b/views.rkt
@@ -9,14 +9,17 @@
new-measurement-page
new-rotation-page
new-fertilizer-page
+ new-crop-page
+ new-crop-requirement-page
edit-measurement-page
edit-fertilizer-page
+ edit-crop-page
+ edit-crop-requirement-page
show-measurement-page
show-rotation-page
show-fertilizer-page
+ show-crop-page
show-crop-requirement-page
- new-crop-requirement-page
- edit-crop-requirement-page
fallback-page)
(require gregor
@@ -167,17 +170,19 @@
`(table ((class "table table-striped"))
(tr (th "Profil") (th "Culture"))
,@(for/list ([cr crop-requirements])
- (define crop-id (crop-requirement-crop-id cr))
+ (define cid (crop-requirement-crop-id cr))
`(tr (td (a ((href ,(format "/ferti/crop-requirements/~a" (crop-requirement-id cr))))
,(string-titlecase (crop-requirement-profile cr))))
- (td ,(if crop-id
- (string-titlecase (crop-name (get-crop #:id crop-id)))
+ (td ,(if cid
+ (let ([crop (get-crop #:id cid)])
+ `(a ((href ,(format "/ferti/crops/~a" cid)))
+ ,(string-titlecase (crop-name crop))))
"—"))))))
(define button-group
'(div ((class "btn-group mb-3"))
(a ((class "btn btn-primary") [href "/ferti/crop-requirements/new"]) "Ajouter un profil")
- (a ((class "btn btn-secondary") [href "/ferti/crop/new"]) "Ajouter une culture")))
- (ferti-template "Cultures" `(,button-group ,table)))
+ (a ((class "btn btn-secondary") [href "/ferti/crops/new"]) "Ajouter une culture")))
+ (ferti-template "Cultures" (list button-group accordion)))
;; TODO: add bar chart for comparing to target concentrations
(define (ferti-recipe-page recipe-date fertilizer-recipe)
@@ -218,6 +223,9 @@
(define (new-fertilizer-page)
(form-page-template "Nouvel intrant" "/ferti/fertilizers/create" (fertilizer-formlet)))
+(define (new-crop-page)
+ (form-page-template "Nouvelle culture" "/ferti/crops/create" (crop-formlet)))
+
(define (new-crop-requirement-page)
(form-page-template "Nouveau profil" "/ferti/crop-requirements/create" (crop-requirements-formlet)))
@@ -229,7 +237,12 @@
(measurements-formlet #:value nm)))
(define (edit-fertilizer-page fp)
- (form-page-template "Modifier intrant" "/ferti/fertilizers/update" (fertilizer-formlet #:value fp)))
+ (form-page-template "Modifier l'intrant"
+ "/ferti/fertilizers/update"
+ (fertilizer-formlet #:value fp)))
+
+(define (edit-crop-page crop)
+ (form-page-template "Modifier la culture" "/ferti/crops/update" (crop-formlet #:value crop)))
(define (edit-crop-requirement-page cr)
(form-page-template "Modifier profil"
@@ -285,7 +298,7 @@
(define (show-fertilizer-page fp)
(define id (fertilizer-product-id fp))
- (define product-name (fertilizer-product-name fp))
+ (define product-name (string-titlecase (fertilizer-product-name fp)))
(define brand-name (fertilizer-brand-name fp))
(define sorted-nutrient-values (get-sorted-nutrient-values (fertilizer-product-values fp)))
(define table
@@ -307,9 +320,33 @@
,button-group
,table)))
+(define (show-crop-page crop)
+ (define id (crop-id crop))
+ (define name (string-titlecase (crop-name crop)))
+ (define crop-requirements-for-crop
+ (filter (λ (cr) (equal? (crop-requirement-crop-id cr) (crop-id crop))) (get-crop-requirements)))
+ (define profile-list
+ `(ul ,@(for/list ([cr crop-requirements-for-crop])
+ `(li (a ([href ,(format "/ferti/crop-requirements/~a" (crop-requirement-id cr))])
+ ,(string-titlecase crop-requirement-profile cr))))))
+ (define button-group
+ `(div ((class "btn-group mb-3"))
+ (a ((class "btn btn-primary") [href ,(format "/ferti/crops/~a/edit" id)]) "Modifier")
+ (a ((class "btn btn-danger") [href ,(format "/ferti/crops/~a/destroy" id)]) "Supprimer")))
+ (page-template name `((h1 ((class "display-1 mb-3")) ,name) ,button-group ,profile-list)))
+
(define (show-crop-requirement-page cr)
(define id (crop-requirement-id cr))
- (define title (string-titlecase (crop-requirement-profile cr)))
+ (define cid (crop-requirement-crop-id cr))
+ (define crop
+ (if cid
+ (string-titlecase (crop-name (get-crop #:id cid)))
+ #f))
+ (define profile (string-titlecase (crop-requirement-profile cr)))
+ (define title
+ (if crop
+ (format "~a — ~a" crop profile)
+ profile))
(define table
`(table ((class "table") (style "max-width: 30em"))
(thead (tr (th "Nutriment") (th ((class "text-end")) "Concentration (mg/L)")))
@@ -323,7 +360,11 @@
"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)))
+ (page-template title
+ `((h1 ((class "display-1 mb-3")) ,profile) (h5 ((class "display-5 mb-3"))
+ ,(or crop "Profil générique"))
+ ,button-group
+ ,table)))
(define (index-page user)
(page-template
Copyright 2019--2026 Marius PETER