Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

SummaryPage.java 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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.apache.wicket.markup.repeater.Item;
  29. import org.apache.wicket.markup.repeater.data.DataView;
  30. import org.apache.wicket.markup.repeater.data.ListDataProvider;
  31. import org.eclipse.jgit.lib.Repository;
  32. import org.eclipse.jgit.revwalk.RevCommit;
  33. import org.wicketstuff.googlecharts.Chart;
  34. import org.wicketstuff.googlecharts.ChartAxis;
  35. import org.wicketstuff.googlecharts.ChartAxisType;
  36. import org.wicketstuff.googlecharts.ChartProvider;
  37. import org.wicketstuff.googlecharts.ChartType;
  38. import org.wicketstuff.googlecharts.IChartData;
  39. import org.wicketstuff.googlecharts.LineStyle;
  40. import org.wicketstuff.googlecharts.MarkerType;
  41. import org.wicketstuff.googlecharts.ShapeMarker;
  42. import com.gitblit.Constants.AccessRestrictionType;
  43. import com.gitblit.GitBlit;
  44. import com.gitblit.Keys;
  45. import com.gitblit.models.Metric;
  46. import com.gitblit.models.PathModel;
  47. import com.gitblit.models.RepositoryModel;
  48. import com.gitblit.models.UserModel;
  49. import com.gitblit.utils.JGitUtils;
  50. import com.gitblit.utils.MarkdownUtils;
  51. import com.gitblit.utils.StringUtils;
  52. import com.gitblit.wicket.GitBlitWebSession;
  53. import com.gitblit.wicket.WicketUtils;
  54. import com.gitblit.wicket.panels.BranchesPanel;
  55. import com.gitblit.wicket.panels.LinkPanel;
  56. import com.gitblit.wicket.panels.LogPanel;
  57. import com.gitblit.wicket.panels.RepositoryUrlPanel;
  58. import com.gitblit.wicket.panels.TagsPanel;
  59. public class SummaryPage extends RepositoryPage {
  60. public SummaryPage(PageParameters params) {
  61. super(params);
  62. int numberCommits = GitBlit.getInteger(Keys.web.summaryCommitCount, 20);
  63. if (numberCommits <= 0) {
  64. numberCommits = 20;
  65. }
  66. int numberRefs = GitBlit.getInteger(Keys.web.summaryRefsCount, 5);
  67. Repository r = getRepository();
  68. final RepositoryModel model = getRepositoryModel();
  69. UserModel user = GitBlitWebSession.get().getUser();
  70. if (user == null) {
  71. user = UserModel.ANONYMOUS;
  72. }
  73. List<Metric> metrics = null;
  74. Metric metricsTotal = null;
  75. if (!model.skipSummaryMetrics && GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
  76. metrics = GitBlit.self().getRepositoryDefaultMetrics(model, r);
  77. metricsTotal = metrics.remove(0);
  78. }
  79. addSyndicationDiscoveryLink();
  80. // repository description
  81. add(new Label("repositoryDescription", getRepositoryModel().description));
  82. // owner links
  83. final List<String> owners = new ArrayList<String>(getRepositoryModel().owners);
  84. ListDataProvider<String> ownersDp = new ListDataProvider<String>(owners);
  85. DataView<String> ownersView = new DataView<String>("repositoryOwners", ownersDp) {
  86. private static final long serialVersionUID = 1L;
  87. int counter = 0;
  88. public void populateItem(final Item<String> item) {
  89. UserModel ownerModel = GitBlit.self().getUserModel(item.getModelObject());
  90. if (ownerModel != null) {
  91. item.add(new LinkPanel("owner", null, ownerModel.getDisplayName(), UserPage.class,
  92. WicketUtils.newUsernameParameter(ownerModel.username)).setRenderBodyOnly(true));
  93. } else {
  94. item.add(new Label("owner").setVisible(false));
  95. }
  96. counter++;
  97. item.add(new Label("comma", ",").setVisible(counter < owners.size()));
  98. item.setRenderBodyOnly(true);
  99. }
  100. };
  101. ownersView.setRenderBodyOnly(true);
  102. add(ownersView);
  103. add(WicketUtils.createTimestampLabel("repositoryLastChange",
  104. JGitUtils.getLastChange(r), getTimeZone(), getTimeUtils()));
  105. if (metricsTotal == null) {
  106. add(new Label("branchStats", ""));
  107. } else {
  108. add(new Label("branchStats",
  109. MessageFormat.format(getString("gb.branchStats"), metricsTotal.count,
  110. metricsTotal.tag, getTimeUtils().duration(metricsTotal.duration))));
  111. }
  112. add(new BookmarkablePageLink<Void>("metrics", MetricsPage.class,
  113. WicketUtils.newRepositoryParameter(repositoryName)));
  114. if (GitBlit.getBoolean(Keys.git.enableGitServlet, true)) {
  115. AccessRestrictionType accessRestriction = getRepositoryModel().accessRestriction;
  116. switch (accessRestriction) {
  117. case NONE:
  118. add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
  119. break;
  120. case PUSH:
  121. add(WicketUtils.newImage("accessRestrictionIcon", "lock_go_16x16.png",
  122. getAccessRestrictions().get(accessRestriction)));
  123. break;
  124. case CLONE:
  125. add(WicketUtils.newImage("accessRestrictionIcon", "lock_pull_16x16.png",
  126. getAccessRestrictions().get(accessRestriction)));
  127. break;
  128. case VIEW:
  129. add(WicketUtils.newImage("accessRestrictionIcon", "shield_16x16.png",
  130. getAccessRestrictions().get(accessRestriction)));
  131. break;
  132. default:
  133. add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
  134. }
  135. } else {
  136. add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
  137. }
  138. add(new RepositoryUrlPanel("repositoryUrlPanel", false, user, model, getLocalizer(), this));
  139. add(new LogPanel("commitsPanel", repositoryName, getRepositoryModel().HEAD, r, numberCommits, 0, getRepositoryModel().showRemoteBranches));
  140. add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty());
  141. add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs, false).hideIfEmpty());
  142. if (getRepositoryModel().showReadme) {
  143. String htmlText = null;
  144. String markdownText = null;
  145. String readme = null;
  146. try {
  147. RevCommit head = JGitUtils.getCommit(r, null);
  148. List<String> markdownExtensions = GitBlit.getStrings(Keys.web.markdownExtensions);
  149. List<PathModel> paths = JGitUtils.getFilesInPath(r, null, head);
  150. for (PathModel path : paths) {
  151. if (!path.isTree()) {
  152. String name = path.name.toLowerCase();
  153. if (name.startsWith("readme")) {
  154. if (name.indexOf('.') > -1) {
  155. String ext = name.substring(name.lastIndexOf('.') + 1);
  156. if (markdownExtensions.contains(ext)) {
  157. readme = path.name;
  158. break;
  159. }
  160. }
  161. }
  162. }
  163. }
  164. if (!StringUtils.isEmpty(readme)) {
  165. String [] encodings = GitBlit.getEncodings();
  166. markdownText = JGitUtils.getStringContent(r, head.getTree(), readme, encodings);
  167. htmlText = MarkdownUtils.transformMarkdown(markdownText);
  168. }
  169. } catch (ParseException p) {
  170. markdownText = MessageFormat.format("<div class=\"alert alert-error\"><strong>{0}:</strong> {1}</div>{2}", getString("gb.error"), getString("gb.markdownFailure"), markdownText);
  171. htmlText = StringUtils.breakLinesForHtml(markdownText);
  172. }
  173. Fragment fragment = new Fragment("readme", "markdownPanel");
  174. fragment.add(new Label("readmeFile", readme));
  175. // Add the html to the page
  176. Component content = new Label("readmeContent", htmlText).setEscapeModelStrings(false);
  177. fragment.add(content.setVisible(!StringUtils.isEmpty(htmlText)));
  178. add(fragment);
  179. } else {
  180. add(new Label("readme").setVisible(false));
  181. }
  182. // Display an activity line graph
  183. insertActivityGraph(metrics);
  184. }
  185. @Override
  186. protected String getPageName() {
  187. return getString("gb.summary");
  188. }
  189. private void insertActivityGraph(List<Metric> metrics) {
  190. if ((metrics != null) && (metrics.size() > 0)
  191. && GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
  192. IChartData data = WicketUtils.getChartData(metrics);
  193. ChartProvider provider = new ChartProvider(new Dimension(290, 100), ChartType.LINE,
  194. data);
  195. ChartAxis dateAxis = new ChartAxis(ChartAxisType.BOTTOM);
  196. dateAxis.setLabels(new String[] { metrics.get(0).name,
  197. metrics.get(metrics.size() / 2).name, metrics.get(metrics.size() - 1).name });
  198. provider.addAxis(dateAxis);
  199. ChartAxis commitAxis = new ChartAxis(ChartAxisType.LEFT);
  200. commitAxis.setLabels(new String[] { "",
  201. String.valueOf((int) WicketUtils.maxValue(metrics)) });
  202. provider.addAxis(commitAxis);
  203. provider.setLineStyles(new LineStyle[] { new LineStyle(2, 4, 0), new LineStyle(0, 4, 1) });
  204. provider.addShapeMarker(new ShapeMarker(MarkerType.CIRCLE, Color.BLUE, 1, -1, 5));
  205. add(new Chart("commitsChart", provider));
  206. } else {
  207. add(WicketUtils.newBlankImage("commitsChart"));
  208. }
  209. }
  210. }