Search in sources :

Example 11 with PageParameters

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

the class ProjectsPage 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()) {
        add(new Label("projectsPanel"));
        return;
    }
    List<ProjectModel> projects = getProjects(params);
    Collections.sort(projects);
    ListDataProvider<ProjectModel> dp = new ListDataProvider<ProjectModel>(projects);
    DataView<ProjectModel> dataView = new DataView<ProjectModel>("project", dp) {

        private static final long serialVersionUID = 1L;

        int counter;

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            counter = 0;
        }

        @Override
        public void populateItem(final Item<ProjectModel> item) {
            final ProjectModel entry = item.getModelObject();
            PageParameters pp = WicketUtils.newProjectParameter(entry.name);
            item.add(new LinkPanel("projectTitle", "list", entry.getDisplayName(), ProjectPage.class, pp));
            item.add(new LinkPanel("projectDescription", "list", entry.description, ProjectPage.class, pp));
            item.add(new Label("repositoryCount", entry.repositories.size() + " " + (entry.repositories.size() == 1 ? getString("gb.repository") : getString("gb.repositories"))));
            String lastChange;
            if (entry.lastChange.getTime() == 0) {
                lastChange = "--";
            } else {
                lastChange = getTimeUtils().timeAgo(entry.lastChange);
            }
            Label lastChangeLabel = new Label("projectLastChange", lastChange);
            item.add(lastChangeLabel);
            WicketUtils.setCssClass(lastChangeLabel, getTimeUtils().timeAgoCss(entry.lastChange));
            WicketUtils.setAlternatingBackground(item, counter);
            counter++;
        }
    };
    add(dataView);
}
Also used : ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) Label(org.apache.wicket.markup.html.basic.Label) PageParameters(org.apache.wicket.PageParameters) LinkPanel(com.gitblit.wicket.panels.LinkPanel) DataView(org.apache.wicket.markup.repeater.data.DataView) ParameterMenuItem(com.gitblit.models.Menu.ParameterMenuItem) Item(org.apache.wicket.markup.repeater.Item) ProjectModel(com.gitblit.models.ProjectModel)

Example 12 with PageParameters

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

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

the class UserPage method addDropDownMenus.

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

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

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

the class RootPage method getRootPageParameters.

private PageParameters getRootPageParameters() {
    if (reusePageParameters()) {
        PageParameters pp = getPageParameters();
        if (pp != null) {
            PageParameters params = new PageParameters(pp);
            // remove named project parameter
            params.remove("p");
            // remove named repository parameter
            params.remove("r");
            // remove named user parameter
            params.remove("user");
            // remove days back parameter if it is the default value
            if (params.containsKey("db") && params.getInt("db") == app().settings().getInteger(Keys.web.activityDuration, 7)) {
                params.remove("db");
            }
            return params;
        }
    }
    return null;
}
Also used : 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