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

Allow to link page to next element independently of hierarchy level #6255

Conversation

thomaslow
Copy link
Collaborator

@thomaslow thomaslow commented Oct 8, 2024

Fixes #5457

This pull request allows to add a new link (context menu entry "Assign to next element") for the currently selected page to the following folder independently of its hierarchy level. The selection logic works as follows:

  1. find a parent folder whose next sibling is also a folder (continue with parent of parent, if not found)
  2. select the deepest child folder of the next sibling only if they are the respective first children

This pull request also checks if a link has already been added before such that users cannot accidentally add the same link twice (the menu entry "Assign to next element" disappears).

Demo

2024-10-08.14-56-08.mp4

@thomaslow thomaslow marked this pull request as ready for review October 14, 2024 10:26
@thomaslow thomaslow marked this pull request as draft October 14, 2024 10:26
@thomaslow thomaslow marked this pull request as ready for review October 14, 2024 11:51
@solth solth modified the milestone: Kitodo.Production 3.8.0 Oct 25, 2024
@solth solth requested a review from BartChris November 3, 2024 21:31
Copy link
Collaborator

@BartChris BartChris left a comment

Choose a reason for hiding this comment

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

Works as expected and code looks very solid to me! Thanks a lot.
As suggested in #5457 (comment), we can inspect the effects of dragging linked nodes around at a later point in time.

Comment on lines +1807 to +1848
private TreeNode findNextLogicalNodeForViewAssignmentRecursive(TreeNode node) {
TreeNode current = node;

while (Objects.nonNull(current)) {
if (Objects.isNull(getTreeNodeStructuralElement(current))) {
// node is not a logical node
return null;
}

// check whether next sibling is a logical node as well
List<TreeNode> currentSiblings = current.getParent().getChildren();
int currentIndex = currentSiblings.indexOf(current);

if (currentSiblings.size() > currentIndex + 1) {
TreeNode nextSibling = currentSiblings.get(currentIndex + 1);
if (Objects.isNull(getTreeNodeStructuralElement(nextSibling))) {
// next sibling is not a logical node
return null;
}

// next sibling is a logical node and potential valid result, unless there are children
TreeNode nextLogical = nextSibling;

// check sibling has children (with first child being another logical node)
while (!nextLogical.getChildren().isEmpty()) {
TreeNode firstChild = nextLogical.getChildren().get(0);
if (Objects.isNull(getTreeNodeStructuralElement(firstChild))) {
// first child is not a logical node
return nextLogical;
}
// iterate to child node
nextLogical = firstChild;
}
return nextLogical;
}

// node is last amongst siblings
// iterate to parent node
current = current.getParent();
}
return null;
}
Copy link
Collaborator

@BartChris BartChris Nov 8, 2024

Choose a reason for hiding this comment

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

Method is very long and could probably be refactored in smaller methods, but as the logic is quite complex it is also good to have it in one place. So i think this is all good to go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants