}
Label label = new Label("progress");
WicketUtils.setCssStyle(label, "width:" + currentMilestone.getProgress() + "%;");
milestonePanel.add(label);
milestonePanel.add(new LinkPanel("openTickets", null,
MessageFormat.format(getString("gb.nOpenTickets"), currentMilestone.getOpenTickets()),
TicketsPage.class,
queryParameters(null, currentMilestone.name, TicketsUI.openStatii, null, sortBy, desc, 1)));
milestonePanel.add(new LinkPanel("closedTickets", null,
MessageFormat.format(getString("gb.nClosedTickets"), currentMilestone.getClosedTickets()),
TicketsPage.class,
queryParameters(null, currentMilestone.name, TicketsUI.closedStatii, null, sortBy, desc, 1)));
milestonePanel.add(new Label("totalTickets", MessageFormat.format(getString("gb.nTotalTickets"), currentMilestone.getTotalTickets())));
add(milestonePanel);
}
Fragment milestoneDropdown = new Fragment("milestoneDropdown", "milestoneDropdownFragment", this);
PageParameters resetMilestone = queryParameters(queryParam, null, statiiParam, assignedToParam, sortBy, desc, 1);
milestoneDropdown.add(new BookmarkablePageLink<Void>("resetMilestone", TicketsPage.class, resetMilestone));
ListDataProvider<TicketMilestone> milestonesDp = new ListDataProvider<TicketMilestone>(milestones);
DataView<TicketMilestone> milestonesMenu = new DataView<TicketMilestone>("milestone", milestonesDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<TicketMilestone> item) {
final TicketMilestone tm = item.getModelObject();
PageParameters params = queryParameters(queryParam, tm.name, statiiParam, assignedToParam, sortBy, desc, 1);
item.add(new LinkPanel("milestoneLink", null, tm.name, TicketsPage.class, params).setRenderBodyOnly(true));
}
};
milestoneDropdown.add(milestonesMenu);
milestonePanel.add(milestoneDropdown);
// search or query tickets
int page = Math.max(1, WicketUtils.getPage(params));
int pageSize = app().settings().getInteger(Keys.tickets.perPage, 25);
List<QueryResult> results;
if (StringUtils.isEmpty(searchParam)) {
results = app().tickets().queryFor(luceneQuery, page, pageSize, sortBy, desc);
} else {
results = app().tickets().searchFor(getRepositoryModel(), searchParam, page, pageSize);
}
int totalResults = results.size() == 0 ? 0 : results.get(0).totalResults;
// standard queries
add(new BookmarkablePageLink<Void>("changesQuery", TicketsPage.class,
queryParameters(
Lucene.type.matches(TicketModel.Type.Proposal.name()),
milestoneParam,
statiiParam,
assignedToParam,
sortBy,
desc,
1)));
add(new BookmarkablePageLink<Void>("bugsQuery", TicketsPage.class,
queryParameters(
Lucene.type.matches(TicketModel.Type.Bug.name()),
milestoneParam,
statiiParam,
assignedToParam,
sortBy,
desc,
1)));
add(new BookmarkablePageLink<Void>("enhancementsQuery", TicketsPage.class,
queryParameters(
Lucene.type.matches(TicketModel.Type.Enhancement.name()),
milestoneParam,
statiiParam,
assignedToParam,
sortBy,
desc,
1)));
add(new BookmarkablePageLink<Void>("tasksQuery", TicketsPage.class,
queryParameters(
Lucene.type.matches(TicketModel.Type.Task.name()),
milestoneParam,
statiiParam,
assignedToParam,
sortBy,
desc,
1)));
add(new BookmarkablePageLink<Void>("questionsQuery", TicketsPage.class,
queryParameters(
Lucene.type.matches(TicketModel.Type.Question.name()),
milestoneParam,
statiiParam,
assignedToParam,
sortBy,
desc,
1)));
add(new BookmarkablePageLink<Void>("resetQuery", TicketsPage.class,
queryParameters(
null,
milestoneParam,
TicketsUI.openStatii,
null,
null,
true,
1)));
if (isAuthenticated) {
add(new Label("userDivider"));
add(new BookmarkablePageLink<Void>("createdQuery", TicketsPage.class,
queryParameters(
Lucene.createdby.matches(user.username),
milestoneParam,
statiiParam,
assignedToParam,
sortBy,
desc,
1)));
add(new BookmarkablePageLink<Void>("watchedQuery", TicketsPage.class,
queryParameters(
Lucene.watchedby.matches(user.username),
milestoneParam,
statiiParam,
assignedToParam,
sortBy,
desc,
1)));
add(new BookmarkablePageLink<Void>("mentionsQuery", TicketsPage.class,
queryParameters(
Lucene.mentions.matches(user.username),
milestoneParam,
statiiParam,
assignedToParam,
sortBy,
desc,
1)));
} else {
add(new Label("userDivider").setVisible(false));
add(new Label("createdQuery").setVisible(false));
add(new Label("watchedQuery").setVisible(false));
add(new Label("mentionsQuery").setVisible(false));
}
Set<TicketQuery> dynamicQueries = new TreeSet<TicketQuery>();
for (TicketLabel label : app().tickets().getLabels(getRepositoryModel())) {
String q = QueryBuilder.q(Lucene.labels.matches(label.name)).build();
dynamicQueries.add(new TicketQuery(label.name, q).color(label.color));
}
for (QueryResult ticket : results) {
if (!StringUtils.isEmpty(ticket.topic)) {
String q = QueryBuilder.q(Lucene.topic.matches(ticket.topic)).build();
dynamicQueries.add(new TicketQuery(ticket.topic, q));
}
if (!ArrayUtils.isEmpty(ticket.labels)) {
for (String label : ticket.labels) {
String q = QueryBuilder.q(Lucene.labels.matches(label)).build();
dynamicQueries.add(new TicketQuery(label, q));
}
}
}
if (dynamicQueries.size() == 0) {
add(new Label("dynamicQueries").setVisible(false));
} else {
Fragment fragment = new Fragment("dynamicQueries", "dynamicQueriesFragment", this);
ListDataProvider<TicketQuery> dynamicQueriesDp = new ListDataProvider<TicketQuery>(new ArrayList<TicketQuery>(dynamicQueries));
DataView<TicketQuery> dynamicQueriesList = new DataView<TicketQuery>("dynamicQuery", dynamicQueriesDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<TicketQuery> item) {
final TicketQuery tq = item.getModelObject();
Component swatch = new Label("swatch", " ").setEscapeModelStrings(false);
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, TicketsUI.openStatii, assignedToParam, sortBy, desc, 1)));
add(new BookmarkablePageLink<Void>("closedTickets", TicketsPage.class, queryParameters(queryParam, milestoneParam, TicketsUI.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 = TicketsUI.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);
add(new TicketListPanel("ticketList", results, false, false));
// new milestone link
RepositoryModel repositoryModel = getRepositoryModel();
final boolean acceptingUpdates = app().tickets().isAcceptingTicketUpdates(repositoryModel)
&& user != null && user.canAdmin(getRepositoryModel());
if (acceptingUpdates) {
add(new LinkPanel("newMilestone", null, getString("gb.newMilestone"),
NewMilestonePage.class, WicketUtils.newRepositoryParameter(repositoryName)));
} else {
add(new Label("newMilestone").setVisible(false));
}