Skip to content

Commit

Permalink
Delegate closed ticket changes to the Edit Ticket page
Browse files Browse the repository at this point in the history
  • Loading branch information
gitblit committed Mar 5, 2014
1 parent 0353c1f commit 85775ac
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 138 deletions.
15 changes: 13 additions & 2 deletions src/main/java/com/gitblit/wicket/pages/TicketPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ <h4><wicket:message key="gb.ptSimplifiedMerge"></wicket:message></h4>
</wicket:fragment>


<!-- TICKET CONTROLS FRAGMENT -->
<wicket:fragment wicket:id="controlsFragment">
<!-- OPEN TICKET CONTROLS FRAGMENT -->
<wicket:fragment wicket:id="openControlsFragment">
<div class="hidden-phone hidden-tablet">
<div class="btn-group" style="display:inline-block;">
<a class="btn btn-small dropdown-toggle" data-toggle="dropdown" href="#"><wicket:message key="gb.status"></wicket:message> <span class="caret"></span></a>
Expand Down Expand Up @@ -167,6 +167,17 @@ <h4><wicket:message key="gb.ptSimplifiedMerge"></wicket:message></h4>
</wicket:fragment>


<!-- CLOSED TICKET CONTROLS FRAGMENT -->
<wicket:fragment wicket:id="closedControlsFragment">
<div class="hidden-phone hidden-tablet">

<div class="btn-group" style="display:inline-block;">
<a class="btn btn-small" wicket:id="editLink"></a>
</div>
</div>
</wicket:fragment>


