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.

OverviewPage.java 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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.text.MessageFormat;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import org.apache.wicket.PageParameters;
  21. import org.apache.wicket.behavior.HeaderContributor;
  22. import org.apache.wicket.markup.html.basic.Label;
  23. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  24. import org.apache.wicket.markup.repeater.Item;
  25. import org.apache.wicket.markup.repeater.data.DataView;
  26. import org.apache.wicket.markup.repeater.data.ListDataProvider;
  27. import org.eclipse.jgit.lib.Repository;
  28. import com.gitblit.Keys;
  29. import com.gitblit.models.Metric;
  30. import com.gitblit.models.RepositoryModel;
  31. import com.gitblit.models.UserModel;
  32. import com.gitblit.utils.JGitUtils;
  33. import com.gitblit.wicket.CacheControl;
  34. import com.gitblit.wicket.CacheControl.LastModified;
  35. import com.gitblit.wicket.GitBlitWebSession;
  36. import com.gitblit.wicket.WicketUtils;
  37. import com.gitblit.wicket.charting.Chart;
  38. import com.gitblit.wicket.charting.Charts;
  39. import com.gitblit.wicket.charting.Flotr2Charts;
  40. import com.gitblit.wicket.panels.BranchesPanel;
  41. import com.gitblit.wicket.panels.LinkPanel;
  42. import com.gitblit.wicket.panels.ReflogPanel;
  43. import com.gitblit.wicket.panels.RepositoryUrlPanel;
  44. import com.gitblit.wicket.panels.TagsPanel;
  45. @CacheControl(LastModified.REPOSITORY)
  46. public class OverviewPage extends RepositoryPage {
  47. public OverviewPage(PageParameters params) {
  48. super(params);
  49. int numberRefs = app().settings().getInteger(Keys.web.summaryRefsCount, 5);
  50. Repository r = getRepository();
  51. final RepositoryModel model = getRepositoryModel();
  52. UserModel user = GitBlitWebSession.get().getUser();
  53. if (user == null) {
  54. user = UserModel.ANONYMOUS;
  55. }
  56. List<Metric> metrics = null;
  57. Metric metricsTotal = null;
  58. if (!model.skipSummaryMetrics && app().settings().getBoolean(Keys.web.generateActivityGraph, true)) {
  59. metrics = app().repositories().getRepositoryDefaultMetrics(model, r);
  60. metricsTotal = metrics.remove(0);
  61. }
  62. addSyndicationDiscoveryLink();
  63. // repository description
  64. add(new Label("repositoryDescription", getRepositoryModel().description));
  65. // owner links
  66. final List<String> owners = new ArrayList<String>(getRepositoryModel().owners);
  67. ListDataProvider<String> ownersDp = new ListDataProvider<String>(owners);
  68. DataView<String> ownersView = new DataView<String>("repositoryOwners", ownersDp) {
  69. private static final long serialVersionUID = 1L;
  70. int counter = 0;
  71. @Override
  72. public void populateItem(final Item<String> item) {
  73. String ownername = item.getModelObject();
  74. UserModel ownerModel = app().users().getUserModel(ownername);
  75. if (ownerModel != null) {
  76. item.add(new LinkPanel("owner", null, ownerModel.getDisplayName(), UserPage.class,
  77. WicketUtils.newUsernameParameter(ownerModel.username)).setRenderBodyOnly(true));
  78. } else {
  79. Label owner = new Label("owner", ownername);
  80. WicketUtils.setCssStyle(owner, "text-decoration: line-through;");
  81. WicketUtils.setHtmlTooltip(owner, MessageFormat.format(getString("gb.failedToFindAccount"), ownername));
  82. item.add(owner);
  83. }
  84. counter++;
  85. item.add(new Label("comma", ",").setVisible(counter < owners.size()));
  86. item.setRenderBodyOnly(true);
  87. }
  88. };
  89. ownersView.setRenderBodyOnly(true);
  90. add(ownersView);
  91. add(WicketUtils.createTimestampLabel("repositoryLastChange",
  92. JGitUtils.getLastChange(r).when, getTimeZone(), getTimeUtils()));
  93. add(new Label("repositorySize", model.size));
  94. if (metricsTotal == null) {
  95. add(new Label("branchStats", ""));
  96. } else {
  97. add(new Label("branchStats",
  98. MessageFormat.format(getString("gb.branchStats"), metricsTotal.count,
  99. metricsTotal.tag, getTimeUtils().duration(metricsTotal.duration))));
  100. }
  101. add(new BookmarkablePageLink<Void>("metrics", MetricsPage.class,
  102. WicketUtils.newRepositoryParameter(repositoryName)));
  103. add(new RepositoryUrlPanel("repositoryUrlPanel", false, user, model));
  104. int reflogCount = app().settings().getInteger(Keys.web.overviewReflogCount, 5);
  105. ReflogPanel reflog = new ReflogPanel("reflogPanel", getRepositoryModel(), r, reflogCount, 0);
  106. add(reflog);
  107. add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty());
  108. add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs, false).hideIfEmpty());
  109. // Display an activity line graph
  110. insertActivityGraph(metrics);
  111. }
  112. @Override
  113. protected String getPageName() {
  114. return getString("gb.overview");
  115. }
  116. private void insertActivityGraph(List<Metric> metrics) {
  117. if ((metrics != null) && (metrics.size() > 0)
  118. && app().settings().getBoolean(Keys.web.generateActivityGraph, true)) {
  119. Charts charts = new Flotr2Charts();
  120. // daily line chart
  121. Chart chart = charts.createLineChart("chartDaily", "", "unit",
  122. getString("gb.commits"));
  123. for (Metric metric : metrics) {
  124. chart.addValue(metric.name, metric.count);
  125. }
  126. chart.setWidth(375);
  127. chart.setHeight(150);
  128. charts.addChart(chart);
  129. add(new HeaderContributor(charts));
  130. }
  131. }
  132. }