Skip to content

Commit b93e8b9

Browse files
committed
Landmark widget: auto-select target group in some cases
If the source is a project other than the current one, and no target group has been selected yet, selecting a source group will auto-select any target group with the same name. This works for both single mappings and multiple mappings. See #2287
1 parent eef8783 commit b93e8b9

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ Landmark widget:
9191
the new edit button right next to the skeleton set entry. A dialog will ask
9292
for a skeleton source to pull neurons from.
9393

94+
- If the source is a project other than the current one, and no target group has
95+
been selected yet, selecting a source group will auto-select any target group
96+
with the same name.
97+
9498
Stack viewer:
9599

96100
- WebGL layers can now define a so called blending window through the layer

django/applications/catmaid/static/js/widgets/landmark-widget.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3016,6 +3016,8 @@
30163016

30173017
var fromGroup, toGroup;
30183018
let activeMappings = [];
3019+
const autoSelectMatchingRemoteTargetGroup = true;
3020+
const targetGroupWrapperId = `landmark-widget-target-group-select-${widget.widgetID}`;
30193021

30203022
let sourceGroupCache;
30213023
var initSourceGroupList = function(forceFromGroup, forceGroupUpdate) {
@@ -3026,6 +3028,26 @@
30263028
groups, forceFromGroup || fromGroup, true, 'selected');
30273029
sourceSelect.onchange = function(e) {
30283030
fromGroup = e.target.value;
3031+
3032+
// Auto-select target group with same name if target if the
3033+
// source is remote and no target group was selected yet.
3034+
if (autoSelectMatchingRemoteTargetGroup && sourceRemote &&
3035+
sourceRemote.length > 0) {
3036+
const fromGroupName = sourceGroupCache.find(g => g.value == fromGroup).title;
3037+
let matchingTargetGroup = groupOptions.find(g => g.title === fromGroupName);
3038+
if (!toGroup) {
3039+
if (matchingTargetGroup) {
3040+
// A string is used to capture the group IDs.
3041+
toGroup = `${matchingTargetGroup.value}`;
3042+
const targetRadioButton = document.querySelector(`#${targetGroupWrapperId} input[type="radio"][value="${toGroup}"]`);
3043+
// Easiest way of triggering an update
3044+
$(targetRadioButton).click();
3045+
CATMAID.msg("Success", `Auto-selected local target group with same name ("${fromGroupName}")`);
3046+
} else {
3047+
CATMAID.msg("Info", "No target group with same name found, no auto-selection");
3048+
}
3049+
}
3050+
}
30293051
};
30303052
return sourceSelect;
30313053
});
@@ -3048,6 +3070,7 @@
30483070

30493071
// Target select
30503072
let targetGroupWrapper = document.createElement('span');
3073+
targetGroupWrapper.id = targetGroupWrapperId;
30513074
let updateTargetGroupSelect = function(forceTargetGroup) {
30523075
while (targetGroupWrapper.lastChild) {
30533076
targetGroupWrapper.removeChild(targetGroupWrapper.lastChild);

0 commit comments

Comments
 (0)