use of com.gitblit.extensions.NavLinkExtension in project gitblit by gitblit.
the class RootPage method setupPage.
@Override
protected void setupPage(String repositoryName, String pageName) {
// CSS header overrides
add(new HeaderContributor(new IHeaderContributor() {
private static final long serialVersionUID = 1L;
@Override
public void renderHead(IHeaderResponse response) {
StringBuilder buffer = new StringBuilder();
buffer.append("<style type=\"text/css\">\n");
buffer.append(".navbar-inner {\n");
final String headerBackground = app().settings().getString(Keys.web.headerBackgroundColor, null);
if (!StringUtils.isEmpty(headerBackground)) {
buffer.append(MessageFormat.format("background-color: {0};\n", headerBackground));
}
final String headerBorder = app().settings().getString(Keys.web.headerBorderColor, null);
if (!StringUtils.isEmpty(headerBorder)) {
buffer.append(MessageFormat.format("border-bottom: 1px solid {0} !important;\n", headerBorder));
}
buffer.append("}\n");
final String headerBorderFocus = app().settings().getString(Keys.web.headerBorderFocusColor, null);
if (!StringUtils.isEmpty(headerBorderFocus)) {
buffer.append(".navbar ul li:focus, .navbar .active {\n");
buffer.append(MessageFormat.format("border-bottom: 4px solid {0};\n", headerBorderFocus));
buffer.append("}\n");
}
final String headerForeground = app().settings().getString(Keys.web.headerForegroundColor, null);
if (!StringUtils.isEmpty(headerForeground)) {
buffer.append(".navbar ul.nav li a {\n");
buffer.append(MessageFormat.format("color: {0};\n", headerForeground));
buffer.append("}\n");
buffer.append(".navbar ul.nav .active a {\n");
buffer.append(MessageFormat.format("color: {0};\n", headerForeground));
buffer.append("}\n");
}
final String headerHover = app().settings().getString(Keys.web.headerHoverColor, null);
if (!StringUtils.isEmpty(headerHover)) {
buffer.append(".navbar ul.nav li a:hover {\n");
buffer.append(MessageFormat.format("color: {0} !important;\n", headerHover));
buffer.append("}\n");
}
buffer.append("</style>\n");
response.renderString(buffer.toString());
}
}));
boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, false);
boolean authenticateAdmin = app().settings().getBoolean(Keys.web.authenticateAdminPages, true);
boolean allowAdmin = app().settings().getBoolean(Keys.web.allowAdministration, true);
boolean allowLucene = app().settings().getBoolean(Keys.web.allowLuceneIndexing, true);
boolean displayUserPanel = app().settings().getBoolean(Keys.web.displayUserPanel, true);
boolean isLoggedIn = GitBlitWebSession.get().isLoggedIn();
if (authenticateAdmin) {
showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();
// authentication requires state and session
setStatelessHint(false);
} else {
showAdmin = allowAdmin;
if (authenticateView) {
// authentication requires state and session
setStatelessHint(false);
} else {
// no authentication required, no state and no session required
setStatelessHint(true);
}
}
if (displayUserPanel && (authenticateView || authenticateAdmin)) {
if (isLoggedIn) {
UserMenu userFragment = new UserMenu("userPanel", "userMenuFragment", RootPage.this);
add(userFragment);
} else {
LoginForm loginForm = new LoginForm("userPanel", "loginFormFragment", RootPage.this);
add(loginForm);
}
} else {
add(new Label("userPanel").setVisible(false));
}
// navigation links
List<NavLink> navLinks = new ArrayList<NavLink>();
if (!authenticateView || (authenticateView && isLoggedIn)) {
UserModel user = UserModel.ANONYMOUS;
if (isLoggedIn) {
user = GitBlitWebSession.get().getUser();
}
navLinks.add(new PageNavLink(isLoggedIn ? "gb.myDashboard" : "gb.dashboard", MyDashboardPage.class, getRootPageParameters()));
if (isLoggedIn && app().tickets().isReady()) {
navLinks.add(new PageNavLink("gb.myTickets", MyTicketsPage.class));
}
navLinks.add(new PageNavLink("gb.repositories", RepositoriesPage.class, getRootPageParameters()));
navLinks.add(new PageNavLink("gb.filestore", FilestorePage.class, getRootPageParameters()));
navLinks.add(new PageNavLink("gb.activity", ActivityPage.class, getRootPageParameters()));
if (allowLucene) {
navLinks.add(new PageNavLink("gb.search", LuceneSearchPage.class));
}
if (!authenticateView || (authenticateView && isLoggedIn)) {
addDropDownMenus(navLinks);
}
// add nav link extensions
List<NavLinkExtension> extensions = app().plugins().getExtensions(NavLinkExtension.class);
for (NavLinkExtension ext : extensions) {
navLinks.addAll(ext.getNavLinks(user));
}
}
NavigationPanel navPanel = new NavigationPanel("navPanel", getRootNavPageClass(), navLinks);
add(navPanel);
// display an error message cached from a redirect
String cachedMessage = GitBlitWebSession.get().clearErrorMessage();
if (!StringUtils.isEmpty(cachedMessage)) {
error(cachedMessage);
} else if (showAdmin) {
int pendingProposals = app().federation().getPendingFederationProposals().size();
if (pendingProposals == 1) {
info(getString("gb.OneProposalToReview"));
} else if (pendingProposals > 1) {
info(MessageFormat.format(getString("gb.nFederationProposalsToReview"), pendingProposals));
}
}
super.setupPage(repositoryName, pageName);
}
Aggregations