Search in sources :

Example 1 with PageParameters

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

the class TicketsPage method milestoneList.

protected DataView<TicketMilestone> milestoneList(String wicketId, List<TicketMilestone> milestones, final boolean acceptingUpdates) {
    ListDataProvider<TicketMilestone> milestonesDp = new ListDataProvider<TicketMilestone>(milestones);
    DataView<TicketMilestone> milestonesList = new DataView<TicketMilestone>(wicketId, milestonesDp) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<TicketMilestone> item) {
            Fragment entryPanel = new Fragment("entryPanel", "milestoneListFragment", this);
            item.add(entryPanel);
            final TicketMilestone tm = item.getModelObject();
            String[] states;
            if (tm.isOpen()) {
                states = TicketsUI.openStatii;
            } else {
                states = TicketsUI.closedStatii;
            }
            PageParameters params = queryParameters(null, tm.name, states, null, null, true, 1);
            entryPanel.add(new LinkPanel("milestoneName", null, tm.name, TicketsPage.class, params).setRenderBodyOnly(true));
            String css;
            String status = tm.status.name();
            switch(tm.status) {
                case Open:
                    if (tm.isOverdue()) {
                        css = "aui-lozenge aui-lozenge-subtle aui-lozenge-error";
                        status = "overdue";
                    } else {
                        css = "aui-lozenge aui-lozenge-subtle";
                    }
                    break;
                default:
                    css = "aui-lozenge";
                    break;
            }
            Label stateLabel = new Label("milestoneState", status);
            WicketUtils.setCssClass(stateLabel, css);
            entryPanel.add(stateLabel);
            if (tm.due == null) {
                entryPanel.add(new Label("milestoneDue", getString("gb.notSpecified")));
            } else {
                entryPanel.add(WicketUtils.createDatestampLabel("milestoneDue", tm.due, getTimeZone(), getTimeUtils()));
            }
            if (acceptingUpdates) {
                entryPanel.add(new LinkPanel("editMilestone", null, getString("gb.edit"), EditMilestonePage.class, WicketUtils.newObjectParameter(repositoryName, tm.name)));
            } else {
                entryPanel.add(new Label("editMilestone").setVisible(false));
            }
            if (tm.isOpen()) {
                // re-load milestone with query results
                TicketMilestone m = app().tickets().getMilestone(getRepositoryModel(), tm.name);
                Fragment milestonePanel = new Fragment("milestonePanel", "openMilestoneFragment", this);
                Label label = new Label("progress");
                WicketUtils.setCssStyle(label, "width:" + m.getProgress() + "%;");
                milestonePanel.add(label);
                milestonePanel.add(new LinkPanel("openTickets", null, MessageFormat.format(getString("gb.nOpenTickets"), m.getOpenTickets()), TicketsPage.class, queryParameters(null, tm.name, TicketsUI.openStatii, null, null, true, 1)));
                milestonePanel.add(new LinkPanel("closedTickets", null, MessageFormat.format(getString("gb.nClosedTickets"), m.getClosedTickets()), TicketsPage.class, queryParameters(null, tm.name, TicketsUI.closedStatii, null, null, true, 1)));
                milestonePanel.add(new Label("totalTickets", MessageFormat.format(getString("gb.nTotalTickets"), m.getTotalTickets())));
                entryPanel.add(milestonePanel);
            } else {
                entryPanel.add(new Label("milestonePanel").setVisible(false));
            }
        }
    };
    return milestonesList;
}
Also used : ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) TicketLabel(com.gitblit.tickets.TicketLabel) Label(org.apache.wicket.markup.html.basic.Label) PageParameters(org.apache.wicket.PageParameters) Fragment(org.apache.wicket.markup.html.panel.Fragment) LinkPanel(com.gitblit.wicket.panels.LinkPanel) DataView(org.apache.wicket.markup.repeater.data.DataView) Item(org.apache.wicket.markup.repeater.Item) TicketMilestone(com.gitblit.tickets.TicketMilestone)

Example 2 with PageParameters

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

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

