Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- added statewide property
- added behaviour changes based on national and statewide selection
- electorate selection automatically adds its states
  • Loading branch information
temi committed Nov 1, 2024
1 parent 853db52 commit 1db8e08
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 45 deletions.
58 changes: 58 additions & 0 deletions grails-app/assets/javascripts/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,75 @@ function ProjectViewModel(project) {
self.contractEndDate = ko.observable(project.contractEndDate).extend({simpleDate: false});
self.geographicInfo = {
nationwide: ko.observable(project.geographicInfo.nationwide || false),
statewide: ko.observable(project.geographicInfo.statewide || false),
isDefault: ko.observable(project.geographicInfo.isDefault || 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 || [])
};
self.geographicInfo.nationwide.subscribe(function(newValue) {
if (newValue) {
self.geographicInfo.statewide(false);
self.geographicInfo.primaryState("");
self.geographicInfo.primaryElectorate("");
self.geographicInfo.otherStates([]);
self.geographicInfo.otherElectorates([]);
}
});

self.geographicInfo.statewide.subscribe(function(newValue) {
if (newValue) {
self.geographicInfo.nationwide(false);
self.geographicInfo.primaryElectorate("");
self.geographicInfo.otherStates([]);
self.geographicInfo.otherElectorates([]);
}
});

self.geographicInfo.primaryElectorate.subscribe(function(newValue) {
if (newValue) {
var electorate = findElectorate(newValue);
if (electorate && electorate.state && electorate.state.length > 0) {
self.geographicInfo.primaryState(electorate.state[0]);
// if state is set to primary state, remove it from other states
if (self.geographicInfo.otherStates.indexOf(electorate.state[0]) > -1) {
self.geographicInfo.otherStates.remove(electorate.state[0]);
}
}
}
});

// automatically add states of selected electorates to other states field
self.geographicInfo.otherElectorates.subscribe(function(newValue) {
if (newValue) {
var otherElectorates = self.geographicInfo.otherElectorates();
otherElectorates && _.each(otherElectorates, function(name) {
var electorate = findElectorate(name);
var states = electorate && electorate.state;
_.each(states, function(state) {
if (state && self.geographicInfo.otherStates.indexOf(state) === -1 && self.geographicInfo.primaryState() !== state) {
self.geographicInfo.otherStates.push(state);
}
})
});
}
});
self.transients.programs = [];
self.transients.subprograms = {};
self.transients.subprogramsToDisplay = ko.computed(function () {
return self.transients.subprograms[self.associatedProgram()];
});
self.transients.fixedProjectDuration = ko.observable(false);


function findElectorate(electorateName) {
var electorates = self.transients.electorates.originalElectorateList;
return electorates && _.find(electorates, function(electorate) {
return electorate.name === electorateName;
});
};

var isBeforeToday = function(date) {
return moment(date) < moment().startOf('day');
};
Expand Down Expand Up @@ -448,13 +504,15 @@ function ProjectViewModel(project) {
});

self.transients.electorates(electorates);
self.transients.electorates.originalElectorateList = data;
});

$.when(promise1, promse2).done(self.loadGeographicInfo);
}

