Search in sources :

Example 1 with PageNavLink

use of com.gitblit.models.NavLink.PageNavLink in project gitblit by gitblit.

the class RepositoryPage method registerNavLinks.

private List<NavLink> registerNavLinks() {
    Repository r = getRepository();
    RepositoryModel model = getRepositoryModel();
    PageParameters params = null;
    PageParameters objectParams = null;
    if (!StringUtils.isEmpty(repositoryName)) {
        params = WicketUtils.newRepositoryParameter(getRepositoryName());
        objectParams = params;
        // preserve the objectid iff the objectid directly (or indirectly) refers to a ref
        if (isCommitPage() && !StringUtils.isEmpty(objectId)) {
            RevCommit commit = JGitUtils.getCommit(r, objectId);
            if (commit != null) {
                String bestId = getBestCommitId(commit);
                if (!commit.getName().equals(bestId)) {
                    objectParams = WicketUtils.newObjectParameter(getRepositoryName(), bestId);
                }
            }
        }
    }
    List<NavLink> navLinks = new ArrayList<NavLink>();
    // standard links
    if (RefLogUtils.getRefLogBranch(r) == null) {
        navLinks.add(new PageNavLink("gb.summary", SummaryPage.class, params));
    } else {
        navLinks.add(new PageNavLink("gb.summary", SummaryPage.class, params));
        //			pages.put("overview", new PageRegistration("gb.overview", OverviewPage.class, params));
        navLinks.add(new PageNavLink("gb.reflog", ReflogPage.class, params));
    }
    if (!model.hasCommits) {
        return navLinks;
    }
    navLinks.add(new PageNavLink("gb.commits", LogPage.class, objectParams));
    navLinks.add(new PageNavLink("gb.tree", TreePage.class, objectParams));
    if (app().tickets().isReady() && (app().tickets().isAcceptingNewTickets(model) || app().tickets().hasTickets(model))) {
        PageParameters tParams = WicketUtils.newOpenTicketsParameter(getRepositoryName());
        navLinks.add(new PageNavLink("gb.tickets", TicketsPage.class, tParams));
    }
    navLinks.add(new PageNavLink("gb.docs", DocsPage.class, objectParams, true));
    if (app().settings().getBoolean(Keys.web.allowForking, true)) {
        navLinks.add(new PageNavLink("gb.forks", ForksPage.class, params, true));
    }
    navLinks.add(new PageNavLink("gb.compare", ComparePage.class, params, true));
    // per-repository extra navlinks
    if (JGitUtils.getPagesBranch(r) != null) {
        ExternalNavLink pagesLink = new ExternalNavLink("gb.pages", PagesServlet.asLink(getRequest().getRelativePathPrefixToContextRoot(), getRepositoryName(), null), true);
        navLinks.add(pagesLink);
    }
    UserModel user = UserModel.ANONYMOUS;
    if (GitBlitWebSession.get().isLoggedIn()) {
        user = GitBlitWebSession.get().getUser();
    }
    // add repository nav link extensions
    List<RepositoryNavLinkExtension> extensions = app().plugins().getExtensions(RepositoryNavLinkExtension.class);
    for (RepositoryNavLinkExtension ext : extensions) {
        navLinks.addAll(ext.getNavLinks(user, model));
    }
    return navLinks;
}
Also used : ExternalNavLink(com.gitblit.models.NavLink.ExternalNavLink) ArrayList(java.util.ArrayList) RepositoryModel(com.gitblit.models.RepositoryModel) PageParameters(org.apache.wicket.PageParameters) UserModel(com.gitblit.models.UserModel) Repository(org.eclipse.jgit.lib.Repository) ExternalNavLink(com.gitblit.models.NavLink.ExternalNavLink) PageNavLink(com.gitblit.models.NavLink.PageNavLink) NavLink(com.gitblit.models.NavLink) PageNavLink(com.gitblit.models.NavLink.PageNavLink) RepositoryNavLinkExtension(com.gitblit.extensions.RepositoryNavLinkExtension) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 2 with PageNavLink

use of com.gitblit.models.NavLink.PageNavLink 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);
}
Also used : Label(org.apache.wicket.markup.html.basic.Label) ArrayList(java.util.ArrayList) NavigationPanel(com.gitblit.wicket.panels.NavigationPanel) UserModel(com.gitblit.models.UserModel) PageNavLink(com.gitblit.models.NavLink.PageNavLink) NavLink(com.gitblit.models.NavLink) IHeaderContributor(org.apache.wicket.markup.html.IHeaderContributor) PageNavLink(com.gitblit.models.NavLink.PageNavLink) HeaderContributor(org.apache.wicket.behavior.HeaderContributor) IHeaderContributor(org.apache.wicket.markup.html.IHeaderContributor) IHeaderResponse(org.apache.wicket.markup.html.IHeaderResponse) NavLinkExtension(com.gitblit.extensions.NavLinkExtension)

Aggregations

NavLink (com.gitblit.models.NavLink)2 PageNavLink (com.gitblit.models.NavLink.PageNavLink)2 UserModel (com.gitblit.models.UserModel)2 ArrayList (java.util.ArrayList)2 NavLinkExtension (com.gitblit.extensions.NavLinkExtension)1 RepositoryNavLinkExtension (com.gitblit.extensions.RepositoryNavLinkExtension)1 ExternalNavLink (com.gitblit.models.NavLink.ExternalNavLink)1 RepositoryModel (com.gitblit.models.RepositoryModel)1 NavigationPanel (com.gitblit.wicket.panels.NavigationPanel)1 PageParameters (org.apache.wicket.PageParameters)1 HeaderContributor (org.apache.wicket.behavior.HeaderContributor)1 IHeaderContributor (org.apache.wicket.markup.html.IHeaderContributor)1 IHeaderResponse (org.apache.wicket.markup.html.IHeaderResponse)1 Label (org.apache.wicket.markup.html.basic.Label)1 Repository (org.eclipse.jgit.lib.Repository)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1