diff options
author | James Moger <james.moger@gitblit.com> | 2014-04-25 23:52:30 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-05-01 14:27:28 -0400 |
commit | ce048e750f7ae986dddfc8ab9b57750114d2b7b9 (patch) | |
tree | 05c085d9fdfaf00109a31fd98ef12f41012b2357 /src/main/java/com/gitblit/wicket/pages | |
parent | 16ef06d210bec7dd5b44d82f70d9f7bb9e4dbf6f (diff) | |
download | gitblit-ce048e750f7ae986dddfc8ab9b57750114d2b7b9.tar.gz gitblit-ce048e750f7ae986dddfc8ab9b57750114d2b7b9.zip |
Create and update milestone pages with rename support
Diffstat (limited to 'src/main/java/com/gitblit/wicket/pages')
6 files changed, 388 insertions, 2 deletions
diff --git a/src/main/java/com/gitblit/wicket/pages/EditMilestonePage.html b/src/main/java/com/gitblit/wicket/pages/EditMilestonePage.html new file mode 100644 index 00000000..66b47848 --- /dev/null +++ b/src/main/java/com/gitblit/wicket/pages/EditMilestonePage.html @@ -0,0 +1,38 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"
+ xml:lang="en"
+ lang="en">
+
+<wicket:extend>
+<body onload="document.getElementById('name').focus();">
+
+<div class="container">
+ <!-- page header -->
+ <div class="title" style="font-size: 22px; color: rgb(0, 32, 96);padding: 3px 0px 7px;">
+ <span class="project"><wicket:message key="gb.editMilestone"></wicket:message></span>
+ </div>
+
+ <form style="padding-top:5px;" wicket:id="editForm">
+ <div class="row">
+ <div class="span12">
+ <!-- Edit Milestone Table -->
+ <table class="ticket">
+ <tr><th><wicket:message key="gb.milestone"></wicket:message></th><td class="edit"><input class="input-large" type="text" wicket:id="name" id="name"></input></td></tr>
+ <tr><th><wicket:message key="gb.due"></wicket:message></th><td class="edit"><input class="input-large" type="text" wicket:id="due"></input></td></tr>
+ <tr><th><wicket:message key="gb.status"></wicket:message><span style="color:red;">*</span></th><td class="edit"><select class="input-large" wicket:id="status"></select></td></tr>
+ </table>
+ </div>
+ </div>
+
+ <div class="row">
+ <div class="span12">
+ <div class="form-actions"><input class="btn btn-appmenu" type="submit" value="Save" wicket:message="value:gb.save" wicket:id="save" /> <input class="btn" type="submit" value="Cancel" wicket:message="value:gb.cancel" wicket:id="cancel" /></div>
+ </div>
+ </div>
+ </form>
+</div>
+</body>
+
+</wicket:extend>
+</html>
\ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/pages/EditMilestonePage.java b/src/main/java/com/gitblit/wicket/pages/EditMilestonePage.java new file mode 100644 index 00000000..44077884 --- /dev/null +++ b/src/main/java/com/gitblit/wicket/pages/EditMilestonePage.java @@ -0,0 +1,166 @@ +/*
+ * Copyright 2014 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.wicket.pages;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.wicket.PageParameters;
+import org.apache.wicket.RestartResponseException;
+import org.apache.wicket.extensions.markup.html.form.DateTextField;
+import org.apache.wicket.markup.html.form.Button;
+import org.apache.wicket.markup.html.form.DropDownChoice;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.parboiled.common.StringUtils;
+
+import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.TicketModel;
+import com.gitblit.models.TicketModel.Status;
+import com.gitblit.models.UserModel;
+import com.gitblit.tickets.TicketMilestone;
+import com.gitblit.wicket.GitBlitWebSession;
+import com.gitblit.wicket.WicketUtils;
+
+/**
+ * Page for creating a new milestone.
+ *
+ * @author James Moger
+ *
+ */
+public class EditMilestonePage extends RepositoryPage {
+
+ private final String oldName;
+
+ private IModel<String> nameModel;
+
+ private IModel<Date> dueModel;
+
+ private IModel<Status> statusModel;
+
+ private IModel<Boolean> notificationModel;
+
+ public EditMilestonePage(PageParameters params) {
+ super(params);
+
+ RepositoryModel model = getRepositoryModel();
+ if (!app().tickets().isAcceptingTicketUpdates(model)) {
+ // ticket service is read-only
+ throw new RestartResponseException(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));
+ }
+
+ UserModel currentUser = GitBlitWebSession.get().getUser();
+ if (currentUser == null) {
+ currentUser = UserModel.ANONYMOUS;
+ }
+
+ if (!currentUser.isAuthenticated || !currentUser.canAdmin(model)) {
+ // administration prohibited
+ throw new RestartResponseException(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));
+ }
+
+ oldName = WicketUtils.getObject(params);
+ if (StringUtils.isEmpty(oldName)) {
+ // milestone not specified
+ throw new RestartResponseException(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));
+ }
+
+ TicketMilestone tm = app().tickets().getMilestone(getRepositoryModel(), oldName);
+ if (tm == null) {
+ // milestone does not exist
+ throw new RestartResponseException(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));
+ }
+
+ setStatelessHint(false);
+ setOutputMarkupId(true);
+
+ Form<Void> form = new Form<Void>("editForm") {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void onSubmit() {
+
+ String name = nameModel.getObject();
+ if (StringUtils.isEmpty(name)) {
+ return;
+ }
+
+ Date due = dueModel.getObject();
+ Status status = statusModel.getObject();
+ boolean rename = !name.equals(oldName);
+ boolean notify = notificationModel.getObject();
+
+ UserModel currentUser = GitBlitWebSession.get().getUser();
+ String createdBy = currentUser.username;
+
+ TicketMilestone tm = app().tickets().getMilestone(getRepositoryModel(), oldName);
+ tm.setName(name);
+ tm.setDue(due);
+ tm.status = status;
+
+ boolean success = true;
+ if (rename) {
+ success = app().tickets().renameMilestone(getRepositoryModel(), oldName, name, createdBy, notify);
+ }
+
+ if (success && app().tickets().updateMilestone(getRepositoryModel(), tm, createdBy)) {
+ setResponsePage(TicketsPage.class, WicketUtils.newRepositoryParameter(getRepositoryModel().name));
+ } else {
+ // TODO error
+ }
+ }
+ };
+ add(form);
+
+ nameModel = Model.of(tm.name);
+ dueModel = Model.of(tm.due);
+ statusModel = Model.of(tm.status);
+ notificationModel = Model.of(true);
+
+ form.add(new TextField<String>("name", nameModel));
+ form.add(new DateTextField("due", dueModel, "yyyy-MM-dd"));
+
+ List<Status> statusChoices = Arrays.asList(Status.Open, Status.Closed);
+ form.add(new DropDownChoice<TicketModel.Status>("status", statusModel, statusChoices));
+
+ form.add(new Button("save"));
+ Button cancel = new Button("cancel") {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void onSubmit() {
+ setResponsePage(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));
+ }
+ };
+ cancel.setDefaultFormProcessing(false);
+ form.add(cancel);
+
+ }
+
+ @Override
+ protected String getPageName() {
+ return getString("gb.editMilestone");
+ }
+
+ @Override
+ protected Class<? extends BasePage> getRepoNavPageClass() {
+ return TicketsPage.class;
+ }
+}
diff --git a/src/main/java/com/gitblit/wicket/pages/NewMilestonePage.html b/src/main/java/com/gitblit/wicket/pages/NewMilestonePage.html new file mode 100644 index 00000000..1b7e11ae --- /dev/null +++ b/src/main/java/com/gitblit/wicket/pages/NewMilestonePage.html @@ -0,0 +1,37 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"
+ xml:lang="en"
+ lang="en">
+
+<wicket:extend>
+<body onload="document.getElementById('name').focus();">
+
+<div class="container">
+ <!-- page header -->
+ <div class="title" style="font-size: 22px; color: rgb(0, 32, 96);padding: 3px 0px 7px;">
+ <span class="project"><wicket:message key="gb.newMilestone"></wicket:message></span>
+ </div>
+
+ <form style="padding-top:5px;" wicket:id="editForm">
+ <div class="row">
+ <div class="span12">
+ <!-- New Milestone Table -->
+ <table class="ticket">
+ <tr><th><wicket:message key="gb.milestone"></wicket:message></th><td class="edit"><input class="input-large" type="text" wicket:id="name" id="name"></input></td></tr>
+ <tr><th><wicket:message key="gb.due"></wicket:message></th><td class="edit"><input class="input-large" type="text" wicket:id="due"></input></td></tr>
+ </table>
+ </div>
+ </div>
+
+ <div class="row">
+ <div class="span12">
+ <div class="form-actions"><input class="btn btn-appmenu" type="submit" value="Create" wicket:message="value:gb.create" wicket:id="create" /> <input class="btn" type="submit" value="Cancel" wicket:message="value:gb.cancel" wicket:id="cancel" /></div>
+ </div>
+ </div>
+ </form>
+</div>
+</body>
+
+</wicket:extend>
+</html>
\ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/pages/NewMilestonePage.java b/src/main/java/com/gitblit/wicket/pages/NewMilestonePage.java new file mode 100644 index 00000000..2c95f018 --- /dev/null +++ b/src/main/java/com/gitblit/wicket/pages/NewMilestonePage.java @@ -0,0 +1,123 @@ +/*
+ * Copyright 2014 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.wicket.pages;
+
+import java.util.Date;
+
+import org.apache.wicket.PageParameters;
+import org.apache.wicket.RestartResponseException;
+import org.apache.wicket.extensions.markup.html.form.DateTextField;
+import org.apache.wicket.markup.html.form.Button;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+
+import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.UserModel;
+import com.gitblit.tickets.TicketMilestone;
+import com.gitblit.wicket.GitBlitWebSession;
+import com.gitblit.wicket.WicketUtils;
+
+/**
+ * Page for creating a new milestone.
+ *
+ * @author James Moger
+ *
+ */
+public class NewMilestonePage extends RepositoryPage {
+
+ private IModel<String> nameModel;
+
+ private IModel<Date> dueModel;
+
+ public NewMilestonePage(PageParameters params) {
+ super(params);
+
+ RepositoryModel model = getRepositoryModel();
+ if (!app().tickets().isAcceptingTicketUpdates(model)) {
+ // ticket service is read-only
+ throw new RestartResponseException(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));
+ }
+
+ UserModel currentUser = GitBlitWebSession.get().getUser();
+ if (currentUser == null) {
+ currentUser = UserModel.ANONYMOUS;
+ }
+
+ if (!currentUser.isAuthenticated || !currentUser.canAdmin(model)) {
+ // administration prohibited
+ throw new RestartResponseException(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));
+ }
+
+ setStatelessHint(false);
+ setOutputMarkupId(true);
+
+ Form<Void> form = new Form<Void>("editForm") {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void onSubmit() {
+
+ String name = nameModel.getObject();
+ Date due = dueModel.getObject();
+
+ UserModel currentUser = GitBlitWebSession.get().getUser();
+ String createdBy = currentUser.username;
+
+ TicketMilestone milestone = app().tickets().createMilestone(getRepositoryModel(), name, createdBy);
+ if (milestone != null) {
+ milestone.due = due;
+ app().tickets().updateMilestone(getRepositoryModel(), milestone, createdBy);
+ throw new RestartResponseException(TicketsPage.class, WicketUtils.newRepositoryParameter(getRepositoryModel().name));
+ } else {
+ // TODO error
+ }
+ }
+ };
+ add(form);
+
+ nameModel = Model.of("");
+ dueModel = Model.of(new Date());
+
+ form.add(new TextField<String>("name", nameModel));
+ form.add(new DateTextField("due", dueModel, "yyyy-MM-dd"));
+
+ form.add(new Button("create"));
+ Button cancel = new Button("cancel") {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void onSubmit() {
+ setResponsePage(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));
+ }
+ };
+ cancel.setDefaultFormProcessing(false);
+ form.add(cancel);
+
+ }
+
+ @Override
+ protected String getPageName() {
+ return getString("gb.newMilestone");
+ }
+
+ @Override
+ protected Class<? extends BasePage> getRepoNavPageClass() {
+ return TicketsPage.class;
+ }
+}
diff --git a/src/main/java/com/gitblit/wicket/pages/TicketsPage.html b/src/main/java/com/gitblit/wicket/pages/TicketsPage.html index 7d13852b..e144bea1 100644 --- a/src/main/java/com/gitblit/wicket/pages/TicketsPage.html +++ b/src/main/java/com/gitblit/wicket/pages/TicketsPage.html @@ -139,9 +139,12 @@ </div>
<div class="tab-pane" id="milestones">
<div class="row">
+ <span class="span12" style="padding-bottom:10px;" wicket:id="newMilestone"></span>
+ </div>
+ <div class="row">
<div class="span9" wicket:id="milestoneList" style="padding-bottom: 10px;">
<h3><span wicket:id="milestoneName"></span> <small><span wicket:id="milestoneState"></span></small></h3>
- <i style="color:#888;"class="fa fa-calendar"></i> <span wicket:id="milestoneDue"></span>
+ <i style="color:#888;"class="fa fa-calendar"></i> <span wicket:id="milestoneDue"></span> <span wicket:id="editMilestone"></span>
</div>
</div>
</div>
diff --git a/src/main/java/com/gitblit/wicket/pages/TicketsPage.java b/src/main/java/com/gitblit/wicket/pages/TicketsPage.java index ca509e28..984b3754 100644 --- a/src/main/java/com/gitblit/wicket/pages/TicketsPage.java +++ b/src/main/java/com/gitblit/wicket/pages/TicketsPage.java @@ -42,6 +42,7 @@ import com.gitblit.Constants; import com.gitblit.Constants.AccessPermission;
import com.gitblit.Keys;
import com.gitblit.models.RegistrantAccessPermission;
+import com.gitblit.models.RepositoryModel;
import com.gitblit.models.TicketModel;
import com.gitblit.models.TicketModel.Status;
import com.gitblit.models.UserModel;
@@ -646,7 +647,19 @@ public class TicketsPage extends TicketBasePage { };
add(ticketsView);
- List<TicketMilestone> allMilestones = app().tickets().getMilestones(getRepositoryModel());
+ // 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));
+ }
+
+ // milestones list
+ List<TicketMilestone> allMilestones = app().tickets().getMilestones(repositoryModel);
ListDataProvider<TicketMilestone> allMilestonesDp = new ListDataProvider<TicketMilestone>(allMilestones);
DataView<TicketMilestone> milestonesList = new DataView<TicketMilestone>("milestoneList", allMilestonesDp) {
private static final long serialVersionUID = 1L;
@@ -675,6 +688,12 @@ public class TicketsPage extends TicketBasePage { } else {
item.add(WicketUtils.createDatestampLabel("milestoneDue", tm.due, getTimeZone(), getTimeUtils()));
}
+ if (acceptingUpdates) {
+ item.add(new LinkPanel("editMilestone", null, getString("gb.edit"), EditMilestonePage.class,
+ WicketUtils.newObjectParameter(repositoryName, tm.name)));
+ } else {
+ item.add(new Label("editMilestone").setVisible(false));
+ }
}
};
add(milestonesList);
|