Skip to content

Commit

Permalink
Load report selectable features async #3436
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Feb 7, 2025
1 parent 6be628e commit 5d604d3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -918,12 +918,7 @@ class ProjectController {
if (model.activity.siteId) {
model.reportSite = sites?.find { it.siteId == model.activity.siteId }
}

Map siteData = projectService.projectSites(projectId)
if (!siteData.error) {
model.projectArea = siteData.projectArea
model.features = siteData.features
}
model.selectableFeaturesUrl = g.createLink(action:'ajaxProjectSites', id:projectId)
}
model
}
Expand Down
56 changes: 33 additions & 23 deletions grails-app/views/activity/activityReport.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
initialScrollPositionDelay: "${grailsApplication.config.getProperty('reports.initialScrollPositionDelay') ?: 1000}"
},
here = document.location.href;
<g:if test="${selectableFeaturesUrl}">
fcConfig.selectableFeaturesUrl = "${selectableFeaturesUrl}";
</g:if>
</script>
<asset:stylesheet src="common-bs4.css"/>
<asset:stylesheet src="activity.css"/>
Expand Down Expand Up @@ -143,14 +146,37 @@
var metaModel = <fc:modelAsJavascript model="${metaModel}" default="{}"/>
var master = null;
var mapPopupSelector = '#map-modal';
var features = <fc:modelAsJavascript model="${features}" default="{}"/>
var reportMasterOptions = {
locked: locked,
activityUpdateUrl: fcConfig.activityUpdateUrl,
healthCheckUrl: fcConfig.healthCheckUrl,
projectTargetsAndScoresUrl: fcConfig.projectTargetsAndScoresUrl,
performOverDeliveryCheck: true
};
function categoriseSelectableSites(features) {
if (!features || !_.isArray(features)) {
return null;
}
var planningSitesCategory = 'Planning Sites';
var planningFeatures = [];
var allFeatures = [];
_.each(features, function (feature) {
// Group the planning sites together into a single collection
if (feature.properties && feature.properties.category && feature.properties.category == planningSitesCategory) {
planningFeatures.push(feature);
} else {
allFeatures.push(feature);
}
});
if (planningFeatures.length > 0) {
allFeatures.unshift({
type: 'Feature Collection',
features: planningFeatures,
properties: {category: planningSitesCategory, name: planningSitesCategory}
});
}
return allFeatures;
}
if (metaModel.supportsSites) {
// Workaround for problems with IE11 and leaflet draw
L.Browser.touch = false;
Expand All @@ -159,29 +185,13 @@
if (fcConfig.useGoogleBaseMap) {
mapOptions.baseLayersName = 'Google'; // Default is Open Street Maps
}
var planningSitesCategory = 'Planning Sites';
if (features && _.isArray(features)) {
var planningFeatures = [];
var allFeatures = [];
_.each(features, function (feature) {
// Group the planning sites together into a single collection
if (feature.properties && feature.properties.category && feature.properties.category == planningSitesCategory) {
planningFeatures.push(feature);
} else {
allFeatures.push(feature);
}
});
if (planningFeatures.length > 0) {
allFeatures.unshift({
type: 'Feature Collection',
features: planningFeatures,
properties: {category: planningSitesCategory, name: planningSitesCategory}
});
}
mapOptions.selectableFeatures = allFeatures;
}
mapOptions.selectableFeatures = $.Deferred();
$.get(fcConfig.selectableFeaturesUrl).done(function(features) {
if (features && features.features) {
mapOptions.selectableFeatures.resolve(categoriseSelectableSites(features.features));
}
});
var formFeatures = new ecodata.forms.FeatureCollection(reportSite ? reportSite.features : []);
context.featureCollection = formFeatures;
Expand Down

0 comments on commit 5d604d3

Please sign in to comment.