final TicketModel ticket;
public TicketPage(PageParameters params) {
super(params);
final UserModel user = GitBlitWebSession.get().getUser() == null ? UserModel.ANONYMOUS : GitBlitWebSession.get().getUser();
final RepositoryModel repository = getRepositoryModel();
final String id = WicketUtils.getObject(params);
long ticketId = Long.parseLong(id);
ticket = app().tickets().getTicket(repository, ticketId);
if (ticket == null) {
// ticket not found
throw new RestartResponseException(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));
}
final List<Change> revisions = new ArrayList<Change>();
List<Change> comments = new ArrayList<Change>();
List<Change> statusChanges = new ArrayList<Change>();
List<Change> discussion = new ArrayList<Change>();
for (Change change : ticket.changes) {
if (change.hasComment() || (change.isStatusChange() && (change.getStatus() != Status.New))) {
discussion.add(change);
}
if (change.hasComment()) {
comments.add(change);
}
if (change.hasPatchset()) {
revisions.add(change);
}
if (change.isStatusChange() && !change.hasPatchset()) {
statusChanges.add(change);
}
}
final Change currentRevision = revisions.isEmpty() ? null : revisions.get(revisions.size() - 1);
final Patchset currentPatchset = ticket.getCurrentPatchset();
/*
* TICKET HEADER
*/
String href = urlFor(TicketsPage.class, params).toString();
add(new ExternalLink("ticketNumber", href, "#" + ticket.number));
Label headerStatus = new Label("headerStatus", ticket.status.toString());
WicketUtils.setCssClass(headerStatus, getLozengeClass(ticket.status, false));
add(headerStatus);
add(new Label("ticketTitle", ticket.title));
if (currentPatchset == null) {
add(new Label("diffstat").setVisible(false));
} else {
// calculate the current diffstat of the patchset
add(new DiffStatPanel("diffstat", ticket.insertions, ticket.deletions));
}
/*
* TAB TITLES
*/
add(new Label("commentCount", "" + comments.size()).setVisible(!comments.isEmpty()));
add(new Label("commitCount", "" + (currentPatchset == null ? 0 : currentPatchset.commits)).setVisible(currentPatchset != null));
/*
* TICKET AUTHOR and DATE (DISCUSSION TAB)
*/
UserModel createdBy = app().users().getUserModel(ticket.createdBy);
if (createdBy == null) {
add(new Label("whoCreated", ticket.createdBy));
} else {
add(new LinkPanel("whoCreated", null, createdBy.getDisplayName(),
UserPage.class, WicketUtils.newUsernameParameter(createdBy.username)));
}
if (ticket.isProposal()) {
// clearly indicate this is a change ticket
add(new Label("creationMessage", getString("gb.proposedThisChange")));
} else {
// standard ticket
add(new Label("creationMessage", getString("gb.createdThisTicket")));
}
String dateFormat = app().settings().getString(Keys.web.datestampLongFormat, "EEEE, MMMM d, yyyy");
String timestampFormat = app().settings().getString(Keys.web.datetimestampLongFormat, "EEEE, MMMM d, yyyy");
final TimeZone timezone = getTimeZone();
final DateFormat df = new SimpleDateFormat(dateFormat);
df.setTimeZone(timezone);
final DateFormat tsf = new SimpleDateFormat(timestampFormat);
tsf.setTimeZone(timezone);
final Calendar cal = Calendar.getInstance(timezone);
String fuzzydate;
TimeUtils tu = getTimeUtils();
Date createdDate = ticket.created;
if (TimeUtils.isToday(createdDate, timezone)) {
fuzzydate = tu.today();
} else if (TimeUtils.isYesterday(createdDate, timezone)) {
fuzzydate = tu.yesterday();
} else {
// calculate a fuzzy time ago date
cal.setTime(createdDate);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
createdDate = cal.getTime();
fuzzydate = getTimeUtils().timeAgo(createdDate);
}
Label when = new Label("whenCreated", fuzzydate + ", " + df.format(createdDate));
WicketUtils.setHtmlTooltip(when, tsf.format(ticket.created));
add(when);
String exportHref = urlFor(ExportTicketPage.class, params).toString();
add(new ExternalLink("exportJson", exportHref, "json"));
/*
* RESPONSIBLE (DISCUSSION TAB)
*/
if (StringUtils.isEmpty(ticket.responsible)) {
add(new Label("responsible"));
} else {
UserModel responsible = app().users().getUserModel(ticket.responsible);
if (responsible == null) {
add(new Label("responsible", ticket.responsible));
} else {
add(new LinkPanel("responsible", null, responsible.getDisplayName(),
UserPage.class, WicketUtils.newUsernameParameter(responsible.username)));
}
}
/*
* MILESTONE PROGRESS (DISCUSSION TAB)
*/
if (StringUtils.isEmpty(ticket.milestone)) {
add(new Label("milestone"));
} else {
// link to milestone query
TicketMilestone milestone = app().tickets().getMilestone(repository, ticket.milestone);
PageParameters milestoneParameters = new PageParameters();
milestoneParameters.put("r", repositoryName);
milestoneParameters.put(Lucene.milestone.name(), ticket.milestone);
int progress = 0;
int open = 0;
int closed = 0;
if (milestone != null) {
progress = milestone.getProgress();
open = milestone.getOpenTickets();
closed = milestone.getClosedTickets();
}
Fragment milestoneProgress = new Fragment("milestone", "milestoneProgressFragment", this);
milestoneProgress.add(new LinkPanel("link", null, ticket.milestone, TicketsPage.class, milestoneParameters));
Label label = new Label("progress");
WicketUtils.setCssStyle(label, "width:" + progress + "%;");
milestoneProgress.add(label);
WicketUtils.setHtmlTooltip(milestoneProgress, MessageFormat.format(getString("gb.milestoneProgress"), open, closed));
add(milestoneProgress);
}
/*
* TICKET DESCRIPTION (DISCUSSION TAB)
*/
String desc;
if (StringUtils.isEmpty(ticket.body)) {
desc = getString("gb.noDescriptionGiven");
} else {
desc = MarkdownUtils.transformGFM(app().settings(), ticket.body, ticket.repository);
}
add(new Label("ticketDescription", desc).setEscapeModelStrings(false));
/*
* PARTICIPANTS (DISCUSSION TAB)
*/
if (app().settings().getBoolean(Keys.web.allowGravatar, true)) {
// gravatar allowed
List<String> participants = ticket.getParticipants();
add(new Label("participantsLabel", MessageFormat.format(getString(participants.size() > 1 ? "gb.nParticipants" : "gb.oneParticipant"),
"<b>" + participants.size() + "</b>")).setEscapeModelStrings(false));
ListDataProvider<String> participantsDp = new ListDataProvider<String>(participants);
DataView<String> participantsView = new DataView<String>("participants", participantsDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<String> item) {
String username = item.getModelObject();
UserModel user = app().users().getUserModel(username);
if (user == null) {
user = new UserModel(username);
}
item.add(new GravatarImage("participant", user.getDisplayName(),
user.emailAddress, null, 25, true));
}
};
add(participantsView);
} else {
// gravatar prohibited
add(new Label("participantsLabel").setVisible(false));
add(new Label("participants").setVisible(false));
}
/*
* LARGE STATUS INDICATOR WITH ICON (DISCUSSION TAB->SIDE BAR)
*/
Fragment ticketStatus = new Fragment("ticketStatus", "ticketStatusFragment", this);
Label ticketIcon = getStateIcon("ticketIcon", ticket);
ticketStatus.add(ticketIcon);
ticketStatus.add(new Label("ticketStatus", ticket.status.toString()));
WicketUtils.setCssClass(ticketStatus, getLozengeClass(ticket.status, false));
add(ticketStatus);
/*
* UPDATE FORM (DISCUSSION TAB)
*/
if (user.canEdit(ticket, repository) && app().tickets().isAcceptingTicketUpdates(repository)) {
if (user.canAdmin(ticket, repository) && ticket.isOpen()) {
/*
* OPEN TICKET
*/
Fragment controls = new Fragment("controls", "openControlsFragment", this);
/*
* STATUS
*/
List<Status> choices = new ArrayList<Status>();
if (ticket.isProposal()) {
choices.addAll(Arrays.asList(TicketModel.Status.proposalWorkflow));
} else if (ticket.isBug()) {
choices.addAll(Arrays.asList(TicketModel.Status.bugWorkflow));
} else {
choices.addAll(Arrays.asList(TicketModel.Status.requestWorkflow));
}
choices.remove(ticket.status);
ListDataProvider<Status> workflowDp = new ListDataProvider<Status>(choices);
DataView<Status> statusView = new DataView<Status>("newStatus", workflowDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<Status> item) {
SimpleAjaxLink<Status> link = new SimpleAjaxLink<Status>("link", item.getModel()) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
Status status = getModel().getObject();
Change change = new Change(user.username);
change.setField(Field.status, status);
if (!ticket.isWatching(user.username)) {
change.watch(user.username);
}
TicketModel update = app().tickets().updateTicket(repository, ticket.number, change);
app().tickets().createNotifier().sendMailing(update);
setResponsePage(TicketsPage.class, getPageParameters());
}
};
String css = getStatusClass(item.getModel().getObject());
WicketUtils.setCssClass(link, css);
item.add(link);
}
};
controls.add(statusView);
/*
* RESPONSIBLE LIST
*/
Set<String> userlist = new TreeSet<String>(ticket.getParticipants());
for (RegistrantAccessPermission rp : app().repositories().getUserAccessPermissions(getRepositoryModel())) {
if (rp.permission.atLeast(AccessPermission.PUSH) && !rp.isTeam()) {
userlist.add(rp.registrant);
}
}
List<TicketResponsible> responsibles = new ArrayList<TicketResponsible>();
if (!StringUtils.isEmpty(ticket.responsible)) {
// exclude the current responsible
userlist.remove(ticket.responsible);
}
for (String username : userlist) {
UserModel u = app().users().getUserModel(username);
if (u != null) {
responsibles.add(new TicketResponsible(u));
}
}
Collections.sort(responsibles);