]> source.dussan.org Git - gitblit.git/commitdiff
Refactored topbar navigation links to indicate current page.
authorJames Moger <james.moger@gitblit.com>
Wed, 5 Oct 2011 12:04:47 +0000 (08:04 -0400)
committerJames Moger <james.moger@gitblit.com>
Wed, 5 Oct 2011 12:04:47 +0000 (08:04 -0400)
resources/arrow_page.png [new file with mode: 0644]
resources/bootstrap.gb.css
src/com/gitblit/wicket/PageRegistration.java [new file with mode: 0644]
src/com/gitblit/wicket/pages/RepositoryPage.html
src/com/gitblit/wicket/pages/RepositoryPage.java
src/com/gitblit/wicket/pages/RootPage.html
src/com/gitblit/wicket/pages/RootPage.java
src/com/gitblit/wicket/panels/NavigationPanel.html [new file with mode: 0644]
src/com/gitblit/wicket/panels/NavigationPanel.java [new file with mode: 0644]

diff --git a/resources/arrow_page.png b/resources/arrow_page.png
new file mode 100644 (file)
index 0000000..6d93024
Binary files /dev/null and b/resources/arrow_page.png differ
index cf82c87ab51c516168dd560e6c1f7022a233b10c..6ff047b113f82e5d351adbea93bf1dbfbe865a97 100644 (file)
@@ -46,6 +46,12 @@ hr {
        border-bottom: 2px solid #ff9900 !important;\r
 }\r
 \r
