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