Search in sources :

Example 6 with PageParameters

use of org.apache.wicket.PageParameters in project gitblit by gitblit.

the class ProjectsPage method addDropDownMenus.

@Override
protected void addDropDownMenus(List<NavLink> navLinks) {
    PageParameters params = getPageParameters();
    DropDownPageMenuNavLink menu = new DropDownPageMenuNavLink("gb.filters", ProjectsPage.class);
    // preserve time filter option on repository choices
    menu.menuItems.addAll(getRepositoryFilterItems(params));
    // preserve repository filter option on time choices
    menu.menuItems.addAll(getTimeFilterItems(params));
    if (menu.menuItems.size() > 0) {
        // Reset Filter
        menu.menuItems.add(new ParameterMenuItem(getString("gb.reset")));
    }
    navLinks.add(menu);
}
Also used : DropDownPageMenuNavLink(com.gitblit.models.NavLink.DropDownPageMenuNavLink) PageParameters(org.apache.wicket.PageParameters) ParameterMenuItem(com.gitblit.models.Menu.ParameterMenuItem)

Example 7 with PageParameters

use of org.apache.wicket.PageParameters in project gitblit by gitblit.

the class RepositoriesPage method addDropDownMenus.

@Override
protected void addDropDownMenus(List<NavLink> navLinks) {
    PageParameters params = getPageParameters();
    DropDownPageMenuNavLink menu = new DropDownPageMenuNavLink("gb.filters", RepositoriesPage.class);
    // preserve time filter option on repository choices
    menu.menuItems.addAll(getRepositoryFilterItems(params));
    // preserve repository filter option on time choices
    menu.menuItems.addAll(getTimeFilterItems(params));
    if (menu.menuItems.size() > 0) {
        // Reset Filter
        menu.menuItems.add(new ParameterMenuItem(getString("gb.reset")));
    }
    navLinks.add(menu);
}
Also used : DropDownPageMenuNavLink(com.gitblit.models.NavLink.DropDownPageMenuNavLink) PageParameters(org.apache.wicket.PageParameters) ParameterMenuItem(com.gitblit.models.Menu.ParameterMenuItem)

Example 8 with PageParameters

use of org.apache.wicket.PageParameters 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 9 with PageParameters

use of org.apache.wicket.PageParameters in project gitblit by gitblit.

the class LuceneSearchPage method setup.