+.topbar ul li:focus, .topbar .active {\r
+       background-repeat:no-repeat;\r
+       background-image: url(arrow_page.png);\r
+       background-position: center bottom;\r
+}\r
+\r
 .breadcrumb {\r
        margin-top: 5px !important;\r
        margin-bottom: 5px !important;\r
diff --git a/src/com/gitblit/wicket/PageRegistration.java b/src/com/gitblit/wicket/PageRegistration.java
new file mode 100644 (file)
index 0000000..ac00fb5
--- /dev/null
@@ -0,0 +1,47 @@
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.wicket;\r
+\r
+import java.io.Serializable;\r
+\r
+import org.apache.wicket.PageParameters;\r
+\r
+import com.gitblit.wicket.pages.BasePage;\r
+\r
+/**\r
+ * Represents a page link registration for the topbar.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public class PageRegistration implements Serializable {\r
+       private static final long serialVersionUID = 1L;\r
+\r
+       public final String translationKey;\r
+       public final Class<? extends BasePage> pageClass;\r
+       public final PageParameters params;\r
+\r
+       public PageRegistration(String translationKey, Class<? extends BasePage> pageClass) {\r
+               this(translationKey, pageClass, null);\r
+       }\r
+\r
+       public PageRegistration(String translationKey, Class<? extends BasePage> pageClass,\r
+                       PageParameters params) {\r
+               this.translationKey = translationKey;\r
+               this.pageClass = pageClass;\r
+               this.params = params;\r
+       }\r
+}
\ No newline at end of file
index 100016f1545ddce1a869d24cc683328e5b197897..c60275ab68b0c98c3ab076ad656c764045bb9588 100644 (file)
                                <a class="brand" wicket:id="rootLink">\r
                                        <img src="gitblt_25_white.png" width="79" height="25" alt="gitblit" class="logo"/>\r
                                </a>\r
-                               <ul class="nav">                                \r
-                                       <li><a wicket:id="repositories"><wicket:message key="gb.repositories"></wicket:message></a></li>\r
-                                       <li><a wicket:id="summary"><wicket:message key="gb.summary"></wicket:message></a></li>\r
-                                       <li><a wicket:id="log"><wicket:message key="gb.log"></wicket:message></a></li>\r
-                                       <li><a wicket:id="branches"><wicket:message key="gb.branches"></wicket:message></a></li>\r
-                                       <li><a wicket:id="tags"><wicket:message key="gb.tags"></wicket:message></a></li>\r
-                                       <li><a wicket:id="tree"><wicket:message key="gb.tree"></wicket:message></a></li>\r
-                                       <li wicket:id="extra"><span wicket:id="extraLink"></span></li>\r
-                                       <li><a style="text-decoration: none;" wicket:id="syndication">\r
-                                               <img style="border:0px;vertical-align:middle;" src="feed_16x16.png"></img></a>\r
-                                       </li>                                                                   \r
-                               </ul>\r
+                               \r
+                               <span wicket:id="navPanel"></span>\r
+                               \r
+                               <a class="brand" style="text-decoration: none;" wicket:id="syndication">\r
+                                       <img style="border:0px;vertical-align:middle;" src="feed_16x16.png"></img>\r
+                               </a>\r
+                               \r
                                <form class="pull-right" wicket:id="searchForm">\r
                                        <div class="search">\r
                                                <select class="small" wicket:id="searchType"/>                  \r
index 1b6ae082bfe12dce8b7a5f1e17acc6564d81b2d5..272a3f5aed194b8c0c622f69a5c6556ac7e68551 100644 (file)
@@ -19,7 +19,7 @@ import java.io.Serializable;
 import java.text.MessageFormat;\r
 import java.util.ArrayList;\r
 import java.util.Arrays;\r
-import java.util.HashMap;\r
+import java.util.LinkedHashMap;\r
 import java.util.List;\r
 import java.util.Map;\r
 \r
@@ -29,12 +29,8 @@ import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.form.DropDownChoice;\r
 import org.apache.wicket.markup.html.form.StatelessForm;\r
 import org.apache.wicket.markup.html.form.TextField;\r
-import org.apache.wicket.markup.html.link.BookmarkablePageLink;\r
 import org.apache.wicket.markup.html.link.ExternalLink;\r
 import org.apache.wicket.markup.html.panel.Fragment;\r
-import org.apache.wicket.markup.repeater.Item;\r
-import org.apache.wicket.markup.repeater.data.DataView;\r
-import org.apache.wicket.markup.repeater.data.ListDataProvider;\r
 import org.apache.wicket.model.IModel;\r
 import org.apache.wicket.model.Model;\r
 import org.eclipse.jgit.diff.DiffEntry.ChangeType;\r
@@ -51,8 +47,10 @@ import com.gitblit.utils.JGitUtils.SearchType;
 import com.gitblit.utils.StringUtils;\r
 import com.gitblit.utils.TicgitUtils;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
+import com.gitblit.wicket.PageRegistration;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.panels.LinkPanel;\r
+import com.gitblit.wicket.panels.NavigationPanel;\r
 import com.gitblit.wicket.panels.RefsPanel;\r
 \r
 public abstract class RepositoryPage extends BasePage {\r
@@ -64,22 +62,7 @@ public abstract class RepositoryPage extends BasePage {
 \r
        private RepositoryModel m;\r
 \r
-       private final Map<String, PageRegistration> registeredPages = new HashMap<String, PageRegistration>() {\r
-\r
-               private static final long serialVersionUID = 1L;\r
-\r
-               {\r
-                       put("repositories", new PageRegistration("gb.repositories", RepositoriesPage.class, false));\r
-                       put("summary", new PageRegistration("gb.summary", SummaryPage.class));\r
-                       put("log", new PageRegistration("gb.log", LogPage.class));\r
-                       put("branches", new PageRegistration("gb.branches", BranchesPage.class));\r
-                       put("tags", new PageRegistration("gb.tags", TagsPage.class));\r
-                       put("tree", new PageRegistration("gb.tree", TreePage.class));\r
-                       put("tickets", new PageRegistration("gb.tickets", TicketsPage.class));\r
-                       put("edit", new PageRegistration("gb.edit", EditRepositoryPage.class));\r
-                       put("docs", new PageRegistration("gb.docs", DocsPage.class));\r
-               }\r
-       };\r
+       private final Map<String, PageRegistration> registeredPages;\r
 \r
        public RepositoryPage(PageParameters params) {\r
                super(params);\r
@@ -90,26 +73,53 @@ public abstract class RepositoryPage extends BasePage {
                        error(MessageFormat.format("Repository not specified for {0}!", getPageName()), true);\r
                }\r
 \r
-               Repository r = getRepository();\r
-               RepositoryModel model = getRepositoryModel();\r
+               // register the available page links for this page and user\r
+               registeredPages = registerPages();\r
 \r
                // standard page links\r
-               addRegisteredPageLink("repositories");\r
-               addRegisteredPageLink("summary");\r
-               addRegisteredPageLink("log");\r
-               addRegisteredPageLink("branches");\r
-               addRegisteredPageLink("tags");\r
-               addRegisteredPageLink("tree");\r
+               List<PageRegistration> pages = new ArrayList<PageRegistration>(registeredPages.values());\r
+               NavigationPanel navigationPanel = new NavigationPanel("navPanel", getClass(), pages);\r
+               add(navigationPanel);\r
+\r
+               add(new ExternalLink("syndication", SyndicationServlet.asLink(getRequest()\r
+                               .getRelativePathPrefixToContextRoot(), repositoryName, null, 0)));\r
+\r
+               // add floating search form\r
+               SearchForm searchForm = new SearchForm("searchForm", repositoryName);\r
+               add(searchForm);\r
+               searchForm.setTranslatedAttributes();\r
+\r
+               // set stateless page preference\r
+               setStatelessHint(true);\r
+       }\r
+\r
+       private Map<String, PageRegistration> registerPages() {\r
+               PageParameters params = null;\r
+               if (!StringUtils.isEmpty(repositoryName)) {\r
+                       params = WicketUtils.newRepositoryParameter(repositoryName);\r
+               }\r
+               Map<String, PageRegistration> pages = new LinkedHashMap<String, PageRegistration>();\r
+\r
+               // standard links\r
+               pages.put("repositories", new PageRegistration("gb.repositories", RepositoriesPage.class));\r
+               pages.put("summary", new PageRegistration("gb.summary", SummaryPage.class, params));\r
+               pages.put("log", new PageRegistration("gb.log", LogPage.class, params));\r
+               pages.put("branches", new PageRegistration("gb.branches", BranchesPage.class, params));\r
+               pages.put("tags", new PageRegistration("gb.tags", TagsPage.class, params));\r
+               pages.put("tree", new PageRegistration("gb.tree", TreePage.class, params));\r
+\r
+               // conditional links\r
+               Repository r = getRepository();\r
+               RepositoryModel model = getRepositoryModel();\r
 \r
                // per-repository extra page links\r
-               List<String> extraPageLinks = new ArrayList<String>();\r
                if (model.useTickets && TicgitUtils.getTicketsBranch(r) != null) {\r
-                       extraPageLinks.add("tickets");\r
+                       pages.put("tickets", new PageRegistration("gb.tickets", TicketsPage.class, params));\r
                }\r
                if (model.useDocs) {\r
-                       extraPageLinks.add("docs");\r
+                       pages.put("docs", new PageRegistration("gb.docs", DocsPage.class, params));\r
                }\r
-\r
+               // Conditionally add edit link\r
                final boolean showAdmin;\r
                if (GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) {\r
                        boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);\r
@@ -117,45 +127,15 @@ public abstract class RepositoryPage extends BasePage {
                } else {\r
                        showAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);\r
                }\r
-\r
-               // Conditionally add edit link\r
                if (showAdmin\r
                                || GitBlitWebSession.get().isLoggedIn()\r
                                && (model.owner != null && model.owner.equalsIgnoreCase(GitBlitWebSession.get()\r
                                                .getUser().username))) {\r
-                       extraPageLinks.add("edit");\r
+                       pages.put("edit", new PageRegistration("gb.edit", EditRepositoryPage.class, params));\r
                }\r
-\r
-               final String pageName = getPageName();\r
-               final String pageWicketId = getLinkWicketId(pageName);\r
-               ListDataProvider<String> extrasDp = new ListDataProvider<String>(extraPageLinks);\r
-               DataView<String> extrasView = new DataView<String>("extra", extrasDp) {\r
-                       private static final long serialVersionUID = 1L;\r
-\r
-                       public void populateItem(final Item<String> item) {\r
-                               String extra = item.getModelObject();\r
-                               PageRegistration pageReg = registeredPages.get(extra);\r
-                               item.add(new LinkPanel("extraLink", null, getString(pageReg.translationKey),\r
-                                               pageReg.pageClass, WicketUtils.newRepositoryParameter(repositoryName)));\r
-                       }\r
-               };\r
-               add(extrasView);\r
-\r
-               add(new ExternalLink("syndication", SyndicationServlet.asLink(getRequest()\r
-                               .getRelativePathPrefixToContextRoot(), repositoryName, null, 0)));\r
-\r
-               // disable current page\r
-               disableRegisteredPageLink(pageName);\r
-\r
-               // add floating search form\r
-               SearchForm searchForm = new SearchForm("searchForm", repositoryName);\r
-               add(searchForm);\r
-               searchForm.setTranslatedAttributes();\r
-\r
-               // set stateless page preference\r
-               setStatelessHint(true);\r
+               return pages;\r
        }\r
-       \r
+\r
        @Override\r
        protected void setupPage(String repositoryName, String pageName) {\r
                add(new LinkPanel("repositoryName", null, repositoryName, SummaryPage.class,\r
@@ -165,38 +145,6 @@ public abstract class RepositoryPage extends BasePage {
                super.setupPage(repositoryName, pageName);\r
        }\r
 \r
-       public String getLinkWicketId(String pageName) {\r
-               for (String wicketId : registeredPages.keySet()) {\r
-                       String key = registeredPages.get(wicketId).translationKey;\r
-                       String linkName = getString(key);\r
-                       if (linkName.equals(pageName)) {\r
-                               return wicketId;\r
-                       }\r
-               }\r
-               return null;\r
-       }\r
-\r
-       public void disableRegisteredPageLink(String pageName) {\r
-               String wicketId = getLinkWicketId(pageName);\r
-               if (!StringUtils.isEmpty(wicketId)) {\r
-                       Component c = get(wicketId);\r
-                       if (c != null) {\r
-//                             c.setEnabled(false);\r
-//                             WicketUtils.setCssClass(c, "selected");\r
-                       }\r
-               }\r
-       }\r
-\r
-       private void addRegisteredPageLink(String key) {\r
-               PageRegistration pageReg = registeredPages.get(key);\r
-               if (pageReg.repositoryLink) {\r
-                       add(new BookmarkablePageLink<Void>(key, pageReg.pageClass,\r
-                                       WicketUtils.newRepositoryParameter(repositoryName)));\r
-               } else {\r
-                       add(new BookmarkablePageLink<Void>(key, pageReg.pageClass));\r
-               }\r
-       }\r
-\r
        protected void addSyndicationDiscoveryLink() {\r
                add(WicketUtils.syndicationDiscoveryLink(SyndicationServlet.getTitle(repositoryName,\r
                                objectId), SyndicationServlet.asLink(getRequest()\r
@@ -344,24 +292,6 @@ public abstract class RepositoryPage extends BasePage {
                return WicketUtils.newObjectParameter(repositoryName, commitId);\r
        }\r
 \r
-       private static class PageRegistration implements Serializable {\r
-               private static final long serialVersionUID = 1L;\r
-\r
-               final String translationKey;\r
-               final Class<? extends BasePage> pageClass;\r
-               final boolean repositoryLink;\r
-\r
-               PageRegistration(String translationKey, Class<? extends BasePage> pageClass) {\r
-                       this(translationKey, pageClass, true);\r
-               }\r
-               \r
-               PageRegistration(String translationKey, Class<? extends BasePage> pageClass, boolean repositoryLink) {\r
-                       this.translationKey = translationKey;\r
-                       this.pageClass = pageClass;\r
-                       this.repositoryLink = repositoryLink;\r
-               }\r
-       }\r
-\r
        private static class SearchForm extends StatelessForm<Void> implements Serializable {\r
                private static final long serialVersionUID = 1L;\r
 \r
@@ -384,7 +314,8 @@ public abstract class RepositoryPage extends BasePage {
 \r
                void setTranslatedAttributes() {\r
                        WicketUtils.setHtmlTooltip(get("searchType"), getString("gb.searchTypeTooltip"));\r
-                       WicketUtils.setHtmlTooltip(get("searchBox"), MessageFormat.format(getString("gb.searchTooltip"), repositoryName));\r
+                       WicketUtils.setHtmlTooltip(get("searchBox"),\r
+                                       MessageFormat.format(getString("gb.searchTooltip"), repositoryName));\r
                        WicketUtils.setInputPlaceholder(get("searchBox"), getString("gb.search"));\r
                }\r
 \r
index c94709237a9d5a7ef358ad1b202a09a32a6b1a63..a4dcb2c192febb8e5a9e9107bdd844adbe62e876 100644 (file)
                                        <img src="gitblt_25_white.png" width="79" height="25" alt="gitblit" class="logo"/>\r
                                </a>\r
                                \r
-                               <ul class="nav">                                \r
-                                       <li><a wicket:id="repositories"><wicket:message key="gb.repositories"></wicket:message></a></li>\r
-                                       <li><a wicket:id="users"><wicket:message key="gb.users"></wicket:message></a></li>\r
-                                       <li><a wicket:id="federation"><wicket:message key="gb.federation"></wicket:message></a></li>\r
-                               </ul>\r
+                               <span wicket:id="navPanel"></span>\r
                                \r
                                <form class="pull-right" wicket:id="loginForm">\r
                                        <div class="login">\r
index 69ac25d0e5e01feb4fd6511a7cdb0aa222af3e78..f00c0411163310ee44249ef1047251b16a4571a1 100644 (file)
 package com.gitblit.wicket.pages;\r
 \r
 import java.text.MessageFormat;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
 \r
 import org.apache.wicket.PageParameters;\r
 import org.apache.wicket.markup.html.form.PasswordTextField;\r
 import org.apache.wicket.markup.html.form.StatelessForm;\r
 import org.apache.wicket.markup.html.form.TextField;\r
-import org.apache.wicket.markup.html.link.BookmarkablePageLink;\r
 import org.apache.wicket.model.IModel;\r
 import org.apache.wicket.model.Model;\r
 import org.apache.wicket.protocol.http.WebResponse;\r
@@ -32,7 +33,9 @@ import com.gitblit.Keys;
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
+import com.gitblit.wicket.PageRegistration;\r
 import com.gitblit.wicket.WicketUtils;\r
+import com.gitblit.wicket.panels.NavigationPanel;\r
 \r
 /**\r
  * Root page is a topbar, navigable page like Repositories, Users, or\r
@@ -77,10 +80,16 @@ public abstract class RootPage extends BasePage {
                                && GitBlit.getBoolean(Keys.web.showFederationRegistrations, false);\r
 \r
                // navigation links\r
-               add(new BookmarkablePageLink<Void>("repositories", RepositoriesPage.class));\r
-               add(new BookmarkablePageLink<Void>("users", UsersPage.class).setVisible(showAdmin));\r
-               add(new BookmarkablePageLink<Void>("federation", FederationPage.class).setVisible(showAdmin\r
-                               || showRegistrations));\r
+               List<PageRegistration> pages = new ArrayList<PageRegistration>();\r
+               pages.add(new PageRegistration("gb.repositories", RepositoriesPage.class));\r
+               if (showAdmin) {\r
+                       pages.add(new PageRegistration("gb.users", UsersPage.class));\r
+               }\r
+               if (showAdmin || showRegistrations) {\r
+                       pages.add(new PageRegistration("gb.federation", FederationPage.class));\r
+               }               \r
+               NavigationPanel navPanel = new NavigationPanel("navPanel", getClass(), pages);\r
+               add(navPanel);\r
 \r
                // login form\r
                StatelessForm<Void> loginForm = new StatelessForm<Void>("loginForm") {\r
diff --git a/src/com/gitblit/wicket/panels/NavigationPanel.html b/src/com/gitblit/wicket/panels/NavigationPanel.html
new file mode 100644 (file)
index 0000000..f883e49
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
+<html xmlns="http://www.w3.org/1999/xhtml"  \r
+      xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"  \r
+      xml:lang="en"  \r
+      lang="en"> \r
+\r
+<wicket:panel>\r
+       <ul class="nav">\r
+               <li wicket:id="navLink"><span wicket:id="link">[link]</span></li>                       \r
+       </ul>   \r
+</wicket:panel>\r
+</html>
\ No newline at end of file
diff --git a/src/com/gitblit/wicket/panels/NavigationPanel.java b/src/com/gitblit/wicket/panels/NavigationPanel.java
new file mode 100644 (file)
index 0000000..6ec461f
--- /dev/null
@@ -0,0 +1,52 @@
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.wicket.panels;\r
+\r
+import java.util.List;\r
+\r
+import org.apache.wicket.Component;\r
+import org.apache.wicket.markup.html.panel.Panel;\r
+import org.apache.wicket.markup.repeater.Item;\r
+import org.apache.wicket.markup.repeater.data.DataView;\r
+import org.apache.wicket.markup.repeater.data.ListDataProvider;\r
+\r
+import com.gitblit.wicket.PageRegistration;\r
+import com.gitblit.wicket.WicketUtils;\r
+import com.gitblit.wicket.pages.BasePage;\r
+\r
+public class NavigationPanel extends Panel {\r
+\r
+       private static final long serialVersionUID = 1L;\r
+\r
+       public NavigationPanel(String id, final Class<? extends BasePage> pageClass, List<PageRegistration> registeredPages) {\r
+               super(id);\r
+                               \r
+               ListDataProvider<PageRegistration> refsDp = new ListDataProvider<PageRegistration>(registeredPages);\r
+               DataView<PageRegistration> refsView = new DataView<PageRegistration>("navLink", refsDp) {\r
+                       private static final long serialVersionUID = 1L;\r
+\r
+                       public void populateItem(final Item<PageRegistration> item) {\r
+                               PageRegistration entry = item.getModelObject();\r
+                               Component c = new LinkPanel("link", null, getString(entry.translationKey), entry.pageClass, entry.params);\r
+                               if (entry.pageClass.equals(pageClass)) {\r
+                                       WicketUtils.setCssClass(item, "active");\r
+                               }\r
+                               item.add(c);\r
+                       }\r
+               };\r
+               add(refsView);\r
+       }\r
+}
\ No newline at end of file