Skip to content

Commit aafa048

Browse files
committed
added service targets to organisation
1 parent 468e159 commit aafa048

File tree

10 files changed

+535
-6
lines changed

10 files changed

+535
-6
lines changed

grails-app/assets/javascripts/organisation-manifest.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
//= require sites.js
77
//= require reporting.js
88
//= require document.js
9+
//= require organisationService.js
10+
//= require services.js
911
//= require organisation.js

grails-app/assets/javascripts/organisation.js

+55
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,8 @@ OrganisationPageViewModel = function (props, options) {
548548
}
549549
}
550550
};
551+
var organisationService = new OrganisationService(options);
552+
self.periods = organisationService.getBudgetHeaders();
551553

552554
self.initialise = function() {
553555
$.fn.dataTable.moment( 'dd-MM-yyyy' );
@@ -634,6 +636,32 @@ OrganisationPageViewModel = function (props, options) {
634636
self.reportingEnabled = ko.observable();
635637
self.selectedOrganisationReportCategories = ko.observableArray();
636638

639+
// List of service / target measure
640+
self.allTargetMeasures = [];
641+
var services = options.services || [];
642+
for (var i=0; i<services.length; i++) {
643+
if (services[i].scores) {
644+
for (var j=0; j<services[i].scores.length; j++) {
645+
self.allTargetMeasures.push( {
646+
label:services[i].name+' - '+services[i].scores[j].label,
647+
serviceId:services[i].id,
648+
scoreId:services[i].scores[j].scoreId,
649+
service:services[i],
650+
score:services[i].scores[j],
651+
value:services[i].scores[j].scoreId
652+
});
653+
}
654+
}
655+
}
656+
657+
self.allTargetMeasures = _.sortBy(self.allTargetMeasures, 'label');
658+
var propDetails = props && props.custom && props.custom.details || {};
659+
self.selectedTargetMeasures = ko.observableArray();
660+
var details = new DetailsViewModel(propDetails, props, self.periods, self.allTargetMeasures, options);
661+
updatedTargetMeasures(details);
662+
self.reportingTargets = ko.observable(details);
663+
self.isProjectDetailsLocked = ko.observable(false);
664+
637665
var setStartAndEndDateDefaults = function() {
638666
var currentConfig = parsedConfig();
639667
if (!currentConfig || !currentConfig.organisationReports || currentConfig.organisationReports.length == 0) {
@@ -692,6 +720,26 @@ OrganisationPageViewModel = function (props, options) {
692720
reportService.regenerateReports(data,options.regenerateOrganisationReportsUrl);
693721
};
694722

723+
function updatedTargetMeasures (details) {
724+
var reportingTargets = details,
725+
selectedServices = reportingTargets.services.services(),
726+
allServices = self.allTargetMeasures;
727+
728+
_.each(allServices, function (service) {
729+
var found = _.find(selectedServices, function (selectedService) {
730+
return selectedService.scoreId() === service.scoreId;
731+
});
732+
733+
if (!found) {
734+
reportingTargets.services.addServiceTarget(service);
735+
}
736+
})
737+
}
738+
739+
self.attachValidation = function() {
740+
$("#organisation-targets").validationEngine('attach', {validationAttribute: "data-validation-engine"});
741+
};
742+
695743
self.saveOrganisationConfiguration = function() {
696744
var currentConfig = parsedConfig();
697745
if (!currentConfig) {
@@ -713,6 +761,13 @@ OrganisationPageViewModel = function (props, options) {
713761
return saveOrganisation(json);
714762
};
715763

764+
self.saveCustomFields = function() {
765+
if ($("#organisation-targets form").validationEngine('validate')) {
766+
var json = JSON.parse(self.reportingTargets().modelAsJSON());
767+
return saveOrganisation(json);
768+
}
769+
};
770+
716771

717772
var saveOrganisation = function(json) {
718773
return $.ajax({
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function OrganisationService(organisation, options) {
2+
var self = this;
3+
var defaults = {
4+
excludeFinancialYearData : false
5+
};
6+
7+
var config = _.defaults(options, defaults);
8+
9+
self.getBudgetHeaders = function() {
10+
if (config.excludeFinancialYearData) {
11+
return []; // Return a single period header for the organisation
12+
}
13+
var headers = [];
14+
var startYr = moment(organisation.plannedStartDate).format('YYYY');
15+
var endYr = moment(organisation.plannedEndDate).format('YYYY');
16+
var startMonth = moment(organisation.plannedStartDate).format('M');
17+
var endMonth = moment(organisation.plannedEndDate).format('M');
18+
19+
//Is startYr is between jan to june?
20+
if(startMonth >= 1 && startMonth <= 6 ){
21+
startYr--;
22+
}
23+
24+
//Is the end year is between july to dec?
25+
if(endMonth >= 7 && endMonth <= 12 ){
26+
endYr++;
27+
}
28+
29+
var count = endYr - startYr;
30+
for (i = 0; i < count; i++){
31+
headers.push(startYr + '/' + ++startYr);
32+
}
33+
34+
return headers;
35+
};
36+
}

0 commit comments

Comments
 (0)