]> source.dussan.org Git - gitblit.git/commitdiff
Added repository counts to filters menu
authorJames Moger <james.moger@gitblit.com>
Mon, 26 Dec 2011 17:45:35 +0000 (12:45 -0500)
committerJames Moger <james.moger@gitblit.com>
Mon, 26 Dec 2011 17:45:35 +0000 (12:45 -0500)
src/com/gitblit/wicket/pages/RootPage.java

index 74122bc92396df6069dad4b4c64151ac14961979..7983f0e50283a8f546b3dfa95201e195eac1c3ad 100644 (file)
@@ -17,9 +17,13 @@ package com.gitblit.wicket.pages;
 \r
 import java.text.MessageFormat;\r
 import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.HashMap;\r
 import java.util.LinkedHashSet;\r
 import java.util.List;\r
+import java.util.Map;\r
 import java.util.Set;\r
+import java.util.concurrent.atomic.AtomicInteger;\r
 import java.util.regex.Pattern;\r
 \r
 import org.apache.wicket.PageParameters;\r
@@ -70,8 +74,8 @@ public abstract class RootPage extends BasePage {
                boolean authenticateView = GitBlit.getBoolean(Keys.web.authenticateViewPages, false);\r
                boolean authenticateAdmin = GitBlit.getBoolean(Keys.web.authenticateAdminPages, true);\r
                boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, true);\r
-               \r
-               if (authenticateAdmin) {                        \r
+\r
+               if (authenticateAdmin) {\r
                        showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();\r
                        // authentication requires state and session\r
                        setStatelessHint(false);\r
@@ -136,7 +140,7 @@ public abstract class RootPage extends BasePage {
                WicketUtils.setInputPlaceholder(pwField, getString("gb.password"));\r
                loginForm.add(pwField);\r
                add(loginForm);\r
-               \r
+\r
                if (authenticateView || authenticateAdmin) {\r
                        loginForm.setVisible(!GitBlitWebSession.get().isLoggedIn());\r
                } else {\r
@@ -185,22 +189,38 @@ public abstract class RootPage extends BasePage {
        protected List<DropDownMenuItem> getFilterMenuItems() {\r
                final UserModel user = GitBlitWebSession.get().getUser();\r
                Set<DropDownMenuItem> filters = new LinkedHashSet<DropDownMenuItem>();\r
+               List<RepositoryModel> repositories = GitBlit.self().getRepositoryModels(user);\r
 \r
                // accessible repositories by federation set\r
-               for (RepositoryModel repository : GitBlit.self().getRepositoryModels(user)) {\r
+               Map<String, AtomicInteger> setMap = new HashMap<String, AtomicInteger>();\r
+               for (RepositoryModel repository : repositories) {\r
                        for (String set : repository.federationSets) {\r
-                               filters.add(new DropDownMenuItem(set, "set", set));\r
+                               String key = set.toLowerCase();\r
+                               if (setMap.containsKey(key)) {\r
+                                       setMap.get(key).incrementAndGet();\r
+                               } else {\r
+                                       setMap.put(key, new AtomicInteger(1));\r
+                               }\r
                        }\r
                }\r
-               if (filters.size() > 0) {\r
+               if (setMap.size() > 0) {\r
+                       List<String> sets = new ArrayList<String>(setMap.keySet());\r
+                       Collections.sort(sets);\r
+                       for (String set : sets) {\r
+                               filters.add(new DropDownMenuItem(MessageFormat.format("{0} ({1})", set,\r
+                                               setMap.get(set).get()), "set", set));\r
+                       }\r
                        // divider\r
                        filters.add(new DropDownMenuItem());\r
                }\r
 \r
                // user's team memberships\r
                if (user != null && user.teams.size() > 0) {\r
-                       for (TeamModel team : user.teams) {\r
-                               filters.add(new DropDownMenuItem(team.name, "team", team.name));\r
+                       List<TeamModel> teams = new ArrayList<TeamModel>(user.teams);\r
+                       Collections.sort(teams);\r
+                       for (TeamModel team : teams) {\r
+                               filters.add(new DropDownMenuItem(MessageFormat.format("{0} ({1})", team.name,\r
+                                               team.repositories.size()), "team", team.name));\r
                        }\r
                        // divider\r
                        filters.add(new DropDownMenuItem());\r
@@ -225,7 +245,8 @@ public abstract class RootPage extends BasePage {
 \r
                if (filters.size() > 0) {\r
                        // add All Repositories\r
-                       filters.add(new DropDownMenuItem("All Repositories", null, null));\r
+                       filters.add(new DropDownMenuItem(MessageFormat.format("All Repositories ({0})",\r
+                                       repositories.size()), null, null));\r
                }\r
 \r
                return new ArrayList<DropDownMenuItem>(filters);\r