<!-- STATUS INDICATOR FRAGMENT -->
<wicket:fragment wicket:id="ticketStatusFragment">
<div style="font-size:2.5em;padding-bottom: 5px;">
Expand Down
283 changes: 147 additions & 136 deletions src/main/java/com/gitblit/wicket/pages/TicketPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,159 +328,170 @@ public void populateItem(final Item<String> item) {
* UPDATE FORM (DISCUSSION TAB)
*/
if (isAuthenticated && app().tickets().isAcceptingTicketUpdates(repository)) {
Fragment controls = new Fragment("controls", "controlsFragment", this);


/*
* STATUS
*/
List<Status> choices = new ArrayList<Status>();
if (ticket.isClosed()) {
// re-open
choices.addAll(Arrays.asList(TicketModel.Status.Open));
} else 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);
if (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;
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()) {
@Override
public void populateItem(final Item<Status> item) {
SimpleAjaxLink<Status> link = new SimpleAjaxLink<Status>("link", item.getModel()) {

private static final long serialVersionUID = 1L;
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);
@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());
}
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);
};
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);
}
}
};
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);
}
}
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));
for (String username : userlist) {
UserModel u = app().users().getUserModel(username);
if (u != null) {
responsibles.add(new TicketResponsible(u));
}
}
}
Collections.sort(responsibles);
responsibles.add(new TicketResponsible(ESC_NIL, "", ""));
ListDataProvider<TicketResponsible> responsibleDp = new ListDataProvider<TicketResponsible>(responsibles);
DataView<TicketResponsible> responsibleView = new DataView<TicketResponsible>("newResponsible", responsibleDp) {
private static final long serialVersionUID = 1L;

@Override
public void populateItem(final Item<TicketResponsible> item) {
SimpleAjaxLink<TicketResponsible> link = new SimpleAjaxLink<TicketResponsible>("link", item.getModel()) {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
TicketResponsible responsible = getModel().getObject();
Change change = new Change(user.username);
change.setField(Field.responsible, responsible.username);
if (!StringUtils.isEmpty(responsible.username)) {
if (!ticket.isWatching(responsible.username)) {
change.watch(responsible.username);
Collections.sort(responsibles);
responsibles.add(new TicketResponsible(ESC_NIL, "", ""));
ListDataProvider<TicketResponsible> responsibleDp = new ListDataProvider<TicketResponsible>(responsibles);
DataView<TicketResponsible> responsibleView = new DataView<TicketResponsible>("newResponsible", responsibleDp) {
private static final long serialVersionUID = 1L;

@Override
public void populateItem(final Item<TicketResponsible> item) {
SimpleAjaxLink<TicketResponsible> link = new SimpleAjaxLink<TicketResponsible>("link", item.getModel()) {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
TicketResponsible responsible = getModel().getObject();
Change change = new Change(user.username);
change.setField(Field.responsible, responsible.username);
if (!StringUtils.isEmpty(responsible.username)) {
if (!ticket.isWatching(responsible.username)) {
change.watch(responsible.username);
}
}
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());
}
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());
};
item.add(link);
}
};
controls.add(responsibleView);

/*
* MILESTONE LIST
*/
List<TicketMilestone> milestones = app().tickets().getMilestones(repository, Status.Open);
if (!StringUtils.isEmpty(ticket.milestone)) {
for (TicketMilestone milestone : milestones) {
if (milestone.name.equals(ticket.milestone)) {
milestones.remove(milestone);
break;
}
};
item.add(link);
}
};
controls.add(responsibleView);

/*
* MILESTONE LIST
*/
List<TicketMilestone> milestones = app().tickets().getMilestones(repository, Status.Open);
if (!StringUtils.isEmpty(ticket.milestone)) {
for (TicketMilestone milestone : milestones) {
if (milestone.name.equals(ticket.milestone)) {
milestones.remove(milestone);
break;
}
}
}
milestones.add(new TicketMilestone(ESC_NIL));
ListDataProvider<TicketMilestone> milestoneDp = new ListDataProvider<TicketMilestone>(milestones);
DataView<TicketMilestone> milestoneView = new DataView<TicketMilestone>("newMilestone", milestoneDp) {
private static final long serialVersionUID = 1L;

@Override
public void populateItem(final Item<TicketMilestone> item) {
SimpleAjaxLink<TicketMilestone> link = new SimpleAjaxLink<TicketMilestone>("link", item.getModel()) {
milestones.add(new TicketMilestone(ESC_NIL));
ListDataProvider<TicketMilestone> milestoneDp = new ListDataProvider<TicketMilestone>(milestones);
DataView<TicketMilestone> milestoneView = new DataView<TicketMilestone>("newMilestone", milestoneDp) {
private static final long serialVersionUID = 1L;

@Override
public void populateItem(final Item<TicketMilestone> item) {
SimpleAjaxLink<TicketMilestone> link = new SimpleAjaxLink<TicketMilestone>("link", item.getModel()) {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
TicketMilestone milestone = getModel().getObject();
Change change = new Change(user.username);
if (NIL.equals(milestone.name) || ESC_NIL.equals(milestone.name)) {
change.setField(Field.milestone, "");
} else {
change.setField(Field.milestone, milestone.name);
}
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());
}
};
item.add(link);
}
};
controls.add(milestoneView);

private static final long serialVersionUID = 1L;
String editHref = urlFor(EditTicketPage.class, params).toString();
controls.add(new ExternalLink("editLink", editHref, getString("gb.edit")));

@Override
public void onClick(AjaxRequestTarget target) {
TicketMilestone milestone = getModel().getObject();
Change change = new Change(user.username);
if (NIL.equals(milestone.name) || ESC_NIL.equals(milestone.name)) {
change.setField(Field.milestone, "");
} else {
change.setField(Field.milestone, milestone.name);
}
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());
}
};
item.add(link);
}
};
controls.add(milestoneView);
add(controls);
} else {
/*
* CLOSED TICKET
*/
Fragment controls = new Fragment("controls", "closedControlsFragment", this);

String editHref = urlFor(EditTicketPage.class, params).toString();
controls.add(new ExternalLink("editLink", editHref, getString("gb.edit")));
String editHref = urlFor(EditTicketPage.class, params).toString();
controls.add(new ExternalLink("editLink", editHref, getString("gb.edit")));

add(controls);
add(controls);
}
} else {
add(new Label("controls").setVisible(false));
}
Expand Down

0 comments on commit 85775ac

Please sign in to comment.