Skip to content

Commit 4f8b2a2

Browse files
committed
commit WIP #2970
1 parent a9b66b0 commit 4f8b2a2

File tree

7 files changed

+23
-88
lines changed

7 files changed

+23
-88
lines changed

grails-app/controllers/au/org/ala/merit/ManagementUnitController.groovy

+4-40
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
package au.org.ala.merit
22

33
import au.org.ala.merit.command.EditManagementUnitReportCommand
4-
import au.org.ala.merit.command.ManagementUnitReportCommand
54
import au.org.ala.merit.command.PrintManagementUnitReportCommand
65
import au.org.ala.merit.command.SaveReportDataCommand
76
import au.org.ala.merit.command.ViewManagementUnitReportCommand
87
import au.org.ala.merit.util.ProjectGroupingHelper
98
import grails.converters.JSON
109
import grails.core.GrailsApplication
11-
import grails.plugin.cache.Cacheable
1210
import grails.web.mapping.LinkGenerator
1311
import org.apache.http.HttpStatus
14-
15-
import java.text.DateFormat
1612
import java.text.ParseException
17-
import java.text.SimpleDateFormat
18-
19-
import static ReportService.ReportMode
2013

2114
/**
2215
* Processes requests relating to MUs
@@ -29,7 +22,6 @@ class ManagementUnitController {
2922

3023
ReportService reportService
3124
ActivityService activityService
32-
PdfGenerationService pdfGenerationService
3325
ProjectService projectService
3426
ProjectGroupingHelper projectGroupingHelper
3527

@@ -239,19 +231,6 @@ class ManagementUnitController {
239231
chain(action:'editReport', id:id, params:[reportId:reportId])
240232
}
241233

242-
private Map activityReportModel(String managementUnitId, String reportId, ReportMode mode, Integer formVersion = null) {
243-
Map mu = managementUnitService.get(managementUnitId)
244-
Map config = mu.config
245-
Map model = reportService.activityReportModel(reportId, mode, formVersion)
246-
247-
model.context = mu
248-
model.returnTo = createLink(action:'index', id:managementUnitId)
249-
model.contextViewUrl = model.returnTo
250-
model.reportHeaderTemplate = '/managementUnit/managementUnitReportHeader'
251-
model.config = config
252-
model
253-
}
254-
255234
@PreAuthorise(accessLevel = 'readOnly', redirectController = 'managementUnit')
256235
def viewReport(ViewManagementUnitReportCommand cmd) {
257236
if (cmd.hasErrors()) {
@@ -263,29 +242,14 @@ class ManagementUnitController {
263242
}
264243

265244
@PreAuthorise(accessLevel = 'readOnly')
266-
def printableReport(String id, String reportId) {
267-
if (!id || !reportId) {
268-
error('An invalid report was selected for download', id)
245+
def printManagementUnitReport(PrintManagementUnitReportCommand cmd) {
246+
if (cmd.hasErrors()) {
247+
error(cmd.errors.toString(), cmd.id)
269248
return
270249
}
271-
Map model = activityReportModel(id, reportId, ReportMode.PRINT)
272250

273-
render view:'/activity/activityReportView', model:model
274-
}
275-
276-
/**
277-
* This is designed as a callback from the PDF generation service. It produces a HTML report that will
278-
* be converted into PDF.
279-
* @param id the project id
280-
*/
281-
def viewReportCallback(PrintManagementUnitReportCommand cmd) {
251+
render model:cmd.model, view:'/activity/activityReportView'
282252

283-
if (pdfGenerationService.authorizePDF(request)) {
284-
render view:'/activity/activityReportView', model:cmd.model
285-
}
286-
else {
287-
render status:HttpStatus.SC_UNAUTHORIZED
288-
}
289253
}
290254

291255
@PreAuthorise(accessLevel = 'editor')

grails-app/controllers/au/org/ala/merit/OrganisationController.groovy

-24
Original file line numberDiff line numberDiff line change
@@ -584,30 +584,6 @@ class OrganisationController {
584584
}
585585
}
586586