self.loadGeographicInfo = function () {
self.geographicInfo.nationwide(project.geographicInfo.nationwide);
self.geographicInfo.statewide(project.geographicInfo.statewide);
self.geographicInfo.isDefault(project.geographicInfo.isDefault);
self.geographicInfo.primaryState(project.geographicInfo.primaryState);
self.geographicInfo.primaryElectorate(project.geographicInfo.primaryElectorate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1227,8 +1227,8 @@ class ProjectController {
render reportData as JSON
}

def spatialFeatures (String layerId) {
webService.proxyGetRequest(response, grailsApplication.config.getProperty('ecodata.baseUrl') + "spatial/features?layerId=${layerId}", false, true, 120000)
def spatialFeatures (String layerId, String intersectWith) {
webService.proxyGetRequest(response, grailsApplication.config.getProperty('ecodata.baseUrl') + "spatial/features?layerId=${layerId}&intersectWith=${intersectWith?:''}", false, true, 120000)
return null
}

Expand Down
93 changes: 52 additions & 41 deletions grails-app/views/project/_editProject.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -264,63 +264,74 @@

<div class="row mb-2">
<div class="col-sm-12">
<label for="projectGeoInfo">Geographic information
<fc:iconHelp title="Project geographic information">Geographic location of project i.e. States and electorates</fc:iconHelp>
<label>Override Sites
<fc:iconHelp title="Project geographic information">Override sites based geographic location calculation of a project to find geographic extent</fc:iconHelp>
</label>
<div class="alert alert-info">
The following information only needs to be filled out if:
<ul>
<li>Downloaded information contradicts the actual electorate/state names that should be displayed.</li>
<li>There is no information available in the Sites tab.</li>
</ul>
</div>
<div class="control">
<table class="table">
<thead>
<tr>
<th>Geographic information</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>
Settings
</td>
<td>
The sites for this project should be:
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="national" data-bind="checked: geographicInfo.nationwide">
<label class="form-check-label" for="national">National</label>
</div>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="statewide" data-bind="checked: geographicInfo.statewide">
<label class="form-check-label" for="statewide">Statewide</label>
</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>
</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>
</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'" class="select form-control"></select>
<select id="primaryState" data-bind="options:transients.states, value:geographicInfo.primaryState, optionsCaption: 'Select a state', disable: geographicInfo.nationwide()" class="select form-control"></select>
</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:''}" class="select form-control"></select>
</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'" class="select form-control"></select>
</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:''}" class="select form-control"></select>
</td>
</tr>
<tr>
<td>
<label for="otherElectorates">Settings</label>
</td>
<td>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="nationwide" data-bind="checked: geographicInfo.nationwide">
<label class="form-check-label" for="nationwide">Is project nationwide?</label>
</div>
<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="nationwide">Override state and electorate values with above manual selections. Ignores calculated values for project.</label>
</div>
<select id="otherStates" multiple="multiple" data-bind="options:transients.states.filteredStates, multiSelect2:{value:geographicInfo.otherStates, placeholder:''}, disable: geographicInfo.nationwide()" class="select form-control"></select>
</td>
</tr>
</tbody>
Expand Down
3 changes: 2 additions & 1 deletion grails-app/views/project/_projectSites.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<!-- /ko -->
<div id="site-photo-points">
<a href="#"><i>Click to view photo points and photos</i></a>
</div>
</div>
<g:render template="geographicInfo" model="${[project:project]}"/>
2 changes: 1 addition & 1 deletion grails-app/views/project/index.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
healthCheckUrl: "${createLink(controller:'ajax', action:'keepSessionAlive')}",
projectDatesValidationUrl: "${createLink(controller:'project', action:'ajaxValidateProjectDates', id:project.projectId)}",
listOfStatesUrl: "${createLink(controller:'project', action:'spatialFeatures', params: [layerId: "${grailsApplication.config.getProperty('layers.states')}"])}",
listOfElectoratesUrl: "${createLink(controller:'project', action:'spatialFeatures', params: [layerId: "${grailsApplication.config.getProperty('layers.elect')}"])}",
listOfElectoratesUrl: "${createLink(controller:'project', action:'spatialFeatures', params: [layerId: "${grailsApplication.config.getProperty('layers.elect')}", intersectWith: "${grailsApplication.config.getProperty('layers.states')}"])}",
spinnerUrl: "${asset.assetPath(src:'loading.gif')}",
projectSitesUrl: "${createLink(action:'ajaxProjectSites', id:project.projectId)}",
useGoogleBaseMap: ${grails.util.Environment.current == grails.util.Environment.PRODUCTION},
Expand Down

0 comments on commit 1db8e08

Please sign in to comment.