Search in sources :

Example 1 with ExternalLink

use of org.apache.wicket.markup.html.link.ExternalLink 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 2 with ExternalLink

use of org.apache.wicket.markup.html.link.ExternalLink in project gitblit by gitblit.

the class ProjectPage method setup.

private void setup(PageParameters params) {
    setupPage("", "");
    // check to see if we should display a login message
    boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, true);
    if (authenticateView && !GitBlitWebSession.get().isLoggedIn()) {
        authenticationError("Please login");
        return;
    }
    String projectName = params == null ? null : WicketUtils.getProjectName(params);
    if (StringUtils.isEmpty(projectName)) {
        throw new GitblitRedirectException(GitBlitWebApp.get().getHomePage());
    }
    ProjectModel project = getProjectModel(projectName);
    if (project == null) {
        throw new GitblitRedirectException(GitBlitWebApp.get().getHomePage());
    }
    add(new Label("projectTitle", project.getDisplayName()));
    add(new Label("projectDescription", project.description));
    String feedLink = SyndicationServlet.asLink(getRequest().getRelativePathPrefixToContextRoot(), projectName, null, 0);
    add(new ExternalLink("syndication", feedLink));
    add(WicketUtils.syndicationDiscoveryLink(SyndicationServlet.getTitle(project.getDisplayName(), null), feedLink));
    // project markdown message
    String pmessage = transformMarkdown(project.projectMarkdown);
    Component projectMessage = new Label("projectMessage", pmessage).setEscapeModelStrings(false).setVisible(pmessage.length() > 0);
    add(projectMessage);
    // markdown message above repositories list
    String rmessage = transformMarkdown(project.repositoriesMarkdown);
    Component repositoriesMessage = new Label("repositoriesMessage", rmessage).setEscapeModelStrings(false).setVisible(rmessage.length() > 0);
    add(repositoriesMessage);
    UserModel user = GitBlitWebSession.get().getUser();
    if (user == null) {
        user = UserModel.ANONYMOUS;
    }
    int daysBack = params == null ? 0 : WicketUtils.getDaysBack(params);
    if (daysBack < 1) {
        daysBack = app().settings().getInteger(Keys.web.activityDuration, 7);
    }
    // reflog utils.
    if (params != null) {
        params.remove("db");
    }
    List<RepositoryModel> repositories = getRepositories(params);
    Collections.sort(repositories, new Comparator<RepositoryModel>() {

        @Override
        public int compare(RepositoryModel o1, RepositoryModel o2) {
            // reverse-chronological sort
            return o2.lastChange.compareTo(o1.lastChange);
        }
    });
    addActivity(user, repositories, getString("gb.recentActivity"), daysBack);
    if (repositories.isEmpty()) {
        add(new Label("repositoryList").setVisible(false));
    } else {
        FilterableRepositoryList repoList = new FilterableRepositoryList("repositoryList", repositories);
        repoList.setAllowCreate(user.canCreate(project.name + "/"));
        add(repoList);
    }
}
Also used : FilterableRepositoryList(com.gitblit.wicket.panels.FilterableRepositoryList) Label(org.apache.wicket.markup.html.basic.Label) RepositoryModel(com.gitblit.models.RepositoryModel) ExternalLink(org.apache.wicket.markup.html.link.ExternalLink) GitblitRedirectException(com.gitblit.wicket.GitblitRedirectException) UserModel(com.gitblit.models.UserModel) ProjectModel(com.gitblit.models.ProjectModel) Component(org.apache.wicket.Component)

Example 3 with ExternalLink

use of org.apache.wicket.markup.html.link.ExternalLink in project gitblit by gitblit.

the class RepositoryPage method setupPage.

