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.

TicketListPanel.java 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * Copyright 2014 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.MessageFormat;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import org.apache.wicket.PageParameters;
  21. import org.apache.wicket.behavior.SimpleAttributeModifier;
  22. import org.apache.wicket.markup.html.basic.Label;
  23. import org.apache.wicket.markup.html.panel.Fragment;
  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.Constants;
  29. import com.gitblit.models.RepositoryModel;
  30. import com.gitblit.models.UserModel;
  31. import com.gitblit.tickets.QueryResult;
  32. import com.gitblit.tickets.TicketLabel;
  33. import com.gitblit.utils.ArrayUtils;
  34. import com.gitblit.utils.BugtraqProcessor;
  35. import com.gitblit.utils.StringUtils;
  36. import com.gitblit.wicket.GitBlitWebSession;
  37. import com.gitblit.wicket.TicketsUI;
  38. import com.gitblit.wicket.TicketsUI.Indicator;
  39. import com.gitblit.wicket.WicketUtils;
  40. import com.gitblit.wicket.pages.TicketsPage;
  41. import com.gitblit.wicket.pages.UserPage;
  42. /**
  43. *
  44. * The ticket list panel lists tickets in a table.
  45. *
  46. * @author James Moger
  47. *
  48. */
  49. public class TicketListPanel extends BasePanel {
  50. private static final long serialVersionUID = 1L;
  51. public TicketListPanel(String wicketId, List<QueryResult> list, final boolean showSwatch, final boolean showRepository) {
  52. super(wicketId);
  53. final ListDataProvider<QueryResult> dp = new ListDataProvider<QueryResult>(list);
  54. DataView<QueryResult> dataView = new DataView<QueryResult>("row", dp) {
  55. private static final long serialVersionUID = 1L;
  56. @Override
  57. protected void populateItem(Item<QueryResult> item) {
  58. final QueryResult ticket = item.getModelObject();
  59. if (showSwatch) {
  60. // set repository color
  61. String color = StringUtils.getColor(StringUtils.stripDotGit(ticket.repository));
  62. WicketUtils.setCssStyle(item, MessageFormat.format("border-left: 2px solid {0};", color));
  63. }
  64. PageParameters tp = WicketUtils.newObjectParameter(ticket.repository, "" + ticket.number);
  65. if (showRepository) {
  66. String name = StringUtils.stripDotGit(ticket.repository);
  67. PageParameters rp = WicketUtils.newOpenTicketsParameter(ticket.repository);
  68. LinkPanel link = new LinkPanel("ticketsLink", null, name, TicketsPage.class, rp);
  69. WicketUtils.setCssBackground(link, name);
  70. item.add(link);
  71. } else {
  72. item.add(new Label("ticketsLink").setVisible(false));
  73. }
  74. Label icon = TicketsUI.getStateIcon("state", ticket.type, ticket.status);
  75. WicketUtils.addCssClass(icon, TicketsUI.getSeverityClass(ticket.severity));
  76. item.add(icon);
  77. item.add(new Label("id", "" + ticket.number));
  78. UserModel creator = app().users().getUserModel(ticket.createdBy);
  79. if (creator != null) {
  80. item.add(new LinkPanel("createdBy", null, creator.getDisplayName(),
  81. UserPage.class, WicketUtils.newUsernameParameter(ticket.createdBy)));
  82. } else {
  83. item.add(new Label("createdBy", ticket.createdBy));
  84. }
  85. item.add(WicketUtils.createDateLabel("createDate", ticket.createdAt, GitBlitWebSession
  86. .get().getTimezone(), getTimeUtils(), false));
  87. if (ticket.updatedAt == null) {
  88. item.add(new Label("updated").setVisible(false));
  89. } else {
  90. Fragment updated = new Fragment("updated", "updatedFragment", this);
  91. UserModel updater = app().users().getUserModel(ticket.updatedBy);
  92. if (updater != null) {
  93. updated.add(new LinkPanel("updatedBy", null, updater.getDisplayName(),
  94. UserPage.class, WicketUtils.newUsernameParameter(ticket.updatedBy)));
  95. } else {
  96. updated.add(new Label("updatedBy", ticket.updatedBy));
  97. }
  98. updated.add(WicketUtils.createDateLabel("updateDate", ticket.updatedAt, GitBlitWebSession
  99. .get().getTimezone(), getTimeUtils(), false));
  100. item.add(updated);
  101. }
  102. item.add(new LinkPanel("title", "list subject", StringUtils.trimString(
  103. ticket.title, Constants.LEN_SHORTLOG), TicketsPage.class, tp));
  104. ListDataProvider<String> labelsProvider = new ListDataProvider<String>(ticket.getLabels());
  105. DataView<String> labelsView = new DataView<String>("labels", labelsProvider) {
  106. private static final long serialVersionUID = 1L;
  107. @Override
  108. public void populateItem(final Item<String> labelItem) {
  109. RepositoryModel repository = app().repositories().getRepositoryModel(ticket.repository);
  110. Label label;
  111. TicketLabel tLabel;
  112. if (repository == null) {
  113. label = new Label("label", labelItem.getModelObject());
  114. tLabel = new TicketLabel(labelItem.getModelObject());
  115. } else {
  116. Repository db = app().repositories().getRepository(repository.name);
  117. BugtraqProcessor btp = new BugtraqProcessor(app().settings());
  118. String content = btp.processText(db, repository.name, labelItem.getModelObject());
  119. String safeContent = app().xssFilter().relaxed(content);
  120. db.close();
  121. label = new Label("label", safeContent);
  122. label.setEscapeModelStrings(false);
  123. tLabel = app().tickets().getLabel(repository, labelItem.getModelObject());
  124. }
  125. String background = MessageFormat.format("background-color:{0};", tLabel.color);
  126. label.add(new SimpleAttributeModifier("style", background));
  127. labelItem.add(label);
  128. }
  129. };
  130. item.add(labelsView);
  131. if (StringUtils.isEmpty(ticket.responsible)) {
  132. item.add(new Label("responsible").setVisible(false));
  133. } else {
  134. UserModel responsible = app().users().getUserModel(ticket.responsible);
  135. if (responsible == null) {
  136. responsible = new UserModel(ticket.responsible);
  137. }
  138. GravatarImage avatar = new GravatarImage("responsible", responsible.getDisplayName(),
  139. responsible.emailAddress, null, 16, true);
  140. avatar.setTooltip(getString("gb.responsible") + ": " + responsible.getDisplayName());
  141. item.add(avatar);
  142. }
  143. // votes indicator
  144. Label v = new Label("votes", "" + ticket.votesCount);
  145. WicketUtils.setHtmlTooltip(v, getString("gb.votes"));
  146. item.add(v.setVisible(ticket.votesCount > 0));
  147. // watching indicator
  148. item.add(new Label("watching").setVisible(ticket.isWatching(GitBlitWebSession.get().getUsername())));
  149. // priority indicator
  150. Label priorityIcon = TicketsUI.getPriorityIcon("priority", ticket.priority);
  151. WicketUtils.addCssClass(priorityIcon, TicketsUI.getPriorityClass(ticket.priority));
  152. item.add(priorityIcon.setVisible(true));
  153. // status indicator
  154. String css = TicketsUI.getLozengeClass(ticket.status, true);
  155. Label l = new Label("status", ticket.status.toString());
  156. WicketUtils.setCssClass(l, css);
  157. item.add(l);
  158. // add the ticket indicators/icons
  159. List<Indicator> indicators = new ArrayList<Indicator>();
  160. // comments
  161. if (ticket.commentsCount > 0) {
  162. int count = ticket.commentsCount;
  163. String pattern = getString("gb.nComments");
  164. if (count == 1) {
  165. pattern = getString("gb.oneComment");
  166. }
  167. indicators.add(new Indicator("fa fa-comment", count, pattern));
  168. }
  169. // participants
  170. if (!ArrayUtils.isEmpty(ticket.participants)) {
  171. int count = ticket.participants.size();
  172. if (count > 1) {
  173. String pattern = getString("gb.nParticipants");
  174. indicators.add(new Indicator("fa fa-user", count, pattern));
  175. }
  176. }
  177. // attachments
  178. if (!ArrayUtils.isEmpty(ticket.attachments)) {
  179. int count = ticket.attachments.size();
  180. String pattern = getString("gb.nAttachments");
  181. if (count == 1) {
  182. pattern = getString("gb.oneAttachment");
  183. }
  184. indicators.add(new Indicator("fa fa-file", count, pattern));
  185. }
  186. // patchset revisions
  187. if (ticket.patchset != null) {
  188. int count = ticket.patchset.commits;
  189. String pattern = getString("gb.nCommits");
  190. if (count == 1) {
  191. pattern = getString("gb.oneCommit");
  192. }
  193. indicators.add(new Indicator("fa fa-code", count, pattern));
  194. }
  195. // milestone
  196. if (!StringUtils.isEmpty(ticket.milestone)) {
  197. indicators.add(new Indicator("fa fa-bullseye", ticket.milestone));
  198. }
  199. ListDataProvider<Indicator> indicatorsDp = new ListDataProvider<Indicator>(indicators);
  200. DataView<Indicator> indicatorsView = new DataView<Indicator>("indicators", indicatorsDp) {
  201. private static final long serialVersionUID = 1L;
  202. @Override
  203. public void populateItem(final Item<Indicator> item) {
  204. Indicator indicator = item.getModelObject();
  205. String tooltip = indicator.getTooltip();
  206. Label icon = new Label("icon");
  207. WicketUtils.setCssClass(icon, indicator.css);
  208. item.add(icon);
  209. if (indicator.count > 0) {
  210. Label count = new Label("count", "" + indicator.count);
  211. item.add(count.setVisible(!StringUtils.isEmpty(tooltip)));
  212. } else {
  213. item.add(new Label("count").setVisible(false));
  214. }
  215. WicketUtils.setHtmlTooltip(item, tooltip);
  216. }
  217. };
  218. item.add(indicatorsView);
  219. }
  220. };
  221. add(dataView);
  222. }
  223. }