]> source.dussan.org Git - gitblit.git/commitdiff
Calculate repository color from name. Show swatch on repository list.
authorJames Moger <james.moger@gitblit.com>
Fri, 18 Nov 2011 22:46:06 +0000 (17:46 -0500)
committerJames Moger <james.moger@gitblit.com>
Fri, 18 Nov 2011 22:46:06 +0000 (17:46 -0500)
distrib/gitblit.properties
resources/bootstrap.gb.css
src/com/gitblit/utils/StringUtils.java
src/com/gitblit/wicket/panels/RepositoriesPanel.html
src/com/gitblit/wicket/panels/RepositoriesPanel.java

index 5c50a2ce87bfde20c71878c144a617611bca1090..7ce4ddfa1f6b45ca509bbc6c0cd4cc2a6cbee7b8 100644 (file)
@@ -228,6 +228,12 @@ web.repositoryListType = grouped
 # SINCE 0.5.0\r
 web.repositoryRootGroupName = main\r
 \r
+# Display the repository swatch color next to the repository name link in the \r
+# repositories list. \r
+#\r
+# SINCE 0.8.0\r
+web.repositoryListSwatches = true\r
+\r
 # Choose the diff presentation style: gitblt, gitweb, or plain\r
 #\r
 # SINCE 0.5.0\r
index 06c4670954a4950abf42430291d80e9f009df6e0..32aac08a5f52f19902516507360eb7fccef610b2 100644 (file)
@@ -160,6 +160,15 @@ span.link em, div.link span em {
        font-size: 11px;        \r
 }\r
 \r
+span.repositorySwatch {\r
+       border-radius: 3px;\r
+       padding: 2px 5px;       \r
+       color: #ffffff;\r
+}\r
+span.repositorySwatch a {\r
+       color: inherit;\r
+}\r
+\r
 img.inlineIcon {\r
        padding-left: 1px;\r
        padding-right: 1px;\r
index 746fbe2e8bce574953ce707e8d4a58dc4c242796..a51c157f9e46109749477fc1ad8296527da36499 100644 (file)
@@ -33,7 +33,7 @@ import java.util.regex.PatternSyntaxException;
 public class StringUtils {\r
 \r
        public static final String MD5_TYPE = "MD5:";\r
-       \r
+\r
        public static final String COMBINED_MD5_TYPE = "CMD5:";\r
 \r
        /**\r
@@ -443,4 +443,48 @@ public class StringUtils {
                        }\r
                });\r
        }\r
-}\r
+\r
+       public static String getColor(String value) {\r
+               int cs = 0;\r
+               for (char c : getMD5(value.toLowerCase()).toCharArray()) {\r
+                       cs += c;\r
+               }\r
+               int n = (cs % 360);             \r
+               float hue = ((float) n) / 360;\r
+               return hsvToRgb(hue, 0.90f, 0.65f);\r
+       }\r
+\r
+       public static String hsvToRgb(float hue, float saturation, float value) {\r
+               int h = (int) (hue * 6);\r
+               float f = hue * 6 - h;\r
+               float p = value * (1 - saturation);\r
+               float q = value * (1 - f * saturation);\r
+               float t = value * (1 - (1 - f) * saturation);\r
+\r
+               switch (h) {\r
+               case 0:\r
+                       return rgbToString(value, t, p);\r
+               case 1:\r
+                       return rgbToString(q, value, p);\r
+               case 2:\r
+                       return rgbToString(p, value, t);\r
+               case 3:\r
+                       return rgbToString(p, q, value);\r
+               case 4:\r
+                       return rgbToString(t, p, value);\r
+               case 5:\r
+                       return rgbToString(value, p, q);\r
+               default:\r
+                       throw new RuntimeException(\r
+                                       "Something went wrong when converting from HSV to RGB. Input was " + hue + ", "\r
+                                                       + saturation + ", " + value);\r
+               }\r
+       }\r
+\r
+       public static String rgbToString(float r, float g, float b) {\r
+               String rs = Integer.toHexString((int) (r * 256));\r
+               String gs = Integer.toHexString((int) (g * 256));\r
+               String bs = Integer.toHexString((int) (b * 256));\r
+               return "#" + rs + gs + bs;\r
+       }\r
+}
\ No newline at end of file
index 41741e8998e6e02d848264f08ea64628923a5619..54a498e19b6a62c3c0cfa2a16b8f7d026343df5b 100644 (file)
@@ -71,7 +71,7 @@
        </wicket:fragment>\r
                \r
        <wicket:fragment wicket:id="repositoryRow">\r
-        <td class="left" style="padding-left:10px;" ><div class="list" wicket:id="repositoryName">[repository name]</div></td>\r
+        <td class="left" style="padding-left:3px;" ><span class="repositorySwatch" wicket:id="repositorySwatch"></span> <span style="padding-left:3px;" wicket:id="repositoryName">[repository name]</span></td>\r
         <td><div class="list" wicket:id="repositoryDescription">[repository description]</div></td>\r
         <td class="author"><span wicket:id="repositoryOwner">[repository owner]</span></td>\r
         <td style="text-align: right;padding-right:10px;"><img class="inlineIcon" wicket:id="ticketsIcon" /><img class="inlineIcon" wicket:id="docsIcon" /><img class="inlineIcon" wicket:id="frozenIcon" /><img class="inlineIcon" wicket:id="federatedIcon" /><img class="inlineIcon" wicket:id="accessRestrictionIcon" /></td>\r
index d18d5bb3d5db2db645c33c52602a61b2e1f1e7bd..fd5e34f78d391ca62228b469fb7300ad0a4092b0 100644 (file)
@@ -120,6 +120,7 @@ public class RepositoriesPanel extends BasePanel {
                }\r
 \r
                final String baseUrl = WicketUtils.getGitblitURL(getRequest());\r
+               final boolean showSwatch = GitBlit.getBoolean(Keys.web.repositoryListSwatches, true);\r
 \r
                DataView<RepositoryModel> dataView = new DataView<RepositoryModel>("row", dp) {\r
                        private static final long serialVersionUID = 1L;\r
@@ -146,13 +147,19 @@ public class RepositoriesPanel extends BasePanel {
                                }\r
                                Fragment row = new Fragment("rowContent", "repositoryRow", this);\r
                                item.add(row);\r
-                               \r
+\r
                                // try to strip group name for less cluttered list\r
                                String repoName = entry.name;\r
                                if (!StringUtils.isEmpty(currGroupName) && (repoName.indexOf('/') > -1)) {\r
                                        repoName = repoName.substring(currGroupName.length() + 1);\r
                                }\r
-                               \r
+\r
+                               // repository swatch\r
+                               Label swatch = new Label("repositorySwatch", " ");\r
+                               WicketUtils.setCssBackground(swatch, entry.name);\r
+                               row.add(swatch);\r
+                               swatch.setVisible(showSwatch);\r
+\r
                                if (entry.hasCommits && linksActive) {\r
                                        PageParameters pp = WicketUtils.newRepositoryParameter(entry.name);\r
                                        row.add(new LinkPanel("repositoryName", "list", repoName, SummaryPage.class, pp));\r