the class DashboardPage method addDropDownMenus.

@Override
protected void addDropDownMenus(List<NavLink> navLinks) {
    PageParameters params = getPageParameters();
    DropDownPageMenuNavLink menu = new DropDownPageMenuNavLink("gb.filters", GitBlitWebApp.get().getHomePage());
    // 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 4 with PageParameters

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

the class RootPage method getTimeFilterItems.

protected List<MenuItem> getTimeFilterItems(PageParameters params) {
    // days back choices - additive parameters
    int daysBack = app().settings().getInteger(Keys.web.activityDuration, 7);
    int maxDaysBack = app().settings().getInteger(Keys.web.activityDurationMaximum, 30);
    if (daysBack < 1) {
        daysBack = 7;
    }
    if (daysBack > maxDaysBack) {
        daysBack = maxDaysBack;
    }
    PageParameters clonedParams;
    if (params == null) {
        clonedParams = new PageParameters();
    } else {
        clonedParams = new PageParameters(params);
    }
    if (!clonedParams.containsKey("db")) {
        clonedParams.put("db", daysBack);
    }
    List<MenuItem> items = new ArrayList<MenuItem>();
    Set<Integer> choicesSet = new TreeSet<Integer>(app().settings().getIntegers(Keys.web.activityDurationChoices));
    if (choicesSet.isEmpty()) {
        choicesSet.addAll(Arrays.asList(1, 3, 7, 14, 21, 28));
    }
    List<Integer> choices = new ArrayList<Integer>(choicesSet);
    Collections.sort(choices);
    String lastDaysPattern = getString("gb.lastNDays");
    for (Integer db : choices) {
        if (db == 1) {
            items.add(new ParameterMenuItem(getString("gb.time.today"), "db", db.toString(), clonedParams));
        } else {
            String txt = MessageFormat.format(lastDaysPattern, db);
            items.add(new ParameterMenuItem(txt, "db", db.toString(), clonedParams));
        }
    }
    items.add(new MenuDivider());
    return items;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MenuDivider(com.gitblit.models.Menu.MenuDivider) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) PageLinkMenuItem(com.gitblit.models.Menu.PageLinkMenuItem) ParameterMenuItem(com.gitblit.models.Menu.ParameterMenuItem) ExternalLinkMenuItem(com.gitblit.models.Menu.ExternalLinkMenuItem) MenuItem(com.gitblit.models.Menu.MenuItem) ToggleMenuItem(com.gitblit.models.Menu.ToggleMenuItem) PageParameters(org.apache.wicket.PageParameters) ParameterMenuItem(com.gitblit.models.Menu.ParameterMenuItem)

Example 5 with PageParameters

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

the class RootPage method loginUser.

private void loginUser(UserModel user) {
    if (user != null) {
        HttpServletRequest request = ((WebRequest) getRequest()).getHttpServletRequest();
        HttpServletResponse response = ((WebResponse) getResponse()).getHttpServletResponse();
        // Set the user into the session
        GitBlitWebSession session = GitBlitWebSession.get();
        // issue 62: fix session fixation vulnerability
        session.replaceSession();
        session.setUser(user);
        request = ((WebRequest) getRequest()).getHttpServletRequest();
        response = ((WebResponse) getResponse()).getHttpServletResponse();
        request.getSession().setAttribute(Constants.ATTRIB_AUTHTYPE, AuthenticationType.CREDENTIALS);
        // Set Cookie
        app().authentication().setCookie(request, response, user);
        if (!session.continueRequest()) {
            PageParameters params = getPageParameters();
            if (params == null) {
                // redirect to this page
                redirectTo(getClass());
            } else {
                // Strip username and password and redirect to this page
                params.remove("username");
                params.remove("password");
                redirectTo(getClass(), params);
            }
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebResponse(org.apache.wicket.protocol.http.WebResponse) WebRequest(org.apache.wicket.protocol.http.WebRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) GitBlitWebSession(com.gitblit.wicket.GitBlitWebSession) PageParameters(org.apache.wicket.PageParameters)

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