DataView<QueryResult> dataView = new DataView<QueryResult>("row", dp) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(Item<QueryResult> item) {
final QueryResult ticket = item.getModelObject();
if (showSwatch) {
// set repository color
String color = StringUtils.getColor(StringUtils.stripDotGit(ticket.repository));
WicketUtils.setCssStyle(item, MessageFormat.format("border-left: 2px solid {0};", color));
}
PageParameters tp = WicketUtils.newObjectParameter(ticket.repository, "" + ticket.number);
if (showRepository) {
String name = StringUtils.stripDotGit(ticket.repository);
PageParameters rp = WicketUtils.newOpenTicketsParameter(ticket.repository);
LinkPanel link = new LinkPanel("ticketsLink", null, name, TicketsPage.class, rp);
WicketUtils.setCssBackground(link, name);
item.add(link);
} else {
item.add(new Label("ticketsLink").setVisible(false));
}
item.add(TicketsUI.getStateIcon("state", ticket.type, ticket.status));
item.add(new Label("id", "" + ticket.number));
UserModel creator = app().users().getUserModel(ticket.createdBy);
if (creator != null) {
item.add(new LinkPanel("createdBy", null, creator.getDisplayName(),
UserPage.class, WicketUtils.newUsernameParameter(ticket.createdBy)));
} else {
item.add(new Label("createdBy", ticket.createdBy));
}
item.add(WicketUtils.createDateLabel("createDate", ticket.createdAt, GitBlitWebSession
.get().getTimezone(), getTimeUtils(), false));
if (ticket.updatedAt == null) {
item.add(new Label("updated").setVisible(false));
} else {
Fragment updated = new Fragment("updated", "updatedFragment", this);
UserModel updater = app().users().getUserModel(ticket.updatedBy);
if (updater != null) {
updated.add(new LinkPanel("updatedBy", null, updater.getDisplayName(),
UserPage.class, WicketUtils.newUsernameParameter(ticket.updatedBy)));
} else {
updated.add(new Label("updatedBy", ticket.updatedBy));
}
updated.add(WicketUtils.createDateLabel("updateDate", ticket.updatedAt, GitBlitWebSession
.get().getTimezone(), getTimeUtils(), false));
item.add(updated);
}
item.add(new LinkPanel("title", "list subject", StringUtils.trimString(
ticket.title, Constants.LEN_SHORTLOG), TicketsPage.class, tp));
ListDataProvider<String> labelsProvider = new ListDataProvider<String>(ticket.getLabels());
DataView<String> labelsView = new DataView<String>("labels", labelsProvider) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<String> labelItem) {
RepositoryModel repository = app().repositories().getRepositoryModel(ticket.repository);
Label label;
TicketLabel tLabel;
if (repository == null) {
label = new Label("label", labelItem.getModelObject());
tLabel = new TicketLabel(labelItem.getModelObject());
} else {
Repository db = app().repositories().getRepository(repository.name);
BugtraqProcessor btp = new BugtraqProcessor(app().settings());
String content = btp.processText(db, repository.name, labelItem.getModelObject());
String safeContent = app().xssFilter().relaxed(content);
db.close();
label = new Label("label", safeContent);
label.setEscapeModelStrings(false);
tLabel = app().tickets().getLabel(repository, labelItem.getModelObject());
}
String background = MessageFormat.format("background-color:{0};", tLabel.color);
label.add(new SimpleAttributeModifier("style", background));
labelItem.add(label);
}
};
item.add(labelsView);
if (StringUtils.isEmpty(ticket.responsible)) {
item.add(new Label("responsible").setVisible(false));
} else {
UserModel responsible = app().users().getUserModel(ticket.responsible);
if (responsible == null) {
responsible = new UserModel(ticket.responsible);
}
GravatarImage avatar = new GravatarImage("responsible", responsible.getDisplayName(),
responsible.emailAddress, null, 16, true);
avatar.setTooltip(getString("gb.responsible") + ": " + responsible.getDisplayName());
item.add(avatar);
}
// votes indicator
Label v = new Label("votes", "" + ticket.votesCount);
WicketUtils.setHtmlTooltip(v, getString("gb.votes"));
item.add(v.setVisible(ticket.votesCount > 0));
// watching indicator
item.add(new Label("watching").setVisible(ticket.isWatching(GitBlitWebSession.get().getUsername())));
// status indicator
String css = TicketsUI.getLozengeClass(ticket.status, true);
Label l = new Label("status", ticket.status.toString());
WicketUtils.setCssClass(l, css);