Skip to content

Commit 5d604d3

Browse files
committed
Load report selectable features async #3436
1 parent 6be628e commit 5d604d3

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

grails-app/controllers/au/org/ala/merit/ProjectController.groovy

+1-6
Original file line numberDiff line numberDiff line change
@@ -918,12 +918,7 @@ class ProjectController {
918918
if (model.activity.siteId) {
919919
model.reportSite = sites?.find { it.siteId == model.activity.siteId }
920920
}
921-
922-
Map siteData = projectService.projectSites(projectId)
923-
if (!siteData.error) {
924-
model.projectArea = siteData.projectArea
925-
model.features = siteData.features
926-
}
921+
model.selectableFeaturesUrl = g.createLink(action:'ajaxProjectSites', id:projectId)
927922
}
928923
model
929924
}

grails-app/views/activity/activityReport.gsp

+33-23
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
initialScrollPositionDelay: "${grailsApplication.config.getProperty('reports.initialScrollPositionDelay') ?: 1000}"
4141
},
4242
here = document.location.href;
43+
<g:if test="${selectableFeaturesUrl}">
44+
fcConfig.selectableFeaturesUrl = "${selectableFeaturesUrl}";
45+
</g:if>
4346
</script>
4447
<asset:stylesheet src="common-bs4.css"/>
4548
<asset:stylesheet src="activity.css"/>
@@ -143,14 +146,37 @@
143146
var metaModel = <fc:modelAsJavascript model="${metaModel}" default="{}"/>
144147
var master = null;
145148
var mapPopupSelector = '#map-modal';
146-
var features = <fc:modelAsJavascript model="${features}" default="{}"/>
147149
var reportMasterOptions = {
148150
locked: locked,
149151
activityUpdateUrl: fcConfig.activityUpdateUrl,
150152
healthCheckUrl: fcConfig.healthCheckUrl,
151153
projectTargetsAndScoresUrl: fcConfig.projectTargetsAndScoresUrl,
152154
performOverDeliveryCheck: true
153155
};
156+
function categoriseSelectableSites(features) {
157+
if (!features || !_.isArray(features)) {
158+
return null;
159+
}
160+
var planningSitesCategory = 'Planning Sites';
161+
var planningFeatures = [];
162+
var allFeatures = [];
163+
_.each(features, function (feature) {
164+
// Group the planning sites together into a single collection
165+
if (feature.properties && feature.properties.category && feature.properties.category == planningSitesCategory) {
166+
planningFeatures.push(feature);
167+
} else {
168+
allFeatures.push(feature);
169+
}
170+
});
171+
if (planningFeatures.length > 0) {
172+
allFeatures.unshift({
173+
type: 'Feature Collection',
174+
features: planningFeatures,
175+
properties: {category: planningSitesCategory, name: planningSitesCategory}
176+
});
177+
}
178+
return allFeatures;
179+
}
154180
if (metaModel.supportsSites) {
155181
// Workaround for problems with IE11 and leaflet draw
156182
L.Browser.touch = false;
@@ -159,29 +185,13 @@
159185
if (fcConfig.useGoogleBaseMap) {
160186
mapOptions.baseLayersName = 'Google'; // Default is Open Street Maps
161187
}
162-
var planningSitesCategory = 'Planning Sites';
163-
if (features && _.isArray(features)) {
164-
var planningFeatures = [];
165-
var allFeatures = [];
166-
_.each(features, function (feature) {
167-
// Group the planning sites together into a single collection
168-
if (feature.properties && feature.properties.category && feature.properties.category == planningSitesCategory) {
169-
planningFeatures.push(feature);
170-
} else {
171-
allFeatures.push(feature);
172-
}
173-
});
174-
if (planningFeatures.length > 0) {
175-
allFeatures.unshift({
176-
type: 'Feature Collection',
177-
features: planningFeatures,
178-
properties: {category: planningSitesCategory, name: planningSitesCategory}
179-
});
180-
}
181-
mapOptions.selectableFeatures = allFeatures;
182-
183188
184-
}
189+
mapOptions.selectableFeatures = $.Deferred();
190+
$.get(fcConfig.selectableFeaturesUrl).done(function(features) {
191+
if (features && features.features) {
192+
mapOptions.selectableFeatures.resolve(categoriseSelectableSites(features.features));
193+
}
194+
});
185195
186196
var formFeatures = new ecodata.forms.FeatureCollection(reportSite ? reportSite.features : []);
187197
context.featureCollection = formFeatures;

0 commit comments

Comments
 (0)