From: Martin Spielmann Date: Mon, 6 Nov 2017 12:45:39 +0000 (+0100) Subject: Add repositoryListType tree. Addresses #725, 527 and includes #1224 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8da5f6d5967894f157251c320928acdab3a451e7;p=gitblit.git Add repositoryListType tree. Addresses #725, 527 and includes #1224 --- diff --git a/src/main/java/com/gitblit/models/TreeNodeModel.java b/src/main/java/com/gitblit/models/TreeNodeModel.java new file mode 100644 index 00000000..a69393e2 --- /dev/null +++ b/src/main/java/com/gitblit/models/TreeNodeModel.java @@ -0,0 +1,178 @@ +package com.gitblit.models; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import com.gitblit.utils.StringUtils; + +public class TreeNodeModel implements Serializable, Comparable { + + private static final long serialVersionUID = 1L; + final TreeNodeModel parent; + final String name; + final List subFolders = new ArrayList<>(); + final List repositories = new ArrayList<>(); + + /** + * Create a new tree root + */ + public TreeNodeModel() { + this.name = "/"; + this.parent = null; + } + + protected TreeNodeModel(String name, TreeNodeModel parent) { + this.name = name; + this.parent = parent; + } + + public int getDepth() { + if(parent == null) { + return 0; + }else { + return parent.getDepth() +1; + } + } + + /** + * Add a new sub folder to the current folder + * + * @param subFolder the subFolder to create + * @return the newly created folder to allow chaining + */ + public TreeNodeModel add(String subFolder) { + TreeNodeModel n = new TreeNodeModel(subFolder, this); + subFolders.add(n); + Collections.sort(subFolders); + return n; + } + + /** + * Add the given repo to the current folder + * + * @param repo + */ + public void add(RepositoryModel repo) { + repositories.add(repo); + Collections.sort(repositories); + } + + /** + * Adds the given repository model within the given path. Creates parent folders if they do not exist + * + * @param path + * @param model + */ + public void add(String path, RepositoryModel model) { + TreeNodeModel folder = getSubTreeNode(this, path, true); + folder.add(model); + } + + @Override + public String toString() { + String string = name + "\n"; + for(TreeNodeModel n : subFolders) { + string += "f"; + for(int i = 0; i < n.getDepth(); i++) { + string += "-"; + } + string += n.toString(); + } + + for(RepositoryModel n : repositories) { + string += "r"; + for(int i = 0; i < getDepth()+1; i++) { + string += "-"; + } + string += n.toString() + "\n"; + } + + return string; + } + + public boolean containsSubFolder(String path) { + return containsSubFolder(this, path); + } + + public TreeNodeModel getSubFolder(String path) { + return getSubTreeNode(this, path, false); + } + + public List getTreeAsListForFrontend(){ + List l = new ArrayList<>(); + getTreeAsListForFrontend(l, this); + return l; + } + + private static void getTreeAsListForFrontend(List list, TreeNodeModel node) { + list.add(node); + for(TreeNodeModel t : node.subFolders) { + getTreeAsListForFrontend(list, t); + } + for(RepositoryModel r : node.repositories) { + list.add(r); + } + } + + private static TreeNodeModel getSubTreeNode(TreeNodeModel node, String path, boolean create) { + if(!StringUtils.isEmpty(path)) { + boolean isPathInCurrentHierarchyLevel = path.lastIndexOf('/') < 0; + if(isPathInCurrentHierarchyLevel) { + for(TreeNodeModel t : node.subFolders) { + if(t.name.equals(path) ) { + return t; + } + } + + if(create) { + node.add(path); + return getSubTreeNode(node, path, true); + } + }else { + //traverse into subFolder + String folderInCurrentHierarchyLevel = StringUtils.getFirstPathElement(path); + + for(TreeNodeModel t : node.subFolders) { + if(t.name.equals(folderInCurrentHierarchyLevel) ) { + String folderInNextHierarchyLevel = path.substring(path.indexOf('/') + 1, path.length()); + return getSubTreeNode(t, folderInNextHierarchyLevel, create); + } + } + + if(create) { + String folderInNextHierarchyLevel = path.substring(path.indexOf('/') + 1, path.length()); + return getSubTreeNode(node.add(folderInCurrentHierarchyLevel), folderInNextHierarchyLevel, true); + } + } + } + + return null; + } + + private static boolean containsSubFolder(TreeNodeModel node, String path) { + return getSubTreeNode(node, path, false) != null; + } + + @Override + public int compareTo(TreeNodeModel t) { + return StringUtils.compareRepositoryNames(name, t.name); + } + + public TreeNodeModel getParent() { + return parent; + } + + public String getName() { + return name; + } + + public List getSubFolders() { + return subFolders; + } + + public List getRepositories() { + return repositories; + } +} diff --git a/src/main/java/com/gitblit/wicket/panels/NestedRepositoryTreePanel.html b/src/main/java/com/gitblit/wicket/panels/NestedRepositoryTreePanel.html new file mode 100644 index 00000000..563e022f --- /dev/null +++ b/src/main/java/com/gitblit/wicket/panels/NestedRepositoryTreePanel.html @@ -0,0 +1,106 @@ + + + + + + + + + + + + +
 
