[533] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
[545] | 2 | import org.codehaus.groovy.grails.commons.ConfigurationHolder |
---|
[533] | 3 | import org.springframework.web.servlet.support.RequestContextUtils as RCU |
---|
| 4 | |
---|
| 5 | class 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 | |
---|
[545] | 18 | params.startDate = new Date() |
---|
| 19 | params.endDate = new Date() |
---|
| 20 | |
---|
[533] | 21 | params.reportTitle = "Template Report (Portrait)" |
---|
[545] | 22 | params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL() |
---|
[533] | 23 | params.currentUser = authService.currentUser |
---|
[545] | 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 | |
---|
[533] | 27 | def dataModel = createTemplateData() |
---|
| 28 | |
---|
[545] | 29 | // Jasper plugin controller expects data to be a Collection. |
---|
| 30 | chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params) |
---|
[533] | 31 | |
---|
[545] | 32 | } // templatePortrait |
---|
| 33 | |
---|
[533] | 34 | def templateLandscape = { |
---|
| 35 | |
---|
[545] | 36 | params.startDate = new Date() |
---|
| 37 | params.endDate = new Date() |
---|
| 38 | |
---|
[533] | 39 | params.reportTitle = "Template Report (Landscape)" |
---|
[545] | 40 | params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL() |
---|
[533] | 41 | params.currentUser = authService.currentUser |
---|
[545] | 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 | |
---|
[533] | 45 | def dataModel = createTemplateData() |
---|
| 46 | |
---|
[545] | 47 | // Jasper plugin controller expects data to be a Collection. |
---|
| 48 | chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params) |
---|
[533] | 49 | |
---|
[545] | 50 | } // templateLandscape |
---|
| 51 | |
---|
[533] | 52 | private createTemplateData() { |
---|
[545] | 53 | |
---|
| 54 | def result = [:] |
---|
| 55 | result.summaryOfCalculationMethod = "Summary string of the calculations performed." |
---|
| 56 | result.dataList = [] |
---|
[533] | 57 | for(i in 1..5) { |
---|
[545] | 58 | def dataDetails = [:] |
---|
| 59 | dataDetails.description = "Data description " + i.toString() |
---|
| 60 | result.dataList << dataDetails |
---|
[533] | 61 | } |
---|
| 62 | |
---|
[545] | 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 | |
---|
[533] | 83 | def reactiveRatio = { |
---|
| 84 | |
---|
| 85 | params.reportTitle = "Reactive Ratio Report" |
---|
[538] | 86 | params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL() |
---|
[533] | 87 | params.currentUser = authService.currentUser |
---|
[535] | 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 | |
---|
[545] | 91 | def dataModel = taskReportService.getReactiveRatio(params, RCU.getLocale(request)) |
---|
[533] | 92 | |
---|
[545] | 93 | // Jasper plugin controller expects data to be a Collection. |
---|
| 94 | chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params) |
---|
[533] | 95 | |
---|
[545] | 96 | } // reactiveRatio |
---|
| 97 | |
---|
[542] | 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 | |
---|
[545] | 106 | def dataModel = taskReportService.getImmediateCallouts(params, RCU.getLocale(request)) |
---|
[542] | 107 | |
---|
[545] | 108 | // Jasper plugin controller expects data to be a Collection. |
---|
| 109 | chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params) |
---|
[542] | 110 | |
---|
[545] | 111 | } // immediateCallouts |
---|
[533] | 112 | |
---|
| 113 | } // end of class. |
---|