Search in sources :

Example 1 with RedirectRequestTarget

use of org.apache.wicket.request.target.basic.RedirectRequestTarget in project gitblit by gitblit.

the class BranchesPanel method createDeleteBranchLink.

private Link<Void> createDeleteBranchLink(final RepositoryModel repositoryModel, final RefModel entry) {
    Link<Void> deleteLink = new Link<Void>("deleteBranch") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            Repository r = app().repositories().getRepository(repositoryModel.name);
            if (r == null) {
                if (app().repositories().isCollectingGarbage(repositoryModel.name)) {
                    error(MessageFormat.format(getString("gb.busyCollectingGarbage"), repositoryModel.name));
                } else {
                    error(MessageFormat.format("Failed to find repository {0}", repositoryModel.name));
                }
                return;
            }
            final String branch = entry.getName();
            Ref ref = null;
            try {
                ref = r.getRef(branch);
                if (ref == null && !branch.startsWith(Constants.R_HEADS)) {
                    ref = r.getRef(Constants.R_HEADS + branch);
                }
            } catch (IOException e) {
            }
            if (ref != null) {
                boolean success = JGitUtils.deleteBranchRef(r, ref.getName());
                if (success) {
                    // clear commit cache
                    CommitCache.instance().clear(repositoryModel.name, branch);
                    // optionally update reflog
                    if (RefLogUtils.hasRefLogBranch(r)) {
                        UserModel user = GitBlitWebSession.get().getUser();
                        RefLogUtils.deleteRef(user, r, ref);
                    }
                }
                if (success) {
                    info(MessageFormat.format("Branch \"{0}\" deleted", branch));
                } else {
                    error(MessageFormat.format("Failed to delete branch \"{0}\"", branch));
                }
            }
            r.close();
            // redirect to the owning page
            PageParameters params = WicketUtils.newRepositoryParameter(repositoryModel.name);
            String relativeUrl = urlFor(getPage().getClass(), params).toString();
            String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
            getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
        }
    };
    deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format("Delete branch \"{0}\"?", entry.displayName)));
    return deleteLink;
}
Also used : UserModel(com.gitblit.models.UserModel) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) RedirectRequestTarget(org.apache.wicket.request.target.basic.RedirectRequestTarget) IOException(java.io.IOException) PageParameters(org.apache.wicket.PageParameters) ExternalLink(org.apache.wicket.markup.html.link.ExternalLink) Link(org.apache.wicket.markup.html.link.Link) BookmarkablePageLink(org.apache.wicket.markup.html.link.BookmarkablePageLink)

Example 2 with RedirectRequestTarget

use of org.apache.wicket.request.target.basic.RedirectRequestTarget in project gitblit by gitblit.

the class BasePage method redirectTo.

protected void redirectTo(Class<? extends BasePage> pageClass, PageParameters parameters) {
    String absoluteUrl = getCanonicalUrl(pageClass, parameters);
    getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
}
Also used : RedirectRequestTarget(org.apache.wicket.request.target.basic.RedirectRequestTarget)

Example 3 with RedirectRequestTarget

use of org.apache.wicket.request.target.basic.RedirectRequestTarget in project gitblit by gitblit.

the class CommentPanel method onInitialize.

