]> source.dussan.org Git - gitblit.git/commitdiff
Filtering repositories and activity pages via url parameters (issue 27)
authorJames Moger <james.moger@gitblit.com>
Thu, 22 Dec 2011 23:10:44 +0000 (18:10 -0500)
committerJames Moger <james.moger@gitblit.com>
Thu, 22 Dec 2011 23:10:44 +0000 (18:10 -0500)
docs/04_releases.mkd
src/com/gitblit/wicket/WicketUtils.java
src/com/gitblit/wicket/pages/ActivityPage.java
src/com/gitblit/wicket/pages/RepositoriesPage.java
src/com/gitblit/wicket/pages/ReviewProposalPage.java
src/com/gitblit/wicket/pages/RootPage.java
src/com/gitblit/wicket/pages/SendProposalPage.java
src/com/gitblit/wicket/panels/RepositoriesPanel.java

index 3e49c1883f912d0d70d41d4b7856f58b442b1585..ea8ff722ac5946ad3953c4ea3d2703ded42f2658 100644 (file)
@@ -29,7 +29,13 @@ The original `users.properties` file and it's corresponding implementation are *
 - fixed: several a bugs in FileUserService related to cleaning up old repository permissions on a rename or delete\r
 - added: optional flash-based 1-step *copy to clipboard* of the primary repository url\r
 - added: javascript-based 3-step (click, ctrl+c, enter) *copy to clipboard* of the primary repository url  \r
-   **New:** *web.allowFlashCopyToClipboard = true*  \r
+   **New:** *web.allowFlashCopyToClipboard = true*\r
+- added: Name, regex, set, and team filtering of the repositories list and the activity page via url parameters (issue 27)  \r
+    Here are some url examples:  \r
+    localhost/gb?r=myrepo.git  *(specific repository)*  \r
+    localhost/gb?x=my  *(regex matching. encoding may be an issue. YMMV)*  \r
+    localhost/gb?set=animal,mineral  *(animal and mineral federation sets)*  \r
+    localhost/qb/activity?team=qa,qa2 *(qa and qa2 teams)*\r
 - improved: empty repositories now link to a new *empty repository* page which gives some direction to the user for the next step in using Gitblit.  This page displays the primary push/clone url of the repository and gives sample syntax for the git command-line client. (issue 31)\r
 - improved: unit testing framework has been migrated to JUnit4 syntax and the test suite has been redesigned to run all unit tests, including rpc, federation, and git push/clone tests\r
 \r
index dbeb47f710de77ae0fd8125558f5bffa4c6863bd..59a94500ba7916523fea9fd7ebe47e215588da4b 100644 (file)
@@ -369,10 +369,18 @@ public class WicketUtils {
                return params.getInt("pg", 1);\r
        }\r
 \r
+       public static String getRegEx(PageParameters params) {\r
+               return params.getString("x", "");\r
+       }\r
+\r
        public static String getSet(PageParameters params) {\r
                return params.getString("set", "");\r
        }\r
 \r
+       public static String getTeam(PageParameters params) {\r
+               return params.getString("team", "");\r
+       }\r
+\r
        public static int getDaysBack(PageParameters params) {\r
                return params.getInt("db", 14);\r
        }\r
index 011eef14135a4b1170cabe69a611a986c85cfa53..e8a172e385883fc3f215a9b49b4a7575b27906a5 100644 (file)
@@ -17,7 +17,6 @@ package com.gitblit.wicket.pages;
 \r
 import java.text.MessageFormat;\r
 import java.text.SimpleDateFormat;\r
-import java.util.ArrayList;\r
 import java.util.Collections;\r
 import java.util.HashMap;\r
 import java.util.HashSet;\r
@@ -29,14 +28,10 @@ import org.apache.wicket.PageParameters;
 import org.apache.wicket.behavior.HeaderContributor;\r
 import org.apache.wicket.markup.html.basic.Label;\r
 \r
-import com.gitblit.GitBlit;\r
 import com.gitblit.models.Activity;\r
 import com.gitblit.models.Metric;\r
 import com.gitblit.models.RepositoryModel;\r
