From 12dd3908965431cdfcfcb2f9776c50fc8bdb6f75 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 13 Jul 2023 14:52:43 +1000 Subject: [PATCH] First cut of support for outcomes in Outputs Report #2940 --- forms/rdp/rdpOutputReport.json | 320 +++++++++++++----- gradle.properties | 2 +- .../au/org/ala/merit/ProjectController.groovy | 23 ++ .../au/org/ala/merit/ProjectService.groovy | 16 + grails-app/views/activity/activityReport.gsp | 4 +- 5 files changed, 278 insertions(+), 87 deletions(-) diff --git a/forms/rdp/rdpOutputReport.json b/forms/rdp/rdpOutputReport.json index 658dcd64d..54981a46f 100644 --- a/forms/rdp/rdpOutputReport.json +++ b/forms/rdp/rdpOutputReport.json @@ -663,7 +663,7 @@ "validate": "required,maxSize[500]" }, { - "name": "outcomeStatementPrePop", + "name": "relatedOutcomes", "dataType": "text", "description": "More than one outcome statement/s if relevant for this Project Baseline could be selected.", "validate": "required", @@ -762,7 +762,7 @@ "title": "Briefly describe the baseline you have established under this service and its purpose." }, { - "source": "outcomeStatementPrePop", + "source": "relatedOutcomes", "type": "select2Many", "width": "25%", "title": "Which outcome statement/s aligns with this Baseline Dataset?" @@ -2177,17 +2177,27 @@ "validate": "required,maxSize[300]" }, { - "name": "outcomeStatementPrePop", + "name": "relatedOutcomes", "dataType": "text", "description": "More than one outcome statement/s if relevant for this Project Baseline could be selected.", "validate": "required", "constraints": { - "textProperty": "description", - "valueProperty": "description", + "textProperty": "label", + "valueProperty": "label", "type": "pre-populated", "config": { "source": { - "context-path": "owner.custom.details.outcomes.shortTermOutcomes" + "url": "/project/outcomesByScores", + "params": [{ + "expression": "owner.projectId", + "name": "id", + "type": "computed" + }, { + "expression": "scores", + "name": "scoreIds", + "type": "computed" + } + ] } } } @@ -2205,7 +2215,7 @@ "type": "number", "decimalPlaces": 0, "computed": { - "expression": "count(areasControlled, \"outcomeStatementPrePop\")" + "expression": "count(areasControlled, \"relatedOutcomes\")" } }, { @@ -2598,7 +2608,7 @@ }, { "width": "15%", - "source": "outcomeStatementPrePop", + "source": "relatedOutcomes", "type": "select2Many", "title": "Which outcome statement/s relates to this survey?" } @@ -5032,17 +5042,27 @@ } }, { - "name": "outcomeStatementPrePop", + "name": "relatedOutcomes", "dataType": "text", "description": "More than one outcome statement/s if relevant for this Project Baseline could be selected.", "validate": "required", "constraints": { - "textProperty": "description", - "valueProperty": "description", + "textProperty": "label", + "valueProperty": "label", "type": "pre-populated", "config": { "source": { - "context-path": "owner.custom.details.outcomes.shortTermOutcomes" + "url": "/project/outcomesByScores", + "params": [{ + "expression": "owner.projectId", + "name": "id", + "type": "computed" + }, { + "expression": "scores", + "name": "scoreIds", + "type": "computed" + } + ] } } } @@ -5303,7 +5323,7 @@ "title": "What Dataset supports this?" }, { - "source": "outcomeStatementPrePop", + "source": "relatedOutcomes", "type": "select2Many", "width": "10%", "title": "Which outcome statement/s relates to this survey?" @@ -5546,17 +5566,27 @@ } }, { - "name": "outcomeStatementPrePop", + "name": "relatedOutcomes", "dataType": "text", "description": "More than one outcome statement/s if relevant for this Project Baseline could be selected.", "validate": "required", "constraints": { - "textProperty": "description", - "valueProperty": "description", + "textProperty": "label", + "valueProperty": "label", "type": "pre-populated", "config": { "source": { - "context-path": "owner.custom.details.outcomes.shortTermOutcomes" + "url": "/project/outcomesByScores", + "params": [{ + "expression": "owner.projectId", + "name": "id", + "type": "computed" + }, { + "expression": "scores", + "name": "scoreIds", + "type": "computed" + } + ] } } } @@ -5943,7 +5973,7 @@ "title": "What Dataset supports this?" }, { - "source": "outcomeStatementPrePop", + "source": "relatedOutcomes", "type": "select2Many", "width": "15%", "title": "Which outcome statement/s relates to this survey?" @@ -6299,17 +6329,27 @@ } }, { - "name": "outcomeStatementPrePop", + "name": "relatedOutcomes", "dataType": "text", "description": "More than one outcome statement/s if relevant for this Project Baseline could be selected.", "validate": "required", "constraints": { - "textProperty": "description", - "valueProperty": "description", + "textProperty": "label", + "valueProperty": "label", "type": "pre-populated", "config": { "source": { - "context-path": "owner.custom.details.outcomes.shortTermOutcomes" + "url": "/project/outcomesByScores", + "params": [{ + "expression": "owner.projectId", + "name": "id", + "type": "computed" + }, { + "expression": "scores", + "name": "scoreIds", + "type": "computed" + } + ] } } } @@ -6696,7 +6736,7 @@ "title": "What Dataset supports this?" }, { - "source": "outcomeStatementPrePop", + "source": "relatedOutcomes", "type": "select2Many", "width": "15%", "title": "Which outcome statement/s relates to this survey?" @@ -7333,17 +7373,27 @@ "validate": "required,maxSize[300]" }, { - "name": "outcomeStatementPrePop", + "name": "relatedOutcomes", "dataType": "text", "description": "More than one outcome statement/s if relevant for this Project Baseline could be selected.", "validate": "required", "constraints": { - "textProperty": "description", - "valueProperty": "description", + "textProperty": "label", + "valueProperty": "label", "type": "pre-populated", "config": { "source": { - "context-path": "owner.custom.details.outcomes.shortTermOutcomes" + "url": "/project/outcomesByScores", + "params": [{ + "expression": "owner.projectId", + "name": "id", + "type": "computed" + }, { + "expression": "scores", + "name": "scoreIds", + "type": "computed" + } + ] } } } @@ -7361,7 +7411,7 @@ "type": "number", "decimalPlaces": 0, "computed": { - "expression": "count(areasControlled, \"outcomeStatementPrePop\")" + "expression": "count(areasControlled, \"relatedOutcomes\")" } }, { @@ -7782,7 +7832,7 @@ }, { "width": "15%", - "source": "outcomeStatementPrePop", + "source": "relatedOutcomes", "type": "select2Many", "title": "Which outcome statement/s relates to this survey?" } @@ -7894,17 +7944,27 @@ "validate": "required,maxSize[300]" }, { - "name": "outcomeStatementPrePop", + "name": "relatedOutcomes", "dataType": "text", "description": "More than one outcome statement/s if relevant for this Project Baseline could be selected.", "validate": "required", "constraints": { - "textProperty": "description", - "valueProperty": "description", + "textProperty": "label", + "valueProperty": "label", "type": "pre-populated", "config": { "source": { - "context-path": "owner.custom.details.outcomes.shortTermOutcomes" + "url": "/project/outcomesByScores", + "params": [{ + "expression": "owner.projectId", + "name": "id", + "type": "computed" + }, { + "expression": "scores", + "name": "scoreIds", + "type": "computed" + } + ] } } } @@ -8295,7 +8355,7 @@ "type": "text" }, { - "source": "outcomeStatementPrePop", + "source": "relatedOutcomes", "type": "select2Many", "width": "10%", "title": "Which outcome statement/s relates to this survey?" @@ -8791,17 +8851,27 @@ "validate": "required,maxSize[300]" }, { - "name": "outcomeStatementPrePop", + "name": "relatedOutcomes", "dataType": "text", "description": "More than one outcome statement/s if relevant for this Project Baseline could be selected.", "validate": "required", "constraints": { - "textProperty": "description", - "valueProperty": "description", + "textProperty": "label", + "valueProperty": "label", "type": "pre-populated", "config": { "source": { - "context-path": "owner.custom.details.outcomes.shortTermOutcomes" + "url": "/project/outcomesByScores", + "params": [{ + "expression": "owner.projectId", + "name": "id", + "type": "computed" + }, { + "expression": "scores", + "name": "scoreIds", + "type": "computed" + } + ] } } } @@ -8819,7 +8889,7 @@ "type": "number", "decimalPlaces": 0, "computed": { - "expression": "count(areasControlled, \"outcomeStatementPrePop\")" + "expression": "count(areasControlled, \"relatedOutcomes\")" } }, { @@ -9102,7 +9172,7 @@ }, { "width": "15%", - "source": "outcomeStatementPrePop", + "source": "relatedOutcomes", "type": "select2Many", "title": "Which outcome statement/s relates to this survey?" } @@ -9460,17 +9530,27 @@ "validate": "required,maxSize[300]" }, { - "name": "outcomeStatementPrePop", + "name": "relatedOutcomes", "dataType": "text", "description": "More than one outcome statement/s if relevant for this Project Baseline could be selected.", "validate": "required", "constraints": { - "textProperty": "description", - "valueProperty": "description", + "textProperty": "label", + "valueProperty": "label", "type": "pre-populated", "config": { "source": { - "context-path": "owner.custom.details.outcomes.shortTermOutcomes" + "url": "/project/outcomesByScores", + "params": [{ + "expression": "owner.projectId", + "name": "id", + "type": "computed" + }, { + "expression": "scores", + "name": "scoreIds", + "type": "computed" + } + ] } } } @@ -9488,7 +9568,7 @@ "type": "number", "decimalPlaces": 0, "computed": { - "expression": "count(areasControlled, \"outcomeStatementPrePop\")" + "expression": "count(areasControlled, \"relatedOutcomes\")" } }, { @@ -9776,7 +9856,7 @@ }, { "width": "15%", - "source": "outcomeStatementPrePop", + "source": "relatedOutcomes", "type": "select2Many", "title": "Which outcome statement/s relates to this survey?" } @@ -10214,17 +10294,27 @@ "validate": "required,maxSize[300]" }, { - "name": "outcomeStatementPrePop", + "name": "relatedOutcomes", "dataType": "text", "description": "More than one outcome statement/s if relevant for this Project Baseline could be selected.", "validate": "required", "constraints": { - "textProperty": "description", - "valueProperty": "description", + "textProperty": "label", + "valueProperty": "label", "type": "pre-populated", "config": { "source": { - "context-path": "owner.custom.details.outcomes.shortTermOutcomes" + "url": "/project/outcomesByScores", + "params": [{ + "expression": "owner.projectId", + "name": "id", + "type": "computed" + }, { + "expression": "scores", + "name": "scoreIds", + "type": "computed" + } + ] } } } @@ -10242,7 +10332,7 @@ "type": "number", "decimalPlaces": 0, "computed": { - "expression": "count(areasControlled, \"outcomeStatementPrePop\")" + "expression": "count(areasControlled, \"relatedOutcomes\")" } } ], @@ -10506,7 +10596,7 @@ }, { "width": "15%", - "source": "outcomeStatementPrePop", + "source": "relatedOutcomes", "type": "select2Many", "title": "Which outcome statement/s relates to this survey?" } @@ -10905,17 +10995,27 @@ "validate": "required,maxSize[300]" }, { - "name": "outcomeStatementPrePop", + "name": "relatedOutcomes", "dataType": "text", "description": "More than one outcome statement/s if relevant for this Project Baseline could be selected.", "validate": "required", "constraints": { - "textProperty": "description", - "valueProperty": "description", + "textProperty": "label", + "valueProperty": "label", "type": "pre-populated", "config": { "source": { - "context-path": "owner.custom.details.outcomes.shortTermOutcomes" + "url": "/project/outcomesByScores", + "params": [{ + "expression": "owner.projectId", + "name": "id", + "type": "computed" + }, { + "expression": "scores", + "name": "scoreIds", + "type": "computed" + } + ] } } } @@ -10933,7 +11033,7 @@ "type": "number", "decimalPlaces": 0, "computed": { - "expression": "count(areasControlled, \"outcomeStatementPrePop\")" + "expression": "count(areasControlled, \"relatedOutcomes\")" } }, { @@ -11233,7 +11333,7 @@ }, { "width": "10%", - "source": "outcomeStatementPrePop", + "source": "relatedOutcomes", "type": "select2Many", "title": "Which outcome statement/s relates to this survey?" } @@ -11429,17 +11529,27 @@ } }, { - "name": "outcomeStatementPrePop", + "name": "relatedOutcomes", "dataType": "text", "description": "More than one outcome statement/s if relevant for this Project Baseline could be selected.", "validate": "required", "constraints": { - "textProperty": "description", - "valueProperty": "description", + "textProperty": "label", + "valueProperty": "label", "type": "pre-populated", "config": { "source": { - "context-path": "owner.custom.details.outcomes.shortTermOutcomes" + "url": "/project/outcomesByScores", + "params": [{ + "expression": "owner.projectId", + "name": "id", + "type": "computed" + }, { + "expression": "scores", + "name": "scoreIds", + "type": "computed" + } + ] } } } @@ -11827,7 +11937,7 @@ "title": "What Dataset supports this?" }, { - "source": "outcomeStatementPrePop", + "source": "relatedOutcomes", "type": "select2Many", "width": "15%", "title": "Which outcome statement/s relates to this survey?" @@ -12188,17 +12298,27 @@ } }, { - "name": "outcomeStatementPrePop", + "name": "relatedOutcomes", "dataType": "text", "description": "More than one outcome statement/s if relevant for this Project Baseline could be selected.", "validate": "required", "constraints": { - "textProperty": "description", - "valueProperty": "description", + "textProperty": "label", + "valueProperty": "label", "type": "pre-populated", "config": { "source": { - "context-path": "owner.custom.details.outcomes.shortTermOutcomes" + "url": "/project/outcomesByScores", + "params": [{ + "expression": "owner.projectId", + "name": "id", + "type": "computed" + }, { + "expression": "scores", + "name": "scoreIds", + "type": "computed" + } + ] } } } @@ -12586,7 +12706,7 @@ "title": "What Dataset supports this?" }, { - "source": "outcomeStatementPrePop", + "source": "relatedOutcomes", "type": "select2Many", "width": "15%", "title": "Which outcome statement/s relates to this survey?" @@ -14234,7 +14354,7 @@ "validate": "maxSize[300]" }, { - "name": "outcomeStatementPrePop", + "name": "relatedOutcomes", "dataType": "text", "description": "More than one outcome statement/s if relevant for this Project Baseline could be selected.", "validate": "required", @@ -14583,7 +14703,7 @@ { "preLabel": "Which outcome statement/s relates to this survey?", "css": "span3", - "source": "outcomeStatementPrePop", + "source": "relatedOutcomes", "type": "select2Many" }, { @@ -15663,17 +15783,27 @@ } }, { - "name": "outcomeStatementPrePop", + "name": "relatedOutcomes", "dataType": "text", "description": "More than one outcome statement/s if relevant for this Project Baseline could be selected.", "validate": "required", "constraints": { - "textProperty": "description", - "valueProperty": "description", + "textProperty": "label", + "valueProperty": "label", "type": "pre-populated", "config": { "source": { - "context-path": "owner.custom.details.outcomes.shortTermOutcomes" + "url": "/project/outcomesByScores", + "params": [{ + "expression": "owner.projectId", + "name": "id", + "type": "computed" + }, { + "expression": "scores", + "name": "scoreIds", + "type": "computed" + } + ] } } } @@ -16001,7 +16131,7 @@ "title": "What Dataset supports this?" }, { - "source": "outcomeStatementPrePop", + "source": "relatedOutcomes", "type": "select2Many", "width": "10%", "title": "Which outcome statement/s relates to this survey?" @@ -16847,17 +16977,27 @@ } }, { - "name": "outcomeStatementPrePop", + "name": "relatedOutcomes", "dataType": "text", "description": "More than one outcome statement/s if relevant for this Project Baseline could be selected.", "validate": "required", "constraints": { - "textProperty": "description", - "valueProperty": "description", + "textProperty": "label", + "valueProperty": "label", "type": "pre-populated", "config": { "source": { - "context-path": "owner.custom.details.outcomes.shortTermOutcomes" + "url": "/project/outcomesByScores", + "params": [{ + "expression": "owner.projectId", + "name": "id", + "type": "computed" + }, { + "expression": "scores", + "name": "scoreIds", + "type": "computed" + } + ] } } } @@ -17245,7 +17385,7 @@ "title": "What Dataset supports?" }, { - "source": "outcomeStatementPrePop", + "source": "relatedOutcomes", "type": "select2Many", "width": "15%", "title": "Which outcome statement/s relates to this survey?" @@ -17572,17 +17712,27 @@ } }, { - "name": "outcomeStatementPrePop", + "name": "relatedOutcomes", "dataType": "text", "description": "More than one outcome statement/s if relevant for this Project Baseline could be selected.", "validate": "required", "constraints": { - "textProperty": "description", - "valueProperty": "description", + "textProperty": "label", + "valueProperty": "label", "type": "pre-populated", "config": { "source": { - "context-path": "owner.custom.details.outcomes.shortTermOutcomes" + "url": "/project/outcomesByScores", + "params": [{ + "expression": "owner.projectId", + "name": "id", + "type": "computed" + }, { + "expression": "scores", + "name": "scoreIds", + "type": "computed" + } + ] } } } @@ -17970,7 +18120,7 @@ "title": "What Dataset supports?" }, { - "source": "outcomeStatementPrePop", + "source": "relatedOutcomes", "type": "select2Many", "width": "15%", "title": "Which outcome statement/s relates to this survey?" diff --git a/gradle.properties b/gradle.properties index 5e2e2771f..92538d5d9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,4 +16,4 @@ org.gradle.jvmargs=-Xmx2048M seleniumVersion=3.12.0 seleniumSafariDriverVersion=3.14.0 snapshotCacheTime=1800 -alaSecurityLibsVersion=6.0.0 +alaSecurityLibsVersion=6.0.4 diff --git a/grails-app/controllers/au/org/ala/merit/ProjectController.groovy b/grails-app/controllers/au/org/ala/merit/ProjectController.groovy index 9ac90abd9..0b49505aa 100644 --- a/grails-app/controllers/au/org/ala/merit/ProjectController.groovy +++ b/grails-app/controllers/au/org/ala/merit/ProjectController.groovy @@ -875,6 +875,13 @@ class ProjectController { Map model = reportService.activityReportModel(reportId, mode, formVersion) model.metaModel = projectService.filterOutputModel(model.metaModel, project, model.activity) + model.outputModels.each { k, v -> + if (v.scores) { + Map outputConfig = model.metaModel.outputConfig.find {it.outputName == k} + outputConfig?.outputContext = new JSONObject([scores:v.scores]) + } + } + model.context = new HashMap(project) model.returnTo = g.createLink(action:'exitReport', id:projectId, params:[reportId:reportId]) model.contextViewUrl = g.createLink(action:'index', id:projectId) @@ -1083,6 +1090,22 @@ class ProjectController { render categories as JSON } + @PreAuthorise(accessLevel = 'editor') + def outcomesByScores(String id) { + List scoreIds = params.getList('scoreIds') + if (!scoreIds) { + respond HttpStatus.SC_BAD_REQUEST + } + + List result = projectService.outcomesByScores(id, scoreIds) + result = result?.collect { + List outcomes = new ArrayList(it) // JSONArray quotes strings when joined so we need to work with a normal List + String label = new ArrayList(outcomes).join(',') + [label:label, value:outcomes] + } + render result as JSON + } + private def error(String message, String projectId) { flash.message = message if (projectId) { diff --git a/grails-app/services/au/org/ala/merit/ProjectService.groovy b/grails-app/services/au/org/ala/merit/ProjectService.groovy index 65ec62e01..53245b0da 100644 --- a/grails-app/services/au/org/ala/merit/ProjectService.groovy +++ b/grails-app/services/au/org/ala/merit/ProjectService.groovy @@ -1645,6 +1645,7 @@ class ProjectService { // The values to be filtered can come from either project services or activities in the MERI plan. selectedForProject = getProjectServices(project, config) + if (!selectedForProject) { serviceOutputs = config.activities?.collect{it.output}.findAll() selectedForProject = getProjectActivities(project, config) @@ -1668,6 +1669,21 @@ class ProjectService { filteredModel } + List outcomesByScores(String projectId, List scoreIds) { + + Map project = get(projectId) + List outcomes = [] + scoreIds.each { String scoreId -> + Map target = project.outputTargets?.find{it.scoreId == scoreId} + target?.outcomeTargets?.each { Map outcomeTarget -> + if (outcomeTarget.relatedOutcomes) { + outcomes << outcomeTarget.relatedOutcomes.sort() // Otherwise "unique" won't filter out of order entries + } + } + } + outcomes?.unique() + } + /** * Determines if the FormSections / outputs of the form described by the activityModel * can be filtered by the selection of project services. diff --git a/grails-app/views/activity/activityReport.gsp b/grails-app/views/activity/activityReport.gsp index b746fe0a0..97644249d 100644 --- a/grails-app/views/activity/activityReport.gsp +++ b/grails-app/views/activity/activityReport.gsp @@ -253,8 +253,10 @@ config.featureCollection = context.featureCollection; config.namespace = blockId; + var outputContext = _.extend({}, context, config.outputContext || {}); + config = _.extend({}, outputModelConfig, config); - master.createAndBindOutput(output, context, config); + master.createAndBindOutput(output, outputContext, config);