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) {