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