Skip to content

Commit

Permalink
WIP for org targets #3369
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Dec 1, 2024
1 parent bcf9e9d commit c8cc478
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion grails-app/assets/javascripts/organisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ OrganisationPageViewModel = function (props, options) {
}
};
var organisationService = new OrganisationService(options);
self.periods = organisationService.getBudgetHeaders();
self.periods = options.targetPeriods || [];

self.initialise = function() {
$.fn.dataTable.moment( 'dd-MM-yyyy' );
Expand Down
6 changes: 5 additions & 1 deletion grails-app/assets/javascripts/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function ServicesViewModel(serviceIds, allServices, outputTargets, periods) {
target.targetDate = ko.observable().extend({simpleDate:false});

target.periodTargets = _.map(periods, function (period) {
return {period: period, target: ko.observable(0)};
return {period: period.value, target: ko.observable(0)};
});

function evaluateAndAssignAverage() {
Expand Down Expand Up @@ -196,6 +196,10 @@ function ServicesViewModel(serviceIds, allServices, outputTargets, periods) {
};

self.periods = periods;
self.periodLabel = function (period) {

return period;
};

self.services = ko.observableArray();
self.addService = function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class OrganisationController {
def list() {}

def index(String id) {
def organisation = organisationService.get(id, 'all')
Map organisation = organisationService.get(id, 'all')

if (!organisation || organisation.error) {
organisationNotFound(id, organisation)
Expand Down Expand Up @@ -60,7 +60,7 @@ class OrganisationController {



protected Map content(organisation) {
protected Map content(Map organisation) {

def user = userService.getUser()
def members = userService.getMembersOfOrganisation(organisation.organisationId)
Expand Down Expand Up @@ -102,12 +102,13 @@ class OrganisationController {
List projects = organisation.projects ?: []
List programGroups = organisation.config?.programGroups ?: []
Map projectGroups = projectGroupingHelper.groupProjectsByProgram(projects, programGroups, ["organisationId:"+organisation.organisationId], true)
List targetPeriods = organisationService.generateTargetPeriods(organisation)

[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],
admin : [label: 'Admin', visible: adminVisible, type: 'tab', template:'admin', showEditAnnoucements:showEditAnnoucements, availableReportCategories:availableReportCategories]]
admin : [label: 'Admin', visible: adminVisible, type: 'tab', template:'admin', showEditAnnoucements:showEditAnnoucements, availableReportCategories:availableReportCategories, targetPeriods:targetPeriods]]

}

Expand Down Expand Up @@ -689,4 +690,10 @@ class OrganisationController {

render result as JSON
}

@PreAuthorise(accessLevel = 'admin')
def generateTargetPeriods(String id) {
List<Map> result = organisationService.generateTargetPeriods(id)
render result as JSON
}
}
20 changes: 20 additions & 0 deletions grails-app/services/au/org/ala/merit/OrganisationService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,26 @@ class OrganisationService {
regenerateOrganisationReports(organisation, organisationReportCategories)
}

List<String> generateTargetPeriods(String id) {
Map organisation = get(id)
generateTargetPeriods(organisation)
}

List<Map> generateTargetPeriods(Map organisation) {
Map targetsConfig = organisation.config?.targets
if (!targetsConfig) {
log.info("No target configuration defined for organisation ${organisation.organisationId}")
return null
}
ReportConfig targetsReportConfig = new ReportConfig(targetsConfig.periodGenerationConfig)
ReportOwner owner = new ReportOwner(
id:[organisationId:organisation.organisationId],
name:organisation.name
)
reportService.generateTargetPeriods(targetsReportConfig, owner, targetsConfig.periodLabelFormat)
}


private void regenerateOrganisationReports(Map organisation, List<String> reportCategories = null) {

ReportOwner owner = new ReportOwner(
Expand Down
15 changes: 15 additions & 0 deletions grails-app/services/au/org/ala/merit/ReportService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ class ReportService {

}

/**
* This is to support progress targets using the same
* configuration as we use to generate reports such that
* the targets can be aligned to reports if required.
* (Previously MERIT only supported targets per financial year)
*/
List<Map> generateTargetPeriods(ReportConfig reportConfig, ReportOwner reportOwner, String formatString = null) {
List<Map> reports = new ReportGenerator().generateReports(
reportConfig, reportOwner, 0, null)
Closure dateFormatter = {
formatString ? DateUtils.format(DateUtils.parse(it), formatString) : it
}
reports.collect{[label:dateFormatter(it.toDate), value:it.toDate]}
}

boolean needsRegeneration(Map report1, Map report2) {
return report1.fromDate != report2.fromDate ||
report1.toDate != report2.toDate ||
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/organisation/_serviceTargets.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<tr>

<!-- ko foreach: periods -->
<th class="budget-cell"><div data-bind="text:$data"></div></th>
<th class="budget-cell"><div data-bind="text:$data.label"></div></th>
<!-- /ko -->
</tr>
</thead>
Expand Down
2 changes: 2 additions & 0 deletions grails-app/views/organisation/index.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
cancelReportUrl: "${createLink(action:'ajaxCancelReport', id:organisation.organisationId)}/",
unCancelReportUrl: "${createLink(action:'ajaxUnCancelReport', id:organisation.organisationId)}/",
reportsHistoryUrl:"${createLink(controller: 'report', action:'reportingHistory')}",
targetPeriodsUrl:"${createLink(controller: 'organisation', action:'getTargetPeriods', id:organisation.organisationId)}",
returnTo: '${g.createLink(action:'index', id:"${organisation.organisationId}")}',
dashboardCategoryUrl: "${g.createLink(controller: 'report', action: 'activityOutputs', params: [fq:'organisationFacet:'+organisation.name])}",
reportOwner: {organisationId:'${organisation.organisationId}'},
Expand Down Expand Up @@ -84,6 +85,7 @@
var config = _.extend({
reportingConfigSelector:'#reporting-config form',
availableReportCategories:availableReportCategories,
targetPeriods: <fc:modelAsJavascript model="${content.admin?.targetPeriods}"/>
}, fcConfig);
var organisationViewModel = new OrganisationPageViewModel(organisation, config);

Expand Down

0 comments on commit c8cc478

Please sign in to comment.