You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SummaryPage.java 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright 2011 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.wicket.pages;
  17. import java.awt.Color;
  18. import java.awt.Dimension;
  19. import java.text.MessageFormat;
  20. import java.text.ParseException;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. import org.apache.wicket.Component;
  24. import org.apache.wicket.PageParameters;
  25. import org.apache.wicket.markup.html.basic.Label;
  26. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  27. import org.apache.wicket.markup.html.panel.Fragment;
  28. import org.eclipse.jgit.lib.Repository;
  29. import org.eclipse.jgit.revwalk.RevCommit;
  30. import org.wicketstuff.googlecharts.Chart;
  31. import org.wicketstuff.googlecharts.ChartAxis;
  32. import org.wicketstuff.googlecharts.ChartAxisType;
  33. import org.wicketstuff.googlecharts.ChartProvider;
  34. import org.wicketstuff.googlecharts.ChartType;
  35. import org.wicketstuff.googlecharts.IChartData;
  36. import org.wicketstuff.googlecharts.LineStyle;
  37. import org.wicketstuff.googlecharts.MarkerType;
  38. import org.wicketstuff.googlecharts.ShapeMarker;
  39. import com.gitblit.Constants.AccessRestrictionType;
  40. import com.gitblit.GitBlit;
  41. import com.gitblit.Keys;
  42. import com.gitblit.models.Metric;
  43. import com.gitblit.models.PathModel;
  44. import com.gitblit.models.RepositoryModel;
  45. import com.gitblit.utils.ArrayUtils;
  46. import com.gitblit.utils.JGitUtils;
  47. import com.gitblit.utils.MarkdownUtils;
  48. import com.gitblit.utils.StringUtils;
  49. import com.gitblit.wicket.WicketUtils;
  50. import com.gitblit.wicket.panels.BranchesPanel;
  51. import com.gitblit.wicket.panels.LogPanel;
  52. import com.gitblit.wicket.panels.RepositoryUrlPanel;
  53. import com.gitblit.wicket.panels.TagsPanel;
  54. public class SummaryPage extends RepositoryPage {
  55. public SummaryPage(PageParameters params) {
  56. super(params);
  57. int numberCommits = GitBlit.getInteger(Keys.web.summaryCommitCount, 20);
  58. if (numberCommits <= 0) {
  59. numberCommits = 20;
  60. }
  61. int numberRefs = GitBlit.getInteger(Keys.web.summaryRefsCount, 5);
  62. Repository r = getRepository();
  63. RepositoryModel model = getRepositoryModel();
  64. List<Metric> metrics = null;
  65. Metric metricsTotal = null;
  66. if (!model.skipSummaryMetrics && GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
  67. metrics = GitBlit.self().getRepositoryDefaultMetrics(model, r);
  68. metricsTotal = metrics.remove(0);
  69. }
  70. addSyndicationDiscoveryLink();
  71. // repository description
  72. add(new Label("repositoryDescription", getRepositoryModel().description));
  73. add(new Label("repositoryOwner", getRepositoryModel().owner));
  74. add(WicketUtils.createTimestampLabel("repositoryLastChange",
  75. JGitUtils.getLastChange(r), getTimeZone(), getTimeUtils()));
  76. if (metricsTotal == null) {
  77. add(new Label("branchStats", ""));
  78. } else {
  79. add(new Label("branchStats",
  80. MessageFormat.format(getString("gb.branchStats"), metricsTotal.count,
  81. metricsTotal.tag, getTimeUtils().duration(metricsTotal.duration))));
  82. }
  83. add(new BookmarkablePageLink<Void>("metrics", MetricsPage.class,
  84. WicketUtils.newRepositoryParameter(repositoryName)));
  85. List<String> repositoryUrls = new ArrayList<String>();
  86. if (GitBlit.getBoolean(Keys.git.enableGitServlet, true)) {
  87. AccessRestrictionType accessRestriction = getRepositoryModel().accessRestriction;
  88. switch (accessRestriction) {
  89. case NONE:
  90. add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
  91. break;
  92. case PUSH:
  93. add(WicketUtils.newImage("accessRestrictionIcon", "lock_go_16x16.png",
  94. getAccessRestrictions().get(accessRestriction)));
  95. break;
  96. case CLONE:
  97. add(WicketUtils.newImage("accessRestrictionIcon", "lock_pull_16x16.png",
  98. getAccessRestrictions().get(accessRestriction)));
  99. break;
  100. case VIEW:
  101. add(WicketUtils.newImage("accessRestrictionIcon", "shield_16x16.png",
  102. getAccessRestrictions().get(accessRestriction)));
  103. break;
  104. default:
  105. add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
  106. }
  107. // add the Gitblit repository url
  108. repositoryUrls.add(getRepositoryUrl(getRepositoryModel()));
  109. } else {
  110. add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
  111. }
  112. repositoryUrls.addAll(GitBlit.self().getOtherCloneUrls(repositoryName));
  113. String primaryUrl = ArrayUtils.isEmpty(repositoryUrls) ? "" : repositoryUrls.remove(0);
  114. add(new RepositoryUrlPanel("repositoryCloneUrl", primaryUrl));
  115. add(new Label("otherUrls", StringUtils.flattenStrings(repositoryUrls, "<br/>"))
  116. .setEscapeModelStrings(false));
  117. add(new LogPanel("commitsPanel", repositoryName, getRepositoryModel().HEAD, r, numberCommits, 0, getRepositoryModel().showRemoteBranches));
  118. add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty());
  119. add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs, false).hideIfEmpty());
  120. if (getRepositoryModel().showReadme) {
  121. String htmlText = null;
  122. String markdownText = null;
  123. String readme = null;
  124. try {
  125. RevCommit head = JGitUtils.getCommit(r, null);
  126. List<String> markdownExtensions = GitBlit.getStrings(Keys.web.markdownExtensions);
  127. List<PathModel> paths = JGitUtils.getFilesInPath(r, null, head);
  128. for (PathModel path : paths) {
  129. if (!path.isTree()) {
  130. String name = path.name.toLowerCase();
  131. if (name.startsWith("readme")) {
  132. if (name.indexOf('.') > -1) {
  133. String ext = name.substring(name.lastIndexOf('.') + 1);
  134. if (markdownExtensions.contains(ext)) {
  135. readme = path.name;
  136. break;
  137. }
  138. }
  139. }
  140. }
  141. }
  142. if (!StringUtils.isEmpty(readme)) {
  143. String [] encodings = GitBlit.getEncodings();
  144. markdownText = JGitUtils.getStringContent(r, head.getTree(), readme, encodings);
  145. htmlText = MarkdownUtils.transformMarkdown(markdownText);
  146. }
  147. } catch (ParseException p) {
  148. markdownText = MessageFormat.format("<div class=\"alert alert-error\"><strong>{0}:</strong> {1}</div>{2}", getString("gb.error"), getString("gb.markdownFailure"), markdownText);
  149. htmlText = StringUtils.breakLinesForHtml(markdownText);
  150. }
  151. Fragment fragment = new Fragment("readme", "markdownPanel");
  152. fragment.add(new Label("readmeFile", readme));
  153. // Add the html to the page
  154. Component content = new Label("readmeContent", htmlText).setEscapeModelStrings(false);
  155. fragment.add(content.setVisible(!StringUtils.isEmpty(htmlText)));
  156. add(fragment);
  157. } else {
  158. add(new Label("readme").setVisible(false));
  159. }
  160. // Display an activity line graph
  161. insertActivityGraph(metrics);
  162. }
  163. @Override
  164. protected String getPageName() {
  165. return getString("gb.summary");
  166. }
  167. private void insertActivityGraph(List<Metric> metrics) {
  168. if ((metrics != null) && (metrics.size() > 0)
  169. && GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
  170. IChartData data = WicketUtils.getChartData(metrics);
  171. ChartProvider provider = new ChartProvider(new Dimension(290, 100), ChartType.LINE,
  172. data);
  173. ChartAxis dateAxis = new ChartAxis(ChartAxisType.BOTTOM);
  174. dateAxis.setLabels(new String[] { metrics.get(0).name,
  175. metrics.get(metrics.size() / 2).name, metrics.get(metrics.size() - 1).name });
  176. provider.addAxis(dateAxis);
  177. ChartAxis commitAxis = new ChartAxis(ChartAxisType.LEFT);
  178. commitAxis.setLabels(new String[] { "",
  179. String.valueOf((int) WicketUtils.maxValue(metrics)) });
  180. provider.addAxis(commitAxis);
  181. provider.setLineStyles(new LineStyle[] { new LineStyle(2, 4, 0), new LineStyle(0, 4, 1) });
  182. provider.addShapeMarker(new ShapeMarker(MarkerType.CIRCLE, Color.BLUE, 1, -1, 5));
  183. add(new Chart("commitsChart", provider));
  184. } else {
  185. add(WicketUtils.newBlankImage("commitsChart"));
  186. }
  187. }
  188. }