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 8.5KB

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