import org.apache.wicket.markup.html.basic.Label;\r
\r
import com.gitblit.GitBlit;\r
+import com.gitblit.Keys;\r
import com.gitblit.models.Activity;\r
import com.gitblit.models.Metric;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.utils.ActivityUtils;\r
import com.gitblit.wicket.PageRegistration;\r
+import com.gitblit.wicket.PageRegistration.DropDownMenuItem;\r
import com.gitblit.wicket.PageRegistration.DropDownMenuRegistration;\r
import com.gitblit.wicket.WicketUtils;\r
import com.gitblit.wicket.charting.GoogleChart;\r
add(new ActivityPanel("activityPanel", recentActivity));\r
}\r
}\r
- \r
+\r
+ @Override\r
+ protected boolean reusePageParameters() {\r
+ return true;\r
+ }\r
+\r
@Override\r
protected void addDropDownMenus(List<PageRegistration> pages) {\r
- DropDownMenuRegistration menu = new DropDownMenuRegistration("gb.filters", ActivityPage.class);\r
- menu.menuItems.addAll(getFilterMenuItems());\r
- pages.add(menu);\r
+ DropDownMenuRegistration filters = new DropDownMenuRegistration("gb.filters",\r
+ ActivityPage.class);\r
+\r
+ PageParameters currentParameters = getPageParameters();\r
+ int daysBack = GitBlit.getInteger(Keys.web.activityDuration, 14);\r
+ if (currentParameters.containsKey("db")) {\r
+ daysBack = currentParameters.getInt("db");\r
+ }\r
+ if (daysBack < 1) {\r
+ daysBack = 14;\r
+ }\r
+\r
+ // preserve time filter options on repository choices\r
+ filters.menuItems.addAll(getRepositoryFilterItems(new PageParameters("db=" + daysBack)));\r
+ \r
+ // preserve repository filter options on time choices\r
+ filters.menuItems.addAll(getTimeFilterItems(currentParameters));\r
+\r
+ if (filters.menuItems.size() > 0) {\r
+ // Reset Filter\r
+ filters.menuItems.add(new DropDownMenuItem(getString("gb.reset"), null, null));\r
+ }\r
+ pages.add(filters);\r
}\r
\r
/**\r
\r
return charts;\r
}\r
- \r
+\r
@Override\r
protected void onBeforeRender() {\r
if (GitBlit.isDebugMode()) {\r
}\r
super.onBeforeRender();\r
}\r
+\r
@Override\r
protected void onAfterRender() {\r
if (GitBlit.isDebugMode()) {\r
import com.gitblit.utils.StringUtils;\r
import com.gitblit.wicket.GitBlitWebSession;\r
import com.gitblit.wicket.PageRegistration;\r
+import com.gitblit.wicket.PageRegistration.DropDownMenuItem;\r
import com.gitblit.wicket.PageRegistration.DropDownMenuRegistration;\r
import com.gitblit.wicket.WicketUtils;\r
import com.gitblit.wicket.panels.RepositoriesPanel;\r
setup(params);\r
}\r
\r
+ @Override\r
+ protected boolean reusePageParameters() {\r
+ return true;\r
+ }\r
+\r
private void setup(PageParameters params) {\r
setupPage("", "");\r
// check to see if we should display a login message\r
\r
@Override\r
protected void addDropDownMenus(List<PageRegistration> pages) {\r
- DropDownMenuRegistration menu = new DropDownMenuRegistration("gb.filters", RepositoriesPage.class);\r
- menu.menuItems.addAll(getFilterMenuItems());\r
+ int daysBack = 0;\r
+ PageParameters currentParameters = getPageParameters();\r
+ if (currentParameters != null && currentParameters.containsKey("db")) {\r
+ daysBack = currentParameters.getInt("db");\r
+ }\r
+ PageParameters params = null;\r
+ if (daysBack > 0) {\r
+ params = new PageParameters("db=" + daysBack);\r
+ }\r
+\r
+ DropDownMenuRegistration menu = new DropDownMenuRegistration("gb.filters",\r
+ RepositoriesPage.class);\r
+ // preserve time filter option on repository choices\r
+ menu.menuItems.addAll(getRepositoryFilterItems(params));\r
+ \r
+ // preserve repository filter option on time choices\r
+ menu.menuItems.addAll(getTimeFilterItems(currentParameters));\r
+ \r
+ if (menu.menuItems.size() > 0) {\r
+ // Reset Filter \r
+ menu.menuItems.add(new DropDownMenuItem(getString("gb.reset"), null, null));\r
+ }\r
+\r
pages.add(menu);\r
}\r
\r
}\r
return message;\r
}\r
- \r
+\r
@Override\r
protected void onBeforeRender() {\r
if (GitBlit.isDebugMode()) {\r
}\r
super.onBeforeRender();\r
}\r
+\r
@Override\r
protected void onAfterRender() {\r
if (GitBlit.isDebugMode()) {\r
\r
import java.text.MessageFormat;\r
import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.Calendar;\r
import java.util.Collections;\r
+import java.util.Date;\r
import java.util.HashMap;\r
+import java.util.HashSet;\r
import java.util.LinkedHashSet;\r
import java.util.List;\r
import java.util.Map;\r
\r
// navigation links\r
List<PageRegistration> pages = new ArrayList<PageRegistration>();\r
- pages.add(new PageRegistration("gb.repositories", RepositoriesPage.class, getRootPageParameters()));\r
+ pages.add(new PageRegistration("gb.repositories", RepositoriesPage.class,\r
+ getRootPageParameters()));\r
pages.add(new PageRegistration("gb.activity", ActivityPage.class, getRootPageParameters()));\r
if (showAdmin) {\r
pages.add(new PageRegistration("gb.users", UsersPage.class));\r
\r
super.setupPage(repositoryName, pageName);\r
}\r
- \r
+\r
private PageParameters getRootPageParameters() {\r
- PageParameters params = getPageParameters();\r
- if (params != null) {\r
- // remove named repository parameter\r
- params.remove("r");\r
+ if (reusePageParameters()) {\r
+ PageParameters params = getPageParameters();\r
+ if (params != null) {\r
+ // remove named repository parameter\r
+ params.remove("r");\r
+ }\r
+ return params;\r
}\r
- return params;\r
+ return null;\r
+ }\r
+\r
+ protected boolean reusePageParameters() {\r
+ return false;\r
}\r
\r
private void loginUser(UserModel user) {\r
\r
}\r
\r
- protected List<DropDownMenuItem> getFilterMenuItems() {\r
+ protected List<DropDownMenuItem> getRepositoryFilterItems(PageParameters params) {\r
final UserModel user = GitBlitWebSession.get().getUser();\r
Set<DropDownMenuItem> filters = new LinkedHashSet<DropDownMenuItem>();\r
List<RepositoryModel> repositories = GitBlit.self().getRepositoryModels(user);\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
+ setMap.get(set).get()), "set", set, params));\r
}\r
// divider\r
filters.add(new DropDownMenuItem());\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
+ team.repositories.size()), "team", team.name, params));\r
}\r
// divider\r
filters.add(new DropDownMenuItem());\r
for (String expression : expressions) {\r
if (!StringUtils.isEmpty(expression)) {\r
addedExpression = true;\r
- filters.add(new DropDownMenuItem(null, "x", expression));\r
+ filters.add(new DropDownMenuItem(null, "x", expression, params));\r
}\r
}\r
// if we added any custom expressions, add a divider\r
if (addedExpression) {\r
filters.add(new DropDownMenuItem());\r
}\r
- }\r
+ } \r
+ return new ArrayList<DropDownMenuItem>(filters);\r
+ }\r
\r
- if (filters.size() > 0) {\r
- // add All Repositories\r
- filters.add(new DropDownMenuItem(MessageFormat.format("{0} ({1})",\r
- getString("gb.tokenJurDescription"), repositories.size()), null, null));\r
+ protected List<DropDownMenuItem> getTimeFilterItems(PageParameters params) {\r
+ // days back choices - additive parameters\r
+ int daysBack = GitBlit.getInteger(Keys.web.activityDuration, 14);\r
+ if (daysBack < 1) {\r
+ daysBack = 14;\r
}\r
-\r
- return new ArrayList<DropDownMenuItem>(filters);\r
+ List<DropDownMenuItem> items = new ArrayList<DropDownMenuItem>();\r
+ Set<Integer> choicesSet = new HashSet<Integer>(Arrays.asList(daysBack, 14, 28, 60, 90, 180));\r
+ List<Integer> choices = new ArrayList<Integer>(choicesSet);\r
+ Collections.sort(choices);\r
+ for (Integer db : choices) {\r
+ String txt = "last " + db + (db.intValue() > 1 ? " days" : "day");\r
+ items.add(new DropDownMenuItem(txt, "db", db.toString(), params));\r
+ }\r
+ items.add(new DropDownMenuItem());\r
+ return items;\r
}\r
\r
protected List<RepositoryModel> getRepositories(PageParameters params) {\r
return GitBlit.self().getRepositoryModels(user);\r
}\r
\r
+ boolean hasParameter = false;\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
+ int daysBack = params.getInt("db", 0);\r
\r
- List<RepositoryModel> models = null;\r
+ List<RepositoryModel> availableModels = GitBlit.self().getRepositoryModels(user);\r
+ Set<RepositoryModel> models = new HashSet<RepositoryModel>();\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
+ hasParameter = true;\r
+ for (RepositoryModel model : availableModels) {\r
+ if (model.name.equalsIgnoreCase(repositoryName)) {\r
+ models.add(model);\r
+ break;\r
+ }\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
+ hasParameter = true;\r
Pattern pattern = Pattern.compile(regex);\r
- for (RepositoryModel aModel : accessible) {\r
- if (pattern.matcher(aModel.name).find()) {\r
- matchingModels.add(aModel);\r
+ for (RepositoryModel model : availableModels) {\r
+ if (pattern.matcher(model.name).find()) {\r
+ models.add(model);\r
}\r
}\r
- models = matchingModels;\r
- } else if (!StringUtils.isEmpty(set)) {\r
+ }\r
+\r
+ if (!StringUtils.isEmpty(set)) {\r
// filter the repositories by the specified sets\r
+ hasParameter = true;\r
List<String> sets = StringUtils.getStringsFromValue(set, ",");\r
- List<RepositoryModel> matchingModels = new ArrayList<RepositoryModel>();\r
- for (RepositoryModel model : models) {\r
+ for (RepositoryModel model : availableModels) {\r
for (String curr : sets) {\r
if (model.federationSets.contains(curr)) {\r
- matchingModels.add(model);\r
+ models.add(model);\r
}\r
}\r
}\r
- models = matchingModels;\r
- } else if (!StringUtils.isEmpty(team)) {\r
+ }\r
+\r
+ if (!StringUtils.isEmpty(team)) {\r
// filter the repositories by the specified teams\r
+ hasParameter = true;\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
+ TeamModel teamModel = GitBlit.self().getTeamModel(name);\r
+ if (teamModel != null) {\r
+ teamModels.add(teamModel);\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 (RepositoryModel repositoryModel : availableModels) {\r
for (TeamModel teamModel : teamModels) {\r
if (teamModel.hasRepository(repositoryModel.name)) {\r
- matchingModels.add(repositoryModel);\r
+ models.add(repositoryModel);\r
}\r
}\r
}\r
- models = matchingModels;\r
}\r
- return models;\r
+\r
+ if (!hasParameter) {\r
+ models.addAll(availableModels);\r
+ }\r
+ \r
+ // time-filter the list\r
+ if (daysBack > 0) {\r
+ Calendar cal = Calendar.getInstance();\r
+ cal.set(Calendar.HOUR_OF_DAY, 0);\r
+ cal.set(Calendar.MINUTE, 0);\r
+ cal.set(Calendar.SECOND, 0);\r
+ cal.set(Calendar.MILLISECOND, 0);\r
+ cal.add(Calendar.DATE, -1 * daysBack);\r
+ Date threshold = cal.getTime();\r
+ Set<RepositoryModel> timeFiltered = new HashSet<RepositoryModel>();\r
+ for (RepositoryModel model : models) {\r
+ if (model.lastChange.after(threshold)) {\r
+ timeFiltered.add(model);\r
+ }\r
+ }\r
+ models = timeFiltered;\r
+ }\r
+ return new ArrayList<RepositoryModel>(models);\r
}\r
}\r