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
}\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
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
\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
*/\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
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
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
\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
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
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
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