// set stateless page preference
setStatelessHint(true);
any = new TicketResponsible(getString("gb.any"), "[* TO *]", null);
UserModel user = GitBlitWebSession.get().getUser();
boolean isAuthenticated = user != null && user.isAuthenticated;
final String [] statiiParam = params.getStringArray(Lucene.status.name());
final String assignedToParam = params.getString(Lucene.responsible.name(), null);
final String milestoneParam = params.getString(Lucene.milestone.name(), null);
final String queryParam = params.getString("q", null);
final String searchParam = params.getString("s", null);
final String sortBy = Lucene.fromString(params.getString("sort", Lucene.created.name())).name();
final boolean desc = !"asc".equals(params.getString("direction", "desc"));
// add search form
TicketSearchForm searchForm = new TicketSearchForm("ticketSearchForm", repositoryName, searchParam);
add(searchForm);
searchForm.setTranslatedAttributes();
final String activeQuery;
if (!StringUtils.isEmpty(searchParam)) {
activeQuery = searchParam;
} else if (StringUtils.isEmpty(queryParam)) {
activeQuery = "";
} else {
activeQuery = queryParam;
}
// build Lucene query from defaults and request parameters
QueryBuilder qb = new QueryBuilder(queryParam);
if (!qb.containsField(Lucene.rid.name())) {
// specify the repository
qb.and(Lucene.rid.matches(getRepositoryModel().getRID()));
}
if (!qb.containsField(Lucene.responsible.name())) {
// specify the responsible
qb.and(Lucene.responsible.matches(assignedToParam));
}
if (!qb.containsField(Lucene.milestone.name())) {
// specify the milestone
qb.and(Lucene.milestone.matches(milestoneParam));
}
if (!qb.containsField(Lucene.status.name()) && !ArrayUtils.isEmpty(statiiParam)) {
// specify the states
boolean not = false;
QueryBuilder q = new QueryBuilder();
for (String state : statiiParam) {
if (state.charAt(0) == '!') {
not = true;
q.and(Lucene.status.doesNotMatch(state.substring(1)));
} else {
q.or(Lucene.status.matches(state));
}
}
if (not) {
qb.and(q.toString());
} else {
qb.and(q.toSubquery().toString());
}
}
final String luceneQuery = qb.build();
// open milestones
List<TicketMilestone> milestones = app().tickets().getMilestones(getRepositoryModel(), Status.Open);
TicketMilestone currentMilestone = null;
if (!StringUtils.isEmpty(milestoneParam)) {
for (TicketMilestone tm : milestones) {
if (tm.name.equals(milestoneParam)) {
// get the milestone (queries the index)
currentMilestone = app().tickets().getMilestone(getRepositoryModel(), milestoneParam);
break;
}
}
if (currentMilestone == null) {
// milestone not found, create a temporary one
currentMilestone = new TicketMilestone(milestoneParam);
String q = QueryBuilder.q(Lucene.rid.matches(getRepositoryModel().getRID())).and(Lucene.milestone.matches(milestoneParam)).build();
currentMilestone.tickets = app().tickets().queryFor(q, 1, 0, Lucene.number.name(), true);
milestones.add(currentMilestone);
}
}
Fragment milestonePanel;
if (currentMilestone == null) {
milestonePanel = new Fragment("milestonePanel", "noMilestoneFragment", this);
add(milestonePanel);
} else {
milestonePanel = new Fragment("milestonePanel", "milestoneProgressFragment", this);
milestonePanel.add(new Label("currentMilestone", currentMilestone.name));
if (currentMilestone.due == null) {
milestonePanel.add(new Label("currentDueDate", getString("gb.notSpecified")));
} else {
milestonePanel.add(WicketUtils.createDateLabel("currentDueDate", currentMilestone.due, GitBlitWebSession
.get().getTimezone(), getTimeUtils(), false));
}
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, openStatii, null, sortBy, desc, 1)));
milestonePanel.add(new LinkPanel("closedTickets", null,
MessageFormat.format(getString("gb.nClosedTickets"), currentMilestone.getClosedTickets()),
TicketsPage.class,
queryParameters(null, currentMilestone.name, 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,
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, 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);
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);