]> source.dussan.org Git - gitblit.git/commitdiff
Added a link to delete a branch 39/head
authorajermakovics <andrejs.jermakovics@gmail.com>
Wed, 19 Sep 2012 21:10:29 +0000 (22:10 +0100)
committerajermakovics <andrejs.jermakovics@gmail.com>
Wed, 19 Sep 2012 21:10:29 +0000 (22:10 +0100)
delete link appears on the branches page if an admin user is logged in.

src/com/gitblit/wicket/pages/BranchesPage.java
src/com/gitblit/wicket/pages/RepositoryPage.java
src/com/gitblit/wicket/pages/SummaryPage.java
src/com/gitblit/wicket/panels/BranchesPanel.html
src/com/gitblit/wicket/panels/BranchesPanel.java

index 2b7d51879f390dead65064ef5ee25b6d18af507b..b38a80a2dcca03e2981a0e8d0c9d29174f6a4d7b 100644 (file)
@@ -24,7 +24,7 @@ public class BranchesPage extends RepositoryPage {
        public BranchesPage(PageParameters params) {\r
                super(params);\r
 \r
-               add(new BranchesPanel("branchesPanel", getRepositoryModel(), getRepository(), -1));\r
+               add(new BranchesPanel("branchesPanel", getRepositoryModel(), getRepository(), -1, isShowAdmin()));\r
        }\r
 \r
        @Override\r
index 7e21911b99f0c555aab2a3cb32c22b8ba4a60611..69719464f34b99c2b3d7dcaeebccddea323331d1 100644 (file)
@@ -75,6 +75,7 @@ public abstract class RepositoryPage extends BasePage {
        private Map<String, SubmoduleModel> submodules;\r
        \r
        private final Map<String, PageRegistration> registeredPages;\r
+       private boolean showAdmin;\r
 \r
        public RepositoryPage(PageParameters params) {\r
                super(params);\r
@@ -148,7 +149,7 @@ public abstract class RepositoryPage extends BasePage {
                }\r
 \r
                // Conditionally add edit link\r
-               final boolean showAdmin;\r
+               this.showAdmin = false;\r
                if (GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) {\r
                        boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);\r
                        showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();\r
@@ -412,6 +413,11 @@ public abstract class RepositoryPage extends BasePage {
                return WicketUtils.newObjectParameter(repositoryName, commitId);\r
        }\r
 \r
+       public boolean isShowAdmin()\r
+       {\r
+               return this.showAdmin;\r
+       }\r
+       \r
        private class SearchForm extends SessionlessForm<Void> implements Serializable {\r
                private static final long serialVersionUID = 1L;\r
 \r
index 2a624c266d830059a345ba00336a09458dcdfe51..0b5317869a0ad0a2c9959f77356e05d21eddbd5c 100644 (file)
@@ -132,7 +132,7 @@ public class SummaryPage extends RepositoryPage {
 \r
                add(new LogPanel("commitsPanel", repositoryName, getRepositoryModel().HEAD, r, numberCommits, 0));\r
                add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty());\r
-               add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs).hideIfEmpty());\r
+               add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs, isShowAdmin()).hideIfEmpty());\r
 \r
                if (getRepositoryModel().showReadme) {\r
                        String htmlText = null;\r
index 1322eefd641c028109f642a2c329414c4a29be60..d2d88d38480ec1ec79989a4fb4ab0ae9d2d1c8e2 100644 (file)
@@ -29,7 +29,7 @@
        <!-- branch page links -->\r
        <wicket:fragment wicket:id="branchPageLinks">\r
                <span class="link">\r
-                       <a wicket:id="log"><wicket:message key="gb.log"></wicket:message></a> | <a wicket:id="tree"><wicket:message key="gb.tree"></wicket:message></a> | <a wicket:id="metrics"><wicket:message key="gb.metrics"></wicket:message></a> | <a wicket:id="syndication"><wicket:message key="gb.feed"></wicket:message></a>\r
+                       <a wicket:id="log"><wicket:message key="gb.log"></wicket:message></a> | <a wicket:id="tree"><wicket:message key="gb.tree"></wicket:message></a> | <a wicket:id="metrics"><wicket:message key="gb.metrics"></wicket:message></a> | <a wicket:id="syndication"><wicket:message key="gb.feed"></wicket:message></a> | <a wicket:id="deleteBranch"><wicket:message key="gb.delete"></wicket:message></a>\r
                </span>\r
        </wicket:fragment>\r
 \r
index 8bbab9a0884ca2c7c7f2b5e79c8be4fdfdf8870d..25126531f25683031cdeb5134a786e487797c06a 100644 (file)
@@ -15,6 +15,7 @@
  */\r
 package com.gitblit.wicket.panels;\r
 \r
+import java.text.MessageFormat;\r
 import java.util.ArrayList;\r
 import java.util.Collections;\r
 import java.util.List;\r
@@ -22,6 +23,7 @@ import java.util.List;
 import org.apache.wicket.markup.html.basic.Label;\r
 import org.apache.wicket.markup.html.link.BookmarkablePageLink;\r
 import org.apache.wicket.markup.html.link.ExternalLink;\r
+import org.apache.wicket.markup.html.link.Link;\r
 import org.apache.wicket.markup.html.panel.Fragment;\r
 import org.apache.wicket.markup.repeater.Item;\r
 import org.apache.wicket.markup.repeater.data.DataView;\r
@@ -38,9 +40,9 @@ import com.gitblit.utils.StringUtils;
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.pages.BranchesPage;\r
 import com.gitblit.wicket.pages.CommitPage;\r
+import com.gitblit.wicket.pages.GitSearchPage;\r
 import com.gitblit.wicket.pages.LogPage;\r
 import com.gitblit.wicket.pages.MetricsPage;\r
-import com.gitblit.wicket.pages.GitSearchPage;\r
 import com.gitblit.wicket.pages.TreePage;\r
 \r
 public class BranchesPanel extends BasePanel {\r
@@ -49,8 +51,8 @@ public class BranchesPanel extends BasePanel {
 \r
        private final boolean hasBranches;\r
 \r
-       public BranchesPanel(String wicketId, final RepositoryModel model, Repository r,\r
-                       final int maxCount) {\r
+       public BranchesPanel(String wicketId, final RepositoryModel model, final Repository r,\r
+                       final int maxCount, final boolean showAdmin) {\r
                super(wicketId);\r
 \r
                // branches\r
@@ -106,7 +108,7 @@ public class BranchesPanel extends BasePanel {
                                        WicketUtils.setHtmlTooltip(shortlog, shortMessage);\r
                                }\r
                                item.add(shortlog);\r
-\r
+                               \r
                                if (maxCount <= 0) {\r
                                        Fragment fragment = new Fragment("branchLinks", "branchPageLinks", this);\r
                                        fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class, WicketUtils\r
@@ -118,6 +120,9 @@ public class BranchesPanel extends BasePanel {
                                        fragment.add(new ExternalLink("syndication", SyndicationServlet.asLink(\r
                                                        getRequest().getRelativePathPrefixToContextRoot(), model.name,\r
                                                        entry.getName(), 0)));\r
+                                       \r
+                                       fragment.add(createDeleteBranchLink(r, entry, showAdmin));\r
+                                       \r
                                        item.add(fragment);\r
                                } else {\r
                                        Fragment fragment = new Fragment("branchLinks", "branchPanelLinks", this);\r
@@ -148,4 +153,28 @@ public class BranchesPanel extends BasePanel {
                setVisible(hasBranches);\r
                return this;\r
        }\r
+\r
+       private Link<Void> createDeleteBranchLink(final Repository r, final RefModel entry, final boolean showAdmin)\r
+       {\r
+               Link<Void> deleteLink = new Link<Void>("deleteBranch") {\r
+                       private static final long serialVersionUID = 1L;\r
+\r
+                       @Override\r
+                       public void onClick() {\r
+                               if( showAdmin && JGitUtils.deleteBranchRef(r, entry.getName()) ) {\r
+                                       info(MessageFormat.format("Branch \"{0}\" deleted", entry.displayName));\r
+                               }\r
+                               else {\r
+                                       error(MessageFormat.format("Failed to delete branch \"{0}\"", entry.displayName));\r
+                               }\r
+                       }\r
+               };\r
+               \r
+               deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(\r
+                               "Delete branch \"{0}\"?", entry.displayName )));\r
+               \r
+               deleteLink.setVisible(showAdmin);\r
+               \r
+               return deleteLink;\r
+       }\r
 }\r