mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[report] refactor safely
1. upgrade <report-template> and constructor to top-level 2. convert (args-to-defn) to named-let
This commit is contained in:
parent
5f436ae967
commit
0f8558b7f8
@ -119,35 +119,16 @@ not found.")))
|
|||||||
;; set of options, and generates the report. the renderer must
|
;; set of options, and generates the report. the renderer must
|
||||||
;; return as its final value an <html-document> object.
|
;; return as its final value an <html-document> object.
|
||||||
|
|
||||||
(define (blank-report)
|
(define (args-to-defn)
|
||||||
((record-constructor <report-template>)
|
(let loop ((report-rec (make-report-template)) (args args))
|
||||||
#f ;; version
|
(cond
|
||||||
#f ;; name
|
((null? args) report-rec)
|
||||||
#f ;; report-guid
|
(else
|
||||||
#f ;; parent-type (meaning guid of report-template this template is based on)
|
(let ((modifier (record-modifier <report-template> (car args))))
|
||||||
#f ;; options-generator
|
(modifier report-rec (cadr args))
|
||||||
#f ;; options-cleanup-cb
|
(loop report-rec (cddr args)))))))
|
||||||
#f ;; options-changed-cb
|
|
||||||
#f ;; renderer
|
|
||||||
#t ;; in-menu?
|
|
||||||
#f ;; menu-path
|
|
||||||
#f ;; menu-name
|
|
||||||
#f ;; menu-tip
|
|
||||||
#f ;; export-types
|
|
||||||
#f ;; export-thunk
|
|
||||||
))
|
|
||||||
|
|
||||||
(define (args-to-defn in-report-rec args)
|
(let ((report-rec (args-to-defn)))
|
||||||
(let ((report-rec (or in-report-rec (blank-report))))
|
|
||||||
(if (null? args)
|
|
||||||
report-rec
|
|
||||||
(let ((id (car args))
|
|
||||||
(value (cadr args))
|
|
||||||
(remainder (cddr args)))
|
|
||||||
((record-modifier <report-template> id) report-rec value)
|
|
||||||
(args-to-defn report-rec remainder)))))
|
|
||||||
|
|
||||||
(let ((report-rec (args-to-defn #f args)))
|
|
||||||
(if (and report-rec
|
(if (and report-rec
|
||||||
;; only process reports that have a report-guid
|
;; only process reports that have a report-guid
|
||||||
(gnc:report-template-report-guid report-rec))
|
(gnc:report-template-report-guid report-rec))
|
||||||
@ -228,6 +209,25 @@ not found.")))
|
|||||||
(record-accessor <report-template> 'export-types))
|
(record-accessor <report-template> 'export-types))
|
||||||
(define gnc:report-template-export-thunk
|
(define gnc:report-template-export-thunk
|
||||||
(record-accessor <report-template> 'export-thunk))
|
(record-accessor <report-template> 'export-thunk))
|
||||||
|
(define (make-report-template)
|
||||||
|
((record-constructor <report-template>)
|
||||||
|
#f ;; version
|
||||||
|
#f ;; name
|
||||||
|
#f ;; report-guid
|
||||||
|
#f ;; parent-type (meaning guid of
|
||||||
|
;; report-template this template is
|
||||||
|
;; based on)
|
||||||
|
#f ;; options-generator
|
||||||
|
#f ;; options-cleanup-cb
|
||||||
|
#f ;; options-changed-cb
|
||||||
|
#f ;; renderer
|
||||||
|
#t ;; in-menu?
|
||||||
|
#f ;; menu-path
|
||||||
|
#f ;; menu-name
|
||||||
|
#f ;; menu-tip
|
||||||
|
#f ;; export-types
|
||||||
|
#f ;; export-thunk
|
||||||
|
))
|
||||||
|
|
||||||
(define (gnc:report-template-new-options/report-guid template-id template-name)
|
(define (gnc:report-template-new-options/report-guid template-id template-name)
|
||||||
(let ((templ (hash-ref *gnc:_report-templates_* template-id)))
|
(let ((templ (hash-ref *gnc:_report-templates_* template-id)))
|
||||||
@ -343,20 +343,22 @@ not found.")))
|
|||||||
(define gnc:report-set-custom-template!
|
(define gnc:report-set-custom-template!
|
||||||
(record-modifier <report> 'custom-template))
|
(record-modifier <report> 'custom-template))
|
||||||
|
|
||||||
|
|
||||||
;; gnc:make-report instantiates a report from a report-template.
|
;; gnc:make-report instantiates a report from a report-template.
|
||||||
;; The actual report is stored away in a hash-table -- only the id is returned.
|
;; The actual report is stored away in a hash-table -- only the id is returned.
|
||||||
(define (gnc:make-report template-id . rest)
|
(define (gnc:make-report template-id . rest)
|
||||||
(let* ((template-parent (gnc:report-template-parent-type (hash-ref *gnc:_report-templates_* template-id)))
|
(let* ((template-parent (gnc:report-template-parent-type
|
||||||
|
(hash-ref *gnc:_report-templates_* template-id)))
|
||||||
(report-type (or template-parent template-id))
|
(report-type (or template-parent template-id))
|
||||||
(custom-template (if template-parent template-id ""))
|
(custom-template (if template-parent template-id ""))
|
||||||
(r ((record-constructor <report>)
|
(r ((record-constructor <report>)
|
||||||
report-type ;; type
|
report-type ;; type
|
||||||
#f ;; id
|
#f ;; id
|
||||||
#f ;; options
|
#f ;; options
|
||||||
#t ;; dirty
|
#t ;; dirty
|
||||||
#f ;; needs-save
|
#f ;; needs-save
|
||||||
#f ;; editor-widget
|
#f ;; editor-widget
|
||||||
#f ;; ctext
|
#f ;; ctext
|
||||||
custom-template ;; custom-template
|
custom-template ;; custom-template
|
||||||
))
|
))
|
||||||
(template (hash-ref *gnc:_report-templates_* template-id)))
|
(template (hash-ref *gnc:_report-templates_* template-id)))
|
||||||
@ -369,10 +371,8 @@ not found.")))
|
|||||||
(lambda ()
|
(lambda ()
|
||||||
(gnc:report-set-dirty?! r #t)
|
(gnc:report-set-dirty?! r #t)
|
||||||
(let ((cb (gnc:report-template-options-changed-cb template)))
|
(let ((cb (gnc:report-template-options-changed-cb template)))
|
||||||
(if cb
|
(if cb (cb r))))
|
||||||
(cb r))))
|
|
||||||
options))
|
options))
|
||||||
|
|
||||||
(gnc:report-set-id! r (gnc-report-add r))
|
(gnc:report-set-id! r (gnc-report-add r))
|
||||||
(gnc:report-id r)))
|
(gnc:report-id r)))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user