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.

TicketPage.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 org.apache.wicket.PageParameters;
  18. import org.apache.wicket.markup.html.basic.Label;
  19. import org.apache.wicket.markup.repeater.Item;
  20. import org.apache.wicket.markup.repeater.data.DataView;
  21. import org.apache.wicket.markup.repeater.data.ListDataProvider;
  22. import org.eclipse.jgit.lib.Repository;
  23. import com.gitblit.utils.JGitUtils;
  24. import com.gitblit.utils.StringUtils;
  25. import com.gitblit.wicket.GitBlitWebSession;
  26. import com.gitblit.wicket.RepositoryPage;
  27. import com.gitblit.wicket.WicketUtils;
  28. import com.gitblit.wicket.models.TicketModel;
  29. import com.gitblit.wicket.models.TicketModel.Comment;
  30. public class TicketPage extends RepositoryPage {
  31. public TicketPage(PageParameters params) {
  32. super(params);
  33. final String ticketFolder = WicketUtils.getPath(params);
  34. Repository r = getRepository();
  35. TicketModel t = JGitUtils.getTicket(r, ticketFolder);
  36. add(new Label("ticketTitle", t.title));
  37. add(new Label("ticketId", t.id));
  38. add(new Label("ticketHandler", t.handler.toLowerCase()));
  39. add(WicketUtils.createTimestampLabel("ticketOpenDate", t.date, getTimeZone()));
  40. Label stateLabel = new Label("ticketState", t.state);
  41. WicketUtils.setTicketCssClass(stateLabel, t.state);
  42. add(stateLabel);
  43. add(new Label("ticketTags", StringUtils.flattenStrings(t.tags)));
  44. ListDataProvider<Comment> commentsDp = new ListDataProvider<Comment>(t.comments);
  45. DataView<Comment> commentsView = new DataView<Comment>("comment", commentsDp) {
  46. private static final long serialVersionUID = 1L;
  47. int counter = 0;
  48. public void populateItem(final Item<Comment> item) {
  49. final Comment entry = item.getModelObject();
  50. item.add(WicketUtils.createDateLabel("commentDate", entry.date, GitBlitWebSession.get().getTimezone()));
  51. item.add(new Label("commentAuthor", entry.author.toLowerCase()));
  52. item.add(new Label("commentText", prepareComment(entry.text)).setEscapeModelStrings(false));
  53. WicketUtils.setAlternatingBackground(item, counter);
  54. counter++;
  55. }
  56. };
  57. add(commentsView);
  58. }
  59. @Override
  60. protected String getPageName() {
  61. return getString("gb.ticket");
  62. }
  63. private String prepareComment(String comment) {
  64. String html = StringUtils.escapeForHtml(comment, false);
  65. html = StringUtils.breakLinesForHtml(comment).trim();
  66. return html.replaceAll("\\bcommit\\s*([A-Za-z0-9]*)\\b", "<a href=\"/commit/" + repositoryName + "/$1\">commit $1</a>");
  67. }
  68. }