]> source.dussan.org Git - gitblit.git/commitdiff
Allow milestone deletion within the edit milestone page
authorJames Moger <james.moger@gitblit.com>
Sat, 26 Apr 2014 17:51:39 +0000 (13:51 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 1 May 2014 18:27:28 +0000 (14:27 -0400)
src/main/java/com/gitblit/tickets/ITicketService.java
src/main/java/com/gitblit/tickets/QueryResult.java
src/main/java/com/gitblit/wicket/pages/EditMilestonePage.html
src/main/java/com/gitblit/wicket/pages/EditMilestonePage.java
src/main/java/com/gitblit/wicket/pages/NewMilestonePage.java

index e1a377a692b876d4190dfd1f3d26386e4c7f5eaf..cce805ed0e006a6c43f3ce12e16952752d5fdec0 100644 (file)
@@ -643,7 +643,7 @@ public abstract class ITicketService {
        public synchronized boolean renameMilestone(RepositoryModel repository, String oldName, String newName, String createdBy) {
                return renameMilestone(repository, oldName, newName, createdBy, true);
        }
-       
+
        /**
         * Renames a milestone.
         *
@@ -714,6 +714,7 @@ public abstract class ITicketService {
                }
                Repository db = null;
                try {
+                       TicketMilestone tm = getMilestone(repository, milestone);
                        db = repositoryManager.getRepository(repository.name);
                        StoredConfig config = db.getConfig();
                        config.unsetSection(MILESTONE, milestone);
@@ -721,6 +722,14 @@ public abstract class ITicketService {
 
                        milestonesCache.remove(repository.name);
 
+                       for (QueryResult qr : tm.tickets) {
+                               if (qr.isOpen()) {
+                                       // reset the milestone only for open tickets
+                                       Change change = new Change(createdBy);
+                                       change.setField(Field.milestone, "");
+                                       TicketModel ticket = updateTicket(repository, qr.number, change);
+                               }
+                       }
                        return true;
                } catch (IOException e) {
                        log.error("failed to delete milestone " + milestone + " in " + repository, e);
index 9f5d3a5521488a8e4d8864e06f245ef1b700e04f..7a2b1abe0fb139dda944d0e307544ee0215a9511 100644 (file)
@@ -74,6 +74,14 @@ public class QueryResult implements Serializable {
                return type != null && Type.Proposal == type;
        }
 
+       public boolean isOpen() {
+               return !status.isClosed();
+       }
+
+       public boolean isClosed() {
+               return status.isClosed();
+       }
+
        public boolean isMerged() {
                return Status.Merged == status && !StringUtils.isEmpty(mergeSha);
        }
index 66b4784882d8351e36bcb7c32d110c319cef37ce..31f76f1c50e9813aff37ff13d6461e8b2423e8ab 100644 (file)
@@ -27,7 +27,7 @@
 \r
        <div class="row">\r
        <div class="span12">\r
-               <div class="form-actions"><input class="btn btn-appmenu" type="submit" value="Save" wicket:message="value:gb.save" wicket:id="save" /> &nbsp; <input class="btn" type="submit" value="Cancel" wicket:message="value:gb.cancel" wicket:id="cancel" /></div>\r
+               <div class="form-actions"><input class="btn btn-appmenu" type="submit" value="Save" wicket:message="value:gb.save" wicket:id="save" /> &nbsp; <input class="btn" type="submit" value="Cancel" wicket:message="value:gb.cancel" wicket:id="cancel" /> &nbsp; <input class="btn btn-danger" type="submit" value="Delete" wicket:message="value:gb.delete" wicket:id="delete" /></div>\r
        </div>\r
        </div>\r
        </form>\r
index 44077884c68675bdf54fb9671d5e6a12e7a07a47..b92ba8baa031bdaa116ca1c0ff0271e4f76ff1fd 100644 (file)
@@ -28,13 +28,13 @@ import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.markup.html.form.TextField;\r
 import org.apache.wicket.model.IModel;\r
 import org.apache.wicket.model.Model;\r
-import org.parboiled.common.StringUtils;\r
 \r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.TicketModel;\r
 import com.gitblit.models.TicketModel.Status;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.tickets.TicketMilestone;\r
+import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.WicketUtils;\r
 \r
@@ -47,13 +47,13 @@ import com.gitblit.wicket.WicketUtils;
 public class EditMilestonePage extends RepositoryPage {\r
 \r
        private final String oldName;\r
-       \r
+\r
        private IModel<String> nameModel;\r
 \r
        private IModel<Date> dueModel;\r
-       \r
+\r
        private IModel<Status> statusModel;\r
-       \r
+\r
        private IModel<Boolean> notificationModel;\r
 \r
        public EditMilestonePage(PageParameters params) {\r
@@ -64,7 +64,7 @@ public class EditMilestonePage extends RepositoryPage {
                        // ticket service is read-only\r
                        throw new RestartResponseException(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));\r
                }\r
-               \r
+\r
                UserModel currentUser = GitBlitWebSession.get().getUser();\r
                if (currentUser == null) {\r
                        currentUser = UserModel.ANONYMOUS;\r
@@ -74,13 +74,13 @@ public class EditMilestonePage extends RepositoryPage {
                        // administration prohibited\r
                        throw new RestartResponseException(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));\r
                }\r
-               \r
+\r
                oldName = WicketUtils.getObject(params);\r
                if (StringUtils.isEmpty(oldName)) {\r
                        // milestone not specified\r
                        throw new RestartResponseException(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));\r
                }\r
-               \r
+\r
                TicketMilestone tm = app().tickets().getMilestone(getRepositoryModel(), oldName);\r
                if (tm == null) {\r
                        // milestone does not exist\r
@@ -96,30 +96,30 @@ public class EditMilestonePage extends RepositoryPage {
 \r
                        @Override\r
                        protected void onSubmit() {\r
-                               \r
+\r
                                String name = nameModel.getObject();\r
                                if (StringUtils.isEmpty(name)) {\r
                                        return;\r
                                }\r
-                               \r
+\r
                                Date due = dueModel.getObject();\r
                                Status status = statusModel.getObject();\r
                                boolean rename = !name.equals(oldName);\r
                                boolean notify = notificationModel.getObject();\r
-                               \r
+\r
                                UserModel currentUser = GitBlitWebSession.get().getUser();\r
                                String createdBy = currentUser.username;\r
-                               \r
+\r
                                TicketMilestone tm = app().tickets().getMilestone(getRepositoryModel(), oldName);\r
                                tm.setName(name);\r
                                tm.setDue(due);\r
                                tm.status = status;\r
-                               \r
+\r
                                boolean success = true;\r
                                if (rename) {\r
                                        success = app().tickets().renameMilestone(getRepositoryModel(), oldName, name, createdBy, notify);\r
                                }\r
-                               \r
+\r
                                if (success && app().tickets().updateMilestone(getRepositoryModel(), tm, createdBy)) {\r
                                        setResponsePage(TicketsPage.class, WicketUtils.newRepositoryParameter(getRepositoryModel().name));\r
                                } else {\r
@@ -133,7 +133,7 @@ public class EditMilestonePage extends RepositoryPage {
                dueModel = Model.of(tm.due);\r
                statusModel = Model.of(tm.status);\r
                notificationModel = Model.of(true);\r
-               \r
+\r
                form.add(new TextField<String>("name", nameModel));\r
                form.add(new DateTextField("due", dueModel, "yyyy-MM-dd"));\r
 \r
@@ -152,6 +152,23 @@ public class EditMilestonePage extends RepositoryPage {
                cancel.setDefaultFormProcessing(false);\r
                form.add(cancel);\r
 \r
+               Button delete = new Button("delete") {\r
+                       private static final long serialVersionUID = 1L;\r
+\r
+                       @Override\r
+                       public void onSubmit() {\r
+                               UserModel currentUser = GitBlitWebSession.get().getUser();\r
+                               String createdBy = currentUser.username;\r
+\r
+                               if (app().tickets().deleteMilestone(getRepositoryModel(), oldName, createdBy)) {\r
+                                       setResponsePage(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));\r
+                               } else {\r
+                                       // TODO error processing\r
+                               }\r
+                       }\r
+               };\r
+               delete.setDefaultFormProcessing(false);\r
+               form.add(delete);\r
        }\r
 \r
        @Override\r
index 2c95f0181b742a402db695749ad33ead504a3e42..4c3937869984cef62f612a6acbdb9dc6a52567a6 100644 (file)
@@ -29,6 +29,8 @@ import org.apache.wicket.model.Model;
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.tickets.TicketMilestone;\r
+import com.gitblit.utils.StringUtils;\r
+import com.gitblit.utils.TimeUtils;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.WicketUtils;\r
 \r
@@ -43,7 +45,7 @@ public class NewMilestonePage extends RepositoryPage {
        private IModel<String> nameModel;\r
 \r
        private IModel<Date> dueModel;\r
-       \r
+\r
        public NewMilestonePage(PageParameters params) {\r
                super(params);\r
 \r
@@ -52,7 +54,7 @@ public class NewMilestonePage extends RepositoryPage {
                        // ticket service is read-only\r
                        throw new RestartResponseException(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));\r
                }\r
-               \r
+\r
                UserModel currentUser = GitBlitWebSession.get().getUser();\r
                if (currentUser == null) {\r
                        currentUser = UserModel.ANONYMOUS;\r
@@ -72,13 +74,17 @@ public class NewMilestonePage extends RepositoryPage {
 \r
                        @Override\r
                        protected void onSubmit() {\r
-                               \r
+\r
                                String name = nameModel.getObject();\r
+                               if (StringUtils.isEmpty(name)) {\r
+                                       return;\r
+                               }\r
+\r
                                Date due = dueModel.getObject();\r
 \r
                                UserModel currentUser = GitBlitWebSession.get().getUser();\r
                                String createdBy = currentUser.username;\r
-                               \r
+\r
                                TicketMilestone milestone = app().tickets().createMilestone(getRepositoryModel(), name, createdBy);\r
                                if (milestone != null) {\r
                                        milestone.due = due;\r
@@ -92,8 +98,8 @@ public class NewMilestonePage extends RepositoryPage {
                add(form);\r
 \r
                nameModel = Model.of("");\r
-               dueModel = Model.of(new Date());\r
-               \r
+               dueModel = Model.of(new Date(System.currentTimeMillis() + TimeUtils.ONEDAY));\r
+\r
                form.add(new TextField<String>("name", nameModel));\r
                form.add(new DateTextField("due", dueModel, "yyyy-MM-dd"));\r
 \r