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 | 145 +++++++++++++++++++++++++++++-------------------
1 files changed, 88 insertions(+), 57 deletions(-)
diff --git a/src/main/java/com/gitblit/wicket/pages/DashboardPage.java b/src/main/java/com/gitblit/wicket/pages/DashboardPage.java
index 6a4c565..6c328b1 100644
--- a/src/main/java/com/gitblit/wicket/pages/DashboardPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/DashboardPage.java
@@ -29,8 +29,12 @@
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
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;
@@ -91,7 +95,11 @@
String message = readMarkdown(messageSource, "login.mkd");
Component repositoriesMessage = new Label("repositoriesMessage", message);
add(repositoriesMessage.setEscapeModelStrings(false));
- add(new Label("repositoriesPanel"));
+ add(new Label("digests"));
+ 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;
}
@@ -103,6 +111,9 @@
add(repositoriesMessage);
UserModel user = GitBlitWebSession.get().getUser();
+ if (user == null) {
+ user = UserModel.ANONYMOUS;
+ }
Comparator<RepositoryModel> lastUpdateSort = new Comparator<RepositoryModel>() {
@Override
@@ -111,87 +122,97 @@
}
};
- Map<String, RepositoryModel> reposMap = new HashMap<String, RepositoryModel>();
-
- // owned repositories
- List<RepositoryModel> owned = new ArrayList<RepositoryModel>();
- if (user != null && !UserModel.ANONYMOUS.equals(user)) {
- for (RepositoryModel model : GitBlit.self().getRepositoryModels(user)) {
- reposMap.put(model.name, model);
- if (model.isUsersPersonalRepository(user.username) || model.isOwner(user.username)) {
- owned.add(model);
- }
- }
- }
- Collections.sort(owned, lastUpdateSort);
-
- // starred repositories
- List<RepositoryModel> starred = new ArrayList<RepositoryModel>();
- if (user != null && !UserModel.ANONYMOUS.equals(user)) {
- for (String name : user.getPreferences().getStarredRepositories()) {
- if (!reposMap.containsKey(name)) {
- RepositoryModel repo = GitBlit.self().getRepositoryModel(name);
- reposMap.put(name, repo);
- }
- starred.add(reposMap.get(name));
- }
- }
- Collections.sort(starred, lastUpdateSort);
-
// 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);
Date minimumDate = c.getTime();
+ TimeZone timezone = getTimeZone();
- // active repositories (displayed for anonymous users)
+ // build repo lists
+ List<RepositoryModel> starred = new ArrayList<RepositoryModel>();
+ List<RepositoryModel> owned = new ArrayList<RepositoryModel>();
List<RepositoryModel> active = new ArrayList<RepositoryModel>();
- if (user == null || UserModel.ANONYMOUS.equals(user)) {
- List<RepositoryModel> list = GitBlit.self().getRepositoryModels(UserModel.ANONYMOUS);
- for (RepositoryModel model : list) {
- if (model.lastChange.after(minimumDate)) {
- active.add(model);
- reposMap.put(model.name, model);
- }
+
+ for (RepositoryModel model : getRepositoryModels()) {
+ if (model.isUsersPersonalRepository(user.username) || model.isOwner(user.username)) {
+ owned.add(model);
}
- Collections.sort(active, lastUpdateSort);
+
+ if (user.getPreferences().isStarredRepository(model.name)) {
+ starred.add(model);
+ }
+
+ if (model.isShowActivity() && model.lastChange.after(minimumDate)) {
+ active.add(model);
+ }
}
- // show pushlog feed
+ Collections.sort(owned, lastUpdateSort);
+ Collections.sort(starred, lastUpdateSort);
+ Collections.sort(active, lastUpdateSort);
+
+ Set<RepositoryModel> feedSources = new HashSet<RepositoryModel>();
+ feedSources.addAll(starred);
+ if (feedSources.isEmpty()) {
+ feedSources.addAll(active);
+ }
+
+ // create daily commit digest feed
List<PushLogEntry> pushes = new ArrayList<PushLogEntry>();
- for (RepositoryModel model : reposMap.values()) {
+ for (RepositoryModel model : feedSources) {
Repository repository = GitBlit.self().getRepository(model.name);
- List<DailyLogEntry> entries = PushLogUtils.getDailyLogByRef(model.name, repository, minimumDate);
+ List<DailyLogEntry> entries = PushLogUtils.getDailyLogByRef(model.name, repository, minimumDate, timezone);
pushes.addAll(entries);
repository.close();
}
if (pushes.size() == 0) {
- if (reposMap.size() == 0) {
- add(new LinkPanel("pushes", null, "find some repositories", RepositoriesPage.class));
+ // quiet or no starred repositories
+ if (feedSources.size() == 0) {
+ if (UserModel.ANONYMOUS.equals(user)) {
+ add(new Label("digests", getString("gb.noActivity")));
+ } else {
+ add(new LinkPanel("digests", null, getString("gb.findSomeRepositories"), RepositoriesPage.class));
+ }
} else {
- add(new Label("pushes", "all is quiet"));
+ add(new Label("digests", getString("gb.noActivity")));
}
} else {
+ // show daily commit digest feed
Collections.sort(pushes);
- add(new PushesPanel("pushes", pushes));
+ add(new PushesPanel("digests", pushes));
}
// 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
- if (ArrayUtils.isEmpty(active)) {
- add(new Label("active").setVisible(false));
- } else {
+ if (starred.isEmpty()) {
Fragment activeView = createNgList("active", "activeListFragment", "activeCtrl", active);
add(activeView);
+ } else {
+ add(new Label("active").setVisible(false));
}
// starred repository list
@@ -352,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
@@ -370,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();
@@ -399,7 +430,7 @@
chart.setShowLegend(false);
charts.addChart(chart);
- return charts;
+ add(new HeaderContributor(charts));
}
class RepoListItem implements Serializable {
--
Gitblit v1.9.1