From 4c835e61e8ea2d5af2acf0c85c3c1f0d06f419df Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Wed, 26 Oct 2011 17:19:55 -0400
Subject: [PATCH] Documentation.
---
src/com/gitblit/wicket/WicketUtils.java | 115 +++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 91 insertions(+), 24 deletions(-)
diff --git a/src/com/gitblit/wicket/WicketUtils.java b/src/com/gitblit/wicket/WicketUtils.java
index 614cb7d..e5b7f69 100644
--- a/src/com/gitblit/wicket/WicketUtils.java
+++ b/src/com/gitblit/wicket/WicketUtils.java
@@ -39,9 +39,12 @@
import org.wicketstuff.googlecharts.AbstractChartData;
import org.wicketstuff.googlecharts.IChartData;
+import com.gitblit.Constants.FederationPullStatus;
import com.gitblit.GitBlit;
import com.gitblit.Keys;
+import com.gitblit.models.FederationModel;
import com.gitblit.models.Metric;
+import com.gitblit.utils.HttpUtils;
import com.gitblit.utils.JGitUtils.SearchType;
import com.gitblit.utils.StringUtils;
import com.gitblit.utils.TimeUtils;
@@ -85,13 +88,13 @@
public static void setTicketCssClass(Component container, String state) {
String css = null;
if (state.equals("open")) {
- css = "bug_open";
+ css = "label important";
} else if (state.equals("hold")) {
- css = "bug_hold";
+ css = "label warning";
} else if (state.equals("resolved")) {
- css = "bug_resolved";
+ css = "label success";
} else if (state.equals("invalid")) {
- css = "bug_invalid";
+ css = "label";
}
if (css != null) {
setCssClass(container, css);
@@ -99,7 +102,7 @@
}
public static void setAlternatingBackground(Component c, int i) {
- String clazz = i % 2 == 0 ? "dark" : "light";
+ String clazz = i % 2 == 0 ? "light" : "dark";
setCssClass(c, clazz);
}
@@ -107,6 +110,30 @@
Label label = new Label(wicketId, author);
WicketUtils.setHtmlTooltip(label, author);
return label;
+ }
+
+ public static ContextImage getPullStatusImage(String wicketId, FederationPullStatus status) {
+ String filename = null;
+ switch (status) {
+ case MIRRORED:
+ case PULLED:
+ filename = "bullet_green.png";
+ break;
+ case SKIPPED:
+ filename = "bullet_yellow.png";
+ break;
+ case FAILED:
+ filename = "bullet_red.png";
+ break;
+ case EXCLUDED:
+ filename = "bullet_white.png";
+ break;
+ case PENDING:
+ case NOCHANGE:
+ default:
+ filename = "bullet_black.png";
+ }
+ return WicketUtils.newImage(wicketId, filename, status.name());
}
public static ContextImage getFileImage(String wicketId, String filename) {
@@ -155,6 +182,17 @@
return newImage(wicketId, "file_16x16.png");
}
+ public static ContextImage getRegistrationImage(String wicketId, FederationModel registration,
+ Component c) {
+ if (registration.isResultData()) {
+ return WicketUtils.newImage(wicketId, "information_16x16.png",
+ c.getString("gb.federationResults"));
+ } else {
+ return WicketUtils.newImage(wicketId, "arrow_left.png",
+ c.getString("gb.federationRegistration"));
+ }
+ }
+
public static ContextImage newClearPixel(String wicketId) {
return newImage(wicketId, "pixel.png");
}
@@ -179,21 +217,9 @@
return new ContextRelativeResource(file);
}
- public static String getHostURL(Request request) {
+ public static String getGitblitURL(Request request) {
HttpServletRequest req = ((WebRequest) request).getHttpServletRequest();
- return getHostURL(req);
- }
-
- public static String getHostURL(HttpServletRequest request) {
- StringBuilder sb = new StringBuilder();
- sb.append(request.getScheme());
- sb.append("://");
- sb.append(request.getServerName());
- if ((request.getScheme().equals("http") && request.getServerPort() != 80)
- || (request.getScheme().equals("https") && request.getServerPort() != 443)) {
- sb.append(":" + request.getServerPort());
- }
- return sb.toString();
+ return HttpUtils.getGitblitURL(req);
}
public static HeaderContributor syndicationDiscoveryLink(final String feedTitle,
@@ -213,6 +239,14 @@
}
});
}
+
+ public static PageParameters newTokenParameter(String token) {
+ return new PageParameters("t=" + token);
+ }
+
+ public static PageParameters newRegistrationParameter(String url, String name) {
+ return new PageParameters("u=" + url + ",n=" + name);
+ }
public static PageParameters newUsernameParameter(String username) {
return new PageParameters("user=" + username);
@@ -220,6 +254,10 @@
public static PageParameters newRepositoryParameter(String repositoryName) {
return new PageParameters("r=" + repositoryName);
+ }
+
+ public static PageParameters newObjectParameter(String objectId) {
+ return new PageParameters("h=" + objectId);
}
public static PageParameters newObjectParameter(String repositoryName, String objectId) {
@@ -324,14 +362,35 @@
return params.getString("user", "");
}
+ public static String getToken(PageParameters params) {
+ return params.getString("t", "");
+ }
+
+ public static String getUrlParameter(PageParameters params) {
+ return params.getString("u", "");
+ }
+
+ public static String getNameParameter(PageParameters params) {
+ return params.getString("n", "");
+ }
+
public static Label createDateLabel(String wicketId, Date date, TimeZone timeZone) {
String format = GitBlit.getString(Keys.web.datestampShortFormat, "MM/dd/yy");
DateFormat df = new SimpleDateFormat(format);
if (timeZone != null) {
df.setTimeZone(timeZone);
}
- String dateString = df.format(date);
- String title = TimeUtils.timeAgo(date);
+ String dateString;
+ if (date.getTime() == 0) {
+ dateString = "--";
+ } else {
+ dateString = df.format(date);
+ }
+ String title = null;
+ if (date.getTime() <= System.currentTimeMillis()) {
+ // past
+ title = TimeUtils.timeAgo(date);
+ }
if ((System.currentTimeMillis() - date.getTime()) < 10 * 24 * 60 * 60 * 1000L) {
String tmp = dateString;
dateString = title;
@@ -339,7 +398,9 @@
}
Label label = new Label(wicketId, dateString);
WicketUtils.setCssClass(label, TimeUtils.timeAgoCss(date));
- WicketUtils.setHtmlTooltip(label, title);
+ if (!StringUtils.isEmpty(title)) {
+ WicketUtils.setHtmlTooltip(label, title);
+ }
return label;
}
@@ -356,9 +417,15 @@
} else {
dateString = df.format(date);
}
- String title = TimeUtils.timeAgo(date);
+ String title = null;
+ if (date.getTime() <= System.currentTimeMillis()) {
+ // past
+ title = TimeUtils.timeAgo(date);
+ }
Label label = new Label(wicketId, dateString);
- WicketUtils.setHtmlTooltip(label, title);
+ if (!StringUtils.isEmpty(title)) {
+ WicketUtils.setHtmlTooltip(label, title);
+ }
return label;
}
--
Gitblit v1.9.1