if (StringUtils.isEmpty(tq.color)) {
// calculate a color
tq.color = StringUtils.getColor(tq.name);
}
String background = MessageFormat.format("background-color:{0};", tq.color);
swatch.add(new SimpleAttributeModifier("style", background));
item.add(swatch);
if (activeQuery.contains(tq.query)) {
// selected
String q = QueryBuilder.q(activeQuery).remove(tq.query).build();
PageParameters params = queryParameters(q, milestoneParam, statiiParam, assignedToParam, sortBy, desc, 1);
item.add(new LinkPanel("link", "active", tq.name, TicketsPage.class, params).setRenderBodyOnly(true));
Label checked = new Label("checked");
WicketUtils.setCssClass(checked, "iconic-o-x");
item.add(checked);
item.add(new SimpleAttributeModifier("style", background));
} else {
// unselected
String q = QueryBuilder.q(queryParam).toSubquery().and(tq.query).build();
PageParameters params = queryParameters(q, milestoneParam, statiiParam, assignedToParam, sortBy, desc, 1);
item.add(new LinkPanel("link", null, tq.name, TicketsPage.class, params).setRenderBodyOnly(true));
item.add(new Label("checked").setVisible(false));
}
}
};
fragment.add(dynamicQueriesList);
add(fragment);
}
// states
if (ArrayUtils.isEmpty(statiiParam)) {
add(new Label("selectedStatii", getString("gb.all")));
} else {
add(new Label("selectedStatii", StringUtils.flattenStrings(Arrays.asList(statiiParam), ",")));
}
add(new BookmarkablePageLink<Void>("openTickets", TicketsPage.class, queryParameters(queryParam, milestoneParam, openStatii, assignedToParam, sortBy, desc, 1)));
add(new BookmarkablePageLink<Void>("closedTickets", TicketsPage.class, queryParameters(queryParam, milestoneParam, closedStatii, assignedToParam, sortBy, desc, 1)));
add(new BookmarkablePageLink<Void>("allTickets", TicketsPage.class, queryParameters(queryParam, milestoneParam, null, assignedToParam, sortBy, desc, 1)));
// by status
List<Status> statii = new ArrayList<Status>(Arrays.asList(Status.values()));
statii.remove(Status.Closed);
ListDataProvider<Status> resolutionsDp = new ListDataProvider<Status>(statii);
DataView<Status> statiiLinks = new DataView<Status>("statii", resolutionsDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<Status> item) {
final Status status = item.getModelObject();
PageParameters p = queryParameters(queryParam, milestoneParam, new String [] { status.name().toLowerCase() }, assignedToParam, sortBy, desc, 1);
String css = getStatusClass(status);
item.add(new LinkPanel("statusLink", css, status.toString(), TicketsPage.class, p).setRenderBodyOnly(true));
}
};
add(statiiLinks);
// responsible filter
List<TicketResponsible> responsibles = new ArrayList<TicketResponsible>();
for (RegistrantAccessPermission perm : app().repositories().getUserAccessPermissions(getRepositoryModel())) {
if (perm.permission.atLeast(AccessPermission.PUSH)) {
UserModel u = app().users().getUserModel(perm.registrant);
responsibles.add(new TicketResponsible(u));
}
}
Collections.sort(responsibles);
responsibles.add(0, any);
TicketResponsible currentResponsible = null;
for (TicketResponsible u : responsibles) {
if (u.username.equals(assignedToParam)) {
currentResponsible = u;
break;
}
}
add(new Label("currentResponsible", currentResponsible == null ? "" : currentResponsible.displayname));
ListDataProvider<TicketResponsible> responsibleDp = new ListDataProvider<TicketResponsible>(responsibles);
DataView<TicketResponsible> responsibleMenu = new DataView<TicketResponsible>("responsible", responsibleDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<TicketResponsible> item) {
final TicketResponsible u = item.getModelObject();
PageParameters params = queryParameters(queryParam, milestoneParam, statiiParam, u.username, sortBy, desc, 1);
item.add(new LinkPanel("responsibleLink", null, u.displayname, TicketsPage.class, params).setRenderBodyOnly(true));
}
};
add(responsibleMenu);
PageParameters resetResponsibleParams = queryParameters(queryParam, milestoneParam, statiiParam, null, sortBy, desc, 1);
add(new BookmarkablePageLink<Void>("resetResponsible", TicketsPage.class, resetResponsibleParams));
List<TicketSort> sortChoices = new ArrayList<TicketSort>();
sortChoices.add(new TicketSort(getString("gb.sortNewest"), Lucene.created.name(), true));
sortChoices.add(new TicketSort(getString("gb.sortOldest"), Lucene.created.name(), false));
sortChoices.add(new TicketSort(getString("gb.sortMostRecentlyUpdated"), Lucene.updated.name(), true));
sortChoices.add(new TicketSort(getString("gb.sortLeastRecentlyUpdated"), Lucene.updated.name(), false));
sortChoices.add(new TicketSort(getString("gb.sortMostComments"), Lucene.comments.name(), true));
sortChoices.add(new TicketSort(getString("gb.sortLeastComments"), Lucene.comments.name(), false));
sortChoices.add(new TicketSort(getString("gb.sortMostPatchsetRevisions"), Lucene.patchsets.name(), true));
sortChoices.add(new TicketSort(getString("gb.sortLeastPatchsetRevisions"), Lucene.patchsets.name(), false));
sortChoices.add(new TicketSort(getString("gb.sortMostVotes"), Lucene.votes.name(), true));
sortChoices.add(new TicketSort(getString("gb.sortLeastVotes"), Lucene.votes.name(), false));
TicketSort currentSort = sortChoices.get(0);
for (TicketSort ts : sortChoices) {
if (ts.sortBy.equals(sortBy) && desc == ts.desc) {
currentSort = ts;
break;
}
}
add(new Label("currentSort", currentSort.name));
ListDataProvider<TicketSort> sortChoicesDp = new ListDataProvider<TicketSort>(sortChoices);
DataView<TicketSort> sortMenu = new DataView<TicketSort>("sort", sortChoicesDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<TicketSort> item) {
final TicketSort ts = item.getModelObject();
PageParameters params = queryParameters(queryParam, milestoneParam, statiiParam, assignedToParam, ts.sortBy, ts.desc, 1);
item.add(new LinkPanel("sortLink", null, ts.name, TicketsPage.class, params).setRenderBodyOnly(true));
}
};
add(sortMenu);
// paging links
buildPager(queryParam, milestoneParam, statiiParam, assignedToParam, sortBy, desc, page, pageSize, results.size(), totalResults);
ListDataProvider<QueryResult> resultsDataProvider = new ListDataProvider<QueryResult>(results);
DataView<QueryResult> ticketsView = new DataView<QueryResult>("ticket", resultsDataProvider) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<QueryResult> item) {
final QueryResult ticket = item.getModelObject();
item.add(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, newTicketParameter(ticket)));
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) {
String content = bugtraqProcessor().processPlainCommitMessage(getRepository(), repositoryName, labelItem.getModelObject());
Label label = new Label("label", content);
label.setEscapeModelStrings(false);
TicketLabel tLabel = app().tickets().getLabel(getRepositoryModel(), labelItem.getModelObject());
String background = MessageFormat.format("background-color:{0};", tLabel.color);
label.add(new SimpleAttributeModifier("style", background));
labelItem.add(label);
}
};
item.add(labelsView);