commit | author | age
|
f13c4c
|
1 |
/*
|
JM |
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 |
*/
|
5fe7df
|
16 |
package com.gitblit.wicket;
|
JM |
17 |
|
698678
|
18 |
import java.text.DateFormat;
|
db91a3
|
19 |
import java.text.MessageFormat;
|
698678
|
20 |
import java.text.SimpleDateFormat;
|
f1720c
|
21 |
import java.util.Collection;
|
698678
|
22 |
import java.util.Date;
|
d80588
|
23 |
import java.util.HashMap;
|
G |
24 |
import java.util.Map;
|
698678
|
25 |
import java.util.TimeZone;
|
1e47ab
|
26 |
|
8c9a20
|
27 |
import javax.servlet.http.HttpServletRequest;
|
JM |
28 |
|
5fe7df
|
29 |
import org.apache.wicket.Component;
|
698678
|
30 |
import org.apache.wicket.PageParameters;
|
8c9a20
|
31 |
import org.apache.wicket.Request;
|
f9c78c
|
32 |
import org.apache.wicket.behavior.AttributeAppender;
|
8c9a20
|
33 |
import org.apache.wicket.behavior.HeaderContributor;
|
fc8426
|
34 |
import org.apache.wicket.behavior.SimpleAttributeModifier;
|
8c9a20
|
35 |
import org.apache.wicket.markup.html.IHeaderContributor;
|
JM |
36 |
import org.apache.wicket.markup.html.IHeaderResponse;
|
698678
|
37 |
import org.apache.wicket.markup.html.basic.Label;
|
1e8390
|
38 |
import org.apache.wicket.markup.html.image.ContextImage;
|
f9c78c
|
39 |
import org.apache.wicket.model.Model;
|
8c9a20
|
40 |
import org.apache.wicket.protocol.http.WebRequest;
|
1e8390
|
41 |
import org.apache.wicket.resource.ContextRelativeResource;
|
9bc17d
|
42 |
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
|
698678
|
43 |
|
33d8d8
|
44 |
import com.gitblit.Constants;
|
828add
|
45 |
import com.gitblit.Constants.AccessPermission;
|
831469
|
46 |
import com.gitblit.Constants.FederationPullStatus;
|
11a173
|
47 |
import com.gitblit.IStoredSettings;
|
155bf7
|
48 |
import com.gitblit.Keys;
|
831469
|
49 |
import com.gitblit.models.FederationModel;
|
f1720c
|
50 |
import com.gitblit.models.Metric;
|
831469
|
51 |
import com.gitblit.utils.HttpUtils;
|
f1dfc2
|
52 |
import com.gitblit.utils.StringUtils;
|
87cc1e
|
53 |
import com.gitblit.utils.TimeUtils;
|
5fe7df
|
54 |
|
JM |
55 |
public class WicketUtils {
|
|
56 |
|
566005
|
57 |
public static void setCssClass(Component container, String value) {
|
fc8426
|
58 |
container.add(new SimpleAttributeModifier("class", value));
|
5fe7df
|
59 |
}
|
JM |
60 |
|
f9c78c
|
61 |
public static void addCssClass(Component container, String value) {
|
PM |
62 |
container.add(new AttributeAppender("class", new Model<String>(value), " "));
|
|
63 |
}
|
|
64 |
|
566005
|
65 |
public static void setCssStyle(Component container, String value) {
|
fc8426
|
66 |
container.add(new SimpleAttributeModifier("style", value));
|
db91a3
|
67 |
}
|
JM |
68 |
|
566005
|
69 |
public static void setCssBackground(Component container, String value) {
|
db91a3
|
70 |
String background = MessageFormat.format("background-color:{0};",
|
JM |
71 |
StringUtils.getColor(value));
|
|
72 |
container.add(new SimpleAttributeModifier("style", background));
|
5fe7df
|
73 |
}
|
JM |
74 |
|
566005
|
75 |
public static void setHtmlTooltip(Component container, String value) {
|
fc8426
|
76 |
container.add(new SimpleAttributeModifier("title", value));
|
9bc17d
|
77 |
}
|
JM |
78 |
|
566005
|
79 |
public static void setInputPlaceholder(Component container, String value) {
|
4910c1
|
80 |
container.add(new SimpleAttributeModifier("placeholder", value));
|
JM |
81 |
}
|
|
82 |
|
566005
|
83 |
public static void setChangeTypeCssClass(Component container, ChangeType type) {
|
9bc17d
|
84 |
switch (type) {
|
JM |
85 |
case ADD:
|
|
86 |
setCssClass(container, "addition");
|
|
87 |
break;
|
|
88 |
case COPY:
|
|
89 |
case RENAME:
|
|
90 |
setCssClass(container, "rename");
|
|
91 |
break;
|
|
92 |
case DELETE:
|
|
93 |
setCssClass(container, "deletion");
|
|
94 |
break;
|
|
95 |
case MODIFY:
|
|
96 |
setCssClass(container, "modification");
|
|
97 |
break;
|
|
98 |
}
|
5fe7df
|
99 |
}
|
155bf7
|
100 |
|
828add
|
101 |
public static void setPermissionClass(Component container, AccessPermission permission) {
|
JM |
102 |
if (permission == null) {
|
|
103 |
setCssClass(container, "badge");
|
|
104 |
return;
|
|
105 |
}
|
|
106 |
switch (permission) {
|
|
107 |
case REWIND:
|
|
108 |
case DELETE:
|
|
109 |
case CREATE:
|
|
110 |
setCssClass(container, "badge badge-success");
|
|
111 |
break;
|
|
112 |
case PUSH:
|
|
113 |
setCssClass(container, "badge badge-info");
|
|
114 |
break;
|
|
115 |
case CLONE:
|
|
116 |
setCssClass(container, "badge badge-inverse");
|
|
117 |
break;
|
|
118 |
default:
|
|
119 |
setCssClass(container, "badge");
|
|
120 |
break;
|
699e71
|
121 |
}
|
828add
|
122 |
}
|
155bf7
|
123 |
|
566005
|
124 |
public static void setAlternatingBackground(Component c, int i) {
|
94750e
|
125 |
String clazz = i % 2 == 0 ? "light" : "dark";
|
698678
|
126 |
setCssClass(c, clazz);
|
JM |
127 |
}
|
155bf7
|
128 |
|
698678
|
129 |
public static Label createAuthorLabel(String wicketId, String author) {
|
JM |
130 |
Label label = new Label(wicketId, author);
|
1e8390
|
131 |
WicketUtils.setHtmlTooltip(label, author);
|
698678
|
132 |
return label;
|
1e8390
|
133 |
}
|
JM |
134 |
|
831469
|
135 |
public static ContextImage getPullStatusImage(String wicketId, FederationPullStatus status) {
|
JM |
136 |
String filename = null;
|
|
137 |
switch (status) {
|
2548a7
|
138 |
case MIRRORED:
|
831469
|
139 |
case PULLED:
|
JM |
140 |
filename = "bullet_green.png";
|
|
141 |
break;
|
|
142 |
case SKIPPED:
|
|
143 |
filename = "bullet_yellow.png";
|
|
144 |
break;
|
|
145 |
case FAILED:
|
|
146 |
filename = "bullet_red.png";
|
|
147 |
break;
|
|
148 |
case EXCLUDED:
|
|
149 |
filename = "bullet_white.png";
|
|
150 |
break;
|
|
151 |
case PENDING:
|
db91a3
|
152 |
case NOCHANGE:
|
831469
|
153 |
default:
|
JM |
154 |
filename = "bullet_black.png";
|
|
155 |
}
|
|
156 |
return WicketUtils.newImage(wicketId, filename, status.name());
|
|
157 |
}
|
|
158 |
|
c1c3c6
|
159 |
public static ContextImage getFileImage(String wicketId, String filename) {
|
JM |
160 |
filename = filename.toLowerCase();
|
|
161 |
if (filename.endsWith(".java")) {
|
|
162 |
return newImage(wicketId, "file_java_16x16.png");
|
|
163 |
} else if (filename.endsWith(".rb")) {
|
|
164 |
return newImage(wicketId, "file_ruby_16x16.png");
|
|
165 |
} else if (filename.endsWith(".php")) {
|
|
166 |
return newImage(wicketId, "file_php_16x16.png");
|
|
167 |
} else if (filename.endsWith(".cs")) {
|
|
168 |
return newImage(wicketId, "file_cs_16x16.png");
|
|
169 |
} else if (filename.endsWith(".cpp")) {
|
|
170 |
return newImage(wicketId, "file_cpp_16x16.png");
|
|
171 |
} else if (filename.endsWith(".c")) {
|
|
172 |
return newImage(wicketId, "file_c_16x16.png");
|
|
173 |
} else if (filename.endsWith(".h")) {
|
|
174 |
return newImage(wicketId, "file_h_16x16.png");
|
|
175 |
} else if (filename.endsWith(".sln")) {
|
|
176 |
return newImage(wicketId, "file_vs_16x16.png");
|
2a7306
|
177 |
} else if (filename.endsWith(".csv") || filename.endsWith(".xls")
|
JM |
178 |
|| filename.endsWith(".xlsx")) {
|
c1c3c6
|
179 |
return newImage(wicketId, "file_excel_16x16.png");
|
JM |
180 |
} else if (filename.endsWith(".doc") || filename.endsWith(".docx")) {
|
a9e6d5
|
181 |
return newImage(wicketId, "file_doc_16x16.png");
|
d80588
|
182 |
} else if (filename.endsWith(".ppt") || filename.endsWith(".pptx")) {
|
c1c3c6
|
183 |
return newImage(wicketId, "file_ppt_16x16.png");
|
JM |
184 |
} else if (filename.endsWith(".zip")) {
|
|
185 |
return newImage(wicketId, "file_zip_16x16.png");
|
|
186 |
} else if (filename.endsWith(".pdf")) {
|
|
187 |
return newImage(wicketId, "file_acrobat_16x16.png");
|
|
188 |
} else if (filename.endsWith(".htm") || filename.endsWith(".html")) {
|
|
189 |
return newImage(wicketId, "file_world_16x16.png");
|
|
190 |
} else if (filename.endsWith(".xml")) {
|
|
191 |
return newImage(wicketId, "file_code_16x16.png");
|
|
192 |
} else if (filename.endsWith(".properties")) {
|
|
193 |
return newImage(wicketId, "file_settings_16x16.png");
|
|
194 |
}
|
|
195 |
|
dc7c2f
|
196 |
String ext = StringUtils.getFileExtension(filename).toLowerCase();
|
11a173
|
197 |
IStoredSettings settings = GitBlitWebApp.get().settings();
|
JM |
198 |
if (MarkupProcessor.getMarkupExtensions(settings).contains(ext)) {
|
dc7c2f
|
199 |
return newImage(wicketId, "file_world_16x16.png");
|
c1c3c6
|
200 |
}
|
JM |
201 |
return newImage(wicketId, "file_16x16.png");
|
|
202 |
}
|
|
203 |
|
831469
|
204 |
public static ContextImage getRegistrationImage(String wicketId, FederationModel registration,
|
JM |
205 |
Component c) {
|
|
206 |
if (registration.isResultData()) {
|
|
207 |
return WicketUtils.newImage(wicketId, "information_16x16.png",
|
|
208 |
c.getString("gb.federationResults"));
|
|
209 |
} else {
|
|
210 |
return WicketUtils.newImage(wicketId, "arrow_left.png",
|
|
211 |
c.getString("gb.federationRegistration"));
|
|
212 |
}
|
|
213 |
}
|
|
214 |
|
1e8390
|
215 |
public static ContextImage newClearPixel(String wicketId) {
|
JM |
216 |
return newImage(wicketId, "pixel.png");
|
|
217 |
}
|
c1c3c6
|
218 |
|
1e8390
|
219 |
public static ContextImage newBlankImage(String wicketId) {
|
JM |
220 |
return newImage(wicketId, "blank.png");
|
|
221 |
}
|
|
222 |
|
|
223 |
public static ContextImage newImage(String wicketId, String file) {
|
|
224 |
return newImage(wicketId, file, null);
|
|
225 |
}
|
|
226 |
|
|
227 |
public static ContextImage newImage(String wicketId, String file, String tooltip) {
|
5450d0
|
228 |
ContextImage img = new ContextImage(wicketId, file);
|
1e8390
|
229 |
if (!StringUtils.isEmpty(tooltip)) {
|
JM |
230 |
setHtmlTooltip(img, tooltip);
|
|
231 |
}
|
|
232 |
return img;
|
|
233 |
}
|
c1c3c6
|
234 |
|
a45caa
|
235 |
public static Label newIcon(String wicketId, String css) {
|
JM |
236 |
Label lbl = new Label(wicketId);
|
699e71
|
237 |
setCssClass(lbl, css);
|
a45caa
|
238 |
return lbl;
|
JM |
239 |
}
|
699e71
|
240 |
|
a45caa
|
241 |
public static Label newBlankIcon(String wicketId) {
|
JM |
242 |
Label lbl = new Label(wicketId);
|
|
243 |
setCssClass(lbl, "");
|
|
244 |
lbl.setRenderBodyOnly(true);
|
|
245 |
return lbl;
|
|
246 |
}
|
699e71
|
247 |
|
1e8390
|
248 |
public static ContextRelativeResource getResource(String file) {
|
5450d0
|
249 |
return new ContextRelativeResource(file);
|
8c9a20
|
250 |
}
|
JM |
251 |
|
2179fb
|
252 |
public static String getGitblitURL(Request request) {
|
8c9a20
|
253 |
HttpServletRequest req = ((WebRequest) request).getHttpServletRequest();
|
2179fb
|
254 |
return HttpUtils.getGitblitURL(req);
|
8c9a20
|
255 |
}
|
JM |
256 |
|
|
257 |
public static HeaderContributor syndicationDiscoveryLink(final String feedTitle,
|
|
258 |
final String url) {
|
|
259 |
return new HeaderContributor(new IHeaderContributor() {
|
|
260 |
private static final long serialVersionUID = 1L;
|
|
261 |
|
699e71
|
262 |
@Override
|
8c9a20
|
263 |
public void renderHead(IHeaderResponse response) {
|
JM |
264 |
String contentType = "application/rss+xml";
|
|
265 |
|
8a53c0
|
266 |
StringBuilder buffer = new StringBuilder();
|
8c9a20
|
267 |
buffer.append("<link rel=\"alternate\" ");
|
JM |
268 |
buffer.append("type=\"").append(contentType).append("\" ");
|
|
269 |
buffer.append("title=\"").append(feedTitle).append("\" ");
|
|
270 |
buffer.append("href=\"").append(url).append("\" />");
|
|
271 |
response.renderString(buffer.toString());
|
|
272 |
}
|
|
273 |
});
|
698678
|
274 |
}
|
db91a3
|
275 |
|
831469
|
276 |
public static PageParameters newTokenParameter(String token) {
|
d80588
|
277 |
Map<String, String> parameterMap = new HashMap<String, String>();
|
G |
278 |
parameterMap.put("t", token);
|
|
279 |
return new PageParameters(parameterMap);
|
831469
|
280 |
}
|
db91a3
|
281 |
|
d80588
|
282 |
public static PageParameters newRegistrationParameter(String url,
|
G |
283 |
String name) {
|
|
284 |
Map<String, String> parameterMap = new HashMap<String, String>();
|
|
285 |
parameterMap.put("u", url);
|
|
286 |
parameterMap.put("n", name);
|
|
287 |
return new PageParameters(parameterMap);
|
831469
|
288 |
}
|
155bf7
|
289 |
|
a4d249
|
290 |
public static PageParameters newUsernameParameter(String username) {
|
d80588
|
291 |
Map<String, String> parameterMap = new HashMap<String, String>();
|
G |
292 |
parameterMap.put("user", username);
|
|
293 |
return new PageParameters(parameterMap);
|
a4d249
|
294 |
}
|
JM |
295 |
|
fe24a0
|
296 |
public static PageParameters newTeamnameParameter(String teamname) {
|
d80588
|
297 |
Map<String, String> parameterMap = new HashMap<String, String>();
|
G |
298 |
parameterMap.put("team", teamname);
|
|
299 |
return new PageParameters(parameterMap);
|
fe24a0
|
300 |
}
|
JM |
301 |
|
13a3f5
|
302 |
public static PageParameters newProjectParameter(String projectName) {
|
d80588
|
303 |
Map<String, String> parameterMap = new HashMap<String, String>();
|
G |
304 |
parameterMap.put("p", projectName);
|
|
305 |
return new PageParameters(parameterMap);
|
13a3f5
|
306 |
}
|
JM |
307 |
|
698678
|
308 |
public static PageParameters newRepositoryParameter(String repositoryName) {
|
d80588
|
309 |
Map<String, String> parameterMap = new HashMap<String, String>();
|
fdd82f
|
310 |
if (!StringUtils.isEmpty(repositoryName)) {
|
JM |
311 |
parameterMap.put("r", repositoryName);
|
|
312 |
}
|
d80588
|
313 |
return new PageParameters(parameterMap);
|
831469
|
314 |
}
|
JM |
315 |
|
|
316 |
public static PageParameters newObjectParameter(String objectId) {
|
d80588
|
317 |
Map<String, String> parameterMap = new HashMap<String, String>();
|
G |
318 |
parameterMap.put("h", objectId);
|
|
319 |
return new PageParameters(parameterMap);
|
698678
|
320 |
}
|
JM |
321 |
|
d80588
|
322 |
public static PageParameters newObjectParameter(String repositoryName,
|
G |
323 |
String objectId) {
|
|
324 |
Map<String, String> parameterMap = new HashMap<String, String>();
|
f1dfc2
|
325 |
if (StringUtils.isEmpty(objectId)) {
|
698678
|
326 |
return newRepositoryParameter(repositoryName);
|
JM |
327 |
}
|
d80588
|
328 |
parameterMap.put("r", repositoryName);
|
G |
329 |
parameterMap.put("h", objectId);
|
|
330 |
return new PageParameters(parameterMap);
|
698678
|
331 |
}
|
JM |
332 |
|
d80588
|
333 |
public static PageParameters newRangeParameter(String repositoryName,
|
G |
334 |
String startRange, String endRange) {
|
|
335 |
Map<String, String> parameterMap = new HashMap<String, String>();
|
|
336 |
parameterMap.put("r", repositoryName);
|
|
337 |
parameterMap.put("h", startRange + ".." + endRange);
|
|
338 |
return new PageParameters(parameterMap);
|
722e23
|
339 |
}
|
JM |
340 |
|
d80588
|
341 |
public static PageParameters newPathParameter(String repositoryName,
|
G |
342 |
String objectId, String path) {
|
|
343 |
Map<String, String> parameterMap = new HashMap<String, String>();
|
f1dfc2
|
344 |
if (StringUtils.isEmpty(path)) {
|
ef5c58
|
345 |
return newObjectParameter(repositoryName, objectId);
|
698678
|
346 |
}
|
a2709d
|
347 |
if (StringUtils.isEmpty(objectId)) {
|
d80588
|
348 |
parameterMap.put("r", repositoryName);
|
G |
349 |
parameterMap.put("f", path);
|
|
350 |
return new PageParameters(parameterMap);
|
a2709d
|
351 |
}
|
d80588
|
352 |
parameterMap.put("r", repositoryName);
|
G |
353 |
parameterMap.put("h", objectId);
|
|
354 |
parameterMap.put("f", path);
|
|
355 |
return new PageParameters(parameterMap);
|
ef5c58
|
356 |
}
|
155bf7
|
357 |
|
d80588
|
358 |
public static PageParameters newLogPageParameter(String repositoryName,
|
G |
359 |
String objectId, int pageNumber) {
|
|
360 |
Map<String, String> parameterMap = new HashMap<String, String>();
|
|
361 |
if (pageNumber <= 1) {
|
|
362 |
return newObjectParameter(repositoryName, objectId);
|
|
363 |
}
|
|
364 |
if (StringUtils.isEmpty(objectId)) {
|
|
365 |
parameterMap.put("r", repositoryName);
|
|
366 |
parameterMap.put("pg", String.valueOf(pageNumber));
|
|
367 |
return new PageParameters(parameterMap);
|
|
368 |
}
|
|
369 |
parameterMap.put("r", repositoryName);
|
|
370 |
parameterMap.put("h", objectId);
|
|
371 |
parameterMap.put("pg", String.valueOf(pageNumber));
|
|
372 |
return new PageParameters(parameterMap);
|
|
373 |
}
|
|
374 |
|
|
375 |
public static PageParameters newHistoryPageParameter(String repositoryName,
|
|
376 |
String objectId, String path, int pageNumber) {
|
|
377 |
Map<String, String> parameterMap = new HashMap<String, String>();
|
|
378 |
if (pageNumber <= 1) {
|
|
379 |
return newObjectParameter(repositoryName, objectId);
|
|
380 |
}
|
|
381 |
if (StringUtils.isEmpty(objectId)) {
|
|
382 |
parameterMap.put("r", repositoryName);
|
|
383 |
parameterMap.put("f", path);
|
|
384 |
parameterMap.put("pg", String.valueOf(pageNumber));
|
|
385 |
return new PageParameters(parameterMap);
|
|
386 |
}
|
|
387 |
parameterMap.put("r", repositoryName);
|
|
388 |
parameterMap.put("h", objectId);
|
|
389 |
parameterMap.put("f", path);
|
|
390 |
parameterMap.put("pg", String.valueOf(pageNumber));
|
|
391 |
return new PageParameters(parameterMap);
|
|
392 |
}
|
|
393 |
|
|
394 |
public static PageParameters newBlobDiffParameter(String repositoryName,
|
|
395 |
String baseCommitId, String commitId, String path) {
|
|
396 |
Map<String, String> parameterMap = new HashMap<String, String>();
|
|
397 |
if (StringUtils.isEmpty(commitId)) {
|
|
398 |
parameterMap.put("r", repositoryName);
|
|
399 |
parameterMap.put("f", path);
|
|
400 |
parameterMap.put("hb", baseCommitId);
|
|
401 |
return new PageParameters(parameterMap);
|
|
402 |
}
|
|
403 |
parameterMap.put("r", repositoryName);
|
|
404 |
parameterMap.put("h", commitId);
|
|
405 |
parameterMap.put("f", path);
|
|
406 |
parameterMap.put("hb", baseCommitId);
|
|
407 |
return new PageParameters(parameterMap);
|
|
408 |
}
|
|
409 |
|
|
410 |
public static PageParameters newSearchParameter(String repositoryName,
|
|
411 |
String commitId, String search, Constants.SearchType type) {
|
|
412 |
Map<String, String> parameterMap = new HashMap<String, String>();
|
|
413 |
if (StringUtils.isEmpty(commitId)) {
|
|
414 |
parameterMap.put("r", repositoryName);
|
|
415 |
parameterMap.put("s", search);
|
|
416 |
parameterMap.put("st", type.name());
|
|
417 |
return new PageParameters(parameterMap);
|
|
418 |
}
|
|
419 |
parameterMap.put("r", repositoryName);
|
|
420 |
parameterMap.put("h", commitId);
|
|
421 |
parameterMap.put("s", search);
|
|
422 |
parameterMap.put("st", type.name());
|
|
423 |
return new PageParameters(parameterMap);
|
|
424 |
}
|
|
425 |
|
|
426 |
public static PageParameters newSearchParameter(String repositoryName,
|
|
427 |
String commitId, String search, Constants.SearchType type,
|
2a7306
|
428 |
int pageNumber) {
|
d80588
|
429 |
Map<String, String> parameterMap = new HashMap<String, String>();
|
a2709d
|
430 |
if (StringUtils.isEmpty(commitId)) {
|
d80588
|
431 |
parameterMap.put("r", repositoryName);
|
G |
432 |
parameterMap.put("s", search);
|
|
433 |
parameterMap.put("st", type.name());
|
|
434 |
parameterMap.put("pg", String.valueOf(pageNumber));
|
|
435 |
return new PageParameters(parameterMap);
|
a2709d
|
436 |
}
|
d80588
|
437 |
parameterMap.put("r", repositoryName);
|
G |
438 |
parameterMap.put("h", commitId);
|
|
439 |
parameterMap.put("s", search);
|
|
440 |
parameterMap.put("st", type.name());
|
|
441 |
parameterMap.put("pg", String.valueOf(pageNumber));
|
|
442 |
return new PageParameters(parameterMap);
|
98ce17
|
443 |
}
|
01ffd4
|
444 |
|
e3733c
|
445 |
public static PageParameters newBlameTypeParameter(String repositoryName,
|
AL |
446 |
String commitId, String path, String blameType) {
|
|
447 |
Map<String, String> parameterMap = new HashMap<String, String>();
|
|
448 |
parameterMap.put("r", repositoryName);
|
|
449 |
parameterMap.put("h", commitId);
|
|
450 |
parameterMap.put("f", path);
|
|
451 |
parameterMap.put("blametype", blameType);
|
|
452 |
return new PageParameters(parameterMap);
|
|
453 |
}
|
98ce17
|
454 |
|
3b23dc
|
455 |
public static PageParameters newTicketsParameters(String repositoryName, String... states) {
|
JM |
456 |
PageParameters tParams = newRepositoryParameter(repositoryName);
|
|
457 |
if (states != null) {
|
|
458 |
for (String state : states) {
|
|
459 |
tParams.add("status", state);
|
|
460 |
}
|
|
461 |
}
|
|
462 |
return tParams;
|
|
463 |
}
|
|
464 |
|
|
465 |
public static PageParameters newOpenTicketsParameter(String repositoryName) {
|
|
466 |
return newTicketsParameters(repositoryName, TicketsUI.openStatii);
|
|
467 |
}
|
|
468 |
|
13a3f5
|
469 |
public static String getProjectName(PageParameters params) {
|
JM |
470 |
return params.getString("p", "");
|
|
471 |
}
|
|
472 |
|
7d35e2
|
473 |
public static String getRepositoryName(PageParameters params) {
|
JM |
474 |
return params.getString("r", "");
|
|
475 |
}
|
|
476 |
|
|
477 |
public static String getObject(PageParameters params) {
|
a2709d
|
478 |
return params.getString("h", null);
|
7d35e2
|
479 |
}
|
JM |
480 |
|
|
481 |
public static String getPath(PageParameters params) {
|
|
482 |
return params.getString("f", null);
|
|
483 |
}
|
98ce17
|
484 |
|
f1dfc2
|
485 |
public static String getBaseObjectId(PageParameters params) {
|
JM |
486 |
return params.getString("hb", null);
|
|
487 |
}
|
7d35e2
|
488 |
|
98ce17
|
489 |
public static String getSearchString(PageParameters params) {
|
JM |
490 |
return params.getString("s", null);
|
|
491 |
}
|
|
492 |
|
|
493 |
public static String getSearchType(PageParameters params) {
|
|
494 |
return params.getString("st", null);
|
|
495 |
}
|
|
496 |
|
7d35e2
|
497 |
public static int getPage(PageParameters params) {
|
2a7306
|
498 |
// index from 1
|
e33b91
|
499 |
return params.getInt("pg", 1);
|
7d35e2
|
500 |
}
|
2a7306
|
501 |
|
cb57ec
|
502 |
public static String getRegEx(PageParameters params) {
|
JM |
503 |
return params.getString("x", "");
|
|
504 |
}
|
|
505 |
|
6e6f9f
|
506 |
public static String getSet(PageParameters params) {
|
JM |
507 |
return params.getString("set", "");
|
|
508 |
}
|
|
509 |
|
cb57ec
|
510 |
public static String getTeam(PageParameters params) {
|
JM |
511 |
return params.getString("team", "");
|
|
512 |
}
|
|
513 |
|
6e6f9f
|
514 |
public static int getDaysBack(PageParameters params) {
|
5abe33
|
515 |
return params.getInt("db", 0);
|
6e6f9f
|
516 |
}
|
JM |
517 |
|
dfb889
|
518 |
public static String getUsername(PageParameters params) {
|
JM |
519 |
return params.getString("user", "");
|
|
520 |
}
|
7d35e2
|
521 |
|
fe24a0
|
522 |
public static String getTeamname(PageParameters params) {
|
JM |
523 |
return params.getString("team", "");
|
|
524 |
}
|
|
525 |
|
831469
|
526 |
public static String getToken(PageParameters params) {
|
JM |
527 |
return params.getString("t", "");
|
|
528 |
}
|
db91a3
|
529 |
|
831469
|
530 |
public static String getUrlParameter(PageParameters params) {
|
JM |
531 |
return params.getString("u", "");
|
|
532 |
}
|
|
533 |
|
|
534 |
public static String getNameParameter(PageParameters params) {
|
|
535 |
return params.getString("n", "");
|
|
536 |
}
|
|
537 |
|
9adf62
|
538 |
public static Label createDateLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) {
|
235ad9
|
539 |
return createDateLabel(wicketId, date, timeZone, timeUtils, true);
|
JM |
540 |
}
|
699e71
|
541 |
|
235ad9
|
542 |
public static Label createDateLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils, boolean setCss) {
|
99d0d4
|
543 |
String format = GitBlitWebApp.get().settings().getString(Keys.web.datestampShortFormat, "MM/dd/yy");
|
2a7306
|
544 |
DateFormat df = new SimpleDateFormat(format);
|
6c6e7d
|
545 |
if (timeZone == null) {
|
99d0d4
|
546 |
timeZone = GitBlitWebApp.get().getTimezone();
|
698678
|
547 |
}
|
6c6e7d
|
548 |
df.setTimeZone(timeZone);
|
831469
|
549 |
String dateString;
|
JM |
550 |
if (date.getTime() == 0) {
|
|
551 |
dateString = "--";
|
|
552 |
} else {
|
|
553 |
dateString = df.format(date);
|
|
554 |
}
|
|
555 |
String title = null;
|
|
556 |
if (date.getTime() <= System.currentTimeMillis()) {
|
|
557 |
// past
|
9adf62
|
558 |
title = timeUtils.timeAgo(date);
|
831469
|
559 |
}
|
01ffd4
|
560 |
if (title != null && (System.currentTimeMillis() - date.getTime()) < 10 * 24 * 60 * 60 * 1000L) {
|
698678
|
561 |
String tmp = dateString;
|
JM |
562 |
dateString = title;
|
|
563 |
title = tmp;
|
|
564 |
}
|
|
565 |
Label label = new Label(wicketId, dateString);
|
235ad9
|
566 |
if (setCss) {
|
JM |
567 |
WicketUtils.setCssClass(label, timeUtils.timeAgoCss(date));
|
|
568 |
}
|
831469
|
569 |
if (!StringUtils.isEmpty(title)) {
|
JM |
570 |
WicketUtils.setHtmlTooltip(label, title);
|
|
571 |
}
|
698678
|
572 |
return label;
|
JM |
573 |
}
|
db91a3
|
574 |
|
9adf62
|
575 |
public static Label createTimeLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) {
|
99d0d4
|
576 |
String format = GitBlitWebApp.get().settings().getString(Keys.web.timeFormat, "HH:mm");
|
6e6f9f
|
577 |
DateFormat df = new SimpleDateFormat(format);
|
6c6e7d
|
578 |
if (timeZone == null) {
|
99d0d4
|
579 |
timeZone = GitBlitWebApp.get().getTimezone();
|
6e6f9f
|
580 |
}
|
6c6e7d
|
581 |
df.setTimeZone(timeZone);
|
6e6f9f
|
582 |
String timeString;
|
JM |
583 |
if (date.getTime() == 0) {
|
|
584 |
timeString = "--";
|
|
585 |
} else {
|
|
586 |
timeString = df.format(date);
|
|
587 |
}
|
9adf62
|
588 |
String title = timeUtils.timeAgo(date);
|
6e6f9f
|
589 |
Label label = new Label(wicketId, timeString);
|
JM |
590 |
if (!StringUtils.isEmpty(title)) {
|
|
591 |
WicketUtils.setHtmlTooltip(label, title);
|
|
592 |
}
|
|
593 |
return label;
|
|
594 |
}
|
db91a3
|
595 |
|
9adf62
|
596 |
public static Label createDatestampLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) {
|
99d0d4
|
597 |
String format = GitBlitWebApp.get().settings().getString(Keys.web.datestampLongFormat, "EEEE, MMMM d, yyyy");
|
6e6f9f
|
598 |
DateFormat df = new SimpleDateFormat(format);
|
6c6e7d
|
599 |
if (timeZone == null) {
|
99d0d4
|
600 |
timeZone = GitBlitWebApp.get().getTimezone();
|
6e6f9f
|
601 |
}
|
6c6e7d
|
602 |
df.setTimeZone(timeZone);
|
6e6f9f
|
603 |
String dateString;
|
JM |
604 |
if (date.getTime() == 0) {
|
|
605 |
dateString = "--";
|
|
606 |
} else {
|
|
607 |
dateString = df.format(date);
|
|
608 |
}
|
|
609 |
String title = null;
|
9b26b7
|
610 |
if (TimeUtils.isToday(date, timeZone)) {
|
9adf62
|
611 |
title = timeUtils.today();
|
9b26b7
|
612 |
} else if (TimeUtils.isYesterday(date, timeZone)) {
|
a96110
|
613 |
title = timeUtils.yesterday();
|
712210
|
614 |
} else if (date.getTime() <= System.currentTimeMillis()) {
|
6e6f9f
|
615 |
// past
|
9adf62
|
616 |
title = timeUtils.timeAgo(date);
|
a96110
|
617 |
} else {
|
JM |
618 |
// future
|
|
619 |
title = timeUtils.inFuture(date);
|
6e6f9f
|
620 |
}
|
JM |
621 |
if ((System.currentTimeMillis() - date.getTime()) < 10 * 24 * 60 * 60 * 1000L) {
|
|
622 |
String tmp = dateString;
|
|
623 |
dateString = title;
|
|
624 |
title = tmp;
|
|
625 |
}
|
|
626 |
Label label = new Label(wicketId, dateString);
|
|
627 |
if (!StringUtils.isEmpty(title)) {
|
|
628 |
WicketUtils.setHtmlTooltip(label, title);
|
|
629 |
}
|
|
630 |
return label;
|
|
631 |
}
|
155bf7
|
632 |
|
9adf62
|
633 |
public static Label createTimestampLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) {
|
99d0d4
|
634 |
String format = GitBlitWebApp.get().settings().getString(Keys.web.datetimestampLongFormat,
|
a4ed6d
|
635 |
"EEEE, MMMM d, yyyy HH:mm Z");
|
2a7306
|
636 |
DateFormat df = new SimpleDateFormat(format);
|
6c6e7d
|
637 |
if (timeZone == null) {
|
99d0d4
|
638 |
timeZone = GitBlitWebApp.get().getTimezone();
|
bc10f9
|
639 |
}
|
6c6e7d
|
640 |
df.setTimeZone(timeZone);
|
a2709d
|
641 |
String dateString;
|
JM |
642 |
if (date.getTime() == 0) {
|
|
643 |
dateString = "--";
|
|
644 |
} else {
|
|
645 |
dateString = df.format(date);
|
|
646 |
}
|
831469
|
647 |
String title = null;
|
JM |
648 |
if (date.getTime() <= System.currentTimeMillis()) {
|
|
649 |
// past
|
9adf62
|
650 |
title = timeUtils.timeAgo(date);
|
831469
|
651 |
}
|
bc10f9
|
652 |
Label label = new Label(wicketId, dateString);
|
831469
|
653 |
if (!StringUtils.isEmpty(title)) {
|
JM |
654 |
WicketUtils.setHtmlTooltip(label, title);
|
|
655 |
}
|
bc10f9
|
656 |
return label;
|
JM |
657 |
}
|
008322
|
658 |
|
f1720c
|
659 |
public static double maxValue(Collection<Metric> metrics) {
|
JM |
660 |
double max = Double.MIN_VALUE;
|
|
661 |
for (Metric m : metrics) {
|
|
662 |
if (m.count > max) {
|
|
663 |
max = m.count;
|
|
664 |
}
|
|
665 |
}
|
|
666 |
return max;
|
|
667 |
}
|
5fe7df
|
668 |
}
|