Search in sources :

Example 1 with LinkPanel

use of com.gitblit.wicket.panels.LinkPanel in project gitblit by gitblit.

the class TicketsPage method buildPager.

protected void buildPager(final String query, final String milestone, final String[] states, final String assignedTo, final String sort, final boolean desc, final int page, int pageSize, int count, int total) {
    boolean showNav = total > (2 * pageSize);
    boolean allowPrev = page > 1;
    boolean allowNext = (pageSize * (page - 1) + count) < total;
    add(new BookmarkablePageLink<Void>("prevLink", TicketsPage.class, queryParameters(query, milestone, states, assignedTo, sort, desc, page - 1)).setEnabled(allowPrev).setVisible(showNav));
    add(new BookmarkablePageLink<Void>("nextLink", TicketsPage.class, queryParameters(query, milestone, states, assignedTo, sort, desc, page + 1)).setEnabled(allowNext).setVisible(showNav));
    if (total <= pageSize) {
        add(new Label("pageLink").setVisible(false));
        return;
    }
    // determine page numbers to display
    int pages = count == 0 ? 0 : ((total / pageSize) + (total % pageSize == 0 ? 0 : 1));
    // preferred number of pagelinks
    int segments = 5;
    if (pages < segments) {
        // not enough data for preferred number of page links
        segments = pages;
    }
    int minpage = Math.min(Math.max(1, page - 2), pages - (segments - 1));
    int maxpage = Math.min(pages, minpage + (segments - 1));
    List<Integer> sequence = new ArrayList<Integer>();
    for (int i = minpage; i <= maxpage; i++) {
        sequence.add(i);
    }
    ListDataProvider<Integer> pagesDp = new ListDataProvider<Integer>(sequence);
    DataView<Integer> pagesView = new DataView<Integer>("pageLink", pagesDp) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<Integer> item) {
            final Integer i = item.getModelObject();
            LinkPanel link = new LinkPanel("page", null, "" + i, TicketsPage.class, queryParameters(query, milestone, states, assignedTo, sort, desc, i));
            link.setRenderBodyOnly(true);
            if (i == page) {
                WicketUtils.setCssClass(item, "active");
            }
            item.add(link);
        }
    };
    add(pagesView);
}
Also used : ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) TicketLabel(com.gitblit.tickets.TicketLabel) Label(org.apache.wicket.markup.html.basic.Label) ArrayList(java.util.ArrayList) LinkPanel(com.gitblit.wicket.panels.LinkPanel) DataView(org.apache.wicket.markup.repeater.data.DataView) Item(org.apache.wicket.markup.repeater.Item)

Example 2 with LinkPanel

use of com.gitblit.wicket.panels.LinkPanel 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 3 with LinkPanel

use of com.gitblit.wicket.panels.LinkPanel in project gitblit by gitblit.

the class RepositoryPage method createPersonPanel.

protected Component createPersonPanel(String wicketId, PersonIdent identity, Constants.SearchType searchType) {
    String name = identity == null ? "" : identity.getName();
    String address = identity == null ? "" : identity.getEmailAddress();
    name = StringUtils.removeNewlines(name);
    address = StringUtils.removeNewlines(address);
    boolean showEmail = app().settings().getBoolean(Keys.web.showEmailAddresses, false);
    if (!showEmail || StringUtils.isEmpty(name) || StringUtils.isEmpty(address)) {
        String value = name;
        if (StringUtils.isEmpty(value)) {
            if (showEmail) {
                value = address;
            } else {
                value = getString("gb.missingUsername");
            }
        }
        Fragment partial = new Fragment(wicketId, "partialPersonIdent", this);
        LinkPanel link = new LinkPanel("personName", "list", value, GitSearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId, value, searchType));
        setPersonSearchTooltip(link, value, searchType);
        partial.add(link);
        return partial;
    } else {
        Fragment fullPerson = new Fragment(wicketId, "fullPersonIdent", this);
        LinkPanel nameLink = new LinkPanel("personName", "list", name, GitSearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId, name, searchType));
        setPersonSearchTooltip(nameLink, name, searchType);
        fullPerson.add(nameLink);
        LinkPanel addressLink = new LinkPanel("personAddress", "hidden-phone list", "<" + address + ">", GitSearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId, address, searchType));
        setPersonSearchTooltip(addressLink, address, searchType);
        fullPerson.add(addressLink);
        return fullPerson;
    }
}
Also used : Fragment(org.apache.wicket.markup.html.panel.Fragment) LinkPanel(com.gitblit.wicket.panels.LinkPanel)

Example 4 with LinkPanel

use of com.gitblit.wicket.panels.LinkPanel in project gitblit by gitblit.

the class DashboardPage method addActivity.

