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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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.GitBlit;
  29. import com.gitblit.Keys;
  30. import com.gitblit.models.Metric;
  31. import com.gitblit.models.RepositoryModel;
  32. import com.gitblit.models.UserModel;
  33. import com.gitblit.utils.JGitUtils;
  34. import com.gitblit.wicket.GitBlitWebSession;
  35. import com.gitblit.wicket.WicketUtils;
  36. import com.gitblit.wicket.charting.GoogleChart;
  37. import com.gitblit.wicket.charting.GoogleCharts;
  38. import com.gitblit.wicket.charting.GoogleLineChart;
  39. import com.gitblit.wicket.panels.BranchesPanel;
  40. import com.gitblit.wicket.panels.LinkPanel;
  41. import com.gitblit.wicket.panels.PushesPanel;
  42. import com.gitblit.wicket.panels.RepositoryUrlPanel;
  43. import com.gitblit.wicket.panels.TagsPanel;
  44. public class OverviewPage extends RepositoryPage {
  45. public OverviewPage(PageParameters params) {
  46. super(params);
  47. int numberRefs = GitBlit.getInteger(Keys.web.summaryRefsCount, 5);
  48. Repository r = getRepository();
  49. final RepositoryModel model = getRepositoryModel();
  50. UserModel user = GitBlitWebSession.get().getUser();
  51. if (user == null) {
  52. user = UserModel.ANONYMOUS;
  53. }
  54. List<Metric> metrics = null;
  55. Metric metricsTotal = null;
  56. if (!model.skipSummaryMetrics && GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
  57. metrics = GitBlit.self().getRepositoryDefaultMetrics(model, r);
  58. metricsTotal = metrics.remove(0);
  59. }
  60. addSyndicationDiscoveryLink();
  61. // repository description
  62. add(new Label("repositoryDescription", getRepositoryModel().description));
  63. // owner links
  64. final List<String> owners = new ArrayList<String>(getRepositoryModel().owners);
  65. ListDataProvider<String> ownersDp = new ListDataProvider<String>(owners);
  66. DataView<String> ownersView = new DataView<String>("repositoryOwners", ownersDp) {
  67. private static final long serialVersionUID = 1L;
  68. int counter = 0;
  69. public void populateItem(final Item<String> item) {
  70. UserModel ownerModel = GitBlit.self().getUserModel(item.getModelObject());
  71. if (ownerModel != null) {
  72. item.add(new LinkPanel("owner", null, ownerModel.getDisplayName(), UserPage.class,
  73. WicketUtils.newUsernameParameter(ownerModel.username)).setRenderBodyOnly(true));
  74. } else {
  75. item.add(new Label("owner").setVisible(false));
  76. }
  77. counter++;
  78. item.add(new Label("comma", ",").setVisible(counter < owners.size()));
  79. item.setRenderBodyOnly(true);
  80. }
  81. };
  82. ownersView.setRenderBodyOnly(true);
  83. add(ownersView);
  84. add(WicketUtils.createTimestampLabel("repositoryLastChange",
  85. JGitUtils.getLastChange(r), getTimeZone(), getTimeUtils()));
  86. add(new Label("repositorySize", model.size));
  87. if (metricsTotal == null) {
  88. add(new Label("branchStats", ""));
  89. } else {
  90. add(new Label("branchStats",
  91. MessageFormat.format(getString("gb.branchStats"), metricsTotal.count,
  92. metricsTotal.tag, getTimeUtils().duration(metricsTotal.duration))));
  93. }
  94. add(new BookmarkablePageLink<Void>("metrics", MetricsPage.class,
  95. WicketUtils.newRepositoryParameter(repositoryName)));
  96. add(new RepositoryUrlPanel("repositoryUrlPanel", false, user, model));
  97. int pushCount = GitBlit.getInteger(Keys.web.overviewPushCount, 5);
  98. PushesPanel pushes = new PushesPanel("pushesPanel", getRepositoryModel(), r, pushCount, 0, false);
  99. add(pushes);
  100. add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty());
  101. add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs, false).hideIfEmpty());
  102. // Display an activity line graph
  103. insertActivityGraph(metrics);
  104. }
  105. @Override
  106. protected String getPageName() {
  107. return getString("gb.overview");
  108. }
  109. private void insertActivityGraph(List<Metric> metrics) {
  110. if ((metrics != null) && (metrics.size() > 0)
  111. && GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
  112. // daily line chart
  113. GoogleChart chart = new GoogleLineChart("chartDaily", "", "unit",
  114. getString("gb.commits"));
  115. for (Metric metric : metrics) {
  116. chart.addValue(metric.name, metric.count);
  117. }
  118. chart.setWidth(375);
  119. chart.setHeight(150);
  120. GoogleCharts charts = new GoogleCharts();
  121. charts.addChart(chart);
  122. add(new HeaderContributor(charts));
  123. }
  124. }
  125. }