Skip to content

Commit 333667c

Browse files
committed
displaying the subgroups in ascending order
fixes #1628
1 parent ca9a887 commit 333667c

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/org/opensolaris/opengrok/configuration/Groups.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,10 @@ private static void deleteGroup(Set<Group> groups, String groupname) {
329329
private static boolean treeTraverseGroups(Set<Group> groups, Walker f) {
330330
LinkedList<Group> stack = new LinkedList<>();
331331
for (Group g : groups) {
332+
// the flag here represents the group's depth in the group tree
332333
g.setFlag(0);
333334
if (g.getParent() == null) {
334-
stack.add(g);
335+
stack.addLast(g);
335336
}
336337
}
337338

@@ -343,10 +344,9 @@ private static boolean treeTraverseGroups(Set<Group> groups, Walker f) {
343344
return true;
344345
}
345346

346-
for (Group x : g.getSubgroups()) {
347-
x.setFlag(g.getFlag() + 1);
348-
stack.addFirst(x);
349-
}
347+
g.getSubgroups().forEach((x) -> x.setFlag(g.getFlag() + 1));
348+
// add all the subgroups respecting the sorted order
349+
stack.addAll(0, g.getSubgroups());
350350
}
351351
return false;
352352
}

web/repos.jspf

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ CDDL HEADER END
2121
Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
2222

2323
--%>
24+
<%@page import="java.util.TreeSet"%>
25+
<%@page import="java.util.Iterator"%>
2426
<%@page import="org.opensolaris.opengrok.web.Scripts"%>
2527
<%@page import="org.json.simple.JSONArray"%>
2628
<%@page import="org.opensolaris.opengrok.configuration.messages.Message"%>
2729
<%@page import="java.util.SortedSet"%>
28-
<%@page import="java.util.SortedSet"%>
2930
<%@page import="java.util.Set"%>
3031
<%@page import="java.text.ParseException"%>
3132
<%@page import="java.util.ArrayList"%>
@@ -80,6 +81,7 @@ Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
8081
LinkedList<Group> stack = new LinkedList<>();
8182
for ( Group x : groups ) {
8283
if (x.getParent() == null && (pHelper.hasAllowedSubgroup(x) || cfg.isAllowed(x))) {
84+
// the flag here represents the state of the group - open/close
8385
x.setFlag(0);
8486
stack.addLast(x);
8587
}
@@ -97,14 +99,19 @@ Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
9799
}
98100

99101
stack.element().setFlag(1);
100-
101-
for (Group x : pHelper.getSubgroups(group)) {
102+
103+
Set<Group> subgroups = new TreeSet<>(pHelper.getSubgroups(group));
104+
for (Iterator<Group> it = subgroups.iterator(); it.hasNext();) {
105+
Group x = it.next();
102106
if (cfg.isAllowed(x) || pHelper.hasAllowedSubgroup(x)) {
103107
x.setFlag(0);
104-
stack.addFirst(x);
108+
} else {
109+
it.remove();
105110
}
106111
}
107-
112+
// add all the subgroups to the beginning respecting the order
113+
stack.addAll(0, subgroups);
114+
108115
%><div class="panel">
109116
<div class="panel-heading-accordion">
110117

0 commit comments

Comments
 (0)