protected void addActivity(UserModel user, Collection<RepositoryModel> repositories, String feedTitle, int daysBack) {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DATE, -1 * daysBack);
    Date minimumDate = c.getTime();
    TimeZone timezone = getTimeZone();
    // create daily commit digest feed
    List<DailyLogEntry> digests = new ArrayList<DailyLogEntry>();
    for (RepositoryModel model : repositories) {
        if (model.isCollectingGarbage) {
            continue;
        }
        if (model.hasCommits && model.lastChange.after(minimumDate)) {
            Repository repository = app().repositories().getRepository(model.name);
            List<DailyLogEntry> entries = RefLogUtils.getDailyLogByRef(model.name, repository, minimumDate, timezone);
            digests.addAll(entries);
            repository.close();
        }
    }
    Fragment activityFragment = new Fragment("activity", "activityFragment", this);
    add(activityFragment);
    activityFragment.add(new Label("feedTitle", feedTitle));
    if (digests.size() == 0) {
        // quiet or no starred repositories
        if (repositories.size() == 0) {
            if (UserModel.ANONYMOUS.equals(user)) {
                if (daysBack == 1) {
                    activityFragment.add(new Label("digests", getString("gb.noActivityToday")));
                } else {
                    activityFragment.add(new Label("digests", MessageFormat.format(getString("gb.noActivity"), daysBack)));
                }
            } else {
                activityFragment.add(new LinkPanel("digests", null, getString("gb.findSomeRepositories"), RepositoriesPage.class));
            }
        } else {
            if (daysBack == 1) {
                activityFragment.add(new Label("digests", getString("gb.noActivityToday")));
            } else {
                activityFragment.add(new Label("digests", MessageFormat.format(getString("gb.noActivity"), daysBack)));
            }
        }
    } else {
        // show daily commit digest feed
        Collections.sort(digests);
        DigestsPanel digestsPanel = new DigestsPanel("digests", digests);
        activityFragment.add(digestsPanel);
    }
    // add the nifty charts
    if (!ArrayUtils.isEmpty(digests)) {
        // aggregate author exclusions
        Set<String> authorExclusions = new TreeSet<String>();
        for (String author : app().settings().getStrings(Keys.web.metricAuthorExclusions)) {
            authorExclusions.add(author.toLowerCase());
        }
        for (RepositoryModel model : repositories) {
            if (!ArrayUtils.isEmpty(model.metricAuthorExclusions)) {
                for (String author : model.metricAuthorExclusions) {
                    authorExclusions.add(author.toLowerCase());
                }
            }
        }
        addCharts(activityFragment, digests, authorExclusions, daysBack);
    } else {
        activityFragment.add(new Label("charts").setVisible(false));
        activityFragment.add(new Label("feedheader").setVisible(false));
    }
}
Also used : DigestsPanel(com.gitblit.wicket.panels.DigestsPanel) Calendar(java.util.Calendar) DailyLogEntry(com.gitblit.models.DailyLogEntry) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) RepositoryModel(com.gitblit.models.RepositoryModel) Fragment(org.apache.wicket.markup.html.panel.Fragment) Date(java.util.Date) LinkPanel(com.gitblit.wicket.panels.LinkPanel) TimeZone(java.util.TimeZone) Repository(org.eclipse.jgit.lib.Repository) TreeSet(java.util.TreeSet)

Example 5 with LinkPanel

use of com.gitblit.wicket.panels.LinkPanel 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)

Aggregations

LinkPanel (com.gitblit.wicket.panels.LinkPanel)10 Label (org.apache.wicket.markup.html.basic.Label)9 Fragment (org.apache.wicket.markup.html.panel.Fragment)6 Item (org.apache.wicket.markup.repeater.Item)6 DataView (org.apache.wicket.markup.repeater.data.DataView)6 ListDataProvider (org.apache.wicket.markup.repeater.data.ListDataProvider)6 ArrayList (java.util.ArrayList)5 UserModel (com.gitblit.models.UserModel)4 TicketLabel (com.gitblit.tickets.TicketLabel)4 PageParameters (org.apache.wicket.PageParameters)4 RepositoryModel (com.gitblit.models.RepositoryModel)3 ProjectModel (com.gitblit.models.ProjectModel)2 ExternalLink (org.apache.wicket.markup.html.link.ExternalLink)2 SearchType (com.gitblit.Constants.SearchType)1 DailyLogEntry (com.gitblit.models.DailyLogEntry)1 ParameterMenuItem (com.gitblit.models.Menu.ParameterMenuItem)1 PathChangeModel (com.gitblit.models.PathModel.PathChangeModel)1 SearchResult (com.gitblit.models.SearchResult)1 SubmoduleModel (com.gitblit.models.SubmoduleModel)1 Change (com.gitblit.models.TicketModel.Change)1