[report] simplify functions to use srfi-1, annotate

hash-map->list is simpler than hash-fold

All refactored functions are tested in test-report-system.scm
pull/475/head
Christopher Lam 7 years ago
parent 0b8ff4b5d6
commit 50e9640243

@ -461,37 +461,30 @@ not found.")))
;; Load and save helper functions
;; list of all report guids in existence (includes standard & custom
;; reports, but not instantiated ones)
(define (gnc:all-report-template-guids)
(hash-fold
(lambda (k v p)
(cons k p))
'() *gnc:_report-templates_*))
(map car (hash-map->list cons *gnc:_report-templates_*)))
;; return a list of the custom report template guids.
(define (gnc:custom-report-template-guids)
(hash-fold
(lambda (k v p)
(if (gnc:report-template-parent-type v)
(begin
(gnc:debug "template " v)
(cons k p))
p))
'() *gnc:_report-templates_*))
(map car (gnc:custom-report-templates-list)))
(define (gnc:find-report-template report-type)
(hash-ref *gnc:_report-templates_* report-type))
(define (gnc:find-report-template guid)
(hash-ref *gnc:_report-templates_* guid))
(define (gnc:report-template-is-custom/template-guid? guid)
(let* ((custom-template (and (string? guid)
(not (string-null? guid))
(hash-ref *gnc:_report-templates_* guid))))
(and custom-template
(gnc:report-template-parent-type custom-template)
#t)))
(assoc guid (gnc:custom-report-templates-list)))
(define (gnc:is-custom-report-type report)
(gnc:report-template-is-custom/template-guid? (gnc:report-custom-template report)))
;; list of reports saved within the saved-reports; returns a list of
;; pairs whose cars = guid <string> and cdrs = report-template <record>
(define (gnc:custom-report-templates-list)
(filter (compose gnc:report-template-parent-type cdr)
(hash-map->list cons *gnc:_report-templates_*)))
;; This function should be called right before changing a custom-template's name
;; to test if the new name is unique among the existting custom reports.
;; If not the calling function can prevent the name from being updated.
@ -740,18 +733,14 @@ not found.")))
;; saved-reports file aside as a backup
;; return #t if all templates were saved successfully
(define (gnc:save-all-reports)
(let ((save-ok? #t))
(gnc-saved-reports-backup)
(gnc-saved-reports-write-to-file "" #t)
(hash-for-each
(lambda (k v)
(if (gnc:report-template-parent-type v)
(begin
(gnc:debug "saving report " k)
(if (not (gnc:report-template-save-to-savefile v))
(set! save-ok? #f)))))
*gnc:_report-templates_*)
save-ok?))
(gnc-saved-reports-backup)
(gnc-saved-reports-write-to-file "" #t)
(every identity
(map
(lambda (p)
(gnc:debug "saving report " (car p))
(gnc:report-template-save-to-savefile (cdr p)))
(gnc:custom-report-templates-list))))
;; gets the renderer from the report template;

Loading…
Cancel
Save