summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Peter <dev@marius-peter.com>2025-11-22 12:34:09 +0100
committerMarius Peter <dev@marius-peter.com>2025-11-22 12:34:09 +0100
commit8efac69f40fb1d499b409f79283cc8e6518cc1ab (patch)
tree8e75bd02be090ff7e2183fa9f8a4df8e917f84f4
parent5408b445776234c35fb61374d2d3abc6b83b2904 (diff)
raco fmt.
-rw-r--r--db/conn.rkt2
-rw-r--r--handlers.rkt16
-rw-r--r--main.rkt7
-rw-r--r--views.rkt90
4 files changed, 56 insertions, 59 deletions
diff --git a/db/conn.rkt b/db/conn.rkt
index 793cf03..2208e54 100644
--- a/db/conn.rkt
+++ b/db/conn.rkt
@@ -15,7 +15,7 @@
[(connection? (current-conn)) (printf "Database connection already exists: ~e\n" (current-conn))]
[else
(current-conn (sqlite3-connect #:database path #:mode 'create))
- (printf "Created database connection at path: ~a\n" path)]))
+ (printf "Connected to database: ~a\n" path)]))
(define (disconnect!)
(disconnect (current-conn))
diff --git a/handlers.rkt b/handlers.rkt
index fb3f864..42ed13a 100644
--- a/handlers.rkt
+++ b/handlers.rkt
@@ -17,16 +17,16 @@
(define (wrap-basic-auth handler)
(lambda (req)
(match (request->basic-credentials req)
- [(cons user pass)
- ;; credentials found → continue to dispatcher
- (handler req)]
+ ;; credentials found → continue to dispatcher
+ [(cons user pass) (handler req)]
[else
;; no credentials → trigger auth challenge
- (response
- 401 #"Unauthorized" (current-seconds) TEXT/HTML-MIME-TYPE
- (list
- (make-basic-auth-header "Ferti Private Area"))
- void)])))
+ (response 401
+ #"Unauthorized"
+ (current-seconds)
+ TEXT/HTML-MIME-TYPE
+ (list (make-basic-auth-header "Ferti Private Area"))
+ void)])))
(define-values (app-dispatch _)
(dispatch-rules [("ferti") #:method "get" ferti]
diff --git a/main.rkt b/main.rkt
index 4cf8e9f..03cceeb 100644
--- a/main.rkt
+++ b/main.rkt
@@ -9,10 +9,9 @@
(define-runtime-path development-db-path "storage/development.sqlite3")
(module+ main
- (with-handlers ([exn:fail?
- (λ (e)
- (printf "Startup error: ~a\n" (exn-message e))
- (exit 1))])
+ (with-handlers ([exn:fail? (λ (e)
+ (printf "Startup error: ~a\n" (exn-message e))
+ (exit 1))])
(connect! #:path development-db-path)
(if (file-exists? development-db-path)
(printf "Database already exists: ~a" development-db-path)
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