From ed21d23885c2f112e5c5650e9436870b1ac99392 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Tue, 05 Jul 2011 17:32:45 -0400 Subject: [PATCH] Documentation. Added JavaDoc. Clarified repository access restriction. --- src/com/gitblit/wicket/pages/SummaryPage.java | 141 ++++++++++++++++++++-------------------------- 1 files changed, 62 insertions(+), 79 deletions(-) diff --git a/src/com/gitblit/wicket/pages/SummaryPage.java b/src/com/gitblit/wicket/pages/SummaryPage.java index 181de0d..e753e5d 100644 --- a/src/com/gitblit/wicket/pages/SummaryPage.java +++ b/src/com/gitblit/wicket/pages/SummaryPage.java @@ -18,16 +18,15 @@ import java.awt.Color; import java.awt.Dimension; import java.text.MessageFormat; +import java.text.ParseException; import java.util.ArrayList; import java.util.List; -import javax.servlet.http.HttpServletRequest; - import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.basic.Label; -import org.apache.wicket.protocol.http.WebRequest; +import org.apache.wicket.markup.html.link.BookmarkablePageLink; import org.eclipse.jgit.lib.Repository; -import org.wicketstuff.googlecharts.AbstractChartData; +import org.eclipse.jgit.revwalk.RevCommit; import org.wicketstuff.googlecharts.Chart; import org.wicketstuff.googlecharts.ChartAxis; import org.wicketstuff.googlecharts.ChartAxisType; @@ -43,7 +42,10 @@ import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.models.Metric; +import com.gitblit.models.PathModel; import com.gitblit.utils.JGitUtils; +import com.gitblit.utils.MarkdownUtils; +import com.gitblit.utils.MetricUtils; import com.gitblit.utils.StringUtils; import com.gitblit.utils.TimeUtils; import com.gitblit.wicket.WicketUtils; @@ -56,40 +58,37 @@ public SummaryPage(PageParameters params) { super(params); - int numCommitsDef = 20; - int numRefsDef = 5; - - int numberCommits = GitBlit.getInteger(Keys.web.summaryCommitCount, numCommitsDef); + int numberCommits = GitBlit.getInteger(Keys.web.summaryCommitCount, 20); if (numberCommits <= 0) { - numberCommits = numCommitsDef; + numberCommits = 20; } - - int numberRefs = GitBlit.getInteger(Keys.web.summaryRefsCount, numRefsDef); - if (numberRefs <= 0) { - numberRefs = numRefsDef; - } + int numberRefs = GitBlit.getInteger(Keys.web.summaryRefsCount, 5); Repository r = getRepository(); List<Metric> metrics = null; Metric metricsTotal = null; if (GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) { - metrics = JGitUtils.getDateMetrics(r); + metrics = MetricUtils.getDateMetrics(r, null, true, null); metricsTotal = metrics.remove(0); } + + addSyndicationDiscoveryLink(); // repository description add(new Label("repositoryDescription", getRepositoryModel().description)); add(new Label("repositoryOwner", getRepositoryModel().owner)); - add(WicketUtils.createTimestampLabel("repositoryLastChange", JGitUtils.getLastChange(r), + add(WicketUtils.createTimestampLabel("repositoryLastChange", JGitUtils.getLastChange(r, null), getTimeZone())); if (metricsTotal == null) { - add(new Label("repositoryStats", "")); + add(new Label("branchStats", "")); } else { - add(new Label("repositoryStats", MessageFormat.format( - "{0} commits and {1} tags in {2}", metricsTotal.count, metricsTotal.tag, - TimeUtils.duration(metricsTotal.duration)))); + add(new Label("branchStats", + MessageFormat.format("{0} commits and {1} tags in {2}", metricsTotal.count, + metricsTotal.tag, TimeUtils.duration(metricsTotal.duration)))); } + add(new BookmarkablePageLink<Void>("metrics", MetricsPage.class, + WicketUtils.newRepositoryParameter(repositoryName))); List<String> repositoryUrls = new ArrayList<String>(); @@ -114,18 +113,9 @@ default: add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false)); } - - HttpServletRequest req = ((WebRequest) getRequestCycle().getRequest()) - .getHttpServletRequest(); StringBuilder sb = new StringBuilder(); - sb.append(req.getScheme()); - sb.append("://"); - sb.append(req.getServerName()); - if ((req.getScheme().equals("http") && req.getServerPort() != 80) - || (req.getScheme().equals("https") && req.getServerPort() != 443)) { - sb.append(":" + req.getServerPort()); - } - sb.append(Constants.GIT_SERVLET_PATH); + sb.append(WicketUtils.getHostURL(getRequestCycle().getRequest())); + sb.append(Constants.GIT_PATH); sb.append(repositoryName); repositoryUrls.add(sb.toString()); } else { @@ -137,8 +127,44 @@ .setEscapeModelStrings(false)); add(new LogPanel("commitsPanel", repositoryName, null, r, numberCommits, 0)); - add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs)); - add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs)); + add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty()); + add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs).hideIfEmpty()); + + if (getRepositoryModel().showReadme) { + String htmlText = 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; + for (PathModel path : paths) { + if (!path.isTree()) { + String name = path.name.toLowerCase(); + + if (name.startsWith("readme")) { + if (name.indexOf('.') > -1) { + String ext = name.substring(name.lastIndexOf('.') + 1); + if (markdownExtensions.contains(ext)) { + readme = path.name; + break; + } + } + } + } + } + if (!StringUtils.isEmpty(readme)) { + String markdownText = JGitUtils.getStringContent(r, head.getTree(), readme); + htmlText = MarkdownUtils.transformMarkdown(markdownText); + } + } catch (ParseException p) { + error(p.getMessage()); + } + // Add the html to the page + add(new Label("readme", htmlText).setEscapeModelStrings(false).setVisible( + !StringUtils.isEmpty(htmlText))); + } else { + add(new Label("readme").setVisible(false)); + } // Display an activity line graph insertActivityGraph(metrics); @@ -152,7 +178,7 @@ private void insertActivityGraph(List<Metric> metrics) { if ((metrics != null) && (metrics.size() > 0) && GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) { - IChartData data = getChartData(metrics); + IChartData data = WicketUtils.getChartData(metrics); ChartProvider provider = new ChartProvider(new Dimension(400, 100), ChartType.LINE, data); @@ -162,9 +188,9 @@ provider.addAxis(dateAxis); ChartAxis commitAxis = new ChartAxis(ChartAxisType.LEFT); - commitAxis.setLabels(new String[] { "", String.valueOf((int) maxValue(metrics)) }); + commitAxis.setLabels(new String[] { "", + String.valueOf((int) WicketUtils.maxValue(metrics)) }); provider.addAxis(commitAxis); - provider.setLineStyles(new LineStyle[] { new LineStyle(2, 4, 0), new LineStyle(0, 4, 1) }); provider.addShapeMarker(new ShapeMarker(MarkerType.CIRCLE, Color.BLUE, 1, -1, 5)); @@ -172,48 +198,5 @@ } else { add(WicketUtils.newBlankImage("commitsChart")); } - } - - protected IChartData getChartData(List<Metric> metrics) { - final double[] commits = new double[metrics.size()]; - final double[] tags = new double[metrics.size()]; - int i = 0; - double max = 0; - for (Metric m : metrics) { - commits[i] = m.count; - if (m.tag > 0) { - tags[i] = m.count; - } else { - tags[i] = -1d; - } - max = Math.max(max, m.count); - i++; - } - IChartData data = new AbstractChartData(max) { - private static final long serialVersionUID = 1L; - - public double[][] getData() { - return new double[][] { commits, tags }; - } - }; - return data; - } - - protected String[] getNames(List<Metric> results) { - String[] names = new String[results.size()]; - for (int i = 0; i < results.size(); i++) { - names[i] = results.get(i).name; - } - return names; - } - - protected double maxValue(List<Metric> metrics) { - double max = Double.MIN_VALUE; - for (Metric m : metrics) { - if (m.count > max) { - max = m.count; - } - } - return max; } } -- Gitblit v1.9.1