diff options
author | James Moger <james.moger@gitblit.com> | 2011-10-05 08:04:47 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2011-10-05 08:04:47 -0400 |
commit | 9e5beeecd2a462337ca5a893bf1458c25df26060 (patch) | |
tree | 31f3f1b5a8cbf78749eaea201b5770c7b430eae9 /src/com/gitblit/wicket/pages | |
parent | 10177fb0a59cc9fc61fb78c724f7b0816b69b798 (diff) | |
download | gitblit-9e5beeecd2a462337ca5a893bf1458c25df26060.tar.gz gitblit-9e5beeecd2a462337ca5a893bf1458c25df26060.zip |
Refactored topbar navigation links to indicate current page.
Diffstat (limited to 'src/com/gitblit/wicket/pages')
-rw-r--r-- | src/com/gitblit/wicket/pages/RepositoryPage.html | 19 | ||||
-rw-r--r-- | src/com/gitblit/wicket/pages/RepositoryPage.java | 165 | ||||
-rw-r--r-- | src/com/gitblit/wicket/pages/RootPage.html | 6 | ||||
-rw-r--r-- | src/com/gitblit/wicket/pages/RootPage.java | 19 |
4 files changed, 70 insertions, 139 deletions
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") {
|