summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2011-12-30 07:53:00 -0500
committerJames Moger <james.moger@gitblit.com>2011-12-30 07:53:00 -0500
commit8f86e2d6469269323bcd7b0788c56cf08ac34c49 (patch)
tree945175e3a6d9ab3317e5deedd822a2ef4a5f76b7 /src/com
parentbc57cd86db78fccf6b981375425d74bab540ad7b (diff)
downloadgitblit-8f86e2d6469269323bcd7b0788c56cf08ac34c49.tar.gz
gitblit-8f86e2d6469269323bcd7b0788c56cf08ac34c49.zip
Indicate selected filters. Strip default db value from links.
Diffstat (limited to 'src/com')
-rw-r--r--src/com/gitblit/wicket/PageRegistration.java43
-rw-r--r--src/com/gitblit/wicket/pages/ActivityPage.java11
-rw-r--r--src/com/gitblit/wicket/pages/RepositoriesPage.java12
-rw-r--r--src/com/gitblit/wicket/pages/RootPage.java19
-rw-r--r--src/com/gitblit/wicket/panels/DropDownMenu.java5
5 files changed, 58 insertions, 32 deletions
diff --git a/src/com/gitblit/wicket/PageRegistration.java b/src/com/gitblit/wicket/PageRegistration.java
index 6c13b82e..fe76a85f 100644
--- a/src/com/gitblit/wicket/PageRegistration.java
+++ b/src/com/gitblit/wicket/PageRegistration.java
@@ -76,19 +76,17 @@ public class PageRegistration implements Serializable {
private static final long serialVersionUID = 1L;
- final PageParameters params;
+ final PageParameters parameters;
final String displayText;
final String parameter;
final String value;
+ final boolean isSelected;
/**
* Divider constructor.
*/
public DropDownMenuItem() {
- displayText = null;
- parameter = null;
- value = null;
- params = null;
+ this(null, null, null, null);
}
/**
@@ -114,16 +112,37 @@ public class PageRegistration implements Serializable {
this.displayText = displayText;
this.parameter = parameter;
this.value = value;
+
if (params == null) {
- this.params = new PageParameters();
+ // no parameters specified
+ parameters = new PageParameters();
+ setParameter(parameter, value);
+ isSelected = false;
} else {
- this.params = new PageParameters(params);
+ parameters = new PageParameters(params);
+ if (parameters.containsKey(parameter)) {
+ isSelected = params.getString(parameter).equals(value);
+ if (isSelected) {
+ // already selected, so remove this enables toggling
+ parameters.remove(parameter);
+ } else {
+ // set the new selection value
+ setParameter(parameter, value);
+ }
+ } else {
+ // not currently selected
+ isSelected = false;
+ setParameter(parameter, value);
+ }
}
+ }
+
+ private void setParameter(String parameter, String value) {
if (!StringUtils.isEmpty(parameter)) {
if (StringUtils.isEmpty(value)) {
- this.params.remove(parameter);
+ this.parameters.remove(parameter);
} else {
- this.params.put(parameter, value);
+ this.parameters.put(parameter, value);
}
}
}
@@ -136,13 +155,17 @@ public class PageRegistration implements Serializable {
}
public PageParameters getPageParameters() {
- return params;
+ return parameters;
}
public boolean isDivider() {
return displayText == null && value == null && parameter == null;
}
+ public boolean isSelected() {
+ return isSelected;
+ }
+
@Override
public int hashCode() {
if (isDivider()) {
diff --git a/src/com/gitblit/wicket/pages/ActivityPage.java b/src/com/gitblit/wicket/pages/ActivityPage.java
index 9b258a72..d548cfb6 100644
--- a/src/com/gitblit/wicket/pages/ActivityPage.java
+++ b/src/com/gitblit/wicket/pages/ActivityPage.java
@@ -109,16 +109,13 @@ public class ActivityPage extends RootPage {
PageParameters currentParameters = getPageParameters();
int daysBack = GitBlit.getInteger(Keys.web.activityDuration, 14);
- if (currentParameters.containsKey("db")) {
- daysBack = currentParameters.getInt("db");
- }
- if (daysBack < 1) {
- daysBack = 14;
+ if (currentParameters != null && !currentParameters.containsKey("db")) {
+ currentParameters.put("db", daysBack);
}
// preserve time filter options on repository choices
- filters.menuItems.addAll(getRepositoryFilterItems(new PageParameters("db=" + daysBack)));
-
+ filters.menuItems.addAll(getRepositoryFilterItems(currentParameters));
+
// preserve repository filter options on time choices
filters.menuItems.addAll(getTimeFilterItems(currentParameters));
diff --git a/src/com/gitblit/wicket/pages/RepositoriesPage.java b/src/com/gitblit/wicket/pages/RepositoriesPage.java
index 21efddac..bc33b01f 100644
--- a/src/com/gitblit/wicket/pages/RepositoriesPage.java
+++ b/src/com/gitblit/wicket/pages/RepositoriesPage.java
@@ -91,20 +91,16 @@ public class RepositoriesPage extends RootPage {
@Override
protected void addDropDownMenus(List<PageRegistration> pages) {
- int daysBack = 0;
PageParameters currentParameters = getPageParameters();
- if (currentParameters != null && currentParameters.containsKey("db")) {
- daysBack = currentParameters.getInt("db");
- }
- PageParameters params = null;
- if (daysBack > 0) {
- params = new PageParameters("db=" + daysBack);
+ int daysBack = GitBlit.getInteger(Keys.web.activityDuration, 14);
+ if (currentParameters != null && !currentParameters.containsKey("db")) {
+ currentParameters.put("db", daysBack);
}
DropDownMenuRegistration menu = new DropDownMenuRegistration("gb.filters",
RepositoriesPage.class);
// preserve time filter option on repository choices
- menu.menuItems.addAll(getRepositoryFilterItems(params));
+ menu.menuItems.addAll(getRepositoryFilterItems(currentParameters));
// preserve repository filter option on time choices
menu.menuItems.addAll(getTimeFilterItems(currentParameters));
diff --git a/src/com/gitblit/wicket/pages/RootPage.java b/src/com/gitblit/wicket/pages/RootPage.java
index 686fc725..cbf9cfe1 100644
--- a/src/com/gitblit/wicket/pages/RootPage.java
+++ b/src/com/gitblit/wicket/pages/RootPage.java
@@ -171,12 +171,19 @@ public abstract class RootPage extends BasePage {
private PageParameters getRootPageParameters() {
if (reusePageParameters()) {
- PageParameters params = getPageParameters();
- if (params != null) {
+ PageParameters pp = getPageParameters();
+ if (pp != null) {
+ PageParameters params = new PageParameters(pp);
// remove named repository parameter
params.remove("r");
- }
- return params;
+
+ // remove days back parameter if it is the default value
+ if (params.containsKey("db")
+ && params.getInt("db") == GitBlit.getInteger(Keys.web.activityDuration, 14)) {
+ params.remove("db");
+ }
+ return params;
+ }
}
return null;
}
@@ -262,7 +269,7 @@ public abstract class RootPage extends BasePage {
if (addedExpression) {
filters.add(new DropDownMenuItem());
}
- }
+ }
return new ArrayList<DropDownMenuItem>(filters);
}
@@ -362,7 +369,7 @@ public abstract class RootPage extends BasePage {
if (!hasParameter) {
models.addAll(availableModels);
}
-
+
// time-filter the list
if (daysBack > 0) {
Calendar cal = Calendar.getInstance();
diff --git a/src/com/gitblit/wicket/panels/DropDownMenu.java b/src/com/gitblit/wicket/panels/DropDownMenu.java
index ef6a2fe4..cc088d74 100644
--- a/src/com/gitblit/wicket/panels/DropDownMenu.java
+++ b/src/com/gitblit/wicket/panels/DropDownMenu.java
@@ -43,9 +43,12 @@ public class DropDownMenu extends Panel {
if (entry.isDivider()) {
item.add(new Label("menuItem").setRenderBodyOnly(true));
WicketUtils.setCssClass(item, "divider");
- } else {
+ } else {
item.add(new LinkPanel("menuItem", null, entry.toString(), menu.pageClass,
entry.getPageParameters()).setRenderBodyOnly(true));
+ if (entry.isSelected()) {
+ WicketUtils.setCssClass(item, "selected");
+ }
}
}
};