@Override
protected void onInitialize() {
    super.onInitialize();
    Form<String> form = new Form<String>("editorForm");
    add(form);
    form.add(new AjaxButton("submit", new Model<String>(getString("gb.comment")), form) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit(AjaxRequestTarget target, Form<?> form) {
            String txt = markdownEditor.getText();
            if (change == null) {
                // new comment
                Change newComment = new Change(user.username);
                newComment.comment(txt);
                if (!ticket.isWatching(user.username)) {
                    newComment.watch(user.username);
                }
                RepositoryModel repository = app().repositories().getRepositoryModel(ticket.repository);
                TicketModel updatedTicket = app().tickets().updateTicket(repository, ticket.number, newComment);
                if (updatedTicket != null) {
                    app().tickets().createNotifier().sendMailing(updatedTicket);
                    redirectTo(pageClass, WicketUtils.newObjectParameter(updatedTicket.repository, "" + ticket.number));
                } else {
                    error("Failed to add comment!");
                }
            } else {
            // TODO update comment
            }
        }

        /**
             * Steal from BasePage to realize redirection.
             * 
             * @see BasePage
             * @author krulls@GitHub; ECG Leipzig GmbH, Germany, 2015
             * 
             * @param pageClass
             * @param parameters
             * @return
             */
        private void redirectTo(Class<? extends BasePage> pageClass, PageParameters parameters) {
            String relativeUrl = urlFor(pageClass, parameters).toString();
            String canonicalUrl = RequestUtils.toAbsolutePath(relativeUrl);
            getRequestCycle().setRequestTarget(new RedirectRequestTarget(canonicalUrl));
        }
    }.setVisible(ticket != null && ticket.number > 0));
    final IModel<String> markdownPreviewModel = Model.of();
    markdownPreview = new Label("markdownPreview", markdownPreviewModel);
    markdownPreview.setEscapeModelStrings(false);
    markdownPreview.setOutputMarkupId(true);
    add(markdownPreview);
    markdownEditor = new MarkdownTextArea("markdownEditor", markdownPreviewModel, markdownPreview);
    markdownEditor.setRepository(repositoryName);
    WicketUtils.setInputPlaceholder(markdownEditor, getString("gb.leaveComment"));
    add(markdownEditor);
}
Also used : Form(org.apache.wicket.markup.html.form.Form) Label(org.apache.wicket.markup.html.basic.Label) TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change) RepositoryModel(com.gitblit.models.RepositoryModel) PageParameters(org.apache.wicket.PageParameters) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxButton(org.apache.wicket.ajax.markup.html.form.AjaxButton) RedirectRequestTarget(org.apache.wicket.request.target.basic.RedirectRequestTarget) BasePage(com.gitblit.wicket.pages.BasePage)

Example 4 with RedirectRequestTarget

use of org.apache.wicket.request.target.basic.RedirectRequestTarget in project gitblit by gitblit.

the class TicketSearchForm method onSubmit.

@Override
public void onSubmit() {
    String searchString = searchBoxModel.getObject();
    if (StringUtils.isEmpty(searchString)) {
        // redirect to self to avoid wicket page update bug
        String absoluteUrl = getAbsoluteUrl();
        getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
        return;
    }
    // use an absolute url to workaround Wicket-Tomcat problems with
    // mounted url parameters (issue-111)
    PageParameters params = WicketUtils.newRepositoryParameter(repositoryName);
    params.add("s", searchString);
    String absoluteUrl = getAbsoluteUrl(pageClass, params);
    getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
}
Also used : RedirectRequestTarget(org.apache.wicket.request.target.basic.RedirectRequestTarget) PageParameters(org.apache.wicket.PageParameters)

Aggregations

RedirectRequestTarget (org.apache.wicket.request.target.basic.RedirectRequestTarget)4 PageParameters (org.apache.wicket.PageParameters)3 RepositoryModel (com.gitblit.models.RepositoryModel)1 TicketModel (com.gitblit.models.TicketModel)1 Change (com.gitblit.models.TicketModel.Change)1 UserModel (com.gitblit.models.UserModel)1 BasePage (com.gitblit.wicket.pages.BasePage)1 IOException (java.io.IOException)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 AjaxButton (org.apache.wicket.ajax.markup.html.form.AjaxButton)1 Label (org.apache.wicket.markup.html.basic.Label)1 Form (org.apache.wicket.markup.html.form.Form)1 BookmarkablePageLink (org.apache.wicket.markup.html.link.BookmarkablePageLink)1 ExternalLink (org.apache.wicket.markup.html.link.ExternalLink)1 Link (org.apache.wicket.markup.html.link.Link)1 Ref (org.eclipse.jgit.lib.Ref)1 Repository (org.eclipse.jgit.lib.Repository)1