Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into feature/issue3169
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Oct 31, 2024
2 parents fbb9e2c + 2b12156 commit 063a26a
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 49 deletions.
68 changes: 67 additions & 1 deletion grails-app/assets/javascripts/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function isValid(p, a) {
}

function ProjectViewModel(project) {
project.geographicInfo = project.geographicInfo || {};
var self = this;
// documents
var docDefaults = newDocumentDefaults(project);
Expand Down Expand Up @@ -175,6 +176,14 @@ function ProjectViewModel(project) {
self.urlWeb = ko.observable(project.urlWeb).extend({url:true});
self.contractStartDate = ko.observable(project.contractStartDate).extend({simpleDate: false});
self.contractEndDate = ko.observable(project.contractEndDate).extend({simpleDate: false});
self.geographicInfo = {
nationwide: ko.observable(project.geographicInfo.nationwide || 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.transients.programs = [];
self.transients.subprograms = {};
self.transients.subprogramsToDisplay = ko.computed(function () {
Expand Down Expand Up @@ -397,6 +406,62 @@ 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);
if (index > -1) {
states.splice(index, 1);
}
}

return states;
});
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.loadStatesAndElectorates = function() {
var promise1 = $.getJSON(fcConfig.listOfStatesUrl, function(data) {
var states = [];
$.each(data, function(i, state) {
states.push(state.name);
});

self.transients.states(states);
});

var promse2 = $.getJSON(fcConfig.listOfElectoratesUrl, function(data) {
var electorates = [];
$.each(data, function(i, electorate) {
electorates.push(electorate.name);
});

self.transients.electorates(electorates);
});

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

self.loadGeographicInfo = function () {
self.geographicInfo.nationwide(project.geographicInfo.nationwide);
self.geographicInfo.isDefault(project.geographicInfo.isDefault);
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.toJS = function() {
var toIgnore = self.ignore; // document properties to ignore.
toIgnore.concat(['transients', 'daysStatus', 'projectDatesChanged', 'collectoryInstitutionId', 'ignore', 'projectStatus']);
Expand Down Expand Up @@ -891,6 +956,7 @@ function ProjectPageViewModel(project, sites, activities, userRoles, config) {
tags: self.tags(),
promoteOnHomepage: self.promoteOnHomepage(),
externalIds: ko.mapping.toJS(self.externalIds),
geographicInfo: ko.mapping.toJS(self.geographicInfo),
options: {
changeActivityDates: self.changeActivityDates(),
includeSubmittedReports: self.includeSubmittedReports(),
Expand Down Expand Up @@ -1362,4 +1428,4 @@ var RisksReportViewModel = function(project, options) {
self.generateRisksReportPDF = function() {
displayReport(options.riskChangesReportPdfUrl);
};
};
};
3 changes: 3 additions & 0 deletions grails-app/conf/application.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ sites.known_shapes = [
[id:'cl11194', name:'Australian Marine Parks (2024)']
]

layers.elect = 'cl11163'
layers.states = 'cl927'

environments {
development {
grails.logging.jul.usebridge = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ class ProjectController {
user.hasViewAccess = projectService.canUserViewProject(user.userId, id) ?: false
}
def project = projectService.get(id, user,'all')
Map stateElectorate = projectService.findStateAndElectorateForProject(project.projectId)
if (stateElectorate) {
project << stateElectorate
}
Map config = null
if (project && !project.error) {
config = projectService.getProgramConfiguration(project)
Expand Down Expand Up @@ -1236,6 +1240,11 @@ 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)
return null
}

private def error(String message, String projectId) {
flash.message = message
if (projectId) {
Expand Down
9 changes: 9 additions & 0 deletions grails-app/services/au/org/ala/merit/ProjectService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ class ProjectService {

}

Map findStateAndElectorateForProject(String projectId) {
Map result = webService.getJson(grailsApplication.config.getProperty('ecodata.baseUrl') + 'project/findStateAndElectorateForProject?projectId=' + projectId) as Map
if (result.error) {
result = [:]
}

result
}

void filterDataSetSummaries(List dataSetSummaries) {
List<Map> forms = activityService.monitoringProtocolForms()

Expand Down
67 changes: 67 additions & 0 deletions grails-app/views/project/_editProject.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,73 @@
</div>
</div>

<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>
<div class="control">
<table class="table">
<thead>
<tr>
<th>Geographic information</th>
<th></th>
</tr>
</thead>
<tbody>
<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>
</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>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>

<div class="row mb-2">
<div class="col-sm-12">
<button data-bind="click:regenerateStageReports" class="btn btn-sm btn-warning" <g:if test="${!canRegenerateReports}">disabled="disabled"</g:if>>Re-create project reports</button>
Expand Down
33 changes: 33 additions & 0 deletions grails-app/views/project/_geographicInfo.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<g:if test="${fc.userIsSiteAdmin()}">
<g:if test="${project.primarystate || project.primaryelect}">
<h4>Geographic range</h4>
<div class="row">
<div class="col-sm-10">
<table class="table">
<tbody>
<g:if test="${project.primarystate}">
<tr>
<th>Primary State</th>
<td>${project.primarystate}</td>
</tr>
<tr>
<th>Other State(s)</th>
<td>${project.otherstate}</td>
</tr>
</g:if>
<g:if test="${project.primaryelect}">
<tr>
<th>Primary Electorate</th>
<td>${project.primaryelect}</td>
</tr>
<tr>
<th>Other Electorate(s)</th>
<td>${project.otherelect}</td>
</tr>
</g:if>
</tbody>
</table>
</div>
</div>
</g:if>
</g:if>
1 change: 1 addition & 0 deletions grails-app/views/project/_overview.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
</div>
</div>

<g:render template="geographicInfo" model="${[project:project]}"/>
</div>
<hr/>

Expand Down
4 changes: 4 additions & 0 deletions grails-app/views/project/index.gsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%@ page import="au.org.ala.merit.config.ProgramConfig; au.org.ala.merit.ProjectController" contentType="text/html;charset=UTF-8" expressionCodec="none"%>
<g:set var="settingService" bean="settingService"></g:set>
<!DOCTYPE html>
<html>
<head>
Expand Down Expand Up @@ -82,6 +83,8 @@
projectScoresUrl: "${createLink(action:'serviceScores', id:project.projectId)}",
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')}"])}",
spinnerUrl: "${asset.assetPath(src:'loading.gif')}",
projectSitesUrl: "${createLink(action:'ajaxProjectSites', id:project.projectId)}",
useGoogleBaseMap: ${grails.util.Environment.current == grails.util.Environment.PRODUCTION},
Expand Down Expand Up @@ -346,6 +349,7 @@ var config = {
project.mapFeatures = $.parseJSON('${mapFeatures?.encodeAsJavaScript()}');
var viewModel = new ProjectPageViewModel(project, project.sites, project.activities || [], userRoles, config);
viewModel.loadPrograms(programs);
viewModel.loadStatesAndElectorates();
ko.applyBindings(viewModel);
window.validateProjectEndDate = viewModel.validateProjectEndDate;

Expand Down
Loading

0 comments on commit 063a26a

Please sign in to comment.