From: James Moger Date: Mon, 26 Dec 2011 17:45:35 +0000 (-0500) Subject: Added repository counts to filters menu X-Git-Tag: v0.8.0~47 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a22eb4f5fdf2adeef9d7f9bfa0a72736ef4b0b5c;p=gitblit.git Added repository counts to filters menu --- diff --git a/src/com/gitblit/wicket/pages/RootPage.java b/src/com/gitblit/wicket/pages/RootPage.java index 74122bc9..7983f0e5 100644 --- a/src/com/gitblit/wicket/pages/RootPage.java +++ b/src/com/gitblit/wicket/pages/RootPage.java @@ -17,9 +17,13 @@ package com.gitblit.wicket.pages; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Pattern; import org.apache.wicket.PageParameters; @@ -70,8 +74,8 @@ public abstract class RootPage extends BasePage { boolean authenticateView = GitBlit.getBoolean(Keys.web.authenticateViewPages, false); boolean authenticateAdmin = GitBlit.getBoolean(Keys.web.authenticateAdminPages, true); boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, true); - - if (authenticateAdmin) { + + if (authenticateAdmin) { showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin(); // authentication requires state and session setStatelessHint(false); @@ -136,7 +140,7 @@ public abstract class RootPage extends BasePage { WicketUtils.setInputPlaceholder(pwField, getString("gb.password")); loginForm.add(pwField); add(loginForm); - + if (authenticateView || authenticateAdmin) { loginForm.setVisible(!GitBlitWebSession.get().isLoggedIn()); } else { @@ -185,22 +189,38 @@ public abstract class RootPage extends BasePage { protected List getFilterMenuItems() { final UserModel user = GitBlitWebSession.get().getUser(); Set filters = new LinkedHashSet(); + List repositories = GitBlit.self().getRepositoryModels(user); // accessible repositories by federation set - for (RepositoryModel repository : GitBlit.self().getRepositoryModels(user)) { + Map setMap = new HashMap(); + for (RepositoryModel repository : repositories) { for (String set : repository.federationSets) { - filters.add(new DropDownMenuItem(set, "set", set)); + String key = set.toLowerCase(); + if (setMap.containsKey(key)) { + setMap.get(key).incrementAndGet(); + } else { + setMap.put(key, new AtomicInteger(1)); + } } } - if (filters.size() > 0) { + if (setMap.size() > 0) { + List sets = new ArrayList(setMap.keySet()); + Collections.sort(sets); + for (String set : sets) { + filters.add(new DropDownMenuItem(MessageFormat.format("{0} ({1})", set, + setMap.get(set).get()), "set", set)); + } // divider filters.add(new DropDownMenuItem()); } // user's team memberships if (user != null && user.teams.size() > 0) { - for (TeamModel team : user.teams) { - filters.add(new DropDownMenuItem(team.name, "team", team.name)); + List teams = new ArrayList(user.teams); + Collections.sort(teams); + for (TeamModel team : teams) { + filters.add(new DropDownMenuItem(MessageFormat.format("{0} ({1})", team.name, + team.repositories.size()), "team", team.name)); } // divider filters.add(new DropDownMenuItem()); @@ -225,7 +245,8 @@ public abstract class RootPage extends BasePage { if (filters.size() > 0) { // add All Repositories - filters.add(new DropDownMenuItem("All Repositories", null, null)); + filters.add(new DropDownMenuItem(MessageFormat.format("All Repositories ({0})", + repositories.size()), null, null)); } return new ArrayList(filters);