Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/issue1724 #3365

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 10 additions & 2 deletions grails-app/views/project/_geographicInfo.gsp
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<g:if test="${fc.userIsSiteAdmin()}">
<g:if test="${project.primarystate || project.primaryelect}">
<g:if test="${project?.geographicInfo?.nationwide}">
<h4>Geographic range</h4>
<div class="row">
<div class="col-sm-10">
This is a national project.
</div>
</div>
</g:if>
<g:elseif test="${project.primarystate || project.primaryelect}">
<h4>Geographic range</h4>
<div class="row">
<div class="col-sm-10">
Expand Down Expand Up @@ -29,5 +37,5 @@
</table>
</div>
</div>
</g:if>
</g:elseif>
</g:if>
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
Loading