From 2a8a74bedafdb56b7e7edcb42642dc1eb5e54fff Mon Sep 17 00:00:00 2001
From: saheba <mail@saheba.net>
Date: Mon, 25 Mar 2013 16:34:45 -0400
Subject: [PATCH] code cleanup
---
src/com/gitblit/wicket/pages/EditRepositoryPage.java | 107 +++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 91 insertions(+), 16 deletions(-)
diff --git a/src/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/com/gitblit/wicket/pages/EditRepositoryPage.java
index 58fdf66..2cbb88c 100644
--- a/src/com/gitblit/wicket/pages/EditRepositoryPage.java
+++ b/src/com/gitblit/wicket/pages/EditRepositoryPage.java
@@ -94,7 +94,7 @@
// personal create permissions, inject personal repository path
model.name = user.getPersonalPath() + "/";
model.projectPath = user.getPersonalPath();
- model.owner = user.username;
+ model.addOwner(user.username);
// personal repositories are private by default
model.accessRestriction = AccessRestrictionType.VIEW;
model.authorizationControl = AuthorizationControl.NAMED;
@@ -114,6 +114,11 @@
setupPage(model);
setStatelessHint(false);
setOutputMarkupId(true);
+ }
+
+ @Override
+ protected boolean requiresPageMap() {
+ return true;
}
protected void setupPage(RepositoryModel model) {
@@ -141,11 +146,11 @@
}
} else {
super.setupPage(getString("gb.edit"), repositoryModel.name);
- if (repositoryModel.accessRestriction.exceeds(AccessRestrictionType.NONE)) {
- repositoryUsers.addAll(GitBlit.self().getUserAccessPermissions(repositoryModel));
- repositoryTeams.addAll(GitBlit.self().getTeamAccessPermissions(repositoryModel));
- Collections.sort(repositoryUsers);
- }
+ repositoryUsers.addAll(GitBlit.self().getUserAccessPermissions(repositoryModel));
+ repositoryTeams.addAll(GitBlit.self().getTeamAccessPermissions(repositoryModel));
+ Collections.sort(repositoryUsers);
+ Collections.sort(repositoryTeams);
+
federationSets.addAll(repositoryModel.federationSets);
if (!ArrayUtils.isEmpty(repositoryModel.indexedBranches)) {
indexedBranches.addAll(repositoryModel.indexedBranches);
@@ -159,6 +164,12 @@
final RegistrantPermissionsPanel teamsPalette = new RegistrantPermissionsPanel("teams",
RegistrantType.TEAM, GitBlit.self().getAllTeamnames(), repositoryTeams, getAccessPermissions());
+ // owners palette
+ List<String> owners = new ArrayList<String>(repositoryModel.owners);
+ List<String> persons = GitBlit.self().getAllUsernames();
+ final Palette<String> ownersPalette = new Palette<String>("owners", new ListModel<String>(owners), new CollectionModel<String>(
+ persons), new StringChoiceRenderer(), 12, true);
+
// indexed local branches palette
List<String> allLocalBranches = new ArrayList<String>();
allLocalBranches.add(Constants.DEFAULT_BRANCH);
@@ -321,6 +332,13 @@
}
repositoryModel.indexedBranches = indexedBranches;
+ // owners
+ repositoryModel.owners.clear();
+ Iterator<String> owners = ownersPalette.getSelectedChoices();
+ while (owners.hasNext()) {
+ repositoryModel.addOwner(owners.next());
+ }
+
// pre-receive scripts
List<String> preReceiveScripts = new ArrayList<String>();
Iterator<String> pres = preReceivePalette.getSelectedChoices();
@@ -372,9 +390,8 @@
// field names reflective match RepositoryModel fields
form.add(new TextField<String>("name").setEnabled(allowEditName));
form.add(new TextField<String>("description"));
- form.add(new DropDownChoice<String>("owner", GitBlit.self().getAllUsernames())
- .setEnabled(GitBlitWebSession.get().canAdmin()));
- form.add(new CheckBox("allowForks"));
+ form.add(ownersPalette);
+ form.add(new CheckBox("allowForks").setEnabled(GitBlit.getBoolean(Keys.web.allowForking, true)));
DropDownChoice<AccessRestrictionType> accessRestriction = new DropDownChoice<AccessRestrictionType>("accessRestriction", Arrays
.asList(AccessRestrictionType.values()), new AccessRestrictionRenderer());
form.add(accessRestriction);
@@ -389,9 +406,10 @@
}
form.add(new DropDownChoice<String>("HEAD", availableRefs).setEnabled(availableRefs.size() > 0));
- List<String> gcPeriods = Arrays.asList("1 day", "2 days", "3 days", "4 days", "5 days", "7 days", "10 days", "14 days");
- form.add(new DropDownChoice<String>("gcPeriod", gcPeriods));
- form.add(new TextField<String>("gcThreshold"));
+ boolean gcEnabled = GitBlit.getBoolean(Keys.git.enableGarbageCollection, false);
+ List<Integer> gcPeriods = Arrays.asList(1, 2, 3, 4, 5, 7, 10, 14 );
+ form.add(new DropDownChoice<Integer>("gcPeriod", gcPeriods, new GCPeriodRenderer()).setEnabled(gcEnabled));
+ form.add(new TextField<String>("gcThreshold").setEnabled(gcEnabled));
// federation strategies - remove ORIGIN choice if this repository has
// no origin.
@@ -404,10 +422,14 @@
new FederationTypeRenderer()));
form.add(new CheckBox("useTickets"));
form.add(new CheckBox("useDocs"));
+ form.add(new CheckBox("useIncrementalRevisionNumbers"));
form.add(new CheckBox("showRemoteBranches"));
form.add(new CheckBox("showReadme"));
form.add(new CheckBox("skipSizeCalculation"));
form.add(new CheckBox("skipSummaryMetrics"));
+ List<Integer> maxActivityCommits = Arrays.asList(-1, 0, 25, 50, 75, 100, 150, 200, 250, 500 );
+ form.add(new DropDownChoice<Integer>("maxActivityCommits", maxActivityCommits, new MaxActivityCommitsRenderer()));
+
mailingLists = new Model<String>(ArrayUtils.isEmpty(repositoryModel.mailingLists) ? ""
: StringUtils.flattenStrings(repositoryModel.mailingLists, " "));
form.add(new TextField<String>("mailingLists", mailingLists));
@@ -417,8 +439,10 @@
final RadioChoice<AuthorizationControl> authorizationControl = new RadioChoice<Constants.AuthorizationControl>(
"authorizationControl", acList, new AuthorizationControlRenderer());
form.add(authorizationControl);
-
- form.add(new CheckBox("verifyCommitter"));
+
+ final CheckBox verifyCommitter = new CheckBox("verifyCommitter");
+ verifyCommitter.setOutputMarkupId(true);
+ form.add(verifyCommitter);
form.add(usersPalette);
form.add(teamsPalette);
@@ -440,14 +464,16 @@
usersPalette.setEnabled(false);
teamsPalette.setEnabled(false);
authorizationControl.setEnabled(false);
+ verifyCommitter.setEnabled(false);
} else {
// authenticated something
// enable authorization controls
authorizationControl.setEnabled(true);
+ verifyCommitter.setEnabled(true);
boolean allowFineGrainedControls = repositoryModel.authorizationControl.equals(AuthorizationControl.NAMED);
usersPalette.setEnabled(allowFineGrainedControls);
- teamsPalette.setEnabled(allowFineGrainedControls);
+ teamsPalette.setEnabled(allowFineGrainedControls);
}
accessRestriction.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@@ -458,6 +484,7 @@
// enable/disable permissions panel based on access restriction
boolean allowAuthorizationControl = repositoryModel.accessRestriction.exceeds(AccessRestrictionType.NONE);
authorizationControl.setEnabled(allowAuthorizationControl);
+ verifyCommitter.setEnabled(allowAuthorizationControl);
boolean allowFineGrainedControls = allowAuthorizationControl && repositoryModel.authorizationControl.equals(AuthorizationControl.NAMED);
usersPalette.setEnabled(allowFineGrainedControls);
@@ -468,6 +495,7 @@
}
target.addComponent(authorizationControl);
+ target.addComponent(verifyCommitter);
target.addComponent(usersPalette);
target.addComponent(teamsPalette);
}
@@ -544,7 +572,7 @@
isAdmin = true;
return;
} else {
- if (!model.owner.equalsIgnoreCase(user.username)) {
+ if (!model.isOwner(user.username)) {
// User is not an Admin nor Owner
error(getString("gb.errorOnlyAdminOrOwnerMayEditRepository"), true);
}
@@ -619,4 +647,51 @@
return Integer.toString(index);
}
}
+
+ private class GCPeriodRenderer implements IChoiceRenderer<Integer> {
+
+ private static final long serialVersionUID = 1L;
+
+ public GCPeriodRenderer() {
+ }
+
+ @Override
+ public String getDisplayValue(Integer value) {
+ if (value == 1) {
+ return getString("gb.duration.oneDay");
+ } else {
+ return MessageFormat.format(getString("gb.duration.days"), value);
+ }
+ }
+
+ @Override
+ public String getIdValue(Integer value, int index) {
+ return Integer.toString(index);
+ }
+ }
+
+ private class MaxActivityCommitsRenderer implements IChoiceRenderer<Integer> {
+
+ private static final long serialVersionUID = 1L;
+
+ public MaxActivityCommitsRenderer() {
+ }
+
+ @Override
+ public String getDisplayValue(Integer value) {
+ if (value == -1) {
+ return getString("gb.excludeFromActivity");
+ } else if (value == 0) {
+ return getString("gb.noMaximum");
+ } else {
+ return value + " " + getString("gb.commits");
+ }
+ }
+
+ @Override
+ public String getIdValue(Integer value, int index) {
+ return Integer.toString(index);
+ }
+ }
+
}
--
Gitblit v1.9.1