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

Load report selectable features async #3436 #3437

Merged
merged 2 commits into from
Feb 14, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -918,12 +918,11 @@ 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like projectArea is removed here but is used in GSP. And projectArea returned via ajax call is not used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @temi I've fixed this.

model.features = siteData.features
Map projectArea = sites?.find { it.type == SiteService.SITE_TYPE_PROJECT_AREA }
if (projectArea) {
model.projectArea = siteService.getSiteGeoJson(projectArea.siteId)
}
model.selectableFeaturesUrl = g.createLink(action:'ajaxProjectSites', id:projectId)
}
model
}
Expand Down
58 changes: 34 additions & 24 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 @@ -140,17 +143,40 @@
};

var locked = ${locked};
var metaModel = <fc:modelAsJavascript model="${metaModel}" default="{}"/>
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
12 changes: 12 additions & 0 deletions src/main/scripts/releases/4.2/restoreSites.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("../../utils/audit.js");
let projectId = '7743afa2-6a8d-4476-a38d-964c037421bd';
let excludedNames = ['219', '259', '284', '1022', '1331', '830', '228', '1434', '1047'];

db.site.find({projects:projectId, type:'worksArea', name: {$nin: excludedNames}}).forEach(function(site) {
site.status = 'active';
site.notes = null;

db.site.replaceOne({_id:site._id}, site);

audit('site', site.siteId, 'update', '<system>');
});
Loading