Skip to content

Commit

Permalink
Merge pull request #3443 from AtlasOfLivingAustralia/feature/issue3432
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala authored Feb 14, 2025
2 parents 6be628e + 93d89aa commit ddbc2ae
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 34 deletions.
88 changes: 67 additions & 21 deletions grails-app/assets/javascripts/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,14 @@ function ProjectViewModel(project) {
self.geographicInfo = {
nationwide: ko.observable(project.geographicInfo.nationwide || false),
statewide: ko.observable(project.geographicInfo.statewide || false),
isDefault: ko.observable(project.geographicInfo.isDefault || false),
overridePrimaryElectorate: ko.observable(project.geographicInfo.overridePrimaryElectorate || false),
overridePrimaryState: ko.observable(project.geographicInfo.overridePrimaryState || false),
primaryState: ko.observable(project.geographicInfo.primaryState),
primaryElectorate: ko.observable(project.geographicInfo.primaryElectorate),
otherStates: ko.observableArray(project.geographicInfo.otherStates || []),
otherElectorates: ko.observableArray(project.geographicInfo.otherElectorates || [])
otherExcludedStates: ko.observableArray(project.geographicInfo.otherExcludedStates || []),
otherElectorates: ko.observableArray(project.geographicInfo.otherElectorates || []),
otherExcludedElectorates: ko.observableArray(project.geographicInfo.otherExcludedElectorates || [])
};
self.geographicInfo.nationwide.subscribe(function(newValue) {
if (newValue) {
Expand All @@ -193,6 +196,8 @@ function ProjectViewModel(project) {
self.geographicInfo.primaryElectorate("");
self.geographicInfo.otherStates([]);
self.geographicInfo.otherElectorates([]);
self.geographicInfo.otherExcludedStates([]);
self.geographicInfo.otherExcludedElectorates([]);
}
});

Expand All @@ -202,6 +207,8 @@ function ProjectViewModel(project) {
self.geographicInfo.primaryElectorate("");
self.geographicInfo.otherStates([]);
self.geographicInfo.otherElectorates([]);
self.geographicInfo.otherExcludedStates([]);
self.geographicInfo.otherExcludedElectorates([]);
}
});

Expand Down Expand Up @@ -462,30 +469,66 @@ function ProjectViewModel(project) {
});
self.associatedProgram(project.associatedProgram); // to trigger the computation of sub-programs
};

