Add custom display functions for certain model entities.

Commit
1b23eec4517a8628a9564c9ed25923e6c9ea5bd8
Author
Marius Peter <dev@marius-peter.com>
Author date
Committer
Marius Peter <dev@marius-peter.com>
Committer date
Changed files
models/fertilizer-product.rkt
index bd6bba92..0a6c03dd 100644..100644
@@ -30,7 +30,22 @@
30 30 "nutrient.rkt")
31 31
32 32 ;; Instances of this struct are persisted in the fertilizer_products table.
33 Removed: (struct fertilizer-product (id canonical-name nutrient-values brand-name) #:transparent)
33 Added: (struct fertilizer-product (id canonical-name nutrient-values brand-name)
34 Added: #:transparent
35 Added: #:property prop:custom-write
36 Added: (λ (v out _mode)
37 Added: (fprintf out "Fertilizer #~a\n" (fertilizer-product-id v))
38 Added: (if (fertilizer-product-brand-name v)
39 Added: (fprintf out "~a (~a)\n"
40 Added: (fertilizer-product-canonical-name v)
41 Added: (fertilizer-product-brand-name v))
42 Added: (fprintf out "~a\n"
43 Added: (fertilizer-product-canonical-name v)))
44 Added: (for ([nv (in-list (fertilizer-product-nutrient-values v))])
45 Added: (match-define (cons n v) nv)
46 Added: (fprintf out "~a ~a\n"
47 Added: (~a (nutrient-name n) #:min-width 14)
48 Added: (~a v #:max-width 6 #:align 'right)))))
34 49
35 50
36 51 ;; CREATE
models/nutrient-measurement.rkt
index d3631dee..e73a10e4 100644..100644
@@ -31,7 +31,18 @@
31 31 "nutrient.rkt")
32 32
33 33 ;; Instances of this struct are persisted in the nutrient_measurements table.
34 Removed: (struct nutrient-measurement (id measured-on nutrient-values) #:transparent)
34 Added: (struct nutrient-measurement (id measured-on nutrient-values)
35 Added: #:transparent
36 Added: #:property prop:custom-write
37 Added: (λ (v out _)
38 Added: (fprintf out "Measurement #~a on ~a\n"
39 Added: (nutrient-measurement-id v)
40 Added: (nutrient-measurement-measured-on v))
41 Added: (for ([nv (nutrient-measurement-nutrient-values v)])
42 Added: (match-define (cons n v) nv)
43 Added: (fprintf out "~a ~a\n"
44 Added: (~a (nutrient-name n) #:min-width 14)
45 Added: (~a v #:max-width 6 #:align 'right)))))
35 46
36 47
37 48 ;; CREATE
models/nutrient-target.rkt
index 8611a40e..5a6d6738 100644..100644
@@ -30,7 +30,18 @@
30 30 "nutrient.rkt")
31 31
32 32 ;; Instances of this struct are persisted in the nutrient_targets table.
33 Removed: (struct nutrient-target (id effective-on nutrient-values) #:transparent)
33 Added: (struct nutrient-target (id effective-on nutrient-values)
34 Added: #:transparent
35 Added: #:property prop:custom-write
36 Added: (λ (v out _)
37 Added: (fprintf out "Target #~a on ~a\n"
38 Added: (nutrient-target-id v)
39 Added: (nutrient-target-effective-on v))
40 Added: (for ([nv (nutrient-target-nutrient-values v)])
41 Added: (match-define (cons n v) nv)
42 Added: (fprintf out "~a ~a\n"
43 Added: (~a (nutrient-name n) #:min-width 14)
44 Added: (~a v #:max-width 6 #:align 'right)))))
34 45
35 46
36 47 ;; CREATE
models/nutrient.rkt
index 6df0989b..10e274ee 100644..100644
@@ -25,7 +25,13 @@
25 25 sql
26 26 "../db/conn.rkt")
27 27
28 Removed: (struct nutrient (id name formula) #:transparent)
28 Added: (struct nutrient (id name formula)
29 Added: #:transparent
30 Added: #:property prop:custom-write
31 Added: (λ (v out _)
32 Added: (fprintf out "#<~a ~a>"
33 Added: (nutrient-id v)
34 Added: (nutrient-name v))))
29 35
30 36
31 37 ;; CREATE