source: trunk/grails-app/controllers/ReportController.groovy @ 545

Last change on this file since 545 was 545, checked in by gav, 14 years ago

Update report templates, add downloadTemplate action and general tidy up of reports.

File size: 4.4 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2import org.codehaus.groovy.grails.commons.ConfigurationHolder
3import org.springframework.web.servlet.support.RequestContextUtils as RCU
4
5class ReportController extends BaseController {
6
7    def authService
8    def dateUtilService
9    def taskReportService
10
11    def index = { redirect(action:templatePortrait,params:params) }
12
13    // the delete, save and update actions only accept POST requests
14    //static allowedMethods = [list:'POST']
15
16    def templatePortrait = {
17
18        params.startDate = new Date()
19        params.endDate = new Date()
20
21        params.reportTitle = "Template Report (Portrait)"
22        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
23        params.currentUser = authService.currentUser
24        params.startDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.startDate)
25        params.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.endDate)
26
27        def dataModel = createTemplateData()
28
29        // Jasper plugin controller expects data to be a Collection.
30        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
31
32    } // templatePortrait
33
34    def templateLandscape = {
35
36        params.startDate = new Date()
37        params.endDate = new Date()
38
39        params.reportTitle = "Template Report (Landscape)"
40        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
41        params.currentUser = authService.currentUser
42        params.startDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.startDate)
43        params.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.endDate)
44
45        def dataModel = createTemplateData()
46
47        // Jasper plugin controller expects data to be a Collection.
48        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
49
50    } // templateLandscape
51
52    private createTemplateData() {
53
54        def result = [:]
55        result.summaryOfCalculationMethod = "Summary string of the calculations performed."
56        result.dataList = []
57        for(i in 1..5) {
58            def dataDetails = [:]
59            dataDetails.description = "Data description " + i.toString()
60            result.dataList << dataDetails
61        }
62
63        // Success.
64        return result
65
66    } // createTemplateData
67
68    def downloadTemplate = {
69
70        // params.fileName is not used directly to negate any security issues..
71        def fileName = (params.fileName == 'templateLandscape.jrxml') ? 'templateLandscape.jrxml' : 'templatePortrait.jrxml'
72        def f = grailsApplication.mainContext.getResource("reports/${fileName}").getFile()
73        if(f.isFile()) {
74            response.contentType = ConfigurationHolder.config.grails.mime.types["text"]
75            response.setHeader("Content-disposition", "attachment; filename=${fileName}")
76            render f.text
77        }
78        else
79            render(status:404, text: "File Not Found: ${f}")
80
81    } // downLoadTemplate
82
83    def reactiveRatio = {
84
85        params.reportTitle = "Reactive Ratio Report"
86        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
87        params.currentUser = authService.currentUser
88        params.startDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.startDate)
89        params.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.endDate)
90
91        def dataModel = taskReportService.getReactiveRatio(params, RCU.getLocale(request))
92
93        // Jasper plugin controller expects data to be a Collection.
94        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
95
96    } // reactiveRatio
97
98    def immediateCallouts = {
99
100        params.reportTitle = "Immediate Callouts"
101        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
102        params.currentUser = authService.currentUser
103        params.startDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.startDate)
104        params.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.endDate)
105
106        def dataModel = taskReportService.getImmediateCallouts(params, RCU.getLocale(request))
107
108        // Jasper plugin controller expects data to be a Collection.
109        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
110
111    } // immediateCallouts
112
113} // end of class.
Note: See TracBrowser for help on using the repository browser.