self.transients.states = ko.observableArray([]);
self.transients.states.filteredStates = ko.computed(function() {
var primaryState = self.geographicInfo.primaryState(), states = self.transients.states().concat([]);
if (primaryState) {
var index = states.indexOf(primaryState);
self.transients.removeAll = function (source, toRemove) {
for(var i = 0; i < toRemove.length; i++) {
var index = source.indexOf(toRemove[i]);
if (index > -1) {
states.splice(index, 1);
source.splice(index, 1);
}
}

return states;
return source
}

self.transients.states = ko.observableArray([]);
self.transients.statesUnavailableForSelection = function (included) {
var result = [],
primaryState = self.geographicInfo.primaryState(),
otherStates = self.geographicInfo.otherStates() || [],
excludedStates = self.geographicInfo.otherExcludedStates() || [];

if (primaryState)
result.push(primaryState)
if (!included)
result.push.apply(result, otherStates)
else
result.push.apply(result, excludedStates)
return result
}
self.transients.states.statesToIncludeOrExclude = function(include) {
var toRemove = self.transients.statesUnavailableForSelection(include), states = self.transients.states().concat([]);
return self.transients.removeAll(states, toRemove);
};
self.transients.states.statesToInclude = ko.computed(function() {
return self.transients.states.statesToIncludeOrExclude(true);
});
self.transients.states.statesToExclude = ko.computed(function() {
return self.transients.states.statesToIncludeOrExclude(false);
});
self.transients.electorates = ko.observableArray([]);
self.transients.electorates.filteredElectorates = ko.computed(function() {
var primaryElectorate = self.geographicInfo.primaryElectorate(), electorates = self.transients.electorates().concat([]);
if (primaryElectorate) {
var index = electorates.indexOf(primaryElectorate);
if (index > -1) {
electorates.splice(index, 1);
}
}

return electorates;
self.transients.electoratesUnavailableForSelection = function (included) {
var result = [],
primaryElectorate = self.geographicInfo.primaryElectorate(),
otherElectorates = self.geographicInfo.otherElectorates() || [],
excludedElectorates = self.geographicInfo.otherExcludedElectorates() || [];

if (primaryElectorate)
result.push(primaryElectorate)
if (!included)
result.push.apply(result, otherElectorates)
else
result.push.apply(result, excludedElectorates)
return result
}
self.transients.electorates.electoratesToIncludeOrExclude = function(include) {
var toRemove = self.transients.electoratesUnavailableForSelection(include), source = self.transients.electorates().concat([]);
return self.transients.removeAll(source, toRemove);
};
self.transients.electorates.electoratesToInclude = ko.computed(function() {
return self.transients.electorates.electoratesToIncludeOrExclude(true);
});
self.transients.electorates.electoratesToExclude = ko.computed(function() {
return self.transients.electorates.electoratesToIncludeOrExclude(false);
});

self.loadStatesAndElectorates = function() {
Expand Down Expand Up @@ -514,11 +557,14 @@ function ProjectViewModel(project) {
self.loadGeographicInfo = function () {
self.geographicInfo.nationwide(project.geographicInfo.nationwide);
self.geographicInfo.statewide(project.geographicInfo.statewide);
self.geographicInfo.isDefault(project.geographicInfo.isDefault);
self.geographicInfo.overridePrimaryElectorate(project.geographicInfo.overridePrimaryElectorate);
self.geographicInfo.overridePrimaryElectorate(project.geographicInfo.overridePrimaryElectorate);
self.geographicInfo.primaryState(project.geographicInfo.primaryState);
self.geographicInfo.primaryElectorate(project.geographicInfo.primaryElectorate);
self.geographicInfo.otherStates(project.geographicInfo.otherStates);
self.geographicInfo.otherElectorates(project.geographicInfo.otherElectorates);
self.geographicInfo.otherExcludedStates(project.geographicInfo.otherExcludedStates);
self.geographicInfo.otherExcludedElectorates(project.geographicInfo.otherExcludedElectorates);
}

self.toJS = function() {
Expand Down
39 changes: 26 additions & 13 deletions grails-app/views/project/_editProject.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -293,45 +293,58 @@
</div>
</td>
</tr>
<tr>
<td></td>
<td>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="geographicInfoBehaviour" data-bind="checked: geographicInfo.isDefault">
<label class="form-check-label" for="geographicInfoBehaviour">Override calculated primary state and electorate with selections below.</label>
</div>
</td>
</tr>
<tr>
<td>
<label for="primaryElectorate">Primary electorate</label>
</td>
<td>
<select id="primaryElectorate" data-bind="options:transients.electorates, value:geographicInfo.primaryElectorate, optionsCaption: 'Select an electorate', disable: geographicInfo.nationwide() || geographicInfo.statewide()" class="select form-control"></select>
<select id="primaryElectorate" data-bind="options:transients.electorates, value:geographicInfo.primaryElectorate, optionsCaption: 'Select an electorate', disable: geographicInfo.nationwide() || geographicInfo.statewide() || !geographicInfo.overridePrimaryElectorate()" class="select form-control" data-validation-engine="validate[required]"></select>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="geographicInfoElectorateBehaviour" name="geographicInfoElectorateBehaviour" data-bind="checked: geographicInfo.overridePrimaryElectorate">
<label class="form-check-label" for="geographicInfoElectorateBehaviour">Override primary electorate with above selection.</label>
</div>
</td>
</tr>
<tr>
<td>
<label for="otherElectorates">Other electorates</label>
</td>
<td>
<select id="otherElectorates" multiple="multiple" data-bind="options:transients.electorates.filteredElectorates, multiSelect2:{value:geographicInfo.otherElectorates, placeholder:''}, disable: geographicInfo.nationwide() || geographicInfo.statewide()" class="select form-control"></select>
<div class="form-group">
<label for="otherElectorates">Include</label>
<select id="otherElectorates" multiple="multiple" data-bind="options:transients.electorates.electoratesToInclude, multiSelect2:{value:geographicInfo.otherElectorates, placeholder:'', tags: false}, disable: geographicInfo.nationwide() || geographicInfo.statewide()" class="select form-control"></select>
</div>
<div class="form-group">
<label for="otherExcludedElectorates">Exclude</label>
<select id="otherExcludedElectorates" multiple="multiple" data-bind="options:transients.electorates.electoratesToExclude, multiSelect2:{value:geographicInfo.otherExcludedElectorates, placeholder:'', tags: false}, disable: geographicInfo.nationwide() || geographicInfo.statewide()" class="select form-control"></select>
</div>
</td>
</tr>
<tr>
<td>
<label for="primaryState">Primary state</label>
</td>
<td>
<select id="primaryState" data-bind="options:transients.states, value:geographicInfo.primaryState, optionsCaption: 'Select a state', disable: geographicInfo.nationwide()" class="select form-control"></select>
<select id="primaryState" data-bind="options:transients.states, value:geographicInfo.primaryState, optionsCaption: 'Select a state', disable: geographicInfo.nationwide() || !geographicInfo.overridePrimaryState()" class="select form-control" data-validation-engine="validate[required]"></select>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="geographicInfoStateBehaviour" name="geographicInfoStateBehaviour" data-bind="checked: geographicInfo.overridePrimaryState">
<label class="form-check-label" for="geographicInfoStateBehaviour">Override primary state with above selection.</label>
</div>
</td>
</tr>
<tr>
<td>
<label for="otherStates">Other states</label>
</td>
<td>
<select id="otherStates" multiple="multiple" data-bind="options:transients.states.filteredStates, multiSelect2:{value:geographicInfo.otherStates, placeholder:''}, disable: geographicInfo.nationwide()" class="select form-control"></select>
<div class="form-group">
<label for="otherStates">Include</label>
<select id="otherStates" multiple="multiple" data-bind="options:transients.states.statesToInclude, multiSelect2:{value:geographicInfo.otherStates, placeholder:'', tags: false}, disable: geographicInfo.nationwide()" class="select form-control"></select>
</div>
<div class="form-group">
<label for="otherExcludedStates">Exclude</label>
<select id="otherExcludedStates" multiple="multiple" data-bind="options:transients.states.statesToExclude, multiSelect2:{value:geographicInfo.otherExcludedStates, placeholder:'', tags: false}, disable: geographicInfo.nationwide()" class="select form-control"></select>
</div>
</td>
</tr>
</tbody>
Expand Down
12 changes: 12 additions & 0 deletions src/main/scripts/releases/4.2/migrateIsDefaultInGeographicInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load( "../../utils/audit.js");
var count = 0;
db.project.find({isMERIT: true, "geographicInfo.isDefault": true}).forEach(function (project) {
project.geographicInfo.overridePrimaryElectorate = true
project.geographicInfo.overridePrimaryState = true
db.project.updateOne({projectId: project.projectId}, {$set: {geographicInfo: project.geographicInfo}});
audit(project, project.projectId, 'au.org.ala.ecodata.Project', "system")
print("updated " + project.projectId);
count ++;
});

print("total updates " + count);

0 comments on commit ddbc2ae

Please sign in to comment.