Paul Martin
2014-09-29 f9c78c0ccc709509cdf7f83c45c898883d329db2
commit | author | age
fdd82f 1 /*
JM 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
18 import java.io.Serializable;
19 import java.text.MessageFormat;
20
21 import org.apache.wicket.markup.html.basic.Label;
22
23 import com.gitblit.models.TicketModel;
f9c78c 24 import com.gitblit.models.TicketModel.Priority;
PM 25 import com.gitblit.models.TicketModel.Severity;
fdd82f 26 import com.gitblit.models.TicketModel.Status;
JM 27 import com.gitblit.models.TicketModel.Type;
28 import com.gitblit.utils.StringUtils;
29
30 /**
31  * Common tickets ui methods and classes.
32  *
33  * @author James Moger
34  *
35  */
36 public class TicketsUI {
37
38     public static final String [] openStatii = new String [] { Status.New.name().toLowerCase(), Status.Open.name().toLowerCase() };
39
40     public static final String [] closedStatii = new String [] { "!" + Status.New.name().toLowerCase(), "!" + Status.Open.name().toLowerCase() };
f9c78c 41     
fdd82f 42     public static Label getStateIcon(String wicketId, TicketModel ticket) {
JM 43         return getStateIcon(wicketId, ticket.type, ticket.status);
44     }
45
46     public static Label getStateIcon(String wicketId, Type type, Status state) {
47         Label label = new Label(wicketId);
48         if (type == null) {
49             type = Type.defaultType;
50         }
51         switch (type) {
52         case Proposal:
f9c78c 53             WicketUtils.setCssClass(label, "fa fa-code-fork fa-fw");
fdd82f 54             break;
JM 55         case Bug:
f9c78c 56             WicketUtils.setCssClass(label, "fa fa-bug fa-fw");
fdd82f 57             break;
JM 58         case Enhancement:
f9c78c 59             WicketUtils.setCssClass(label, "fa fa-magic fa-fw");
fdd82f 60             break;
JM 61         case Question:
f9c78c 62             WicketUtils.setCssClass(label, "fa fa-question fa-fw");
fdd82f 63             break;
f5d568 64         case Maintenance:
f9c78c 65             WicketUtils.setCssClass(label, "fa fa-cogs fa-fw");
f5d568 66             break;
fdd82f 67         default:
JM 68             // standard ticket
f9c78c 69             WicketUtils.setCssClass(label, "fa fa-ticket fa-fw");
fdd82f 70         }
JM 71         WicketUtils.setHtmlTooltip(label, getTypeState(type, state));
f9c78c 72         
fdd82f 73         return label;
JM 74     }
f9c78c 75     
PM 76     public static Label getPriorityIcon(String wicketId, Priority priority) {
77         Label label = new Label(wicketId);
78         if (priority == null) {
79             priority = Priority.defaultPriority;
80         }
81         switch (priority) {
82         case Urgent:
83             WicketUtils.setCssClass(label, "fa fa-step-forward fa-rotate-270");
84             break;
85         case High:
86             WicketUtils.setCssClass(label, "fa fa-caret-up fa-lg");
87             break;
88         case Low:
89             WicketUtils.setCssClass(label, "fa fa-caret-down fa-lg");
90             break;
91         default:
92         }
93         WicketUtils.setHtmlTooltip(label, priority.toString());
94         
95         return label;
96     }
97     
98     public static String getPriorityClass(Priority priority) {
99         return String.format("priority-%s", priority);
100     }
fdd82f 101
f9c78c 102     public static String getSeverityClass(Severity severity) {
PM 103         return String.format("severity-%s", severity);    
104     }
105     
fdd82f 106     public static String getTypeState(Type type, Status state) {
JM 107         return state.toString() + " " + type.toString();
108     }
109
110     public static String getLozengeClass(Status status, boolean subtle) {
111         if (status == null) {
112             status = Status.New;
113         }
114         String css = "";
115         switch (status) {
116         case Declined:
117         case Duplicate:
118         case Invalid:
119         case Wontfix:
120         case Abandoned:
121             css = "aui-lozenge-error";
122             break;
123         case Fixed:
124         case Merged:
125         case Resolved:
126             css = "aui-lozenge-success";
127             break;
128         case New:
129             css = "aui-lozenge-complete";
130             break;
131         case On_Hold:
4881b8 132         case No_Change_Required:
fdd82f 133             css = "aui-lozenge-current";
JM 134             break;
135         default:
136             css = "";
137             break;
138         }
139
140         return "aui-lozenge" + (subtle ? " aui-lozenge-subtle": "") + (css.isEmpty() ? "" : " ") + css;
141     }
142
143     public static String getStatusClass(Status status) {
144         String css = "";
145         switch (status) {
146         case Declined:
147         case Duplicate:
148         case Invalid:
149         case Wontfix:
150         case Abandoned:
151             css = "resolution-error";
152             break;
153         case Fixed:
154         case Merged:
155         case Resolved:
156             css = "resolution-success";
157             break;
158         case New:
159             css = "resolution-complete";
160             break;
161         case On_Hold:
4881b8 162         case No_Change_Required:
fdd82f 163             css = "resolution-current";
JM 164             break;
165         default:
166             css = "";
167             break;
168         }
169
170         return "resolution" + (css.isEmpty() ? "" : " ") + css;
171     }
172
173     public static class TicketSort implements Serializable {
174
175         private static final long serialVersionUID = 1L;
176
177         public final String name;
178         public final String sortBy;
179         public final boolean desc;
180
181         public TicketSort(String name, String sortBy, boolean desc) {
182             this.name = name;
183             this.sortBy = sortBy;
184             this.desc = desc;
185         }
186     }
187
188     public static class Indicator implements Serializable {
189
190         private static final long serialVersionUID = 1L;
191
192         public final String css;
193         public final int count;
194         public final String tooltip;
195
196         public Indicator(String css, String tooltip) {
197             this.css = css;
198             this.tooltip = tooltip;
199             this.count = 0;
200         }
201
202         public Indicator(String css, int count, String pattern) {
203             this.css = css;
204             this.count = count;
205             this.tooltip = StringUtils.isEmpty(pattern) ? "" : MessageFormat.format(pattern, count);
206         }
207
208         public String getTooltip() {
209             return tooltip;
210         }
211     }
212
213     public static class TicketQuery implements Serializable, Comparable<TicketQuery> {
214
215         private static final long serialVersionUID = 1L;
216
217         public final String name;
218         public final String query;
219         public String color;
220
221         public TicketQuery(String name, String query) {
222             this.name = name;
223             this.query = query;
224         }
225
226         public TicketQuery color(String value) {
227             this.color = value;
228             return this;
229         }
230
231         @Override
232         public boolean equals(Object o) {
233             if (o instanceof TicketQuery) {
234                 return ((TicketQuery) o).query.equals(query);
235             }
236             return false;
237         }
238
239         @Override
240         public int hashCode() {
241             return query.hashCode();
242         }
243
244         @Override
245         public int compareTo(TicketQuery o) {
246             return query.compareTo(o.query);
247         }
248     }
249 }