Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 2 decimal places for overall targets #3392 #3396

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions grails-app/assets/javascripts/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ function OrganisationServicesViewModel(serviceIds, allServices, outputTargets, p
target.serviceId = ko.observable(service ? service.id : null);
target.scoreId = ko.observable(score ? score.scoreId : null);

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

target.periodTargets = _.map(periods, function (period) {
Expand All @@ -96,7 +97,7 @@ function OrganisationServicesViewModel(serviceIds, allServices, outputTargets, p
var sum = 0;
var count = 0;
_.each(target.periodTargets, function (periodTarget) {
var target = parseInt(periodTarget.target());
var target = parseFloat(periodTarget.target());
if (!_.isNaN(target)) {
sum += target
count++;
Expand Down Expand Up @@ -209,6 +210,11 @@ function OrganisationServicesViewModel(serviceIds, allServices, outputTargets, p
});

target.scoreId.subscribe(function () {
var score = target.scoreId() ? target.score() : null;
if (score) {
var decimalPlaces = _.isNumber(score && score.decimalPlaces) ? score.decimalPlaces : 2;
target.target = ko.observable().extend({numericString: decimalPlaces});
}
target.updateTargets();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,14 @@ class OrganisationController {
Map availableReportCategories = null
List services = null
List targetPeriods = null
List dashboardData = null
if (adminVisible) {
dashboardReports += [name:'announcements', label:'Announcements']
availableReportCategories = settingService.getJson(SettingPageType.ORGANISATION_REPORT_CONFIG)
services = organisationService.findApplicableServices(organisation, metadataService.getProjectServices())
targetPeriods = organisationService.generateTargetPeriods(organisation)
List scores = services.collect{it.scores}.flatten()
dashboardData = organisationService.scoresForOrganisation(organisation, scores?.collect{it.scoreId}, !hasEditorAccess)
}
boolean showTargets = userService.userIsSiteAdmin() && services && targetPeriods

Expand Down Expand Up @@ -110,7 +113,7 @@ class OrganisationController {
[about : [label: 'About', visible: true, stopBinding: false, type:'tab', default:!reportingVisible, displayedPrograms:projectGroups.displayedPrograms, servicesDashboard:[visible:true]],
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],
sites : [label: 'Sites', visible: reportingVisible, type: 'tab', stopBinding:true, projectCount:organisation.projects?.size()?:0, showShapefileDownload:adminVisible],
dashboard : [label: 'Dashboard', visible: reportingVisible, stopBinding:true, type: 'tab', template:'/shared/dashboard', reports:dashboardReports],
dashboard : [label: 'Dashboard', visible: reportingVisible, stopBinding:true, type: 'tab', template:'dashboard', reports:dashboardReports, dashboardData:dashboardData],
admin : [label: 'Admin', visible: adminVisible, type: 'tab', template:'admin', showEditAnnoucements:showEditAnnoucements, availableReportCategories:availableReportCategories, targetPeriods:targetPeriods, services: services, showTargets:showTargets]]

}
Expand Down Expand Up @@ -200,7 +203,7 @@ class OrganisationController {
}

List existingLinks = links?.findResults { it.documentId }
List toDeleteLinks = originalOrganisation?.links?.findAll { !existingLinks.contains(it.documentId) }
List toDeleteLinks = originalOrganisation?.links?.findAll { !existingLinks?.contains(it.documentId) }
// delete any links that were removed.
if (toDeleteLinks && !result.error) {
toDeleteLinks.each { link ->
Expand Down
17 changes: 17 additions & 0 deletions grails-app/services/au/org/ala/merit/OrganisationService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,23 @@ class OrganisationService {
scoreIds.collectEntries{ String scoreId ->[(scoreId):result.results?.find{it.scoreId == scoreId}?.result?.result ?: 0]}
}

List scoresForOrganisation(Map organisation, List<String> scoreIds, boolean approvedOnly = true) {

String url = grailsApplication.config.getProperty('ecodata.baseUrl')+"organisation/organisationMetrics/"+organisation.organisationId
Map params = [approvedOnly: approvedOnly, scoreIds: scoreIds]

Map result = webService.doPost(url, params)

List scores = result?.resp?.collect { Map score ->
Map target = organisation?.custom?.details?.services?.targets?.find { it.scoreId == score.scoreId }
score.target = target?.target
score
}

scores

}


/**
* Filter services to those supported by organisation.
Expand Down
4 changes: 3 additions & 1 deletion grails-app/taglib/au/org/ala/merit/DashboardTagLib.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ class DashboardTagLib {
percentComplete = Math.min(100, percentComplete)
percentComplete = Math.max(0, percentComplete)

int maxDecimalPlaces = score.decimalPlaces != null ? score.decimalPlaces : 2

out << """
<div class="progress progress-info active " style="position:relative">
<div class="${progressBarClass}" style="width: ${percentComplete}%;"></div>
<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>
<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>
</div>"""
}

Expand Down
12 changes: 12 additions & 0 deletions grails-app/views/organisation/_dashboard.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<g:if test="${dashboardData}">
<div class="dashboard-section" style="padding:10px; margin-top:10px;">
<g:each in="${dashboardData.groupBy{it.category}}" var="category">
<h3 class="serviceTitle">${category.key}</h3>
<g:each in="${category.value}" var="score">
<fc:renderScore score="${score}" includeInvoiced="false"></fc:renderScore>
</g:each>
</g:each>
</div>
</g:if>

<g:render template="/shared/dashboard"></g:render>
Loading