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