587-
private Map performanceReportModel(String organisationId, Map report, ReportService.ReportMode mode, Integer formVersion = null) {
588-
Map organisation = organisationService.get(organisationId)
589-
int version = report.toDate < "2017-01-01T00:00:00Z" ? 1 : 2
590-
Map model = reportService.performanceReportModel(report.reportId, version)
591-
model.state = organisation.state ?: 'Unknown'
592-
model.organisation = organisation
593-
model.printView = true
594-
model.view = '/report/performanceReportView'
595-
model
596-
}
597-
598-
private Map activityReportModel(String organisationId, String reportId, ReportService.ReportMode mode, Integer formVersion = null) {
599-
Map organisation = organisationService.get(organisationId)
600-
Map model = reportService.activityReportModel(reportId, mode, formVersion)
601-
model.context = organisation
602-
model.returnTo = createLink(action:'index', id:organisationId)
603-
model.contextViewUrl = model.returnTo
604-
model.reportHeaderTemplate = '/organisation/organisationReportHeader'
605-
model.config = organisation.config
606-
model.view = '/activity/activityReportView'
607-
model
608-
}
609-
610-
611587
@PreAuthorise(accessLevel = 'admin')
612588
def createAdHocReport(String id) {
613589

grails-app/controllers/au/org/ala/merit/ProgramController.groovy

+5-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package au.org.ala.merit
22

3+
import au.org.ala.merit.command.PrintProgramReportCommand
34
import au.org.ala.merit.command.SaveReportDataCommand
45
import grails.converters.JSON
56
import org.apache.http.HttpStatus
@@ -15,7 +16,6 @@ class ProgramController {
1516
def programService, documentService, userService, roleService, commonService, webService, siteService
1617
ReportService reportService
1718
ActivityService activityService
18-
PdfGenerationService pdfGenerationService
1919
BlogService blogService
2020
ManagementUnitService managementUnitService
2121

@@ -337,30 +337,14 @@ class ProgramController {
337337
}
338338

339339
@PreAuthorise(accessLevel = 'readOnly')
340-
def printableReport(String id, String reportId) {
341-
if (!id || !reportId) {
342-
error('An invalid report was selected for download', id)
340+
def printProgramReport(PrintProgramReportCommand cmd) {
341+
if (cmd.hasErrors()) {
342+
error(cmd.errors.toString(), cmd.id)
343343
return
344344
}
345-
Map model = activityReportModel(id, reportId, ReportMode.PRINT)
346-
347-
render view:'/activity/activityReportView', model:model
348-
}
349345

350-
/**
351-
* This is designed as a callback from the PDF generation service. It produces a HTML report that will
352-
* be converted into PDF.
353-
* @param id the project id
354-
*/
355-
def viewReportCallback(String id, String reportId) {
346+
render model:cmd.model, view:'/activity/activityReportView'
356347

357-
if (pdfGenerationService.authorizePDF(request)) {
358-
Map model = activityReportModel(id, reportId, ReportMode.PRINT)
359-
render view:'/activity/activityReportView', model:model
360-
}
361-
else {
362-
render status:HttpStatus.SC_UNAUTHORIZED
363-
}
364348
}
365349

366350
@PreAuthorise(accessLevel = 'editor')

grails-app/views/managementUnit/index.gsp

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
viewReportUrl: '${createLink(action:"viewReport", id:managementUnit.managementUnitId)}',
1313
editReportUrl: "${createLink(action:"editReport", id:managementUnit.managementUnitId)}",
1414
resetReportUrl: "${createLink(action:'resetReport', id:managementUnit.managementUnitId)}",
15-
reportPDFUrl: "${createLink(action:"printableReport", id:managementUnit.managementUnitId)}",
15+
reportPDFUrl: "${createLink(action:"printManagementUnitReport", id:managementUnit.managementUnitId)}",
1616
approveReportUrl: "${createLink(action:"ajaxApproveReport", id:managementUnit.managementUnitId)}",
1717
submitReportUrl: "${createLink(action:"ajaxSubmitReport", id:managementUnit.managementUnitId)}",
1818
rejectReportUrl: "${createLink(action:"ajaxRejectReport", id:managementUnit.managementUnitId)}",

grails-app/views/program/index.gsp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
viewReportUrl: '${createLink(action:"viewReport", id:program.programId)}',
1414
editReportUrl: "${createLink(action:"editReport", id:program.programId)}",
1515
resetReportUrl: "${createLink(action:'resetReport', id:program.programId)}",
16-
reportPDFUrl: "${createLink(action:"printableReport", id:program.programId)}",
16+
reportPDFUrl: "${createLink(action:"printProgramReport", id:program.programId)}",
1717
approveReportUrl: "${createLink(action:"ajaxApproveReport", id:program.programId)}",
1818
submitReportUrl: "${createLink(action:"ajaxSubmitReport", id:program.programId)}",
1919
rejectReportUrl: "${createLink(action:"ajaxRejectReport", id:program.programId)}",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"devDependencies": {
1313
"@metahub/karma-jasmine-jquery": "^2.0.1",
14-
"chromedriver": "114.0.1",
14+
"chromedriver": "116.0.0",
1515
"jasmine-core": "^3.5.0",
1616
"jasmine-jquery": "^2.0.0",
1717
"jquery": "3.6.2",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package au.org.ala.merit.command
2+
3+
import au.org.ala.merit.ReportService
4+
5+
class PrintProgramReportCommand extends OrganisationReportCommand {
6+
7+
@Override
8+
ReportService.ReportMode getMode() {
9+
return ReportService.ReportMode.PRINT
10+
}
11+
}

0 commit comments

Comments
 (0)