From 9effe1630d97039b3e01cd9b58ed07e75be1d63c Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Mon, 25 Feb 2013 08:40:30 -0500
Subject: [PATCH] Merge pull request #75 from thefake/master

---
 src/com/gitblit/wicket/pages/SummaryPage.java |   87 +++++++++++++++++++++++++++++++------------
 1 files changed, 62 insertions(+), 25 deletions(-)

diff --git a/src/com/gitblit/wicket/pages/SummaryPage.java b/src/com/gitblit/wicket/pages/SummaryPage.java
index 50810a1..bd40a1b 100644
--- a/src/com/gitblit/wicket/pages/SummaryPage.java
+++ b/src/com/gitblit/wicket/pages/SummaryPage.java
@@ -22,9 +22,14 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.wicket.Component;
 import org.apache.wicket.PageParameters;
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.link.BookmarkablePageLink;
+import org.apache.wicket.markup.html.panel.Fragment;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.markup.repeater.data.DataView;
+import org.apache.wicket.markup.repeater.data.ListDataProvider;
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.revwalk.RevCommit;
 import org.wicketstuff.googlecharts.Chart;
@@ -37,19 +42,22 @@
 import org.wicketstuff.googlecharts.MarkerType;
 import org.wicketstuff.googlecharts.ShapeMarker;
 
-import com.gitblit.Constants;
 import com.gitblit.Constants.AccessRestrictionType;
 import com.gitblit.GitBlit;
 import com.gitblit.Keys;
 import com.gitblit.models.Metric;
 import com.gitblit.models.PathModel;
+import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.UserModel;
+import com.gitblit.utils.ArrayUtils;
 import com.gitblit.utils.JGitUtils;
 import com.gitblit.utils.MarkdownUtils;
 import com.gitblit.utils.StringUtils;
-import com.gitblit.utils.TimeUtils;
 import com.gitblit.wicket.WicketUtils;
 import com.gitblit.wicket.panels.BranchesPanel;
+import com.gitblit.wicket.panels.LinkPanel;
 import com.gitblit.wicket.panels.LogPanel;
+import com.gitblit.wicket.panels.RepositoryUrlPanel;
 import com.gitblit.wicket.panels.TagsPanel;
 
 public class SummaryPage extends RepositoryPage {
@@ -64,10 +72,12 @@
 		int numberRefs = GitBlit.getInteger(Keys.web.summaryRefsCount, 5);
 
 		Repository r = getRepository();
+		RepositoryModel model = getRepositoryModel();
+
 		List<Metric> metrics = null;
 		Metric metricsTotal = null;
-		if (GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
-			metrics = GitBlit.self().getRepositoryDefaultMetrics(getRepositoryModel(), r);
+		if (!model.skipSummaryMetrics && GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
+			metrics = GitBlit.self().getRepositoryDefaultMetrics(model, r);
 			metricsTotal = metrics.remove(0);
 		}
 
@@ -75,16 +85,37 @@
 
 		// repository description
 		add(new Label("repositoryDescription", getRepositoryModel().description));
-		add(new Label("repositoryOwner", getRepositoryModel().owner));
-
+		
+		// owner links
+		final List<String> owners = new ArrayList<String>(getRepositoryModel().owners);
+		ListDataProvider<String> ownersDp = new ListDataProvider<String>(owners);
+		DataView<String> ownersView = new DataView<String>("repositoryOwners", ownersDp) {
+			private static final long serialVersionUID = 1L;
+			int counter = 0;
+			public void populateItem(final Item<String> item) {
+				UserModel ownerModel = GitBlit.self().getUserModel(item.getModelObject());
+				if (ownerModel != null) {
+					item.add(new LinkPanel("owner", null, ownerModel.getDisplayName(), UserPage.class,
+							WicketUtils.newUsernameParameter(ownerModel.username)).setRenderBodyOnly(true));
+				} else {
+					item.add(new Label("owner").setVisible(false));
+				}
+				counter++;
+				item.add(new Label("comma", ",").setVisible(counter < owners.size()));
+				item.setRenderBodyOnly(true);
+			}
+		};
+		ownersView.setRenderBodyOnly(true);
+		add(ownersView);
+		
 		add(WicketUtils.createTimestampLabel("repositoryLastChange",
-				JGitUtils.getLastChange(r, null), getTimeZone()));
+				JGitUtils.getLastChange(r), getTimeZone(), getTimeUtils()));
 		if (metricsTotal == null) {
 			add(new Label("branchStats", ""));
 		} else {
 			add(new Label("branchStats",
-					MessageFormat.format("{0} commits and {1} tags in {2}", metricsTotal.count,
-							metricsTotal.tag, TimeUtils.duration(metricsTotal.duration))));
+					MessageFormat.format(getString("gb.branchStats"), metricsTotal.count,
+							metricsTotal.tag, getTimeUtils().duration(metricsTotal.duration))));
 		}
 		add(new BookmarkablePageLink<Void>("metrics", MetricsPage.class,
 				WicketUtils.newRepositoryParameter(repositoryName)));