-import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.ActivityUtils;\r
-import com.gitblit.utils.StringUtils;\r
-import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.charting.GoogleChart;\r
 import com.gitblit.wicket.charting.GoogleCharts;\r
@@ -54,7 +49,7 @@ import com.gitblit.wicket.panels.ActivityPanel;
 public class ActivityPage extends RootPage {\r
 \r
        public ActivityPage(PageParameters params) {\r
-               super();\r
+               super(params);\r
                setupPage("", "");\r
 \r
                // parameters\r
@@ -96,42 +91,6 @@ public class ActivityPage extends RootPage {
                }\r
        }\r
 \r
-       private List<RepositoryModel> getRepositories(PageParameters params) {\r
-               final UserModel user = GitBlitWebSession.get().getUser();\r
-               String set = WicketUtils.getSet(params);\r
-               String repositoryName = WicketUtils.getRepositoryName(params);\r
-\r
-               List<RepositoryModel> models = null;\r
-               if (!StringUtils.isEmpty(repositoryName)) {\r
-                       // named repository\r
-                       models = new ArrayList<RepositoryModel>();\r
-                       RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);\r
-                       if (user.canAccessRepository(model)) {\r
-                               models.add(model);\r
-                       }\r
-               }\r
-\r
-               // get all user accessible repositories\r
-               if (models == null) {\r
-                       models = GitBlit.self().getRepositoryModels(user);\r
-               }\r
-\r
-               // filter the repositories by the specified set\r
-               if (!StringUtils.isEmpty(set)) {\r
-                       List<String> sets = StringUtils.getStringsFromValue(set, ",");\r
-                       List<RepositoryModel> setModels = new ArrayList<RepositoryModel>();\r
-                       for (RepositoryModel model : models) {\r
-                               for (String curr : sets) {\r
-                                       if (model.federationSets.contains(curr)) {\r
-                                               setModels.add(model);\r
-                                       }\r
-                               }\r
-                       }\r
-                       models = setModels;\r
-               }\r
-               return models;\r
-       }\r
-\r
        /**\r
         * Creates the daily activity line chart, the active repositories pie chart,\r
         * and the active authors pie chart\r
index d5a21a7ac262c46eb7a26559c91b6cea535ce719..a15a7d9ae677a95dcce14c1364fd7e6173a7753e 100644 (file)
@@ -20,13 +20,16 @@ import java.io.FileReader;
 import java.io.InputStream;\r
 import java.io.InputStreamReader;\r
 import java.text.MessageFormat;\r
+import java.util.List;\r
 \r
 import org.apache.wicket.Component;\r
+import org.apache.wicket.PageParameters;\r
 import org.apache.wicket.markup.html.basic.Label;\r
 import org.apache.wicket.resource.ContextRelativeResource;\r
 \r
 import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
+import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.utils.MarkdownUtils;\r
 import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
@@ -37,8 +40,16 @@ public class RepositoriesPage extends RootPage {
 \r
        public RepositoriesPage() {\r
                super();\r
-               setupPage("", "");\r
+               setup(null);\r
+       }\r
+\r
+       public RepositoriesPage(PageParameters params) {\r
+               super(params);\r
+               setup(params);\r
+       }\r
 \r
+       private void setup(PageParameters params) {\r
+               setupPage("", "");\r
                // check to see if we should display a login message\r
                boolean authenticateView = GitBlit.getBoolean(Keys.web.authenticateViewPages, true);\r
                if (authenticateView && !GitBlitWebSession.get().isLoggedIn()) {\r
@@ -56,14 +67,17 @@ public class RepositoriesPage extends RootPage {
                Component repositoriesMessage = new Label("repositoriesMessage", message)\r
                                .setEscapeModelStrings(false).setVisible(message.length() > 0);\r
                add(repositoriesMessage);\r
-               RepositoriesPanel repositories = new RepositoriesPanel("repositoriesPanel", showAdmin,\r
-                               null, getAccessRestrictions());\r
+\r
+               List<RepositoryModel> repositories = getRepositories(params);\r
+\r
+               RepositoriesPanel repositoriesPanel = new RepositoriesPanel("repositoriesPanel", showAdmin,\r
+                               repositories, true, getAccessRestrictions());\r
                // push the panel down if we are hiding the admin controls and the\r
                // welcome message\r
                if (!showAdmin && !repositoriesMessage.isVisible()) {\r
-                       WicketUtils.setCssStyle(repositories, "padding-top:5px;");\r
+                       WicketUtils.setCssStyle(repositoriesPanel, "padding-top:5px;");\r
                }\r
-               add(repositories);\r
+               add(repositoriesPanel);\r
        }\r
 \r
        private String readMarkdown(String messageSource, String resource) {\r
index 1d9092a59a38e072dca738d30da51242941a415b..2b095f979ab0d77f739e972132c4cf86eead6cd2 100644 (file)
@@ -92,7 +92,7 @@ public class ReviewProposalPage extends RootSubPage {
                List<RepositoryModel> repositories = new ArrayList<RepositoryModel>(\r
                                proposal.repositories.values());\r
                RepositoriesPanel repositoriesPanel = new RepositoriesPanel("repositoriesPanel", false,\r
-                               repositories, getAccessRestrictions());\r
+                               repositories, false, getAccessRestrictions());\r
                add(repositoriesPanel);\r
        }\r
 \r
index 06ab2985f6b0b26ecbfb28b3421bf36469e81c41..a907c735e04666b66a4581c743212307c581bbfa 100644 (file)
@@ -18,6 +18,7 @@ package com.gitblit.wicket.pages;
 import java.text.MessageFormat;\r
 import java.util.ArrayList;\r
 import java.util.List;\r
+import java.util.regex.Pattern;\r
 \r
 import org.apache.wicket.PageParameters;\r
 import org.apache.wicket.markup.html.form.PasswordTextField;\r
@@ -30,6 +31,8 @@ import org.apache.wicket.protocol.http.WebResponse;
 import com.gitblit.Constants;\r
 import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
+import com.gitblit.models.RepositoryModel;\r
+import com.gitblit.models.TeamModel;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
@@ -88,7 +91,7 @@ public abstract class RootPage extends BasePage {
                }\r
                if (showAdmin || showRegistrations) {\r
                        pages.add(new PageRegistration("gb.federation", FederationPage.class));\r
-               }               \r
+               }\r
                NavigationPanel navPanel = new NavigationPanel("navPanel", getClass(), pages);\r
                add(navPanel);\r
 \r
@@ -163,4 +166,81 @@ public abstract class RootPage extends BasePage {
                        }\r
                }\r
        }\r
+\r
+       protected List<RepositoryModel> getRepositories(PageParameters params) {\r
+               final UserModel user = GitBlitWebSession.get().getUser();\r
+               if (params == null) {\r
+                       return GitBlit.self().getRepositoryModels(user);\r
+               }\r
+\r
+               String repositoryName = WicketUtils.getRepositoryName(params);\r
+               String set = WicketUtils.getSet(params);\r
+               String regex = WicketUtils.getRegEx(params);\r
+               String team = WicketUtils.getTeam(params);\r
+\r
+               List<RepositoryModel> models = null;\r
+\r
+               if (!StringUtils.isEmpty(repositoryName)) {\r
+                       // try named repository\r
+                       models = new ArrayList<RepositoryModel>();\r
+                       RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);\r
+                       if (user.canAccessRepository(model)) {\r
+                               models.add(model);\r
+                       }\r
+               }\r
+\r
+               // get all user accessible repositories\r
+               if (models == null) {\r
+                       models = GitBlit.self().getRepositoryModels(user);\r
+               }\r
+\r
+               if (!StringUtils.isEmpty(regex)) {\r
+                       // filter the repositories by the regex\r
+                       List<RepositoryModel> accessible = GitBlit.self().getRepositoryModels(user);\r
+                       List<RepositoryModel> matchingModels = new ArrayList<RepositoryModel>();\r
+                       Pattern pattern = Pattern.compile(regex);\r
+                       for (RepositoryModel aModel : accessible) {\r
+                               if (pattern.matcher(aModel.name).find()) {\r
+                                       matchingModels.add(aModel);\r
+                               }\r
+                       }\r
+                       models = matchingModels;\r
+               } else if (!StringUtils.isEmpty(set)) {\r
+                       // filter the repositories by the specified sets\r
+                       List<String> sets = StringUtils.getStringsFromValue(set, ",");\r
+                       List<RepositoryModel> matchingModels = new ArrayList<RepositoryModel>();\r
+                       for (RepositoryModel model : models) {\r
+                               for (String curr : sets) {\r
+                                       if (model.federationSets.contains(curr)) {\r
+                                               matchingModels.add(model);\r
+                                       }\r
+                               }\r
+                       }\r
+                       models = matchingModels;\r
+               } else if (!StringUtils.isEmpty(team)) {\r
+                       // filter the repositories by the specified teams\r
+                       List<String> teams = StringUtils.getStringsFromValue(team, ",");\r
+                       \r
+                       // need TeamModels first\r
+                       List<TeamModel> teamModels = new ArrayList<TeamModel>();\r
+                       for (String name : teams) {\r
+                               TeamModel model = GitBlit.self().getTeamModel(name);\r
+                               if (model != null) {\r
+                                       teamModels.add(model);\r
+                               }\r
+                       }\r
+                       \r
+                       // brute-force our way through finding the matching models\r
+                       List<RepositoryModel> matchingModels = new ArrayList<RepositoryModel>();\r
+                       for (RepositoryModel repositoryModel : models) {\r
+                               for (TeamModel teamModel : teamModels) {\r
+                                       if (teamModel.hasRepository(repositoryModel.name)) {\r
+                                               matchingModels.add(repositoryModel);\r
+                                       }\r
+                               }\r
+                       }\r
+                       models = matchingModels;\r
+               }\r
+               return models;\r
+       }\r
 }\r
index ed2004996a3468a1ed2df14cdc377fe964175226..a7fcadcf575d31527498c33bd076d87909775f8d 100644 (file)
@@ -149,7 +149,7 @@ public class SendProposalPage extends RootSubPage {
                List<RepositoryModel> repositories = new ArrayList<RepositoryModel>(\r
                                proposal.repositories.values());\r
                RepositoriesPanel repositoriesPanel = new RepositoriesPanel("repositoriesPanel", false,\r
-                               repositories, getAccessRestrictions());\r
+                               repositories, false, getAccessRestrictions());\r
                add(repositoriesPanel);\r
        }\r
 }\r
index 118ad6da98ea171481c794bb2f33a9b6d7bec3f0..3a876bdd144685d2f06dd0d1abfec93e3dd06ea8 100644 (file)
@@ -62,22 +62,14 @@ public class RepositoriesPanel extends BasePanel {
        private static final long serialVersionUID = 1L;\r
 \r
        public RepositoriesPanel(String wicketId, final boolean showAdmin,\r
-                       List<RepositoryModel> models,\r
+                       List<RepositoryModel> models, boolean enableLinks,\r
                        final Map<AccessRestrictionType, String> accessRestrictionTranslations) {\r
                super(wicketId);\r
 \r
-               final boolean linksActive;\r
+               final boolean linksActive = enableLinks;\r
                final boolean showSize = GitBlit.getBoolean(Keys.web.showRepositorySizes, true);\r
 \r
                final UserModel user = GitBlitWebSession.get().getUser();\r
-               if (models == null) {\r
-                       linksActive = true;\r
-                       models = GitBlit.self().getRepositoryModels(user);\r
-               } else {\r
-                       // disable links if the repositories are already provided\r
-                       // the repositories are most likely from a proposal\r
-                       linksActive = false;\r
-               }\r
 \r
                final IDataProvider<RepositoryModel> dp;\r
 \r