From de3474a1ddd9201dec8246d7fd81e240b98bb6a5 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Mon, 17 Jun 2013 15:50:04 -0400
Subject: [PATCH] Moved #externalAccount string to common constants class

---
 src/main/java/com/gitblit/wicket/pages/DashboardPage.java |   48 +++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/gitblit/wicket/pages/DashboardPage.java b/src/main/java/com/gitblit/wicket/pages/DashboardPage.java
index 39771ae..6c328b1 100644
--- a/src/main/java/com/gitblit/wicket/pages/DashboardPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/DashboardPage.java
@@ -34,6 +34,7 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.TimeZone;
+import java.util.TreeSet;
 
 import org.apache.wicket.Component;
 import org.apache.wicket.PageParameters;
@@ -98,6 +99,7 @@
 			add(new Label("active").setVisible(false));
 			add(new Label("starred").setVisible(false));
 			add(new Label("owned").setVisible(false));
+			add(new Label("feedheader").setVisible(false));
 			return;
 		}
 
@@ -123,7 +125,7 @@
 		// parameters
 		int daysBack = params == null ? 0 : WicketUtils.getDaysBack(params);
 		if (daysBack < 1) {
-			daysBack = 14;
+			daysBack = 7;
 		}
 		Calendar c = Calendar.getInstance();
 		c.add(Calendar.DATE, -1*daysBack);
@@ -135,7 +137,7 @@
 		List<RepositoryModel> owned = new ArrayList<RepositoryModel>();
 		List<RepositoryModel> active = new ArrayList<RepositoryModel>();
 
-		for (RepositoryModel model : GitBlit.self().getRepositoryModels(user)) {
+		for (RepositoryModel model : getRepositoryModels()) {
 			if (model.isUsersPersonalRepository(user.username) || model.isOwner(user.username)) {
 				owned.add(model);
 			}
@@ -187,8 +189,22 @@
 		
 		// add the nifty charts
 		if (!ArrayUtils.isEmpty(pushes)) {
-			GoogleCharts charts = createCharts(pushes);
-			add(new HeaderContributor(charts));
+			// aggregate author exclusions
+			Set<String> authorExclusions = new TreeSet<String>();
+			for (String author : GitBlit.getStrings(Keys.web.metricAuthorExclusions)) {
+				authorExclusions.add(author.toLowerCase());
+			}
+			for (RepositoryModel model : feedSources) {
+				if (!ArrayUtils.isEmpty(model.metricAuthorExclusions)) {
+					for (String author : model.metricAuthorExclusions) {
+						authorExclusions.add(author.toLowerCase());
+					}
+				}
+			}
+
+			addCharts(pushes, authorExclusions, daysBack);
+		} else {
+			add(new Label("feedheader").setVisible(false));
 		}
 		
 		// active repository list
@@ -357,14 +373,16 @@
 	 * and the active authors pie chart
 	 * 
 	 * @param recentPushes
-	 * @return
+	 * @param authorExclusions
+	 * @param daysBack
 	 */
-	private GoogleCharts createCharts(List<PushLogEntry> recentPushes) {
+	private void addCharts(List<PushLogEntry> recentPushes, Set<String> authorExclusions, int daysBack) {
 		// activity metrics
 		Map<String, Metric> repositoryMetrics = new HashMap<String, Metric>();
 		Map<String, Metric> authorMetrics = new HashMap<String, Metric>();
 
 		// aggregate repository and author metrics
+		int totalCommits = 0;
 		for (PushLogEntry push : recentPushes) {
 
 			// aggregate repository metrics
@@ -375,13 +393,21 @@
 			repositoryMetrics.get(repository).count += 1;
 			
 			for (RepositoryCommit commit : push.getCommits()) {
-				String author = commit.getAuthorIdent().getName();
-				if (!authorMetrics.containsKey(author)) {
-					authorMetrics.put(author, new Metric(author));
+				totalCommits++;
+				String author = StringUtils.removeNewlines(commit.getAuthorIdent().getName());
+				String authorName = author.toLowerCase();
+				String authorEmail = StringUtils.removeNewlines(commit.getAuthorIdent().getEmailAddress()).toLowerCase();
+				if (!authorExclusions.contains(authorName) && !authorExclusions.contains(authorEmail)) {
+					if (!authorMetrics.containsKey(author)) {
+						authorMetrics.put(author, new Metric(author));
+					}
+					authorMetrics.get(author).count += 1;
 				}
-				authorMetrics.get(author).count += 1;
 			}
 		}
+		
+		add(new Label("feedheader", MessageFormat.format(getString("gb.recentActivityStats"),
+				daysBack, totalCommits, authorMetrics.size())));
 
 		// build google charts
 		GoogleCharts charts = new GoogleCharts();
@@ -404,7 +430,7 @@
 		chart.setShowLegend(false);
 		charts.addChart(chart);
 
-		return charts;
+		add(new HeaderContributor(charts));
 	}
 	
 	class RepoListItem implements Serializable {

--
Gitblit v1.9.1