Skip to content

Commit

Permalink
commit removed test code #2980
Browse files Browse the repository at this point in the history
  • Loading branch information
salomon-j committed Sep 12, 2023
1 parent dfa3401 commit 5a05a66
Showing 1 changed file with 0 additions and 192 deletions.
192 changes: 0 additions & 192 deletions grails-app/assets/javascripts/meriplan.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function MERIPlan(project, projectService, config) {
}
}
ReadOnlyMeriPlan.apply(this, [project, projectService, config]);
ReadOnlyMeriPlanOriginal.apply(this, [project, projectService, config]);

self.approvedPlans = ko.observableArray();

Expand Down Expand Up @@ -814,197 +813,6 @@ function ReadOnlyMeriPlan(project, projectService, config, original, changed) {
}
};

function ReadOnlyMeriPlanOriginal(project, projectService, config) {
var self = this;
if (!project.custom) {
project.custom = {};
}
if (!project.custom.details) {
project.custom.details = {};
}

self.periods = projectService.getBudgetHeaders(project);

self.plannedStartDate = ko.observable(project.plannedStartDate).extend({simpleDate: false});
self.plannedEndDate = ko.observable(project.plannedEndDate).extend({simpleDate: false});

self.meriPlanStatus = ko.pureComputed(function () {
var result = {
text: 'This plan is not yet approved',
badgeClass: 'badge-warning'
};
if (projectService.isCompletedOrTerminated()) {
if (projectService.isUnlockedForDataCorrection()) {
result = {text: 'The plan has been unlocked for data correction', badgeClass: 'badge-warning'};
} else {
if (projectService.isTerminated()){
result = {text: 'This project is ' + project.status.toLowerCase(), badgeClass: 'badge-danger'};
}else{
result = {text: 'This project is ' + project.status.toLowerCase(), badgeClass: 'badge-info'};
}
}
} else {
if (projectService.isApproved()) {
result = {text: 'This plan has been approved', badgeClass: 'badge-success'};
} else if (projectService.isSubmitted()) {
result = {text: 'This plan has been submitted for approval', badgeClass: 'badge-info'};
}
}
return result;
});

var disableFlag = ko.observable(false);
self.isProjectDetailsLocked = ko.computed(function () {
return projectService.isProjectDetailsLocked();
});
var riskModel;
if (config.useRlpRisksModel) {
riskModel = rlpRiskModel();
} else {
riskModel = meritRiskModel();
}

// List of service / target measure
self.allTargetMeasures = [];
var services = config.services || [];
for (var i=0; i<services.length; i++) {
if (services[i].scores) {
for (var j=0; j<services[i].scores.length; j++) {
self.allTargetMeasures.push( {
label:services[i].name+' - '+services[i].scores[j].label,
serviceId:services[i].id,
scoreId:services[i].scores[j].scoreId,
service:services[i],
score:services[i].scores[j],
value:services[i].scores[j].scoreId
});
}
}
}
self.allTargetMeasures = _.sortBy(self.allTargetMeasures, 'label');
self.monitoringTargetMeasures = _.filter(self.allTargetMeasures, function(targetMeasure) {
return targetMeasure.score.tags && targetMeasure.score.tags.indexOf('Indicator') >= 0;
});
self.baselineTargetMeasures = _.filter(self.allTargetMeasures, function(targetMeasure) {
return targetMeasure.score.tags && targetMeasure.score.tags.indexOf('Baseline') >= 0;
});
/**
* This function allows the UI to convert an array of scoreIds into the same labels
* that are used in the editable version of the MERI plan.
* @param scoreIds {Array} An array of scoreIds
* @returns {string} A string containing the labels for the scoreIds
*/
self.targetMeasureLabels = function(scoreIds) {
var result = '';
scoreIds = ko.utils.unwrapObservable(scoreIds);
for (var i=0; i<scoreIds.length; i++) {
var scoreId = scoreIds[i];
for (var j=0; j<self.allTargetMeasures.length; j++) {
if (self.allTargetMeasures[j].scoreId == scoreId) {
result = result + self.allTargetMeasures[j].label;
}
}
}
return result;
}

_.extend(self, new Risks(project.risks, riskModel, disableFlag, config.risksStorageKey));
self.selectedTargetMeasures = ko.observableArray();
var details = new DetailsViewModel(project.custom.details, project, self.periods, self.risks, self.allTargetMeasures, self.selectedTargetMeasures, config);
self.meriPlanOriginal = ko.observable(details);
self.detailsLastUpdated = ko.observable(project.custom.details.lastUpdated).extend({simpleDate: true});
self.isAgricultureProject = ko.computed(function () {
var agricultureOutcomeStartIndex = 4;
var selectedPrimaryOutcome = self.meriPlanOriginal().outcomes.primaryOutcome.description();
var selectedOutcomeIndex = _.findIndex(project.outcomes, function (outcome) {
return outcome.outcome == selectedPrimaryOutcome;
});
return selectedOutcomeIndex >= agricultureOutcomeStartIndex;
});


function processServicesAndOutcomes(services, outcomes, serviceOutcomeMap) {
services = services || [];
outcomes = outcomes || [];
for (var j=0; j<services.length; j++) {
var service = services[j];
if (service) {
if (!serviceOutcomeMap[service]) {
serviceOutcomeMap[service] = {};
}
for (var k = 0; k < outcomes.length; k++) {
if (outcomes[k]) {
serviceOutcomeMap[service][outcomes[k]] = true;
}
}
}
}
}
/** All parts of the model able to specify services are collected together here */
self.selectedServiceWatcher = ko.computed(function() {

var services = [];
var serviceOutcomeMap = {};
var threats = self.meriPlanOriginal().threats.rows();
for (var i=0; i<threats.length; i++) {
var s = threats[i].relatedTargetMeasures();
var o = threats[i].relatedOutcomes();
processServicesAndOutcomes(s, o, serviceOutcomeMap);
}


var baseLineOutcomeMap = {}; // Tracks the outcomes related to each baseline
var baselines = self.meriPlanOriginal().baseline.rows();
for (var i=0; i<baselines.length; i++) {
baseLineOutcomeMap[baselines[i].code()] = baselines[i].relatedOutcomes();
processServicesAndOutcomes(baselines[i].relatedTargetMeasures(), baselines[i].relatedOutcomes(), serviceOutcomeMap);
}

var monitoring = self.meriPlanOriginal().monitoring.rows();
for (var i=0; i<monitoring.length; i++) {
// The outcome related to this monitoring indicator depends on the related baseline
var monitoringOutcomes = baseLineOutcomeMap[monitoring[i].relatedBaseline()];
processServicesAndOutcomes(monitoring[i].relatedTargetMeasures(), monitoringOutcomes, serviceOutcomeMap);
}

for (var prop in serviceOutcomeMap) {
var service = _.find(self.selectedTargetMeasures(), function(selectedService) {
return selectedService.scoreId == prop;
});
var newService = false;
if (!service) {
var serviceAndTarget = _.find(self.allTargetMeasures, function(target) {
return target.scoreId == prop;
});
service = {scoreId:prop, serviceAndTarget: serviceAndTarget, outcomes:ko.observableArray()};
newService = true;
}
var outcomes = [];
for (var outcome in serviceOutcomeMap[prop]) {
outcomes.push(outcome);
}
service.outcomes(outcomes);
if (newService) {
self.selectedTargetMeasures.push(service);
}
}

_.each(self.selectedTargetMeasures(), function(selectedService) {
if (!serviceOutcomeMap[selectedService.scoreId]) {
self.selectedTargetMeasures.remove(selectedService)
}
});

return services;
}).extend({rateLimit:config.targetMeasureUpdateLimit || 1000});
self.monitoringIndicators = function(code) {
var relatedIndicators = _.filter(self.meriPlanOriginal().monitoring.rows(), function(row) {
return row.relatedBaseline() == ko.utils.unwrapObservable(code);
});
return relatedIndicators;
}
};

function DetailsViewModel(o, project, budgetHeaders, risks, allServices, selectedTargetMeasures, config) {
var self = this;
var period = budgetHeaders;
Expand Down

0 comments on commit 5a05a66

Please sign in to comment.