@@ -112,30 +143,31 @@
 			default:
 				add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
 			}
-			StringBuilder sb = new StringBuilder();
-			sb.append(WicketUtils.getGitblitURL(getRequestCycle().getRequest()));
-			sb.append(Constants.GIT_PATH);
-			sb.append(repositoryName);
-			repositoryUrls.add(sb.toString());
+			// add the Gitblit repository url
+			repositoryUrls.add(getRepositoryUrl(getRepositoryModel()));
 		} else {
 			add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
 		}
 		repositoryUrls.addAll(GitBlit.self().getOtherCloneUrls(repositoryName));
+		
+		String primaryUrl = ArrayUtils.isEmpty(repositoryUrls) ? "" : repositoryUrls.remove(0);
+		add(new RepositoryUrlPanel("repositoryCloneUrl", primaryUrl));
 
-		add(new Label("repositoryCloneUrl", StringUtils.flattenStrings(repositoryUrls, "<br/>"))
-				.setEscapeModelStrings(false));
+		add(new Label("otherUrls", StringUtils.flattenStrings(repositoryUrls, "<br/>"))
+		.setEscapeModelStrings(false));
 
-		add(new LogPanel("commitsPanel", repositoryName, null, r, numberCommits, 0));
+		add(new LogPanel("commitsPanel", repositoryName, getRepositoryModel().HEAD, r, numberCommits, 0, getRepositoryModel().showRemoteBranches));
 		add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty());
-		add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs).hideIfEmpty());
+		add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs, false).hideIfEmpty());
 
 		if (getRepositoryModel().showReadme) {
 			String htmlText = null;
+			String markdownText = null;
+			String readme = null;
 			try {
 				RevCommit head = JGitUtils.getCommit(r, null);
 				List<String> markdownExtensions = GitBlit.getStrings(Keys.web.markdownExtensions);
-				List<PathModel> paths = JGitUtils.getFilesInPath(r, null, head);
-				String readme = null;
+				List<PathModel> paths = JGitUtils.getFilesInPath(r, null, head);				
 				for (PathModel path : paths) {
 					if (!path.isTree()) {
 						String name = path.name.toLowerCase();
@@ -152,15 +184,20 @@
 					}
 				}
 				if (!StringUtils.isEmpty(readme)) {
-					String markdownText = JGitUtils.getStringContent(r, head.getTree(), readme);
+					String [] encodings = GitBlit.getEncodings();
+					markdownText = JGitUtils.getStringContent(r, head.getTree(), readme, encodings);
 					htmlText = MarkdownUtils.transformMarkdown(markdownText);
 				}
 			} catch (ParseException p) {
-				error(p.getMessage());
+				markdownText = MessageFormat.format("<div class=\"alert alert-error\"><strong>{0}:</strong> {1}</div>{2}", getString("gb.error"), getString("gb.markdownFailure"), markdownText);
+				htmlText = StringUtils.breakLinesForHtml(markdownText);
 			}
+			Fragment fragment = new Fragment("readme", "markdownPanel");
+			fragment.add(new Label("readmeFile", readme));
 			// Add the html to the page
-			add(new Label("readme", htmlText).setEscapeModelStrings(false).setVisible(
-					!StringUtils.isEmpty(htmlText)));
+			Component content = new Label("readmeContent", htmlText).setEscapeModelStrings(false);
+			fragment.add(content.setVisible(!StringUtils.isEmpty(htmlText)));
+			add(fragment);
 		} else {
 			add(new Label("readme").setVisible(false));
 		}
@@ -179,7 +216,7 @@
 				&& GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
 			IChartData data = WicketUtils.getChartData(metrics);
 
-			ChartProvider provider = new ChartProvider(new Dimension(400, 100), ChartType.LINE,
+			ChartProvider provider = new ChartProvider(new Dimension(290, 100), ChartType.LINE,
 					data);
 			ChartAxis dateAxis = new ChartAxis(ChartAxisType.BOTTOM);
 			dateAxis.setLabels(new String[] { metrics.get(0).name,

--
Gitblit v1.9.1