From bff123640da3cc5262ea0bf13d4a8909e038e0a5 Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Tue, 29 Oct 2024 11:57:19 +0200 Subject: [PATCH 1/3] only disburse selected users, otherwise do all --- .../static/geospatial/js/case_management.js | 17 +++++++++++------ .../geospatial/static/geospatial/js/models.js | 7 +++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/corehq/apps/geospatial/static/geospatial/js/case_management.js b/corehq/apps/geospatial/static/geospatial/js/case_management.js index 5d630dfc9ae5..623dfa99e028 100644 --- a/corehq/apps/geospatial/static/geospatial/js/case_management.js +++ b/corehq/apps/geospatial/static/geospatial/js/case_management.js @@ -138,12 +138,17 @@ hqDefine("geospatial/js/case_management", [ self.showParams(true); }; - let userData = users.map(function (c) { - return { - id: c.itemId, - lon: c.itemData.coordinates.lng, - lat: c.itemData.coordinates.lat, - }; + const hasSelectedUsers = mapModel.hasSelectedUsers(); + let userData = []; + users.forEach((userMapItem) => { + // Either select all if none selected, or only pick selected users + if (!hasSelectedUsers || userMapItem.isSelected()) { + userData.push({ + id: userMapItem.itemId, + lon: userMapItem.itemData.coordinates.lng, + lat: userMapItem.itemData.coordinates.lat, + }); + } }); $.ajax({ diff --git a/corehq/apps/geospatial/static/geospatial/js/models.js b/corehq/apps/geospatial/static/geospatial/js/models.js index a201051ff20e..75e4189c1d5f 100644 --- a/corehq/apps/geospatial/static/geospatial/js/models.js +++ b/corehq/apps/geospatial/static/geospatial/js/models.js @@ -534,6 +534,13 @@ hqDefine('geospatial/js/models', [ }); return layerRemoved; }; + + self.hasSelectedUsers = function () { + return self.userMapItems().some((userMapItem) => { + return userMapItem.isSelected(); + }); + }; + }; var PolygonFilter = function (mapObj, shouldUpdateQueryParam, shouldSelectAfterFilter) { From 7600394e67e2ccebf65f486de5e4ae0f2057ab08 Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Tue, 29 Oct 2024 11:57:39 +0200 Subject: [PATCH 2/3] only disburse selected cases, otherwsie do all --- .../static/geospatial/js/case_management.js | 14 +++++++++----- .../apps/geospatial/static/geospatial/js/models.js | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/corehq/apps/geospatial/static/geospatial/js/case_management.js b/corehq/apps/geospatial/static/geospatial/js/case_management.js index 623dfa99e028..e6389c35f3d0 100644 --- a/corehq/apps/geospatial/static/geospatial/js/case_management.js +++ b/corehq/apps/geospatial/static/geospatial/js/case_management.js @@ -93,6 +93,7 @@ hqDefine("geospatial/js/case_management", [ self.clearConnectionLines = function (cases) { let mapInstance = mapModel.mapInstance; let caseData = []; + const hasSelectedCases = mapModel.hasSelectedCases(); cases.forEach(function (c) { const layerId = mapModel.getLineFeatureId(c.itemId); if (mapInstance.getLayer(layerId)) { @@ -102,11 +103,14 @@ hqDefine("geospatial/js/case_management", [ mapInstance.removeSource(layerId); } - caseData.push({ - id: c.itemId, - lon: c.itemData.coordinates.lng, - lat: c.itemData.coordinates.lat, - }); + // Either select all if none selected, or only pick selected cases + if (!hasSelectedCases || c.isSelected()) { + caseData.push({ + id: c.itemId, + lon: c.itemData.coordinates.lng, + lat: c.itemData.coordinates.lat, + }); + } }); return caseData; diff --git a/corehq/apps/geospatial/static/geospatial/js/models.js b/corehq/apps/geospatial/static/geospatial/js/models.js index 75e4189c1d5f..39e0340f4680 100644 --- a/corehq/apps/geospatial/static/geospatial/js/models.js +++ b/corehq/apps/geospatial/static/geospatial/js/models.js @@ -541,6 +541,11 @@ hqDefine('geospatial/js/models', [ }); }; + self.hasSelectedCases = function () { + return self.caseMapItems().some((caseMapItem) => { + return caseMapItem.isSelected(); + }); + }; }; var PolygonFilter = function (mapObj, shouldUpdateQueryParam, shouldSelectAfterFilter) { From 8c1d190df21511ce7952e1c6e9d8e955accabd2d Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Tue, 29 Oct 2024 11:58:15 +0200 Subject: [PATCH 3/3] select markers again when adding users to map --- .../apps/geospatial/static/geospatial/js/case_management.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/corehq/apps/geospatial/static/geospatial/js/case_management.js b/corehq/apps/geospatial/static/geospatial/js/case_management.js index e6389c35f3d0..11fb7b6c1a6b 100644 --- a/corehq/apps/geospatial/static/geospatial/js/case_management.js +++ b/corehq/apps/geospatial/static/geospatial/js/case_management.js @@ -252,7 +252,9 @@ hqDefine("geospatial/js/case_management", [ if (polygonFilterModel.activeSavedPolygon()) { features = features.concat(polygonFilterModel.activeSavedPolygon().geoJson.features); } - mapModel.selectAllMapItems(features); + if (features.length) { + mapModel.selectAllMapItems(features); + } } function initPolygonFilters() { @@ -362,6 +364,7 @@ hqDefine("geospatial/js/case_management", [ const userMapItems = mapModel.addMarkersToMap(userData, userMarkerColors); mapModel.userMapItems(userMapItems); + selectMapItemsInPolygons(); }, error: function () { self.hasErrors(true);