From 1a8eb19b3cd55646adde33d922e8bc10f0090050 Mon Sep 17 00:00:00 2001 From: James Moger Date: Mon, 10 Jun 2013 18:42:14 -0400 Subject: [PATCH] Make days back filter a setting --- releases.moxie | 3 ++ src/main/distrib/data/gitblit.properties | 12 +++++-- src/main/java/com/gitblit/GitBlit.java | 13 +++++++ .../java/com/gitblit/IStoredSettings.java | 35 +++++++++++++++++++ .../gitblit/wicket/pages/ActivityPage.java | 2 +- .../com/gitblit/wicket/pages/RootPage.java | 12 ++++--- 6 files changed, 69 insertions(+), 8 deletions(-) diff --git a/releases.moxie b/releases.moxie index 2b72bd22..0a73d5bb 100644 --- a/releases.moxie +++ b/releases.moxie @@ -35,6 +35,8 @@ r17: { - Improve Gerrit change ref decoration in the refs panel (issue 206) - Disable Gson's pretty printing which has a huge performance gain - Properly set application/json content-type on api calls + - Make days back filter choices a setting + - Changed default days back filter setting to 7 days - Improved page title - Updated Polish translation - Updated Japanese translation @@ -105,6 +107,7 @@ r17: { - { name: 'mail.smtps', defaultValue: false } - { name: 'realm.salesforce.backingUserService', defaultValue: 'users.conf' } - { name: 'realm.salesforce.orgId', defaultValue: 0 } + - { name: 'web.activityDurationChoices', defaultValue: '7 14 28 60 90 180' } - { name: 'web.allowAppCloneLinks', defaultValue: true } - { name: 'web.forceDefaultLocale', defaultValue: ' ' } - { name: 'web.overviewPushCount', defaultValue: 5 } diff --git a/src/main/distrib/data/gitblit.properties b/src/main/distrib/data/gitblit.properties index 82e77f35..a6dc3158 100644 --- a/src/main/distrib/data/gitblit.properties +++ b/src/main/distrib/data/gitblit.properties @@ -814,11 +814,17 @@ web.showSearchTypeSelection = false # SINCE 0.5.0 web.generateActivityGraph = true -# The number of days to show on the activity page. -# Value must exceed 0 else default of 14 is used +# The default number of days to show on the activity page. +# Value must exceed 0 else default of 7 is used # # SINCE 0.8.0 -web.activityDuration = 14 +web.activityDuration = 7 + +# Choices for days of activity to display. +# +# SPACE-DELIMITED +# SINCE 1.3.0 +web.activityDurationChoices = 7 14 28 60 90 180 # The number of commits to display on the summary page # Value must exceed 0 else default of 20 is used diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java index 71f33b4a..ceb40c13 100644 --- a/src/main/java/com/gitblit/GitBlit.java +++ b/src/main/java/com/gitblit/GitBlit.java @@ -312,6 +312,19 @@ public class GitBlit implements ServletContextListener { public static int getInteger(String key, int defaultValue) { return self().settings.getInteger(key, defaultValue); } + + /** + * Returns the integer list for the specified key. If the key does not + * exist or the value for the key can not be interpreted as an integer, an + * empty list is returned. + * + * @see IStoredSettings.getIntegers(String key) + * @param key + * @return key value or defaultValue + */ + public static List getIntegers(String key) { + return self().settings.getIntegers(key); + } /** * Returns the value in bytes for the specified key. If the key does not diff --git a/src/main/java/com/gitblit/IStoredSettings.java b/src/main/java/com/gitblit/IStoredSettings.java index f0b1e632..acb9fc60 100644 --- a/src/main/java/com/gitblit/IStoredSettings.java +++ b/src/main/java/com/gitblit/IStoredSettings.java @@ -260,6 +260,41 @@ public abstract class IStoredSettings { return strings; } + /** + * Returns a list of space-separated integers from the specified key. + * + * @param name + * @return list of strings + */ + public List getIntegers(String name) { + return getIntegers(name, " "); + } + + /** + * Returns a list of integers from the specified key using the specified + * string separator. + * + * @param name + * @param separator + * @return list of integers + */ + public List getIntegers(String name, String separator) { + List ints = new ArrayList(); + Properties props = getSettings(); + if (props.containsKey(name)) { + String value = props.getProperty(name); + List strings = StringUtils.getStringsFromValue(value, separator); + for (String str : strings) { + try { + int i = Integer.parseInt(str); + ints.add(i); + } catch (NumberFormatException e) { + } + } + } + return ints; + } + /** * Returns a map of strings from the specified key. * diff --git a/src/main/java/com/gitblit/wicket/pages/ActivityPage.java b/src/main/java/com/gitblit/wicket/pages/ActivityPage.java index 8e841c79..61838ba2 100644 --- a/src/main/java/com/gitblit/wicket/pages/ActivityPage.java +++ b/src/main/java/com/gitblit/wicket/pages/ActivityPage.java @@ -109,7 +109,7 @@ public class ActivityPage extends RootPage { ActivityPage.class); PageParameters currentParameters = getPageParameters(); - int daysBack = GitBlit.getInteger(Keys.web.activityDuration, 14); + int daysBack = GitBlit.getInteger(Keys.web.activityDuration, 7); if (currentParameters != null && !currentParameters.containsKey("db")) { currentParameters.put("db", daysBack); } diff --git a/src/main/java/com/gitblit/wicket/pages/RootPage.java b/src/main/java/com/gitblit/wicket/pages/RootPage.java index bbe20f5b..a279163c 100644 --- a/src/main/java/com/gitblit/wicket/pages/RootPage.java +++ b/src/main/java/com/gitblit/wicket/pages/RootPage.java @@ -27,6 +27,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeSet; import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Pattern; @@ -178,7 +179,7 @@ public abstract class RootPage extends BasePage { // remove days back parameter if it is the default value if (params.containsKey("db") - && params.getInt("db") == GitBlit.getInteger(Keys.web.activityDuration, 14)) { + && params.getInt("db") == GitBlit.getInteger(Keys.web.activityDuration, 7)) { params.remove("db"); } return params; @@ -295,12 +296,15 @@ public abstract class RootPage extends BasePage { protected List getTimeFilterItems(PageParameters params) { // days back choices - additive parameters - int daysBack = GitBlit.getInteger(Keys.web.activityDuration, 14); + int daysBack = GitBlit.getInteger(Keys.web.activityDuration, 7); if (daysBack < 1) { - daysBack = 14; + daysBack = 7; } List items = new ArrayList(); - Set choicesSet = new HashSet(Arrays.asList(daysBack, 14, 28, 60, 90, 180)); + Set choicesSet = new TreeSet(GitBlit.getIntegers(Keys.web.activityDurationChoices)); + if (choicesSet.isEmpty()) { + choicesSet.addAll(Arrays.asList(7, 14, 28, 60, 90, 180)); + } List choices = new ArrayList(choicesSet); Collections.sort(choices); String lastDaysPattern = getString("gb.lastNDays"); -- 2.39.5