use of org.apache.wicket.markup.repeater.data.ListDataProvider 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);
}
use of org.apache.wicket.markup.repeater.data.ListDataProvider 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;
}
use of org.apache.wicket.markup.repeater.data.ListDataProvider in project gitblit by gitblit.
the class UserPage 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 userName = WicketUtils.getUsername(params);
if (StringUtils.isEmpty(userName)) {
throw new GitblitRedirectException(GitBlitWebApp.get().getHomePage());
}
UserModel user = app().users().getUserModel(userName);
if (user == null) {
// construct a temporary user model
user = new UserModel(userName);
}
add(new UserTitlePanel("userTitlePanel", user, user.username));
UserModel sessionUser = GitBlitWebSession.get().getUser();
boolean isMyProfile = sessionUser != null && sessionUser.equals(user);
if (isMyProfile) {
addPreferences(user);
if (app().services().isServingSSH()) {
// show the SSH key management tab
addSshKeys(user);
} else {
// SSH daemon is disabled, hide keys tab
add(new Label("sshKeysLink").setVisible(false));
add(new Label("sshKeysTab").setVisible(false));
}
} else {
// visiting user
add(new Label("preferencesLink").setVisible(false));
add(new Label("preferencesTab").setVisible(false));
add(new Label("sshKeysLink").setVisible(false));
add(new Label("sshKeysTab").setVisible(false));
}
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);
}
});
final ListDataProvider<RepositoryModel> dp = new ListDataProvider<RepositoryModel>(repositories);
DataView<RepositoryModel> dataView = new DataView<RepositoryModel>("repositoryList", dp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<RepositoryModel> item) {
final RepositoryModel entry = item.getModelObject();
ProjectRepositoryPanel row = new ProjectRepositoryPanel("repository", getLocalizer(), this, showAdmin, entry, getAccessRestrictions());
item.add(row);
}
};
add(dataView);
}
use of org.apache.wicket.markup.repeater.data.ListDataProvider in project gitblit by gitblit.
the class ReflogPanel method setup.
protected void setup(List<RefLogEntry> changes) {
ListDataProvider<RefLogEntry> dp = new ListDataProvider<RefLogEntry>(changes);
DataView<RefLogEntry> changeView = new DataView<RefLogEntry>("change", dp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<RefLogEntry> changeItem) {
final RefLogEntry change = changeItem.getModelObject();
String dateFormat = app().settings().getString(Keys.web.datetimestampLongFormat, "EEEE, MMMM d, yyyy HH:mm Z");
TimeZone timezone = getTimeZone();
DateFormat df = new SimpleDateFormat(dateFormat);
df.setTimeZone(timezone);
Calendar cal = Calendar.getInstance(timezone);
String fullRefName = change.getChangedRefs().get(0);
String shortRefName = fullRefName;
String ticketId = null;
boolean isTag = false;
boolean isTicket = false;
if (shortRefName.startsWith(Constants.R_TICKET)) {
ticketId = fullRefName.substring(Constants.R_TICKET.length());
shortRefName = MessageFormat.format(getString("gb.ticketN"), ticketId);
isTicket = true;
} else if (shortRefName.startsWith(Constants.R_HEADS)) {
shortRefName = shortRefName.substring(Constants.R_HEADS.length());
} else if (shortRefName.startsWith(Constants.R_TAGS)) {
shortRefName = shortRefName.substring(Constants.R_TAGS.length());
isTag = true;
}
String fuzzydate;
TimeUtils tu = getTimeUtils();
Date changeDate = change.date;
if (TimeUtils.isToday(changeDate, timezone)) {
fuzzydate = tu.today();
} else if (TimeUtils.isYesterday(changeDate, timezone)) {
fuzzydate = tu.yesterday();
} else {
// calculate a fuzzy time ago date
cal.setTime(changeDate);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Date date = cal.getTime();
fuzzydate = getTimeUtils().timeAgo(date);
}
changeItem.add(new Label("whenChanged", fuzzydate + ", " + df.format(changeDate)));
Label changeIcon = new Label("changeIcon");
if (Type.DELETE.equals(change.getChangeType(fullRefName))) {
WicketUtils.setCssClass(changeIcon, "iconic-trash-stroke");
} else if (isTag) {
WicketUtils.setCssClass(changeIcon, "iconic-tag");
} else if (isTicket) {
WicketUtils.setCssClass(changeIcon, "fa fa-ticket");
} else {
WicketUtils.setCssClass(changeIcon, "iconic-upload");
}
changeItem.add(changeIcon);
if (change.user.username.equals(change.user.emailAddress) && change.user.emailAddress.indexOf('@') > -1) {
// username is an email address - 1.2.1 push log bug
changeItem.add(new Label("whoChanged", change.user.getDisplayName()));
} else if (change.user.username.equals(UserModel.ANONYMOUS.username)) {
// anonymous change
changeItem.add(new Label("whoChanged", getString("gb.anonymousUser")));
} else {
// link to user account page
changeItem.add(new LinkPanel("whoChanged", null, change.user.getDisplayName(), UserPage.class, WicketUtils.newUsernameParameter(change.user.username)));
}
boolean isDelete = false;
boolean isRewind = false;
String what;
String by = null;
switch(change.getChangeType(fullRefName)) {
case CREATE:
if (isTag) {
// new tag
what = getString("gb.pushedNewTag");
} else {
// new branch
what = getString("gb.pushedNewBranch");
}
break;
case DELETE:
isDelete = true;
if (isTag) {
what = getString("gb.deletedTag");
} else {
what = getString("gb.deletedBranch");
}
break;
case UPDATE_NONFASTFORWARD:
isRewind = true;
default:
what = MessageFormat.format(change.getCommitCount() > 1 ? getString("gb.pushedNCommitsTo") : getString("gb.pushedOneCommitTo"), change.getCommitCount());
if (change.getAuthorCount() == 1) {
by = MessageFormat.format(getString("gb.byOneAuthor"), change.getAuthorIdent().getName());
} else {
by = MessageFormat.format(getString("gb.byNAuthors"), change.getAuthorCount());
}
break;
}
changeItem.add(new Label("whatChanged", what));
changeItem.add(new Label("byAuthors", by).setVisible(!StringUtils.isEmpty(by)));
changeItem.add(new Label("refRewind", getString("gb.rewind")).setVisible(isRewind));
if (isDelete) {
// can't link to deleted ref
changeItem.add(new Label("refChanged", shortRefName));
} else if (isTag) {
// link to tag
changeItem.add(new LinkPanel("refChanged", null, shortRefName, TagPage.class, WicketUtils.newObjectParameter(change.repository, fullRefName)));
} else if (isTicket) {
// link to ticket
changeItem.add(new LinkPanel("refChanged", null, shortRefName, TicketsPage.class, WicketUtils.newObjectParameter(change.repository, ticketId)));
} else {
// link to tree
changeItem.add(new LinkPanel("refChanged", null, shortRefName, TreePage.class, WicketUtils.newObjectParameter(change.repository, fullRefName)));
}
int maxCommitCount = 5;
List<RepositoryCommit> commits = change.getCommits();
if (commits.size() > maxCommitCount) {
commits = new ArrayList<RepositoryCommit>(commits.subList(0, maxCommitCount));
}
// compare link
String compareLinkText = null;
if ((change.getCommitCount() <= maxCommitCount) && (change.getCommitCount() > 1)) {
compareLinkText = MessageFormat.format(getString("gb.viewComparison"), commits.size());
} else if (change.getCommitCount() > maxCommitCount) {
int diff = change.getCommitCount() - maxCommitCount;
compareLinkText = MessageFormat.format(diff > 1 ? getString("gb.nMoreCommits") : getString("gb.oneMoreCommit"), diff);
}
if (StringUtils.isEmpty(compareLinkText)) {
changeItem.add(new Label("compareLink").setVisible(false));
} else {
String endRangeId = change.getNewId(fullRefName);
String startRangeId = change.getOldId(fullRefName);
changeItem.add(new LinkPanel("compareLink", null, compareLinkText, ComparePage.class, WicketUtils.newRangeParameter(change.repository, startRangeId, endRangeId)));
}
ListDataProvider<RepositoryCommit> cdp = new ListDataProvider<RepositoryCommit>(commits);
DataView<RepositoryCommit> commitsView = new DataView<RepositoryCommit>("commit", cdp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<RepositoryCommit> commitItem) {
final RepositoryCommit commit = commitItem.getModelObject();
// author gravatar
commitItem.add(new AvatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
// merge icon
if (commit.getParentCount() > 1) {
commitItem.add(WicketUtils.newImage("commitIcon", "commit_merge_16x16.png"));
} else {
commitItem.add(WicketUtils.newBlankImage("commitIcon"));
}
// short message
String shortMessage = commit.getShortMessage();
String trimmedMessage = shortMessage;
if (commit.getRefs() != null && commit.getRefs().size() > 0) {
trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG_REFS);
} else {
trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG);
}
LinkPanel shortlog = new LinkPanel("commitShortMessage", "list", trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(change.repository, commit.getName()));
if (!shortMessage.equals(trimmedMessage)) {
WicketUtils.setHtmlTooltip(shortlog, shortMessage);
}
commitItem.add(shortlog);
// commit hash link
int hashLen = app().settings().getInteger(Keys.web.shortCommitIdLength, 6);
LinkPanel commitHash = new LinkPanel("hashLink", null, commit.getName().substring(0, hashLen), CommitPage.class, WicketUtils.newObjectParameter(change.repository, commit.getName()));
WicketUtils.setCssClass(commitHash, "shortsha1");
WicketUtils.setHtmlTooltip(commitHash, commit.getName());
commitItem.add(commitHash);
}
};
changeItem.add(commitsView);
}
};
add(changeView);
}
use of org.apache.wicket.markup.repeater.data.ListDataProvider in project gitblit by gitblit.
the class RepositoryUrlPanel method createApplicationMenus.
protected Fragment createApplicationMenus(String wicketId, final UserModel user, final RepositoryModel repository, final List<RepositoryUrl> repositoryUrls) {
final List<GitClientApplication> displayedApps = new ArrayList<GitClientApplication>();
final String userAgent = ((WebClientInfo) GitBlitWebSession.get().getClientInfo()).getUserAgent();
if (user.canClone(repository)) {
for (GitClientApplication app : app().gitblit().getClientApplications()) {
if (app.isActive && app.allowsPlatform(userAgent)) {
displayedApps.add(app);
}
}
}
final String baseURL = WicketUtils.getGitblitURL(RequestCycle.get().getRequest());
ListDataProvider<GitClientApplication> displayedAppsDp = new ListDataProvider<GitClientApplication>(displayedApps);
DataView<GitClientApplication> appMenus = new DataView<GitClientApplication>("appMenus", displayedAppsDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<GitClientApplication> item) {
final GitClientApplication clientApp = item.getModelObject();
// filter the urls for the client app
List<RepositoryUrl> urls = new ArrayList<RepositoryUrl>();
for (RepositoryUrl repoUrl : repositoryUrls) {
if (clientApp.minimumPermission == null || !repoUrl.hasPermission()) {
// no minimum permission or untracked permissions, assume it is satisfactory
if (clientApp.supportsTransport(repoUrl.url)) {
urls.add(repoUrl);
}
} else if (repoUrl.permission.atLeast(clientApp.minimumPermission)) {
// repo url meets minimum permission requirement
if (clientApp.supportsTransport(repoUrl.url)) {
urls.add(repoUrl);
}
}
}
if (urls.size() == 0) {
// do not show this app menu because there are no urls
item.add(new Label("appMenu").setVisible(false));
return;
}
Fragment appMenu = new Fragment("appMenu", "appMenuFragment", this);
appMenu.setRenderBodyOnly(true);
item.add(appMenu);
// menu button
appMenu.add(new Label("applicationName", clientApp.name));
// application icon
Component img;
if (StringUtils.isEmpty(clientApp.icon)) {
img = WicketUtils.newClearPixel("applicationIcon").setVisible(false);
} else {
if (clientApp.icon.contains("://")) {
// external image
img = new ExternalImage("applicationIcon", clientApp.icon);
} else {
// context image
img = WicketUtils.newImage("applicationIcon", clientApp.icon);
}
}
appMenu.add(img);
// application menu title, may be a link
if (StringUtils.isEmpty(clientApp.productUrl)) {
appMenu.add(new Label("applicationTitle", clientApp.toString()));
} else {
appMenu.add(new LinkPanel("applicationTitle", null, clientApp.toString(), clientApp.productUrl, true));
}
// brief application description
if (StringUtils.isEmpty(clientApp.description)) {
appMenu.add(new Label("applicationDescription").setVisible(false));
} else {
appMenu.add(new Label("applicationDescription", clientApp.description));
}
// brief application legal info, copyright, license, etc
if (StringUtils.isEmpty(clientApp.legal)) {
appMenu.add(new Label("applicationLegal").setVisible(false));
} else {
appMenu.add(new Label("applicationLegal", clientApp.legal));
}
// a nested repeater for all action items
ListDataProvider<RepositoryUrl> urlsDp = new ListDataProvider<RepositoryUrl>(urls);
DataView<RepositoryUrl> actionItems = new DataView<RepositoryUrl>("actionItems", urlsDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<RepositoryUrl> repoLinkItem) {
RepositoryUrl repoUrl = repoLinkItem.getModelObject();
Fragment fragment = new Fragment("actionItem", "actionFragment", this);
fragment.add(createPermissionBadge("permission", repoUrl));
if (!StringUtils.isEmpty(clientApp.cloneUrl)) {
// custom registered url
String url = substitute(clientApp.cloneUrl, repoUrl.url, baseURL, user.username, repository.name);
fragment.add(new LinkPanel("content", "applicationMenuItem", getString("gb.clone") + " " + repoUrl.url, url));
repoLinkItem.add(fragment);
fragment.add(new Label("copyFunction").setVisible(false));
} else if (!StringUtils.isEmpty(clientApp.command)) {
// command-line
String command = substitute(clientApp.command, repoUrl.url, baseURL, user.username, repository.name);
Label content = new Label("content", command);
WicketUtils.setCssClass(content, "commandMenuItem");
fragment.add(content);
repoLinkItem.add(fragment);
// copy function for command
fragment.add(createCopyFragment(command));
}
}
};
appMenu.add(actionItems);
}
};
Fragment applicationMenus = new Fragment(wicketId, "applicationMenusFragment", this);
applicationMenus.add(appMenus);
return applicationMenus;
}
Aggregations