@Override
protected void setupPage(String repositoryName, String pageName) {
    //It may be attempted to be called again if an info or error message is displayed.
    if (get("projectTitle") != null) {
        return;
    }
    String projectName = StringUtils.getFirstPathElement(repositoryName);
    ProjectModel project = app().projects().getProjectModel(projectName);
    if (project.isUserProject()) {
        // user-as-project
        add(new LinkPanel("projectTitle", null, project.getDisplayName(), UserPage.class, WicketUtils.newUsernameParameter(project.name.substring(1))));
    } else {
        // project
        add(new LinkPanel("projectTitle", null, project.name, ProjectPage.class, WicketUtils.newProjectParameter(project.name)));
    }
    String name = StringUtils.stripDotGit(repositoryName);
    if (!StringUtils.isEmpty(projectName) && name.startsWith(projectName)) {
        name = name.substring(projectName.length() + 1);
    }
    add(new LinkPanel("repositoryName", null, name, SummaryPage.class, WicketUtils.newRepositoryParameter(repositoryName)));
    UserModel user = GitBlitWebSession.get().getUser();
    if (user == null) {
        user = UserModel.ANONYMOUS;
    }
    // indicate origin repository
    RepositoryModel model = getRepositoryModel();
    if (StringUtils.isEmpty(model.originRepository)) {
        if (model.isMirror) {
            add(new Fragment("repoIcon", "mirrorIconFragment", this));
            Fragment mirrorFrag = new Fragment("originRepository", "mirrorFragment", this);
            Label lbl = new Label("originRepository", MessageFormat.format(getString("gb.mirrorOf"), "<b>" + model.origin + "</b>"));
            mirrorFrag.add(lbl.setEscapeModelStrings(false));
            add(mirrorFrag);
        } else {
            if (model.isBare) {
                add(new Fragment("repoIcon", "repoIconFragment", this));
            } else {
                add(new Fragment("repoIcon", "cloneIconFragment", this));
            }
            add(new Label("originRepository", Optional.of(model.description).or("")));
        }
    } else {
        RepositoryModel origin = app().repositories().getRepositoryModel(model.originRepository);
        if (origin == null) {
            // no origin repository, show description if available
            if (model.isBare) {
                add(new Fragment("repoIcon", "repoIconFragment", this));
            } else {
                add(new Fragment("repoIcon", "cloneIconFragment", this));
            }
            add(new Label("originRepository", Optional.of(model.description).or("")));
        } else if (!user.canView(origin)) {
            // show origin repository without link
            add(new Fragment("repoIcon", "forkIconFragment", this));
            Fragment forkFrag = new Fragment("originRepository", "originFragment", this);
            forkFrag.add(new Label("originRepository", StringUtils.stripDotGit(model.originRepository)));
            add(forkFrag);
        } else {
            // link to origin repository
            add(new Fragment("repoIcon", "forkIconFragment", this));
            Fragment forkFrag = new Fragment("originRepository", "originFragment", this);
            forkFrag.add(new LinkPanel("originRepository", null, StringUtils.stripDotGit(model.originRepository), SummaryPage.class, WicketUtils.newRepositoryParameter(model.originRepository)));
            add(forkFrag);
        }
    }
    // new ticket button
    if (user.isAuthenticated && app().tickets().isAcceptingNewTickets(getRepositoryModel())) {
        String newTicketUrl = getRequestCycle().urlFor(NewTicketPage.class, WicketUtils.newRepositoryParameter(repositoryName)).toString();
        addToolbarButton("newTicketLink", "fa fa-ticket", getString("gb.new"), newTicketUrl);
    } else {
        add(new Label("newTicketLink").setVisible(false));
    }
    // (un)star link allows a user to star a repository
    if (user.isAuthenticated && model.hasCommits) {
        PageParameters starParams = DeepCopier.copy(getPageParameters());
        starParams.put(PARAM_STAR, !user.getPreferences().isStarredRepository(model.name));
        String toggleStarUrl = getRequestCycle().urlFor(getClass(), starParams).toString();
        if (user.getPreferences().isStarredRepository(model.name)) {
            // show unstar button
            add(new Label("starLink").setVisible(false));
            addToolbarButton("unstarLink", "icon-star-empty", getString("gb.unstar"), toggleStarUrl);
        } else {
            // show star button
            addToolbarButton("starLink", "icon-star", getString("gb.star"), toggleStarUrl);
            add(new Label("unstarLink").setVisible(false));
        }
    } else {
        // anonymous user
        add(new Label("starLink").setVisible(false));
        add(new Label("unstarLink").setVisible(false));
    }
    // fork controls
    if (!allowForkControls() || !user.isAuthenticated) {
        // must be logged-in to fork, hide all fork controls
        add(new ExternalLink("forkLink", "").setVisible(false));
        add(new ExternalLink("myForkLink", "").setVisible(false));
    } else {
        String fork = app().repositories().getFork(user.username, model.name);
        String userRepo = ModelUtils.getPersonalPath(user.username) + "/" + StringUtils.stripDotGit(StringUtils.getLastPathElement(model.name));
        boolean hasUserRepo = app().repositories().hasRepository(userRepo);
        boolean hasFork = fork != null;
        boolean canFork = user.canFork(model) && model.hasCommits && !hasUserRepo;
        if (hasFork || !canFork) {
            // user not allowed to fork or fork already exists or repo forbids forking
            add(new ExternalLink("forkLink", "").setVisible(false));
            if (hasFork && !fork.equals(model.name)) {
                // user has fork, view my fork link
                String url = getRequestCycle().urlFor(SummaryPage.class, WicketUtils.newRepositoryParameter(fork)).toString();
                add(new ExternalLink("myForkLink", url));
            } else {
                // no fork, hide view my fork link
                add(new ExternalLink("myForkLink", "").setVisible(false));
            }
        } else if (canFork) {
            // can fork and we do not have one
            add(new ExternalLink("myForkLink", "").setVisible(false));
            String url = getRequestCycle().urlFor(ForkPage.class, WicketUtils.newRepositoryParameter(model.name)).toString();
            add(new ExternalLink("forkLink", url));
        }
    }
    if (showAdmin || isOwner) {
        String url = getRequestCycle().urlFor(EditRepositoryPage.class, WicketUtils.newRepositoryParameter(model.name)).toString();
        add(new ExternalLink("editLink", url));
    } else {
        add(new Label("editLink").setVisible(false));
    }
    super.setupPage(repositoryName, pageName);
}
Also used : Label(org.apache.wicket.markup.html.basic.Label) RepositoryModel(com.gitblit.models.RepositoryModel) PageParameters(org.apache.wicket.PageParameters) Fragment(org.apache.wicket.markup.html.panel.Fragment) ExternalLink(org.apache.wicket.markup.html.link.ExternalLink) LinkPanel(com.gitblit.wicket.panels.LinkPanel) UserModel(com.gitblit.models.UserModel) ProjectModel(com.gitblit.models.ProjectModel)

