Skip to content

Commit c71c390

Browse files
authored
Merge pull request #3437 from AtlasOfLivingAustralia/feature/issue3436
Load report selectable features async #3436
2 parents 30b534f + 3a10c85 commit c71c390

File tree

3 files changed

+50
-29
lines changed

3 files changed

+50
-29
lines changed

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -918,12 +918,11 @@ 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
921+
Map projectArea = sites?.find { it.type == SiteService.SITE_TYPE_PROJECT_AREA }
922+
if (projectArea) {
923+
model.projectArea = siteService.getSiteGeoJson(projectArea.siteId)
926924
}
925+
model.selectableFeaturesUrl = g.createLink(action:'ajaxProjectSites', id:projectId)
927926
}
928927
model
929928
}

grails-app/views/activity/activityReport.gsp

+34-24
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"/>
@@ -140,17 +143,40 @@
140143
};
141144
142145
var locked = ${locked};
143-
var metaModel = <fc:modelAsJavascript model="${metaModel}" default="{}"/>
146+
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;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
load("../../utils/audit.js");
2+
let projectId = '7743afa2-6a8d-4476-a38d-964c037421bd';
3+
let excludedNames = ['219', '259', '284', '1022', '1331', '830', '228', '1434', '1047'];
4+
5+
db.site.find({projects:projectId, type:'worksArea', name: {$nin: excludedNames}}).forEach(function(site) {
6+
site.status = 'active';
7+
site.notes = null;
8+
9+
db.site.replaceOne({_id:site._id}, site);
10+
11+
audit('site', site.siteId, 'update', '<system>');
12+
});

0 commit comments

Comments
 (0)