Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

SummaryPage.java 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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.PageParameters;
  24. import org.apache.wicket.markup.html.basic.Label;
  25. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  26. import org.eclipse.jgit.lib.Repository;
  27. import org.eclipse.jgit.revwalk.RevCommit;
  28. import org.wicketstuff.googlecharts.Chart;
  29. import org.wicketstuff.googlecharts.ChartAxis;
  30. import org.wicketstuff.googlecharts.ChartAxisType;
  31. import org.wicketstuff.googlecharts.ChartProvider;
  32. import org.wicketstuff.googlecharts.ChartType;
  33. import org.wicketstuff.googlecharts.IChartData;
  34. import org.wicketstuff.googlecharts.LineStyle;
  35. import org.wicketstuff.googlecharts.MarkerType;
  36. import org.wicketstuff.googlecharts.ShapeMarker;
  37. import com.gitblit.Constants;
  38. import com.gitblit.Constants.AccessRestrictionType;
  39. import com.gitblit.GitBlit;
  40. import com.gitblit.Keys;
  41. import com.gitblit.models.Metric;
  42. import com.gitblit.models.PathModel;
  43. import com.gitblit.utils.JGitUtils;
  44. import com.gitblit.utils.MarkdownUtils;
  45. import com.gitblit.utils.MetricUtils;
  46. import com.gitblit.utils.StringUtils;
  47. import com.gitblit.utils.TimeUtils;
  48. import com.gitblit.wicket.WicketUtils;
  49. import com.gitblit.wicket.panels.BranchesPanel;
  50. import com.gitblit.wicket.panels.LogPanel;
  51. import com.gitblit.wicket.panels.TagsPanel;
  52. public class SummaryPage extends RepositoryPage {
  53. public SummaryPage(PageParameters params) {
  54. super(params);
  55. int numCommitsDef = 20;
  56. int numRefsDef = 5;
  57. int numberCommits = GitBlit.getInteger(Keys.web.summaryCommitCount, numCommitsDef);
  58. if (numberCommits <= 0) {
  59. numberCommits = numCommitsDef;
  60. }
  61. int numberRefs = GitBlit.getInteger(Keys.web.summaryRefsCount, numRefsDef);
  62. if (numberRefs <= 0) {
  63. numberRefs = numRefsDef;
  64. }
  65. Repository r = getRepository();
  66. List<Metric> metrics = null;
  67. Metric metricsTotal = null;
  68. if (GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
  69. metrics = MetricUtils.getDateMetrics(r, null, true, null);
  70. metricsTotal = metrics.remove(0);
  71. }
  72. addSyndicationDiscoveryLink();
  73. // repository description
  74. add(new Label("repositoryDescription", getRepositoryModel().description));
  75. add(new Label("repositoryOwner", getRepositoryModel().owner));
  76. add(WicketUtils.createTimestampLabel("repositoryLastChange", JGitUtils.getLastChange(r),
  77. getTimeZone()));
  78. if (metricsTotal == null) {
  79. add(new Label("branchStats", ""));
  80. } else {
  81. add(new Label("branchStats",
  82. MessageFormat.format("{0} commits and {1} tags in {2}", metricsTotal.count,
  83. metricsTotal.tag, TimeUtils.duration(metricsTotal.duration))));
  84. }
  85. add(new BookmarkablePageLink<Void>("metrics", MetricsPage.class,
  86. WicketUtils.newRepositoryParameter(repositoryName)));
  87. List<String> repositoryUrls = new ArrayList<String>();
  88. if (GitBlit.getBoolean(Keys.git.enableGitServlet, true)) {
  89. AccessRestrictionType accessRestriction = getRepositoryModel().accessRestriction;
  90. switch (accessRestriction) {
  91. case NONE:
  92. add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
  93. break;
  94. case PUSH:
  95. add(WicketUtils.newImage("accessRestrictionIcon", "lock_go_16x16.png",
  96. getAccessRestrictions().get(accessRestriction)));
  97. break;
  98. case CLONE:
  99. add(WicketUtils.newImage("accessRestrictionIcon", "lock_pull_16x16.png",
  100. getAccessRestrictions().get(accessRestriction)));
  101. break;
  102. case VIEW:
  103. add(WicketUtils.newImage("accessRestrictionIcon", "shield_16x16.png",
  104. getAccessRestrictions().get(accessRestriction)));
  105. break;
  106. default:
  107. add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
  108. }
  109. StringBuilder sb = new StringBuilder();
  110. sb.append(WicketUtils.getHostURL(getRequestCycle().getRequest()));
  111. sb.append(Constants.GIT_PATH);
  112. sb.append(repositoryName);
  113. repositoryUrls.add(sb.toString());
  114. } else {
  115. add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
  116. }
  117. repositoryUrls.addAll(GitBlit.self().getOtherCloneUrls(repositoryName));
  118. add(new Label("repositoryCloneUrl", StringUtils.flattenStrings(repositoryUrls, "<br/>"))
  119. .setEscapeModelStrings(false));
  120. add(new LogPanel("commitsPanel", repositoryName, null, r, numberCommits, 0));
  121. add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty());
  122. add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs).hideIfEmpty());
  123. if (getRepositoryModel().showReadme) {
  124. String htmlText = null;
  125. try {
  126. RevCommit head = JGitUtils.getCommit(r, null);
  127. List<String> markdownExtensions = GitBlit.getStrings(Keys.web.markdownExtensions);
  128. List<PathModel> paths = JGitUtils.getFilesInPath(r, null, head);
  129. String readme = null;
  130. for (PathModel path : paths) {
  131. if (!path.isTree()) {
  132. String name = path.name.toLowerCase();
  133. if (name.startsWith("readme")) {
  134. if (name.indexOf('.') > -1) {
  135. String ext = name.substring(name.lastIndexOf('.') + 1);
  136. if (markdownExtensions.contains(ext)) {
  137. readme = path.name;
  138. break;
  139. }
  140. }
  141. }
  142. }
  143. }
  144. if (!StringUtils.isEmpty(readme)) {
  145. String markdownText = JGitUtils.getStringContent(r, head.getTree(), readme);
  146. htmlText = MarkdownUtils.transformMarkdown(markdownText);
  147. }
  148. } catch (ParseException p) {
  149. error(p.getMessage());
  150. }
  151. // Add the html to the page
  152. add(new Label("readme", htmlText).setEscapeModelStrings(false).setVisible(
  153. !StringUtils.isEmpty(htmlText)));
  154. } else {
  155. add(new Label("readme").setVisible(false));
  156. }
  157. // Display an activity line graph
  158. insertActivityGraph(metrics);
  159. }
  160. @Override
  161. protected String getPageName() {
  162. return getString("gb.summary");
  163. }
  164. private void insertActivityGraph(List<Metric> metrics) {
  165. if ((metrics != null) && (metrics.size() > 0)
  166. && GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
  167. IChartData data = WicketUtils.getChartData(metrics);
  168. ChartProvider provider = new ChartProvider(new Dimension(400, 100), ChartType.LINE,
  169. data);
  170. ChartAxis dateAxis = new ChartAxis(ChartAxisType.BOTTOM);
  171. dateAxis.setLabels(new String[] { metrics.get(0).name,
  172. metrics.get(metrics.size() / 2).name, metrics.get(metrics.size() - 1).name });
  173. provider.addAxis(dateAxis);
  174. ChartAxis commitAxis = new ChartAxis(ChartAxisType.LEFT);
  175. commitAxis.setLabels(new String[] { "",
  176. String.valueOf((int) WicketUtils.maxValue(metrics)) });
  177. provider.addAxis(commitAxis);
  178. provider.setLineStyles(new LineStyle[] { new LineStyle(2, 4, 0), new LineStyle(0, 4, 1) });
  179. provider.addShapeMarker(new ShapeMarker(MarkerType.CIRCLE, Color.BLUE, 1, -1, 5));
  180. add(new Chart("commitsChart", provider));
  181. } else {
  182. add(WicketUtils.newBlankImage("commitsChart"));
  183. }
  184. }
  185. }