Example 4 with ExternalLink

use of org.apache.wicket.markup.html.link.ExternalLink in project gitblit by gitblit.

the class TicketPage method addDateAttributions.

protected void addDateAttributions(MarkupContainer container, Change entry) {
    container.add(WicketUtils.createDateLabel("changeDate", entry.date, GitBlitWebSession.get().getTimezone(), getTimeUtils(), false));
    // set the id attribute
    if (entry.hasComment()) {
        container.setOutputMarkupId(true);
        container.add(new AttributeModifier("id", Model.of(entry.getId())));
        ExternalLink link = new ExternalLink("changeLink", "#" + entry.getId());
        container.add(link);
    } else {
        container.add(new Label("changeLink").setVisible(false));
    }
}
Also used : Label(org.apache.wicket.markup.html.basic.Label) TicketLabel(com.gitblit.tickets.TicketLabel) AttributeModifier(org.apache.wicket.AttributeModifier) SimpleAttributeModifier(org.apache.wicket.behavior.SimpleAttributeModifier) ExternalLink(org.apache.wicket.markup.html.link.ExternalLink)

Example 5 with ExternalLink

use of org.apache.wicket.markup.html.link.ExternalLink in project gitblit by gitblit.

the class BasePage method setupPage.

protected void setupPage(String repositoryName, String pageName) {
    add(new Label("title", getPageTitle(repositoryName)));
    getBottomScriptContainer();
    String rootLinkUrl = app().settings().getString(Keys.web.rootLink, urlFor(GitBlitWebApp.get().getHomePage(), null).toString());
    ExternalLink rootLink = new ExternalLink("rootLink", rootLinkUrl);
    WicketUtils.setHtmlTooltip(rootLink, app().settings().getString(Keys.web.siteName, Constants.NAME));
    add(rootLink);
    // Feedback panel for info, warning, and non-fatal error messages
    add(new FeedbackPanel("feedback"));
    add(new Label("gbVersion", "v" + Constants.getVersion()));
    if (app().settings().getBoolean(Keys.web.aggressiveHeapManagement, false)) {
        System.gc();
    }
}
Also used : FeedbackPanel(org.apache.wicket.markup.html.panel.FeedbackPanel) Label(org.apache.wicket.markup.html.basic.Label) ExternalLink(org.apache.wicket.markup.html.link.ExternalLink)

Aggregations

Label (org.apache.wicket.markup.html.basic.Label)6 ExternalLink (org.apache.wicket.markup.html.link.ExternalLink)6 RepositoryModel (com.gitblit.models.RepositoryModel)3 UserModel (com.gitblit.models.UserModel)3 ProjectModel (com.gitblit.models.ProjectModel)2 LinkPanel (com.gitblit.wicket.panels.LinkPanel)2 Component (org.apache.wicket.Component)2 PageParameters (org.apache.wicket.PageParameters)2 Fragment (org.apache.wicket.markup.html.panel.Fragment)2 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)1 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)1 PageMyPasswordQuestions (com.evolveum.midpoint.web.page.admin.home.PageMyPasswordQuestions)1 PasswordQuestionsDto (com.evolveum.midpoint.web.page.admin.home.dto.PasswordQuestionsDto)1 SearchType (com.gitblit.Constants.SearchType)1 SearchResult (com.gitblit.models.SearchResult)1 TicketLabel (com.gitblit.tickets.TicketLabel)1 GitblitRedirectException (com.gitblit.wicket.GitblitRedirectException)1 SessionlessForm (com.gitblit.wicket.SessionlessForm)1 StringChoiceRenderer (com.gitblit.wicket.StringChoiceRenderer)1 FilterableRepositoryList (com.gitblit.wicket.panels.FilterableRepositoryList)1