+ [repository + name] + + [repository description] + [repository owner] + + [last change] + [repository + size] + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Repository + Description + Owner + + Last Change + + + + + + +
 
+ [group + name] + [description] +
+ +
+ + \ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/panels/NestedRepositoryTreePanel.java b/src/main/java/com/gitblit/wicket/panels/NestedRepositoryTreePanel.java new file mode 100644 index 00000000..6c7b01f7 --- /dev/null +++ b/src/main/java/com/gitblit/wicket/panels/NestedRepositoryTreePanel.java @@ -0,0 +1,231 @@ +package com.gitblit.wicket.panels; + +import java.util.Map; + +import org.apache.wicket.Component; +import org.apache.wicket.PageParameters; +import org.apache.wicket.behavior.AttributeAppender; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.list.ListItem; +import org.apache.wicket.markup.html.list.ListView; +import org.apache.wicket.markup.html.panel.Fragment; +import org.apache.wicket.markup.repeater.RepeatingView; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; + +import com.gitblit.Constants.AccessRestrictionType; +import com.gitblit.Keys; +import com.gitblit.models.RepositoryModel; +import com.gitblit.models.TreeNodeModel; +import com.gitblit.models.UserModel; +import com.gitblit.utils.ArrayUtils; +import com.gitblit.utils.ModelUtils; +import com.gitblit.utils.StringUtils; +import com.gitblit.wicket.WicketUtils; +import com.gitblit.wicket.pages.BasePage; +import com.gitblit.wicket.pages.ProjectPage; +import com.gitblit.wicket.pages.SummaryPage; +import com.gitblit.wicket.pages.UserPage; + +public class NestedRepositoryTreePanel extends BasePanel { + + private static final long serialVersionUID = 1L; + + public NestedRepositoryTreePanel(String wicketId, IModel model, final Map accessRestrictionTranslations, boolean linksActive) { + super(wicketId); + + final boolean showSize = app().settings().getBoolean(Keys.web.showRepositorySizes, true); + final boolean showSwatch = app().settings().getBoolean(Keys.web.repositoryListSwatches, true); + + TreeNodeModel node = model.getObject(); + Fragment nodeHeader = new Fragment("nodeHeader", "groupRepositoryRow", this); + add(nodeHeader); + WebMarkupContainer firstColumn = new WebMarkupContainer("firstColumn"); + nodeHeader.add(firstColumn); + RepeatingView depth = new RepeatingView("depth"); + for(int i=0; i("subFolders", node.getSubFolders()) { + private static final long serialVersionUID = 1L; + + @Override + protected void populateItem(ListItem item) { + item.add(new NestedRepositoryTreePanel("rowContent", item.getModel(), accessRestrictionTranslations, linksActive)); + } + + @Override + public boolean isVisible() { + return super.isVisible() && !node.getSubFolders().isEmpty(); + } + }); + + add(new ListView("repositories", node.getRepositories()) { + private static final long serialVersionUID = 1L; + + int counter = 0; + + @Override + public boolean isVisible() { + return super.isVisible() && !node.getRepositories().isEmpty(); + } + + @Override + protected void populateItem(ListItem item) { + + RepositoryModel entry = item.getModelObject(); + WebMarkupContainer rowContent = new WebMarkupContainer("rowContent"); + item.add(rowContent); + addChildOfNodeIdCssClassesToRow(rowContent, node); + WebMarkupContainer firstColumn = new WebMarkupContainer("firstColumn"); + rowContent.add(firstColumn); + RepeatingView depth = new RepeatingView("depth"); + for(int i=0; i linkPage = SummaryPage.class; + PageParameters pp = WicketUtils.newRepositoryParameter(entry.name); + firstColumn.add(new LinkPanel("repositoryName", "list", repoName, linkPage, pp)); + rowContent.add(new LinkPanel("repositoryDescription", "list", entry.description, linkPage, pp)); + } else { + // no links like on a federation page + firstColumn.add(new Label("repositoryName", repoName)); + rowContent.add(new Label("repositoryDescription", entry.description)); + } + if (entry.hasCommits) { + // Existing repository + rowContent.add(new Label("repositorySize", entry.size).setVisible(showSize)); + } else { + // New repository + rowContent.add(new Label("repositorySize", "(" + getString("gb.empty") + ")").setEscapeModelStrings(false)); + } + + if (entry.isSparkleshared()) { + rowContent.add(WicketUtils.newImage("sparkleshareIcon", "star_16x16.png", getString("gb.isSparkleshared"))); + } else { + rowContent.add(WicketUtils.newClearPixel("sparkleshareIcon").setVisible(false)); + } + + if (!entry.isMirror && entry.isFrozen) { + rowContent.add(WicketUtils.newImage("frozenIcon", "cold_16x16.png", getString("gb.isFrozen"))); + } else { + rowContent.add(WicketUtils.newClearPixel("frozenIcon").setVisible(false)); + } + + if (entry.isFederated) { + rowContent.add(WicketUtils.newImage("federatedIcon", "federated_16x16.png", getString("gb.isFederated"))); + } else { + rowContent.add(WicketUtils.newClearPixel("federatedIcon").setVisible(false)); + } + + if (entry.isMirror) { + rowContent.add(WicketUtils.newImage("accessRestrictionIcon", "mirror_16x16.png", getString("gb.isMirror"))); + } else { + switch (entry.accessRestriction) { + case NONE: + rowContent.add(WicketUtils.newBlankImage("accessRestrictionIcon")); + break; + case PUSH: + rowContent.add(WicketUtils.newImage("accessRestrictionIcon", "lock_go_16x16.png", accessRestrictionTranslations.get(entry.accessRestriction))); + break; + case CLONE: + rowContent.add(WicketUtils.newImage("accessRestrictionIcon", "lock_pull_16x16.png", accessRestrictionTranslations.get(entry.accessRestriction))); + break; + case VIEW: + rowContent.add(WicketUtils.newImage("accessRestrictionIcon", "shield_16x16.png", accessRestrictionTranslations.get(entry.accessRestriction))); + break; + default: + rowContent.add(WicketUtils.newBlankImage("accessRestrictionIcon")); + } + } + + String owner = ""; + if (!ArrayUtils.isEmpty(entry.owners)) { + // display first owner + for (String username : entry.owners) { + UserModel ownerModel = app().users().getUserModel(username); + if (ownerModel != null) { + owner = ownerModel.getDisplayName(); + break; + } + } + if (entry.owners.size() > 1) { + owner += ", ..."; + } + } + Label ownerLabel = new Label("repositoryOwner", owner); + WicketUtils.setHtmlTooltip(ownerLabel, ArrayUtils.toString(entry.owners)); + rowContent.add(ownerLabel); + + String lastChange; + if (entry.lastChange.getTime() == 0) { + lastChange = "--"; + } else { + lastChange = getTimeUtils().timeAgo(entry.lastChange); + } + Label lastChangeLabel = new Label("repositoryLastChange", lastChange); + rowContent.add(lastChangeLabel); + WicketUtils.setCssClass(lastChangeLabel, getTimeUtils().timeAgoCss(entry.lastChange)); + if (!StringUtils.isEmpty(entry.lastChangeAuthor)) { + WicketUtils.setHtmlTooltip(lastChangeLabel, getString("gb.author") + ": " + entry.lastChangeAuthor); + } + + String clazz = counter % 2 == 0 ? "light" : "dark"; + WicketUtils.addCssClass(rowContent, clazz); + counter++; + } + }); + + } + + private void addChildOfNodeIdCssClassesToRow(Component row, TreeNodeModel parentNode) { + row.add(new AttributeAppender("class", Model.of("child-of-"+ parentNode.hashCode()), " ")); + if(parentNode.getParent() != null) { + addChildOfNodeIdCssClassesToRow(row, parentNode.getParent()); + } + } +} diff --git a/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.html b/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.html index 7c3b3082..bb5f6759 100644 --- a/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.html +++ b/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.html @@ -104,7 +104,7 @@ - [group name] + [group name] [description] diff --git a/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java b/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java index 6d680229..4b16c201 100644 --- a/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java @@ -30,7 +30,6 @@ import org.apache.wicket.extensions.markup.html.repeater.util.SortParam; import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.basic.Label; -import org.apache.wicket.markup.html.basic.MultiLineLabel; import org.apache.wicket.markup.html.link.BookmarkablePageLink; import org.apache.wicket.markup.html.link.Link; import org.apache.wicket.markup.html.panel.Fragment; @@ -45,6 +44,7 @@ import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.Keys; import com.gitblit.models.ProjectModel; import com.gitblit.models.RepositoryModel; +import com.gitblit.models.TreeNodeModel; import com.gitblit.models.UserModel; import com.gitblit.utils.ArrayUtils; import com.gitblit.utils.ModelUtils; @@ -79,6 +79,7 @@ public class RepositoriesPanel extends BasePanel { return returnVal; } } + public RepositoriesPanel(String wicketId, final boolean showAdmin, final boolean showManagement, List models, boolean enableLinks, final Map accessRestrictionTranslations) { super(wicketId); @@ -118,38 +119,27 @@ public class RepositoriesPanel extends BasePanel { add(new Label("managementPanel").setVisible(false)); } - if (true) { - // if (app().settings().getString(Keys.web.repositoryListType, - // "flat").equalsIgnoreCase("tree")) { + if (app().settings().getString(Keys.web.repositoryListType, "flat").equalsIgnoreCase("tree")) { TreeNodeModel tree = new TreeNodeModel(); for (RepositoryModel model : models) { String rootPath = StringUtils.getRootPath(model.name); if (StringUtils.isEmpty(rootPath)) { - // root repository - // rootRepositories.add(model); tree.add(model); } else { // create folder structure tree.add(rootPath, model); - // non-root, grouped repository - // if (!groups.containsKey(rootPath)) { - // groups.put(rootPath, new ArrayList()); - // } - // groups.get(rootPath).add(model); } } - WebMarkupContainer row = new WebMarkupContainer("row"); - add(row); - row.add(new MultiLineLabel("rowContent", tree.toString())); - + WebMarkupContainer container = new WebMarkupContainer("row"); + add(container); + container.add(new NestedRepositoryTreePanel("rowContent", Model.of(tree), accessRestrictionTranslations, enableLinks)); Fragment fragment = new Fragment("headerContent", "groupRepositoryHeader", this); + Fragment allCollapsible = new Fragment("allCollapsible", "tableAllCollapsible", this); + fragment.add(allCollapsible); add(fragment); - - - } else if (app().settings().getString(Keys.web.repositoryListType, "flat").equalsIgnoreCase("grouped")) { List rootRepositories = new ArrayList(); Map> groups = new HashMap>(); @@ -214,10 +204,10 @@ public class RepositoriesPanel extends BasePanel { GroupRepositoryModel groupRow = (GroupRepositoryModel) entry; currGroupName = entry.name; Fragment row = new Fragment("rowContent", "groupRepositoryRow", this); - if(collapsibleRepoGroups == CollapsibleRepositorySetting.EXPANDED) { + if (collapsibleRepoGroups == CollapsibleRepositorySetting.EXPANDED) { Fragment groupCollapsible = new Fragment("groupCollapsible", "tableGroupMinusCollapsible", this); row.add(groupCollapsible); - } else if(collapsibleRepoGroups == CollapsibleRepositorySetting.COLLAPSED) { + } else if (collapsibleRepoGroups == CollapsibleRepositorySetting.COLLAPSED) { Fragment groupCollapsible = new Fragment("groupCollapsible", "tableGroupPlusCollapsible", this); row.add(groupCollapsible); } else { @@ -375,8 +365,7 @@ public class RepositoriesPanel extends BasePanel { } else { // not sortable Fragment fragment = new Fragment("headerContent", "groupRepositoryHeader", this); - if(collapsibleRepoGroups == CollapsibleRepositorySetting.EXPANDED || - collapsibleRepoGroups == CollapsibleRepositorySetting.COLLAPSED) { + if (collapsibleRepoGroups == CollapsibleRepositorySetting.EXPANDED || collapsibleRepoGroups == CollapsibleRepositorySetting.COLLAPSED) { Fragment allCollapsible = new Fragment("allCollapsible", "tableAllCollapsible", this); fragment.add(allCollapsible); } else { @@ -386,8 +375,6 @@ public class RepositoriesPanel extends BasePanel { add(fragment); } } - - } private static class GroupRepositoryModel extends RepositoryModel { diff --git a/src/main/java/com/gitblit/wicket/panels/TreeNodeModel.java b/src/main/java/com/gitblit/wicket/panels/TreeNodeModel.java deleted file mode 100644 index 4887c65a..00000000 --- a/src/main/java/com/gitblit/wicket/panels/TreeNodeModel.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.gitblit.wicket.panels; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -import com.gitblit.models.RepositoryModel; -import com.gitblit.utils.StringUtils; - -public class TreeNodeModel implements Serializable { - - private static final long serialVersionUID = 1L; - final TreeNodeModel parent; - final String name; - private final List subFolders = new ArrayList<>(); - private final List repositories = new ArrayList<>(); - - /** - * Create a new tree root - */ - public TreeNodeModel() { - this.name = ""; - this.parent = null; - } - - protected TreeNodeModel(String name, TreeNodeModel parent) { - this.name = name; - this.parent = parent; - } - - public int getDepth() { - if(parent == null) { - return 0; - }else { - return parent.getDepth() +1; - } - } - - /** - * Add a new sub folder to the current folder - * - * @param subFolder the subFolder to create - * @return the newly created folder to allow chaining - */ - public TreeNodeModel add(String subFolder) { - TreeNodeModel n = new TreeNodeModel(subFolder, this); - subFolders.add(n); - return n; - } - - /** - * Add the given repo to the current folder - * - * @param repo - */ - public void add(RepositoryModel repo) { - repositories.add(repo); - } - - /** - * Adds the given repository model within the given path. Creates parent folders if they do not exist - * - * @param path - * @param model - */ - public void add(String path, RepositoryModel model) { - TreeNodeModel folder = getSubTreeNode(this, path, true); - folder.add(model); - } - - @Override - public String toString() { - String string = name + "\n"; - for(TreeNodeModel n : subFolders) { - string += "f"; - for(int i = 0; i < n.getDepth(); i++) { - string += "-"; - } - string += n.toString(); - } - - for(RepositoryModel n : repositories) { - string += "r"; - for(int i = 0; i < getDepth()+1; i++) { - string += "-"; - } - string += n.toString() + "\n"; - } - - return string; - } - - public boolean containsSubFolder(String path) { - return containsSubFolder(this, path); - } - - public TreeNodeModel getSubFolder(String path) { - return getSubTreeNode(this, path, false); - } - - - - - private static TreeNodeModel getSubTreeNode(TreeNodeModel node, String path, boolean create) { - if(!StringUtils.isEmpty(path)) { - boolean isPathInCurrentHierarchyLevel = path.lastIndexOf('/') < 0; - if(isPathInCurrentHierarchyLevel) { - for(TreeNodeModel t : node.subFolders) { - if(t.name.equals(path) ) { - return t; - } - } - - if(create) { - node.add(path); - return getSubTreeNode(node, path, true); - } - }else { - //traverse into subFolder - String folderInCurrentHierarchyLevel = path.substring(0, path.indexOf('/')); - - for(TreeNodeModel t : node.subFolders) { - if(t.name.equals(folderInCurrentHierarchyLevel) ) { - String folderInNextHierarchyLevel = path.substring(path.indexOf('/') + 1, path.length()); - return getSubTreeNode(t, folderInNextHierarchyLevel, create); - } - } - - if(create) { - String folderInNextHierarchyLevel = path.substring(path.indexOf('/') + 1, path.length()); - return getSubTreeNode(node.add(folderInCurrentHierarchyLevel), folderInNextHierarchyLevel, true); - } - } - } - - return null; - } - - private static boolean containsSubFolder(TreeNodeModel node, String path) { - return getSubTreeNode(node, path, false) != null; - } -} diff --git a/src/main/resources/gitblit/js/collapsible-table.js b/src/main/resources/gitblit/js/collapsible-table.js index 538b412e..fc28b1e4 100644 --- a/src/main/resources/gitblit/js/collapsible-table.js +++ b/src/main/resources/gitblit/js/collapsible-table.js @@ -1,32 +1,71 @@ $(function() { $('i.table-group-collapsible') .click(function(){ - $(this).closest('tr.group.collapsible').nextUntil('tr.group.collapsible').toggle(); + var nodeId = $(this).closest('tr.group.collapsible.tree').data('nodeId'); + if(nodeId!==undefined){ + //we are in tree view + if($(this).hasClass('fa-minus-square-o')){ + $(this).closest('tr.group.collapsible.tree').nextAll('tr.child-of-'+nodeId).hide(); + $(this).closest('tr.group.collapsible.tree').nextAll('tr.child-of-'+nodeId).addClass('hidden-by-'+nodeId); + }else{ + $(this).closest('tr.group.collapsible.tree').nextAll('tr.child-of-'+nodeId).removeClass('hidden-by-'+nodeId); + $(this).closest('tr.group.collapsible.tree').nextAll('tr.child-of-'+nodeId+':not([class*="hidden-by-"])').show(); + } + }else{ + $(this).closest('tr.group.collapsible').nextUntil('tr.group.collapsible').toggle(); + } $(this).toggleClass('fa-minus-square-o'); $(this).toggleClass('fa-plus-square-o'); }); + $('i.table-openall-collapsible') .click(function(){ $('tr.group.collapsible').first().find('i').addClass('fa-minus-square-o'); $('tr.group.collapsible').first().find('i').removeClass('fa-plus-square-o'); - $('tr.group.collapsible').first().nextAll('tr:not(tr.group.collapsible)').show(); + $('tr.group.collapsible').first().nextAll('tr:not(tr.group.collapsible),tr.group.collapsible.tree').show(); $('tr.group.collapsible').first().nextAll('tr.group.collapsible').find('i').addClass('fa-minus-square-o'); $('tr.group.collapsible').first().nextAll('tr.group.collapsible').find('i').removeClass('fa-plus-square-o'); + + var nodeId = $('tr.group.collapsible.tree').data('nodeId'); + if(nodeId!==undefined){ + //we are in tree view + $('tr[class*="child-of-"]').removeClass(function(index, className){ + return (className.match(/\hidden-by-\S+/g)||[]).join(' '); + }); + $('tr.group.collapsible > i').addClass('fa-minus-square-o'); + $('tr.group.collapsible > i').removeClass('fa-plus-square-o'); + } }); $('i.table-closeall-collapsible') .click(function(){ $('tr.group.collapsible').first().find('i').addClass('fa-plus-square-o'); $('tr.group.collapsible').first().find('i').removeClass('fa-minus-square-o'); - $('tr.group.collapsible').first().nextAll('tr:not(tr.group.collapsible)').hide(); + $('tr.group.collapsible').first().nextAll('tr:not(tr.group.collapsible),tr.group.collapsible.tree').hide(); $('tr.group.collapsible').first().nextAll('tr.group.collapsible').find('i').addClass('fa-plus-square-o'); $('tr.group.collapsible').first().nextAll('tr.group.collapsible').find('i').removeClass('fa-minus-square-o'); + + var nodeId = $('tr.group.collapsible.tree').first().data('nodeId'); + if(nodeId!==undefined){ + //we are in tree view, hide all sub trees + $('tr[class*="child-of-"]').each(function(){ + var row = $(this); + var classList = row.attr('class').split('/\s+/'); + $.each(classList, function(index, c){ + if(c.match(/^child-of-*/)){ + row.addClass(c.replace(/^child-of-(\d)/, 'hidden-by-$1')); + } + }); + }); + $('tr.group.collapsible i').addClass('fa-plus-square-o'); + $('tr.group.collapsible i').removeClass('fa-minus-square-o'); + } }); $( document ).ready(function() { if($('tr.group.collapsible').first().find('i').hasClass('fa-plus-square-o')) { - $('tr.group.collapsible').first().nextAll('tr:not(tr.group.collapsible)').hide(); + $('tr.group.collapsible').first().nextAll('tr:not(tr.group.collapsible),tr.group.collapsible.tree').hide(); } }); }); \ No newline at end of file diff --git a/src/test/java/com/gitblit/wicket/panels/TreeNodeModelTest.java b/src/test/java/com/gitblit/wicket/panels/TreeNodeModelTest.java index 57051dd4..449688b0 100644 --- a/src/test/java/com/gitblit/wicket/panels/TreeNodeModelTest.java +++ b/src/test/java/com/gitblit/wicket/panels/TreeNodeModelTest.java @@ -7,6 +7,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; import com.gitblit.models.RepositoryModel; +import com.gitblit.models.TreeNodeModel; public class TreeNodeModelTest {