From 8f86e2d6469269323bcd7b0788c56cf08ac34c49 Mon Sep 17 00:00:00 2001 From: James Moger Date: Fri, 30 Dec 2011 07:53:00 -0500 Subject: [PATCH] Indicate selected filters. Strip default db value from links. --- resources/bootstrap.gb.css | 10 +++++ src/com/gitblit/wicket/PageRegistration.java | 43 ++++++++++++++----- .../gitblit/wicket/pages/ActivityPage.java | 11 ++--- .../wicket/pages/RepositoriesPage.java | 12 ++---- src/com/gitblit/wicket/pages/RootPage.java | 19 +++++--- .../gitblit/wicket/panels/DropDownMenu.java | 5 ++- 6 files changed, 68 insertions(+), 32 deletions(-) diff --git a/resources/bootstrap.gb.css b/resources/bootstrap.gb.css index 44f2c19b..e1092b03 100644 --- a/resources/bootstrap.gb.css +++ b/resources/bootstrap.gb.css @@ -86,12 +86,22 @@ hr { border-color: #eee; } +.topbar div > ul .menu-dropdown .selected, .nav .menu-dropdown .selected, .topbar div > ul .dropdown-menu .selected, .nav .dropdown-menu .selected { + background-image: url("bullet_blue.png"); + background-repeat: no-repeat; + background-position: left; +} + .topbar div > ul .menu-dropdown li a, .nav .menu-dropdown li a, .topbar div > ul .dropdown-menu li a, .nav .dropdown-menu li a { color: #555; text-shadow: none; outline: 0; } +.topbar ul .menu-dropdown li a, .topbar ul .dropdown-menu li a { + padding: 4px 22px; +} + topbar div>ul .menu-dropdown li a:hover,.nav .menu-dropdown li a:hover,.topbar div>ul .dropdown-menu li a:hover,.nav .dropdown-menu li a:hover{ background-color: #000070; background-repeat:no-repeat; 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 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(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"); + } } } }; -- 2.39.5