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.

LogPanel.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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.panels;
  17. import java.util.Date;
  18. import java.util.List;
  19. import java.util.Map;
  20. import org.apache.wicket.markup.html.basic.Label;
  21. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  22. import org.apache.wicket.markup.repeater.Item;
  23. import org.apache.wicket.markup.repeater.data.DataView;
  24. import org.apache.wicket.markup.repeater.data.ListDataProvider;
  25. import org.apache.wicket.model.StringResourceModel;
  26. import org.eclipse.jgit.lib.ObjectId;
  27. import org.eclipse.jgit.lib.Repository;
  28. import org.eclipse.jgit.revwalk.RevCommit;
  29. import com.gitblit.GitBlit;
  30. import com.gitblit.Keys;
  31. import com.gitblit.utils.JGitUtils;
  32. import com.gitblit.utils.JGitUtils.SearchType;
  33. import com.gitblit.utils.StringUtils;
  34. import com.gitblit.wicket.LinkPanel;
  35. import com.gitblit.wicket.WicketUtils;
  36. import com.gitblit.wicket.pages.CommitDiffPage;
  37. import com.gitblit.wicket.pages.CommitPage;
  38. import com.gitblit.wicket.pages.LogPage;
  39. import com.gitblit.wicket.pages.SearchPage;
  40. import com.gitblit.wicket.pages.SummaryPage;
  41. import com.gitblit.wicket.pages.TreePage;
  42. public class LogPanel extends BasePanel {
  43. private static final long serialVersionUID = 1L;
  44. private boolean hasMore = false;
  45. public LogPanel(String wicketId, final String repositoryName, final String objectId, Repository r, int limit, int pageOffset) {
  46. super(wicketId);
  47. boolean pageResults = limit <= 0;
  48. int itemsPerPage = GitBlit.self().settings().getInteger(Keys.web.itemsPerPage, 50);
  49. if (itemsPerPage <= 1) {
  50. itemsPerPage = 50;
  51. }
  52. final Map<ObjectId, List<String>> allRefs = JGitUtils.getAllRefs(r);
  53. List<RevCommit> commits;
  54. if (pageResults) {
  55. // Paging result set
  56. commits = JGitUtils.getRevLog(r, objectId, pageOffset * itemsPerPage, itemsPerPage);
  57. } else {
  58. // Fixed size result set
  59. commits = JGitUtils.getRevLog(r, objectId, 0, limit);
  60. }
  61. // inaccurate way to determine if there are more commits.
  62. // works unless commits.size() represents the exact end.
  63. hasMore = commits.size() >= itemsPerPage;
  64. // header
  65. if (pageResults) {
  66. // shortlog page
  67. // show repository summary page link
  68. add(new LinkPanel("header", "title", repositoryName, SummaryPage.class, WicketUtils.newRepositoryParameter(repositoryName)));
  69. } else {
  70. // summary page
  71. // show shortlog page link
  72. add(new LinkPanel("header", "title", new StringResourceModel("gb.log", this, null), LogPage.class, WicketUtils.newRepositoryParameter(repositoryName)));
  73. }
  74. ListDataProvider<RevCommit> dp = new ListDataProvider<RevCommit>(commits);
  75. DataView<RevCommit> logView = new DataView<RevCommit>("commit", dp) {
  76. private static final long serialVersionUID = 1L;
  77. int counter = 0;
  78. public void populateItem(final Item<RevCommit> item) {
  79. final RevCommit entry = item.getModelObject();
  80. final Date date = JGitUtils.getCommitDate(entry);
  81. item.add(WicketUtils.createDateLabel("commitDate", date, getTimeZone()));
  82. // author search link
  83. String author = entry.getAuthorIdent().getName();
  84. LinkPanel authorLink = new LinkPanel("commitAuthor", "list", author, SearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId, author, SearchType.AUTHOR));
  85. setPersonSearchTooltip(authorLink, author, SearchType.AUTHOR);
  86. item.add(authorLink);
  87. // merge icon
  88. if (entry.getParentCount() > 1) {
  89. item.add(WicketUtils.newImage("commitIcon", "commit_merge_16x16.png"));
  90. } else {
  91. item.add(WicketUtils.newBlankImage("commitIcon"));
  92. }
  93. // short message
  94. String shortMessage = entry.getShortMessage();
  95. String trimmedMessage = StringUtils.trimShortLog(shortMessage);
  96. LinkPanel shortlog = new LinkPanel("commitShortMessage", "list subject", trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName()));
  97. if (!shortMessage.equals(trimmedMessage)) {
  98. WicketUtils.setHtmlTooltip(shortlog, shortMessage);
  99. }
  100. item.add(shortlog);
  101. item.add(new RefsPanel("commitRefs", repositoryName, entry, allRefs));
  102. item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));
  103. item.add(new BookmarkablePageLink<Void>("diff", CommitDiffPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));
  104. item.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));
  105. WicketUtils.setAlternatingBackground(item, counter);
  106. counter++;
  107. }
  108. };
  109. add(logView);
  110. // determine to show pager, more, or neither
  111. if (limit <= 0) {
  112. // no display limit
  113. add(new Label("moreLogs", "").setVisible(false));
  114. } else {
  115. if (pageResults) {
  116. // paging
  117. add(new Label("moreLogs", "").setVisible(false));
  118. } else {
  119. // more
  120. if (commits.size() == limit) {
  121. // show more
  122. add(new LinkPanel("moreLogs", "link", new StringResourceModel("gb.moreLogs", this, null), LogPage.class, WicketUtils.newRepositoryParameter(repositoryName)));
  123. } else {
  124. // no more
  125. add(new Label("moreLogs", "").setVisible(false));
  126. }
  127. }
  128. }
  129. }
  130. public boolean hasMore() {
  131. return hasMore;
  132. }
  133. }