Skip to content

Commit fbd2de5

Browse files
authored
Merge pull request #3396 from AtlasOfLivingAustralia/feature/issue3392
Use 2 decimal places for overall targets #3392
2 parents b6bb501 + 4aaa50e commit fbd2de5

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

grails-app/assets/javascripts/services.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ function OrganisationServicesViewModel(serviceIds, allServices, outputTargets, p
7272
target.serviceId = ko.observable(service ? service.id : null);
7373
target.scoreId = ko.observable(score ? score.scoreId : null);
7474

75-
target.target = ko.observable();
75+
var decimalPlaces = _.isNumber(score && score.decimalPlaces) ? score.decimalPlaces : 2;
76+
target.target = ko.observable().extend({numericString: decimalPlaces});
7677
target.targetDate = ko.observable().extend({simpleDate:false});
7778

7879
target.periodTargets = _.map(periods, function (period) {
@@ -96,7 +97,7 @@ function OrganisationServicesViewModel(serviceIds, allServices, outputTargets, p
9697
var sum = 0;
9798
var count = 0;
9899
_.each(target.periodTargets, function (periodTarget) {
99-
var target = parseInt(periodTarget.target());
100+
var target = parseFloat(periodTarget.target());
100101
if (!_.isNaN(target)) {
101102
sum += target
102103
count++;
@@ -209,6 +210,11 @@ function OrganisationServicesViewModel(serviceIds, allServices, outputTargets, p
209210
});
210211

211212
target.scoreId.subscribe(function () {
213+
var score = target.scoreId() ? target.score() : null;
214+
if (score) {
215+
var decimalPlaces = _.isNumber(score && score.decimalPlaces) ? score.decimalPlaces : 2;
216+
target.target = ko.observable().extend({numericString: decimalPlaces});
217+
}
212218
target.updateTargets();
213219
});
214220

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,14 @@ class OrganisationController {
7474
Map availableReportCategories = null
7575
List services = null
7676
List targetPeriods = null
77+
List dashboardData = null
7778
if (adminVisible) {
7879
dashboardReports += [name:'announcements', label:'Announcements']
7980
availableReportCategories = settingService.getJson(SettingPageType.ORGANISATION_REPORT_CONFIG)
8081
services = organisationService.findApplicableServices(organisation, metadataService.getProjectServices())
8182
targetPeriods = organisationService.generateTargetPeriods(organisation)
83+
List scores = services.collect{it.scores}.flatten()
84+
dashboardData = organisationService.scoresForOrganisation(organisation, scores?.collect{it.scoreId}, !hasEditorAccess)
8285
}
8386
boolean showTargets = userService.userIsSiteAdmin() && services && targetPeriods
8487

@@ -110,7 +113,7 @@ class OrganisationController {
110113
[about : [label: 'About', visible: true, stopBinding: false, type:'tab', default:!reportingVisible, displayedPrograms:projectGroups.displayedPrograms, servicesDashboard:[visible:true]],
111114
projects : [label: 'Reporting', template:"/shared/projectListByProgram", visible: reportingVisible, stopBinding:true, default:reportingVisible, type: 'tab', reports:organisation.reports, adHocReportTypes:adHocReportTypes, reportOrder:reportOrder, hideDueDate:true, displayedPrograms:projectGroups.displayedPrograms, reportsFirst:true, declarationType:SettingPageType.RDP_REPORT_DECLARATION],
112115
sites : [label: 'Sites', visible: reportingVisible, type: 'tab', stopBinding:true, projectCount:organisation.projects?.size()?:0, showShapefileDownload:adminVisible],
113-
dashboard : [label: 'Dashboard', visible: reportingVisible, stopBinding:true, type: 'tab', template:'/shared/dashboard', reports:dashboardReports],
116+
dashboard : [label: 'Dashboard', visible: reportingVisible, stopBinding:true, type: 'tab', template:'dashboard', reports:dashboardReports, dashboardData:dashboardData],
114117
admin : [label: 'Admin', visible: adminVisible, type: 'tab', template:'admin', showEditAnnoucements:showEditAnnoucements, availableReportCategories:availableReportCategories, targetPeriods:targetPeriods, services: services, showTargets:showTargets]]
115118

116119
}
@@ -200,7 +203,7 @@ class OrganisationController {
200203
}
201204

202205
List existingLinks = links?.findResults { it.documentId }
203-
List toDeleteLinks = originalOrganisation?.links?.findAll { !existingLinks.contains(it.documentId) }
206+
List toDeleteLinks = originalOrganisation?.links?.findAll { !existingLinks?.contains(it.documentId) }
204207
// delete any links that were removed.
205208
if (toDeleteLinks && !result.error) {
206209
toDeleteLinks.each { link ->

grails-app/services/au/org/ala/merit/OrganisationService.groovy

+17
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,23 @@ class OrganisationService {
352352
scoreIds.collectEntries{ String scoreId ->[(scoreId):result.results?.find{it.scoreId == scoreId}?.result?.result ?: 0]}
353353
}
354354

355+
List scoresForOrganisation(Map organisation, List<String> scoreIds, boolean approvedOnly = true) {
356+
357+
String url = grailsApplication.config.getProperty('ecodata.baseUrl')+"organisation/organisationMetrics/"+organisation.organisationId
358+
Map params = [approvedOnly: approvedOnly, scoreIds: scoreIds]
359+
360+
Map result = webService.doPost(url, params)
361+
362+
List scores = result?.resp?.collect { Map score ->
363+
Map target = organisation?.custom?.details?.services?.targets?.find { it.scoreId == score.scoreId }
364+
score.target = target?.target
365+
score
366+
}
367+
368+
scores
369+
370+
}
371+
355372

356373
/**
357374
* Filter services to those supported by organisation.

grails-app/taglib/au/org/ala/merit/DashboardTagLib.groovy

+3-1
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,12 @@ class DashboardTagLib {
147147
percentComplete = Math.min(100, percentComplete)
148148
percentComplete = Math.max(0, percentComplete)
149149

150+
int maxDecimalPlaces = score.decimalPlaces != null ? score.decimalPlaces : 2
151+
150152
out << """
151153
<div class="progress progress-info active " style="position:relative">
152154
<div class="${progressBarClass}" style="width: ${percentComplete}%;"></div>
153-
<span class="pull-right progress-label ${percentComplete >= 99 ? 'progress-100':''}" style="position:absolute; top:0; right:0;"> ${g.formatNumber(type:'number',number:result, maxFractionDigits: 2, groupingUsed:true)}/${g.formatNumber(type:'number',number:target, maxFractionDigits: 2, groupingUsed:true)}</span>
155+
<span class="pull-right progress-label ${percentComplete >= 99 ? 'progress-100':''}" style="position:absolute; top:0; right:0;"> ${g.formatNumber(type:'number',number:result, maxFractionDigits: maxDecimalPlaces, groupingUsed:true)}/${g.formatNumber(type:'number',number:target, maxFractionDigits: maxDecimalPlaces, groupingUsed:true)}</span>
154156
</div>"""
155157
}
156158

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<g:if test="${dashboardData}">
2+
<div class="dashboard-section" style="padding:10px; margin-top:10px;">
3+
<g:each in="${dashboardData.groupBy{it.category}}" var="category">
4+
<h3 class="serviceTitle">${category.key}</h3>
5+
<g:each in="${category.value}" var="score">
6+
<fc:renderScore score="${score}" includeInvoiced="false"></fc:renderScore>
7+
</g:each>
8+
</g:each>
9+
</div>
10+
</g:if>
11+
12+
<g:render template="/shared/dashboard"></g:render>

0 commit comments

Comments
 (0)