private void setup(PageParameters params) {
    setupPage("", "");
    // default values
    ArrayList<String> repositories = new ArrayList<String>();
    String query = "";
    boolean allRepos = false;
    int page = 1;
    int pageSize = app().settings().getInteger(Keys.web.itemsPerPage, 50);
    // display user-accessible selections
    UserModel user = GitBlitWebSession.get().getUser();
    List<String> availableRepositories = new ArrayList<String>();
    for (RepositoryModel model : app().repositories().getRepositoryModels(user)) {
        if (model.hasCommits && !ArrayUtils.isEmpty(model.indexedBranches)) {
            availableRepositories.add(model.name);
        }
    }
    if (params != null) {
        String repository = WicketUtils.getRepositoryName(params);
        if (!StringUtils.isEmpty(repository)) {
            repositories.add(repository);
        }
        page = WicketUtils.getPage(params);
        if (params.containsKey("repositories")) {
            String value = params.getString("repositories", "");
            List<String> list = StringUtils.getStringsFromValue(value);
            repositories.addAll(list);
        }
        allRepos = params.getAsBoolean("allrepos", false);
        if (allRepos) {
            repositories.addAll(availableRepositories);
        }
        if (params.containsKey("query")) {
            query = params.getString("query", "");
        } else {
            String value = WicketUtils.getSearchString(params);
            String type = WicketUtils.getSearchType(params);
            com.gitblit.Constants.SearchType searchType = com.gitblit.Constants.SearchType.forName(type);
            if (!StringUtils.isEmpty(value)) {
                if (searchType == SearchType.COMMIT) {
                    query = "type:" + searchType.name().toLowerCase() + " AND \"" + value + "\"";
                } else {
                    query = searchType.name().toLowerCase() + ":\"" + value + "\"";
                }
            }
        }
    }
    boolean luceneEnabled = app().settings().getBoolean(Keys.web.allowLuceneIndexing, true);
    if (luceneEnabled) {
        if (availableRepositories.size() == 0) {
            info(getString("gb.noIndexedRepositoriesWarning"));
        }
    } else {
        error(getString("gb.luceneDisabled"));
    }
    // enforce user-accessible repository selections
    Set<String> uniqueRepositories = new LinkedHashSet<String>();
    for (String selectedRepository : repositories) {
        if (availableRepositories.contains(selectedRepository)) {
            uniqueRepositories.add(selectedRepository);
        }
    }
    ArrayList<String> searchRepositories = new ArrayList<String>(uniqueRepositories);
    // search form
    final Model<String> queryModel = new Model<String>(query);
    final Model<ArrayList<String>> repositoriesModel = new Model<ArrayList<String>>(searchRepositories);
    final Model<Boolean> allreposModel = new Model<Boolean>(allRepos);
    SessionlessForm<Void> form = new SessionlessForm<Void>("searchForm", getClass()) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit() {
            String q = queryModel.getObject();
            if (StringUtils.isEmpty(q)) {
                error(getString("gb.undefinedQueryWarning"));
                return;
            }
            if (repositoriesModel.getObject().size() == 0 && !allreposModel.getObject()) {
                error(getString("gb.noSelectedRepositoriesWarning"));
                return;
            }
            PageParameters params = new PageParameters();
            params.put("repositories", StringUtils.flattenStrings(repositoriesModel.getObject()));
            params.put("query", queryModel.getObject());
            params.put("allrepos", allreposModel.getObject());
            LuceneSearchPage page = new LuceneSearchPage(params);
            setResponsePage(page);
        }
    };
    ListMultipleChoice<String> selections = new ListMultipleChoice<String>("repositories", repositoriesModel, availableRepositories, new StringChoiceRenderer());
    selections.setMaxRows(8);
    form.add(selections.setEnabled(luceneEnabled));
    form.add(new TextField<String>("query", queryModel).setEnabled(luceneEnabled));
    form.add(new CheckBox("allrepos", allreposModel));
    form.add(new ExternalLink("querySyntax", LUCENE_QUERY_SYNTAX_LINK));
    add(form.setEnabled(luceneEnabled));
    // execute search
    final List<SearchResult> results = new ArrayList<SearchResult>();
    if (!ArrayUtils.isEmpty(searchRepositories) && !StringUtils.isEmpty(query)) {
        results.addAll(app().repositories().search(query, page, pageSize, searchRepositories));
    }
    // results header
    if (results.size() == 0) {
        if (!ArrayUtils.isEmpty(searchRepositories) && !StringUtils.isEmpty(query)) {
            add(new Label("resultsHeader", query).setRenderBodyOnly(true));
            add(new Label("resultsCount", getString("gb.noHits")).setRenderBodyOnly(true));
        } else {
            add(new Label("resultsHeader").setVisible(false));
            add(new Label("resultsCount").setVisible(false));
        }
    } else {
        add(new Label("resultsHeader", query).setRenderBodyOnly(true));
        add(new Label("resultsCount", MessageFormat.format(getString("gb.queryResults"), results.get(0).hitId, results.get(results.size() - 1).hitId, results.get(0).totalHits)).setRenderBodyOnly(true));
    }
    // search results view
    ListDataProvider<SearchResult> resultsDp = new ListDataProvider<SearchResult>(results);
    final DataView<SearchResult> resultsView = new DataView<SearchResult>("searchResults", resultsDp) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<SearchResult> item) {
            final SearchResult sr = item.getModelObject();
            switch(sr.type) {
                case commit:
                    {
                        Label icon = WicketUtils.newIcon("type", "icon-refresh");
                        WicketUtils.setHtmlTooltip(icon, "commit");
                        item.add(icon);
                        item.add(new LinkPanel("summary", null, sr.summary, CommitPage.class, WicketUtils.newObjectParameter(sr.repository, sr.commitId)));
                        // show tags
                        Fragment fragment = new Fragment("tags", "tagsPanel", LuceneSearchPage.this);
                        List<String> tags = sr.tags;
                        if (tags == null) {
                            tags = new ArrayList<String>();
                        }
                        ListDataProvider<String> tagsDp = new ListDataProvider<String>(tags);
                        final DataView<String> tagsView = new DataView<String>("tag", tagsDp) {

                            private static final long serialVersionUID = 1L;

                            @Override
                            public void populateItem(final Item<String> item) {
                                String tag = item.getModelObject();
                                Component c = new LinkPanel("tagLink", null, tag, TagPage.class, WicketUtils.newObjectParameter(sr.repository, Constants.R_TAGS + tag));
                                WicketUtils.setCssClass(c, "tagRef");
                                item.add(c);
                            }
                        };
                        fragment.add(tagsView);
                        item.add(fragment);
                        break;
                    }
                case blob:
                    {
                        Label icon = WicketUtils.newIcon("type", "icon-file");
                        WicketUtils.setHtmlTooltip(icon, "blob");
                        item.add(icon);
                        item.add(new LinkPanel("summary", null, sr.path, BlobPage.class, WicketUtils.newPathParameter(sr.repository, sr.branch, sr.path)));
                        item.add(new Label("tags").setVisible(false));
                        break;
                    }
            }
            item.add(new Label("fragment", sr.fragment).setEscapeModelStrings(false).setVisible(!StringUtils.isEmpty(sr.fragment)));
            item.add(new LinkPanel("repository", null, sr.repository, SummaryPage.class, WicketUtils.newRepositoryParameter(sr.repository)));
            if (StringUtils.isEmpty(sr.branch)) {
                item.add(new Label("branch", "null"));
            } else {
                item.add(new LinkPanel("branch", "branch", StringUtils.getRelativePath(Constants.R_HEADS, sr.branch), LogPage.class, WicketUtils.newObjectParameter(sr.repository, sr.branch)));
            }
            item.add(new Label("author", sr.author));
            item.add(WicketUtils.createDatestampLabel("date", sr.date, getTimeZone(), getTimeUtils()));
        }
    };
    add(resultsView.setVisible(results.size() > 0));
    PageParameters pagerParams = new PageParameters();
    pagerParams.put("repositories", StringUtils.flattenStrings(repositoriesModel.getObject()));
    pagerParams.put("query", queryModel.getObject());
    boolean showPager = false;
    int totalPages = 0;
    if (results.size() > 0) {
        totalPages = (results.get(0).totalHits / pageSize) + (results.get(0).totalHits % pageSize > 0 ? 1 : 0);
        showPager = results.get(0).totalHits > pageSize;
    }
    add(new PagerPanel("topPager", page, totalPages, LuceneSearchPage.class, pagerParams).setVisible(showPager));
    add(new PagerPanel("bottomPager", page, totalPages, LuceneSearchPage.class, pagerParams).setVisible(showPager));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) SearchType(com.gitblit.Constants.SearchType) Fragment(org.apache.wicket.markup.html.panel.Fragment) ListMultipleChoice(org.apache.wicket.markup.html.form.ListMultipleChoice) Item(org.apache.wicket.markup.repeater.Item) SessionlessForm(com.gitblit.wicket.SessionlessForm) TextField(org.apache.wicket.markup.html.form.TextField) ArrayList(java.util.ArrayList) List(java.util.List) PageParameters(org.apache.wicket.PageParameters) ExternalLink(org.apache.wicket.markup.html.link.ExternalLink) StringChoiceRenderer(com.gitblit.wicket.StringChoiceRenderer) CheckBox(org.apache.wicket.markup.html.form.CheckBox) ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) RepositoryModel(com.gitblit.models.RepositoryModel) PagerPanel(com.gitblit.wicket.panels.PagerPanel) LinkPanel(com.gitblit.wicket.panels.LinkPanel) UserModel(com.gitblit.models.UserModel) Component(org.apache.wicket.Component) Constants(org.eclipse.jgit.lib.Constants) SearchResult(com.gitblit.models.SearchResult) DataView(org.apache.wicket.markup.repeater.data.DataView) RepositoryModel(com.gitblit.models.RepositoryModel) Model(org.apache.wicket.model.Model) UserModel(com.gitblit.models.UserModel)

