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

13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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.Constants;
  30. import com.gitblit.GitBlit;
  31. import com.gitblit.Keys;
  32. import com.gitblit.models.RefModel;
  33. import com.gitblit.utils.JGitUtils;
  34. import com.gitblit.utils.StringUtils;
  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.GitSearchPage;
  40. import com.gitblit.wicket.pages.TreePage;
  41. public class LogPanel extends BasePanel {
  42. private static final long serialVersionUID = 1L;
  43. private boolean hasMore;
  44. public LogPanel(String wicketId, final String repositoryName, final String objectId,
  45. Repository r, int limit, int pageOffset, boolean showRemoteRefs) {
  46. super(wicketId);
  47. boolean pageResults = limit <= 0;
  48. int itemsPerPage = GitBlit.getInteger(Keys.web.itemsPerPage, 50);
  49. if (itemsPerPage <= 1) {
  50. itemsPerPage = 50;
  51. }
  52. final Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(r, showRemoteRefs);
  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. add(new Label("header", objectId));
  68. } else {
  69. // summary page
  70. // show shortlog page link
  71. add(new LinkPanel("header", "title", objectId, LogPage.class,
  72. 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;
  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(), getTimeUtils()));
  82. // author search link
  83. String author = entry.getAuthorIdent().getName();
  84. LinkPanel authorLink = new LinkPanel("commitAuthor", "list", author,
  85. GitSearchPage.class, WicketUtils.newSearchParameter(repositoryName,
  86. objectId, author, Constants.SearchType.AUTHOR));
  87. setPersonSearchTooltip(authorLink, author, Constants.SearchType.AUTHOR);
  88. item.add(authorLink);
  89. // merge icon
  90. if (entry.getParentCount() > 1) {
  91. item.add(WicketUtils.newImage("commitIcon", "commit_merge_16x16.png"));
  92. } else {
  93. item.add(WicketUtils.newBlankImage("commitIcon"));
  94. }
  95. // short message
  96. String shortMessage = entry.getShortMessage();
  97. String trimmedMessage = shortMessage;
  98. if (allRefs.containsKey(entry.getId())) {
  99. trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG_REFS);
  100. } else {
  101. trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG);
  102. }
  103. LinkPanel shortlog = new LinkPanel("commitShortMessage", "list subject",
  104. trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(
  105. repositoryName, entry.getName()));
  106. if (!shortMessage.equals(trimmedMessage)) {
  107. WicketUtils.setHtmlTooltip(shortlog, shortMessage);
  108. }
  109. item.add(shortlog);
  110. item.add(new RefsPanel("commitRefs", repositoryName, entry, allRefs));
  111. item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils
  112. .newObjectParameter(repositoryName, entry.getName())));
  113. item.add(new BookmarkablePageLink<Void>("diff", CommitDiffPage.class, WicketUtils
  114. .newObjectParameter(repositoryName, entry.getName())).setEnabled(entry
  115. .getParentCount() > 0));
  116. item.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils
  117. .newObjectParameter(repositoryName, entry.getName())));
  118. WicketUtils.setAlternatingBackground(item, counter);
  119. counter++;
  120. }
  121. };
  122. add(logView);
  123. // determine to show pager, more, or neither
  124. if (limit <= 0) {
  125. // no display limit
  126. add(new Label("moreLogs", "").setVisible(false));
  127. } else {
  128. if (pageResults) {
  129. // paging
  130. add(new Label("moreLogs", "").setVisible(false));
  131. } else {
  132. // more
  133. if (commits.size() == limit) {
  134. // show more
  135. add(new LinkPanel("moreLogs", "link", new StringResourceModel("gb.moreLogs",
  136. this, null), LogPage.class,
  137. WicketUtils.newRepositoryParameter(repositoryName)));
  138. } else {
  139. // no more
  140. add(new Label("moreLogs", "").setVisible(false));
  141. }
  142. }
  143. }
  144. }
  145. public boolean hasMore() {
  146. return hasMore;
  147. }
  148. }