Ignore:
Timestamp:
May 25, 2010, 12:17:20 AM (15 years ago)
Author:
gav
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/ReportController.groovy

    r544 r545  
    11import org.codehaus.groovy.grails.plugins.springsecurity.Secured
     2import org.codehaus.groovy.grails.commons.ConfigurationHolder
    23import org.springframework.web.servlet.support.RequestContextUtils as RCU
    34
     
    1415
    1516    def templatePortrait = {
    16         params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
     17
     18        params.startDate = new Date()
     19        params.endDate = new Date()
    1720
    1821        params.reportTitle = "Template Report (Portrait)"
     22        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
    1923        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
    2027        def dataModel = createTemplateData()
    2128
    22         chain(controller:'jasper', action:'index', model:[data: dataModel], params:params)
    23     }
     29        // Jasper plugin controller expects data to be a Collection.
     30        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
     31
     32    } // templatePortrait
    2433
    2534    def templateLandscape = {
    26         params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
     35
     36        params.startDate = new Date()
     37        params.endDate = new Date()
    2738
    2839        params.reportTitle = "Template Report (Landscape)"
     40        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
    2941        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
    3045        def dataModel = createTemplateData()
    3146
    32         chain(controller:'jasper', action:'index', model:[data: dataModel], params:params)
    33     }
     47        // Jasper plugin controller expects data to be a Collection.
     48        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
     49
     50    } // templateLandscape
    3451
    3552    private createTemplateData() {
    36         def dataModel = []
     53
     54        def result = [:]
     55        result.summaryOfCalculationMethod = "Summary string of the calculations performed."
     56        result.dataList = []
    3757        for(i in 1..5) {
    38             def data = [:]
    39             data.description = "Data description " + i.toString()
    40             dataModel.add(data)
     58            def dataDetails = [:]
     59            dataDetails.description = "Data description " + i.toString()
     60            result.dataList << dataDetails
    4161        }
    42         return dataModel
    43     }
     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
    4482
    4583    def reactiveRatio = {
     
    5189        params.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.endDate)
    5290
    53         def dataModel = [taskReportService.getReactiveRatio(params, RCU.getLocale(request))]
     91        def dataModel = taskReportService.getReactiveRatio(params, RCU.getLocale(request))
    5492
    55         chain(controller:'jasper', action:'index', model:[data: dataModel], params:params)
    56     }
     93        // Jasper plugin controller expects data to be a Collection.
     94        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
     95
     96    } // reactiveRatio
    5797
    5898    def immediateCallouts = {
     
    64104        params.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.endDate)
    65105
    66         def dataModel = [taskReportService.getImmediateCallouts(params, RCU.getLocale(request))]
     106        def dataModel = taskReportService.getImmediateCallouts(params, RCU.getLocale(request))
    67107
    68 //         render dataModel
    69         chain(controller:'jasper', action:'index', model:[data: dataModel], params:params)
     108        // Jasper plugin controller expects data to be a Collection.
     109        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
    70110
    71     }
     111    } // immediateCallouts
    72112
    73113} // end of class.
Note: See TracChangeset for help on using the changeset viewer.