Example 10 with PageParameters

use of org.apache.wicket.PageParameters in project gitblit by gitblit.

the class ProjectPage method addDropDownMenus.

@Override
protected void addDropDownMenus(List<NavLink> navLinks) {
    PageParameters params = getPageParameters();
    DropDownPageMenuNavLink menu = new DropDownPageMenuNavLink("gb.filters", ProjectPage.class);
    // preserve time filter option on repository choices
    menu.menuItems.addAll(getRepositoryFilterItems(params));
    // preserve repository filter option on time choices
    menu.menuItems.addAll(getTimeFilterItems(params));
    if (menu.menuItems.size() > 0) {
        // Reset Filter
        menu.menuItems.add(new ParameterMenuItem(getString("gb.reset"), "p", WicketUtils.getProjectName(params)));
    }
    navLinks.add(menu);
    DropDownPageMenuNavLink projects = new DropDownPageMenuNavLink("gb.projects", ProjectPage.class);
    projects.menuItems.addAll(getProjectsMenu());
    navLinks.add(projects);
}
Also used : DropDownPageMenuNavLink(com.gitblit.models.NavLink.DropDownPageMenuNavLink) PageParameters(org.apache.wicket.PageParameters) ParameterMenuItem(com.gitblit.models.Menu.ParameterMenuItem)

Aggregations

PageParameters (org.apache.wicket.PageParameters)18 ParameterMenuItem (com.gitblit.models.Menu.ParameterMenuItem)8 DropDownPageMenuNavLink (com.gitblit.models.NavLink.DropDownPageMenuNavLink)6 Label (org.apache.wicket.markup.html.basic.Label)5 RepositoryModel (com.gitblit.models.RepositoryModel)4 UserModel (com.gitblit.models.UserModel)4 LinkPanel (com.gitblit.wicket.panels.LinkPanel)4 ArrayList (java.util.ArrayList)3 ExternalLink (org.apache.wicket.markup.html.link.ExternalLink)3 Fragment (org.apache.wicket.markup.html.panel.Fragment)3 Item (org.apache.wicket.markup.repeater.Item)3 DataView (org.apache.wicket.markup.repeater.data.DataView)3 ListDataProvider (org.apache.wicket.markup.repeater.data.ListDataProvider)3 RedirectRequestTarget (org.apache.wicket.request.target.basic.RedirectRequestTarget)3 ProjectModel (com.gitblit.models.ProjectModel)2 Repository (org.eclipse.jgit.lib.Repository)2 SearchType (com.gitblit.Constants.SearchType)1 RepositoryNavLinkExtension (com.gitblit.extensions.RepositoryNavLinkExtension)1 ExternalLinkMenuItem (com.gitblit.models.Menu.ExternalLinkMenuItem)1 MenuDivider (com.gitblit.models.Menu.MenuDivider)1