Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DigestsPanel.java 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * Copyright 2013 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.text.DateFormat;
  18. import java.text.MessageFormat;
  19. import java.text.SimpleDateFormat;
  20. import java.util.ArrayList;
  21. import java.util.Calendar;
  22. import java.util.Date;
  23. import java.util.List;
  24. import java.util.TimeZone;
  25. import org.apache.wicket.markup.html.basic.Label;
  26. import org.apache.wicket.markup.repeater.Item;
  27. import org.apache.wicket.markup.repeater.data.DataView;
  28. import org.apache.wicket.markup.repeater.data.ListDataProvider;
  29. import org.eclipse.jgit.lib.PersonIdent;
  30. import com.gitblit.Constants;
  31. import com.gitblit.GitBlit;
  32. import com.gitblit.Keys;
  33. import com.gitblit.models.DailyLogEntry;
  34. import com.gitblit.models.RepositoryCommit;
  35. import com.gitblit.utils.StringUtils;
  36. import com.gitblit.utils.TimeUtils;
  37. import com.gitblit.wicket.WicketUtils;
  38. import com.gitblit.wicket.pages.CommitPage;
  39. import com.gitblit.wicket.pages.ComparePage;
  40. import com.gitblit.wicket.pages.SummaryPage;
  41. import com.gitblit.wicket.pages.TagPage;
  42. import com.gitblit.wicket.pages.TreePage;
  43. public class DigestsPanel extends BasePanel {
  44. private static final long serialVersionUID = 1L;
  45. private final boolean hasChanges;
  46. private boolean hasMore;
  47. public DigestsPanel(String wicketId, List<DailyLogEntry> digests) {
  48. super(wicketId);
  49. hasChanges = digests.size() > 0;
  50. final int hashLen = GitBlit.getInteger(Keys.web.shortCommitIdLength, 6);
  51. String dateFormat = GitBlit.getString(Keys.web.datestampLongFormat, "EEEE, MMMM d, yyyy");
  52. final TimeZone timezone = getTimeZone();
  53. final DateFormat df = new SimpleDateFormat(dateFormat);
  54. df.setTimeZone(timezone);
  55. final Calendar cal = Calendar.getInstance(timezone);
  56. ListDataProvider<DailyLogEntry> dp = new ListDataProvider<DailyLogEntry>(digests);
  57. DataView<DailyLogEntry> pushView = new DataView<DailyLogEntry>("change", dp) {
  58. private static final long serialVersionUID = 1L;
  59. public void populateItem(final Item<DailyLogEntry> logItem) {
  60. final DailyLogEntry change = logItem.getModelObject();
  61. String fullRefName = change.getChangedRefs().get(0);
  62. String shortRefName = fullRefName;
  63. boolean isTag = false;
  64. if (shortRefName.startsWith(Constants.R_HEADS)) {
  65. shortRefName = shortRefName.substring(Constants.R_HEADS.length());
  66. } else if (shortRefName.startsWith(Constants.R_TAGS)) {
  67. shortRefName = shortRefName.substring(Constants.R_TAGS.length());
  68. isTag = true;
  69. }
  70. String fuzzydate;
  71. TimeUtils tu = getTimeUtils();
  72. Date pushDate = change.date;
  73. if (TimeUtils.isToday(pushDate, timezone)) {
  74. fuzzydate = tu.today();
  75. } else if (TimeUtils.isYesterday(pushDate, timezone)) {
  76. fuzzydate = tu.yesterday();
  77. } else {
  78. // calculate a fuzzy time ago date
  79. cal.setTime(pushDate);
  80. cal.set(Calendar.HOUR_OF_DAY, 0);
  81. cal.set(Calendar.MINUTE, 0);
  82. cal.set(Calendar.SECOND, 0);
  83. cal.set(Calendar.MILLISECOND, 0);
  84. pushDate = cal.getTime();
  85. fuzzydate = getTimeUtils().timeAgo(pushDate);
  86. }
  87. logItem.add(new Label("whenChanged", fuzzydate + ", " + df.format(pushDate)));
  88. Label changeIcon = new Label("changeIcon");
  89. // use the repository hash color to differentiate the icon.
  90. String color = StringUtils.getColor(StringUtils.stripDotGit(change.repository));
  91. WicketUtils.setCssStyle(changeIcon, "color: " + color);
  92. if (isTag) {
  93. WicketUtils.setCssClass(changeIcon, "iconic-tag");
  94. } else {
  95. WicketUtils.setCssClass(changeIcon, "iconic-loop");
  96. }
  97. logItem.add(changeIcon);
  98. if (isTag) {
  99. // tags are special
  100. PersonIdent ident = change.getCommits().get(0).getAuthorIdent();
  101. if (!StringUtils.isEmpty(ident.getName())) {
  102. logItem.add(new Label("whoChanged", ident.getName()));
  103. } else {
  104. logItem.add(new Label("whoChanged", ident.getEmailAddress()));
  105. }
  106. } else {
  107. logItem.add(new Label("whoChanged").setVisible(false));
  108. }
  109. String preposition = "gb.of";
  110. boolean isDelete = false;
  111. String what;
  112. String by = null;
  113. switch(change.getChangeType(fullRefName)) {
  114. case CREATE:
  115. if (isTag) {
  116. // new tag
  117. what = getString("gb.createdNewTag");
  118. preposition = "gb.in";
  119. } else {
  120. // new branch
  121. what = getString("gb.createdNewBranch");
  122. preposition = "gb.in";
  123. }
  124. break;
  125. case DELETE:
  126. isDelete = true;
  127. if (isTag) {
  128. what = getString("gb.deletedTag");
  129. } else {
  130. what = getString("gb.deletedBranch");
  131. }
  132. preposition = "gb.from";
  133. break;
  134. default:
  135. what = MessageFormat.format(change.getCommitCount() > 1 ? getString("gb.commitsTo") : getString("gb.oneCommitTo"), change.getCommitCount());
  136. if (change.getAuthorCount() == 1) {
  137. by = MessageFormat.format(getString("gb.byOneAuthor"), change.getAuthorIdent().getName());
  138. } else {
  139. by = MessageFormat.format(getString("gb.byNAuthors"), change.getAuthorCount());
  140. }
  141. break;
  142. }
  143. logItem.add(new Label("whatChanged", what));
  144. logItem.add(new Label("byAuthors", by).setVisible(!StringUtils.isEmpty(by)));
  145. if (isDelete) {
  146. // can't link to deleted ref
  147. logItem.add(new Label("refChanged", shortRefName));
  148. } else if (isTag) {
  149. // link to tag
  150. logItem.add(new LinkPanel("refChanged", null, shortRefName,
  151. TagPage.class, WicketUtils.newObjectParameter(change.repository, fullRefName)));
  152. } else {
  153. // link to tree
  154. logItem.add(new LinkPanel("refChanged", null, shortRefName,
  155. TreePage.class, WicketUtils.newObjectParameter(change.repository, fullRefName)));
  156. }
  157. // to/from/etc
  158. logItem.add(new Label("repoPreposition", getString(preposition)));
  159. String repoName = StringUtils.stripDotGit(change.repository);
  160. logItem.add(new LinkPanel("repoChanged", null, repoName,
  161. SummaryPage.class, WicketUtils.newRepositoryParameter(change.repository)));
  162. int maxCommitCount = 5;
  163. List<RepositoryCommit> commits = change.getCommits();
  164. if (commits.size() > maxCommitCount) {
  165. commits = new ArrayList<RepositoryCommit>(commits.subList(0, maxCommitCount));
  166. }
  167. // compare link
  168. String compareLinkText = null;
  169. if ((change.getCommitCount() <= maxCommitCount) && (change.getCommitCount() > 1)) {
  170. compareLinkText = MessageFormat.format(getString("gb.viewComparison"), commits.size());
  171. } else if (change.getCommitCount() > maxCommitCount) {
  172. int diff = change.getCommitCount() - maxCommitCount;
  173. compareLinkText = MessageFormat.format(diff > 1 ? getString("gb.nMoreCommits") : getString("gb.oneMoreCommit"), diff);
  174. }
  175. if (StringUtils.isEmpty(compareLinkText)) {
  176. logItem.add(new Label("compareLink").setVisible(false));
  177. } else {
  178. String endRangeId = change.getNewId(fullRefName);
  179. String startRangeId = change.getOldId(fullRefName);
  180. logItem.add(new LinkPanel("compareLink", null, compareLinkText, ComparePage.class, WicketUtils.newRangeParameter(change.repository, startRangeId, endRangeId)));
  181. }
  182. final boolean showSwatch = GitBlit.getBoolean(Keys.web.repositoryListSwatches, true);
  183. ListDataProvider<RepositoryCommit> cdp = new ListDataProvider<RepositoryCommit>(commits);
  184. DataView<RepositoryCommit> commitsView = new DataView<RepositoryCommit>("commit", cdp) {
  185. private static final long serialVersionUID = 1L;
  186. public void populateItem(final Item<RepositoryCommit> commitItem) {
  187. final RepositoryCommit commit = commitItem.getModelObject();
  188. // author gravatar
  189. commitItem.add(new GravatarImage("commitAuthor", commit.getAuthorIdent().getName(),
  190. commit.getAuthorIdent().getEmailAddress(), null, 16, false, false));
  191. // merge icon
  192. if (commit.getParentCount() > 1) {
  193. commitItem.add(WicketUtils.newImage("commitIcon", "commit_merge_16x16.png"));
  194. } else {
  195. commitItem.add(WicketUtils.newBlankImage("commitIcon"));
  196. }
  197. // short message
  198. String shortMessage = commit.getShortMessage();
  199. String trimmedMessage = shortMessage;
  200. if (commit.getRefs() != null && commit.getRefs().size() > 0) {
  201. trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG_REFS);
  202. } else {
  203. trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG);
  204. }
  205. LinkPanel shortlog = new LinkPanel("commitShortMessage", "list",
  206. trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(
  207. change.repository, commit.getName()));
  208. if (!shortMessage.equals(trimmedMessage)) {
  209. WicketUtils.setHtmlTooltip(shortlog, shortMessage);
  210. }
  211. commitItem.add(shortlog);
  212. // commit hash link
  213. LinkPanel commitHash = new LinkPanel("hashLink", null, commit.getName().substring(0, hashLen),
  214. CommitPage.class, WicketUtils.newObjectParameter(
  215. change.repository, commit.getName()));
  216. WicketUtils.setCssClass(commitHash, "shortsha1");
  217. WicketUtils.setHtmlTooltip(commitHash, commit.getName());
  218. commitItem.add(commitHash);
  219. if (showSwatch) {
  220. // set repository color
  221. String color = StringUtils.getColor(StringUtils.stripDotGit(change.repository));
  222. WicketUtils.setCssStyle(commitItem, MessageFormat.format("border-left: 2px solid {0};", color));
  223. }
  224. }
  225. };
  226. logItem.add(commitsView);
  227. }
  228. };
  229. add(pushView);
  230. }
  231. public boolean hasMore() {
  232. return hasMore;
  233. }
  234. public boolean hideIfEmpty() {
  235. setVisible(hasChanges);
  236. return hasChanges;
  237. }
  238. }