From 5bb79fbb553a11e6582392f658233cf58a4ceb11 Mon Sep 17 00:00:00 2001 From: Paul Martin <paul@paulsputer.com> Date: Wed, 06 Apr 2016 14:31:41 -0400 Subject: [PATCH] Fix for #1042 - Filestore items now shown as icons --- src/main/java/com/gitblit/wicket/WicketUtils.java | 190 ++++++++++++++++++++++++----------------------- 1 files changed, 96 insertions(+), 94 deletions(-) diff --git a/src/main/java/com/gitblit/wicket/WicketUtils.java b/src/main/java/com/gitblit/wicket/WicketUtils.java index aa86686..d9ff34a 100644 --- a/src/main/java/com/gitblit/wicket/WicketUtils.java +++ b/src/main/java/com/gitblit/wicket/WicketUtils.java @@ -21,7 +21,6 @@ import java.util.Collection; import java.util.Date; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.TimeZone; @@ -30,25 +29,26 @@ import org.apache.wicket.Component; import org.apache.wicket.PageParameters; import org.apache.wicket.Request; +import org.apache.wicket.behavior.AttributeAppender; import org.apache.wicket.behavior.HeaderContributor; import org.apache.wicket.behavior.SimpleAttributeModifier; import org.apache.wicket.markup.html.IHeaderContributor; import org.apache.wicket.markup.html.IHeaderResponse; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.image.ContextImage; +import org.apache.wicket.model.Model; import org.apache.wicket.protocol.http.WebRequest; import org.apache.wicket.resource.ContextRelativeResource; import org.eclipse.jgit.diff.DiffEntry.ChangeType; -import org.wicketstuff.googlecharts.AbstractChartData; -import org.wicketstuff.googlecharts.IChartData; import com.gitblit.Constants; import com.gitblit.Constants.AccessPermission; import com.gitblit.Constants.FederationPullStatus; -import com.gitblit.GitBlit; +import com.gitblit.IStoredSettings; import com.gitblit.Keys; import com.gitblit.models.FederationModel; import com.gitblit.models.Metric; +import com.gitblit.utils.DiffUtils.DiffComparator; import com.gitblit.utils.HttpUtils; import com.gitblit.utils.StringUtils; import com.gitblit.utils.TimeUtils; @@ -57,6 +57,10 @@ public static void setCssClass(Component container, String value) { container.add(new SimpleAttributeModifier("class", value)); + } + + public static void addCssClass(Component container, String value) { + container.add(new AttributeAppender("class", new Model<String>(value), " ")); } public static void setCssStyle(Component container, String value) { @@ -69,8 +73,8 @@ container.add(new SimpleAttributeModifier("style", background)); } - public static void setHtmlTooltip(Component container, String value) { - container.add(new SimpleAttributeModifier("title", value)); + public static Component setHtmlTooltip(Component container, String value) { + return container.add(new SimpleAttributeModifier("title", value)); } public static void setInputPlaceholder(Component container, String value) { @@ -95,22 +99,6 @@ } } - public static void setTicketCssClass(Component container, String state) { - String css = null; - if (state.equals("open")) { - css = "label label-important"; - } else if (state.equals("hold")) { - css = "label label-warning"; - } else if (state.equals("resolved")) { - css = "label label-success"; - } else if (state.equals("invalid")) { - css = "label"; - } - if (css != null) { - setCssClass(container, css); - } - } - public static void setPermissionClass(Component container, AccessPermission permission) { if (permission == null) { setCssClass(container, "badge"); @@ -131,7 +119,7 @@ default: setCssClass(container, "badge"); break; - } + } } public static void setAlternatingBackground(Component c, int i) { @@ -206,11 +194,10 @@ return newImage(wicketId, "file_settings_16x16.png"); } - List<String> mdExtensions = GitBlit.getStrings(Keys.web.markdownExtensions); - for (String ext : mdExtensions) { - if (filename.endsWith('.' + ext.toLowerCase())) { - return newImage(wicketId, "file_world_16x16.png"); - } + String ext = StringUtils.getFileExtension(filename).toLowerCase(); + IStoredSettings settings = GitBlitWebApp.get().settings(); + if (MarkupProcessor.getMarkupExtensions(settings).contains(ext)) { + return newImage(wicketId, "file_world_16x16.png"); } return newImage(wicketId, "file_16x16.png"); } @@ -248,17 +235,17 @@ public static Label newIcon(String wicketId, String css) { Label lbl = new Label(wicketId); - setCssClass(lbl, css); + setCssClass(lbl, css); return lbl; } - + public static Label newBlankIcon(String wicketId) { Label lbl = new Label(wicketId); setCssClass(lbl, ""); lbl.setRenderBodyOnly(true); return lbl; } - + public static ContextRelativeResource getResource(String file) { return new ContextRelativeResource(file); } @@ -273,6 +260,7 @@ return new HeaderContributor(new IHeaderContributor() { private static final long serialVersionUID = 1L; + @Override public void renderHead(IHeaderResponse response) { String contentType = "application/rss+xml"; @@ -320,7 +308,9 @@ public static PageParameters newRepositoryParameter(String repositoryName) { Map<String, String> parameterMap = new HashMap<String, String>(); - parameterMap.put("r", repositoryName); + if (!StringUtils.isEmpty(repositoryName)) { + parameterMap.put("r", repositoryName); + } return new PageParameters(parameterMap); } @@ -338,6 +328,31 @@ } parameterMap.put("r", repositoryName); parameterMap.put("h", objectId); + return new PageParameters(parameterMap); + } + + public static PageParameters newDiffParameter(String repositoryName, + String objectId, DiffComparator diffComparator) { + Map<String, String> parameterMap = new HashMap<String, String>(); + if (StringUtils.isEmpty(objectId)) { + return newRepositoryParameter(repositoryName); + } + parameterMap.put("r", repositoryName); + parameterMap.put("h", objectId); + parameterMap.put("w", "" + diffComparator.ordinal()); + return new PageParameters(parameterMap); + } + + public static PageParameters newDiffParameter(String repositoryName, + String objectId, DiffComparator diffComparator, String blobPath) { + Map<String, String> parameterMap = new HashMap<String, String>(); + if (StringUtils.isEmpty(objectId)) { + return newRepositoryParameter(repositoryName); + } + parameterMap.put("r", repositoryName); + parameterMap.put("h", objectId); + parameterMap.put("w", "" + diffComparator.ordinal()); + parameterMap.put("f", blobPath); return new PageParameters(parameterMap); } @@ -453,6 +468,30 @@ return new PageParameters(parameterMap); } + public static PageParameters newBlameTypeParameter(String repositoryName, + String commitId, String path, String blameType) { + Map<String, String> parameterMap = new HashMap<String, String>(); + parameterMap.put("r", repositoryName); + parameterMap.put("h", commitId); + parameterMap.put("f", path); + parameterMap.put("blametype", blameType); + return new PageParameters(parameterMap); + } + + public static PageParameters newTicketsParameters(String repositoryName, String... states) { + PageParameters tParams = newRepositoryParameter(repositoryName); + if (states != null) { + for (String state : states) { + tParams.add("status", state); + } + } + return tParams; + } + + public static PageParameters newOpenTicketsParameter(String repositoryName) { + return newTicketsParameters(repositoryName, TicketsUI.openStatii); + } + public static String getProjectName(PageParameters params) { return params.getString("p", ""); } @@ -479,6 +518,11 @@ public static String getSearchType(PageParameters params) { return params.getString("st", null); + } + + public static DiffComparator getDiffComparator(PageParameters params) { + int ordinal = params.getInt("w", 0); + return DiffComparator.values()[ordinal]; } public static int getPage(PageParameters params) { @@ -523,10 +567,14 @@ } public static Label createDateLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) { - String format = GitBlit.getString(Keys.web.datestampShortFormat, "MM/dd/yy"); + return createDateLabel(wicketId, date, timeZone, timeUtils, true); + } + + public static Label createDateLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils, boolean setCss) { + String format = GitBlitWebApp.get().settings().getString(Keys.web.datestampShortFormat, "MM/dd/yy"); DateFormat df = new SimpleDateFormat(format); if (timeZone == null) { - timeZone = GitBlit.getTimezone(); + timeZone = GitBlitWebApp.get().getTimezone(); } df.setTimeZone(timeZone); String dateString; @@ -540,13 +588,15 @@ // past title = timeUtils.timeAgo(date); } - if ((System.currentTimeMillis() - date.getTime()) < 10 * 24 * 60 * 60 * 1000L) { + if (title != null && (System.currentTimeMillis() - date.getTime()) < 10 * 24 * 60 * 60 * 1000L) { String tmp = dateString; dateString = title; title = tmp; } Label label = new Label(wicketId, dateString); - WicketUtils.setCssClass(label, timeUtils.timeAgoCss(date)); + if (setCss) { + WicketUtils.setCssClass(label, timeUtils.timeAgoCss(date)); + } if (!StringUtils.isEmpty(title)) { WicketUtils.setHtmlTooltip(label, title); } @@ -554,10 +604,10 @@ } public static Label createTimeLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) { - String format = GitBlit.getString(Keys.web.timeFormat, "HH:mm"); + String format = GitBlitWebApp.get().settings().getString(Keys.web.timeFormat, "HH:mm"); DateFormat df = new SimpleDateFormat(format); if (timeZone == null) { - timeZone = GitBlit.getTimezone(); + timeZone = GitBlitWebApp.get().getTimezone(); } df.setTimeZone(timeZone); String timeString; @@ -575,10 +625,10 @@ } public static Label createDatestampLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) { - String format = GitBlit.getString(Keys.web.datestampLongFormat, "EEEE, MMMM d, yyyy"); + String format = GitBlitWebApp.get().settings().getString(Keys.web.datestampLongFormat, "EEEE, MMMM d, yyyy"); DateFormat df = new SimpleDateFormat(format); if (timeZone == null) { - timeZone = GitBlit.getTimezone(); + timeZone = GitBlitWebApp.get().getTimezone(); } df.setTimeZone(timeZone); String dateString; @@ -591,10 +641,13 @@ if (TimeUtils.isToday(date, timeZone)) { title = timeUtils.today(); } else if (TimeUtils.isYesterday(date, timeZone)) { - title = timeUtils.yesterday(); + title = timeUtils.yesterday(); } else if (date.getTime() <= System.currentTimeMillis()) { // past title = timeUtils.timeAgo(date); + } else { + // future + title = timeUtils.inFuture(date); } if ((System.currentTimeMillis() - date.getTime()) < 10 * 24 * 60 * 60 * 1000L) { String tmp = dateString; @@ -609,11 +662,11 @@ } public static Label createTimestampLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) { - String format = GitBlit.getString(Keys.web.datetimestampLongFormat, + String format = GitBlitWebApp.get().settings().getString(Keys.web.datetimestampLongFormat, "EEEE, MMMM d, yyyy HH:mm Z"); DateFormat df = new SimpleDateFormat(format); if (timeZone == null) { - timeZone = GitBlit.getTimezone(); + timeZone = GitBlitWebApp.get().getTimezone(); } df.setTimeZone(timeZone); String dateString; @@ -634,31 +687,6 @@ return label; } - public static IChartData getChartData(Collection<Metric> metrics) { - final double[] commits = new double[metrics.size()]; - final double[] tags = new double[metrics.size()]; - int i = 0; - double max = 0; - for (Metric m : metrics) { - commits[i] = m.count; - if (m.tag > 0) { - tags[i] = m.count; - } else { - tags[i] = -1d; - } - max = Math.max(max, m.count); - i++; - } - IChartData data = new AbstractChartData(max) { - private static final long serialVersionUID = 1L; - - public double[][] getData() { - return new double[][] { commits, tags }; - } - }; - return data; - } - public static double maxValue(Collection<Metric> metrics) { double max = Double.MIN_VALUE; for (Metric m : metrics) { @@ -668,30 +696,4 @@ } return max; } - - public static IChartData getScatterData(Collection<Metric> metrics) { - final double[] y = new double[metrics.size()]; - final double[] x = new double[metrics.size()]; - int i = 0; - double max = 0; - for (Metric m : metrics) { - y[i] = m.count; - if (m.duration > 0) { - x[i] = m.duration; - } else { - x[i] = -1d; - } - max = Math.max(max, m.count); - i++; - } - IChartData data = new AbstractChartData(max) { - private static final long serialVersionUID = 1L; - - public double[][] getData() { - return new double[][] { x, y }; - } - }; - return data; - } - } -- Gitblit v1.9.1