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.

TicketsUI.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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;
  17. import java.io.Serializable;
  18. import java.text.MessageFormat;
  19. import org.apache.wicket.markup.html.basic.Label;
  20. import com.gitblit.models.TicketModel;
  21. import com.gitblit.models.TicketModel.Status;
  22. import com.gitblit.models.TicketModel.Type;
  23. import com.gitblit.utils.StringUtils;
  24. /**
  25. * Common tickets ui methods and classes.
  26. *
  27. * @author James Moger
  28. *
  29. */
  30. public class TicketsUI {
  31. public static final String [] openStatii = new String [] { Status.New.name().toLowerCase(), Status.Open.name().toLowerCase() };
  32. public static final String [] closedStatii = new String [] { "!" + Status.New.name().toLowerCase(), "!" + Status.Open.name().toLowerCase() };
  33. public static Label getStateIcon(String wicketId, TicketModel ticket) {
  34. return getStateIcon(wicketId, ticket.type, ticket.status);
  35. }
  36. public static Label getStateIcon(String wicketId, Type type, Status state) {
  37. Label label = new Label(wicketId);
  38. if (type == null) {
  39. type = Type.defaultType;
  40. }
  41. switch (type) {
  42. case Proposal:
  43. WicketUtils.setCssClass(label, "fa fa-code-fork");
  44. break;
  45. case Bug:
  46. WicketUtils.setCssClass(label, "fa fa-bug");
  47. break;
  48. case Enhancement:
  49. WicketUtils.setCssClass(label, "fa fa-magic");
  50. break;
  51. case Question:
  52. WicketUtils.setCssClass(label, "fa fa-question");
  53. break;
  54. case Maintenance:
  55. WicketUtils.setCssClass(label, "fa fa-cogs");
  56. break;
  57. default:
  58. // standard ticket
  59. WicketUtils.setCssClass(label, "fa fa-ticket");
  60. }
  61. WicketUtils.setHtmlTooltip(label, getTypeState(type, state));
  62. return label;
  63. }
  64. public static String getTypeState(Type type, Status state) {
  65. return state.toString() + " " + type.toString();
  66. }
  67. public static String getLozengeClass(Status status, boolean subtle) {
  68. if (status == null) {
  69. status = Status.New;
  70. }
  71. String css = "";
  72. switch (status) {
  73. case Declined:
  74. case Duplicate:
  75. case Invalid:
  76. case Wontfix:
  77. case Abandoned:
  78. css = "aui-lozenge-error";
  79. break;
  80. case Fixed:
  81. case Merged:
  82. case Resolved:
  83. css = "aui-lozenge-success";
  84. break;
  85. case New:
  86. css = "aui-lozenge-complete";
  87. break;
  88. case On_Hold:
  89. case No_Change_Required:
  90. css = "aui-lozenge-current";
  91. break;
  92. default:
  93. css = "";
  94. break;
  95. }
  96. return "aui-lozenge" + (subtle ? " aui-lozenge-subtle": "") + (css.isEmpty() ? "" : " ") + css;
  97. }
  98. public static String getStatusClass(Status status) {
  99. String css = "";
  100. switch (status) {
  101. case Declined:
  102. case Duplicate:
  103. case Invalid:
  104. case Wontfix:
  105. case Abandoned:
  106. css = "resolution-error";
  107. break;
  108. case Fixed:
  109. case Merged:
  110. case Resolved:
  111. css = "resolution-success";
  112. break;
  113. case New:
  114. css = "resolution-complete";
  115. break;
  116. case On_Hold:
  117. case No_Change_Required:
  118. css = "resolution-current";
  119. break;
  120. default:
  121. css = "";
  122. break;
  123. }
  124. return "resolution" + (css.isEmpty() ? "" : " ") + css;
  125. }
  126. public static class TicketSort implements Serializable {
  127. private static final long serialVersionUID = 1L;
  128. public final String name;
  129. public final String sortBy;
  130. public final boolean desc;
  131. public TicketSort(String name, String sortBy, boolean desc) {
  132. this.name = name;
  133. this.sortBy = sortBy;
  134. this.desc = desc;
  135. }
  136. }
  137. public static class Indicator implements Serializable {
  138. private static final long serialVersionUID = 1L;
  139. public final String css;
  140. public final int count;
  141. public final String tooltip;
  142. public Indicator(String css, String tooltip) {
  143. this.css = css;
  144. this.tooltip = tooltip;
  145. this.count = 0;
  146. }
  147. public Indicator(String css, int count, String pattern) {
  148. this.css = css;
  149. this.count = count;
  150. this.tooltip = StringUtils.isEmpty(pattern) ? "" : MessageFormat.format(pattern, count);
  151. }
  152. public String getTooltip() {
  153. return tooltip;
  154. }
  155. }
  156. public static class TicketQuery implements Serializable, Comparable<TicketQuery> {
  157. private static final long serialVersionUID = 1L;
  158. public final String name;
  159. public final String query;
  160. public String color;
  161. public TicketQuery(String name, String query) {
  162. this.name = name;
  163. this.query = query;
  164. }
  165. public TicketQuery color(String value) {
  166. this.color = value;
  167. return this;
  168. }
  169. @Override
  170. public boolean equals(Object o) {
  171. if (o instanceof TicketQuery) {
  172. return ((TicketQuery) o).query.equals(query);
  173. }
  174. return false;
  175. }
  176. @Override
  177. public int hashCode() {
  178. return query.hashCode();
  179. }
  180. @Override
  181. public int compareTo(TicketQuery o) {
  182. return query.compareTo(o.query);
  183. }
  184. }
  185. }