diff options
author | John Crygier <john.crygier@aon.com> | 2012-05-04 13:24:01 -0500 |
---|---|---|
committer | John Crygier <john.crygier@aon.com> | 2012-05-04 13:24:01 -0500 |
commit | ef4a4558ee259e64b1038b69505556a248eeb775 (patch) | |
tree | 8d55079596a9a04f6d3030462f42dfaea07f9508 | |
parent | 4a5a55229bf066bf933dde6cb6f51a4378d67fb7 (diff) | |
download | gitblit-ef4a4558ee259e64b1038b69505556a248eeb775.tar.gz gitblit-ef4a4558ee259e64b1038b69505556a248eeb775.zip |
Web UI done for Custom Fields. Changed variable names to be consistent with "custom" instead of "user"
-rw-r--r-- | distrib/gitblit.properties | 10 | ||||
-rw-r--r-- | src/com/gitblit/GitBlit.java | 6 | ||||
-rw-r--r-- | src/com/gitblit/models/RepositoryModel.java | 2 | ||||
-rw-r--r-- | src/com/gitblit/wicket/GitBlitWebApp.properties | 2 | ||||
-rw-r--r-- | src/com/gitblit/wicket/pages/EditRepositoryPage.html | 6 | ||||
-rw-r--r-- | src/com/gitblit/wicket/pages/EditRepositoryPage.java | 48 | ||||
-rw-r--r-- | tests/com/gitblit/tests/RepositoryModelTest.java | 14 |
7 files changed, 74 insertions, 14 deletions
diff --git a/distrib/gitblit.properties b/distrib/gitblit.properties index 8bfa417e..e04f2c8f 100644 --- a/distrib/gitblit.properties +++ b/distrib/gitblit.properties @@ -816,3 +816,13 @@ server.storePassword = gitblit # SINCE 0.5.0
# RESTART REQUIRED
server.shutdownPort = 8081
+
+# Custom Defined Properties for Repositories
+# Space delimited (use quotes if labels have spaces) list of custom properties
+# to show up on the "Edit Repository" page, with labels. Thes custom properties will
+# then be available for hooks.
+#
+# E.g. "commit-msg-regex=Commit Message Regualar Expression" another-property=Another
+#
+# SINCE 1.0.0
+repository.customFields =
\ No newline at end of file diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index a95e4f74..8ba080af 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -859,9 +859,9 @@ public class GitBlit implements ServletContextListener { "gitblit", null, "indexBranch")));
// Custom defined properties
- model.userDefinedProperties = new HashMap<String, String>();
+ model.customDefinedProperties = new HashMap<String, String>();
for (String aProperty : config.getNames(Constants.CUSTOM_DEFINED_PROP_SECTION, Constants.CUSTOM_DEFINED_PROP_SUBSECTION)) {
- model.userDefinedProperties.put(aProperty, config.getString(Constants.CUSTOM_DEFINED_PROP_SECTION, Constants.CUSTOM_DEFINED_PROP_SUBSECTION, aProperty));
+ model.customDefinedProperties.put(aProperty, config.getString(Constants.CUSTOM_DEFINED_PROP_SECTION, Constants.CUSTOM_DEFINED_PROP_SUBSECTION, aProperty));
}
}
model.HEAD = JGitUtils.getHEADRef(r);
@@ -1111,7 +1111,7 @@ public class GitBlit implements ServletContextListener { updateList(config, "indexBranch", repository.indexedBranches);
// User Defined Properties
- for (Entry<String, String> singleProperty : repository.userDefinedProperties.entrySet()) {
+ for (Entry<String, String> singleProperty : repository.customDefinedProperties.entrySet()) {
config.setString(Constants.CUSTOM_DEFINED_PROP_SECTION, Constants.CUSTOM_DEFINED_PROP_SUBSECTION, singleProperty.getKey(), singleProperty.getValue());
}
diff --git a/src/com/gitblit/models/RepositoryModel.java b/src/com/gitblit/models/RepositoryModel.java index 539aa513..92fc2373 100644 --- a/src/com/gitblit/models/RepositoryModel.java +++ b/src/com/gitblit/models/RepositoryModel.java @@ -64,7 +64,7 @@ public class RepositoryModel implements Serializable, Comparable<RepositoryModel public List<String> preReceiveScripts;
public List<String> postReceiveScripts;
public List<String> mailingLists;
- public Map<String, String> userDefinedProperties;
+ public Map<String, String> customDefinedProperties;
private String displayName;
public RepositoryModel() {
diff --git a/src/com/gitblit/wicket/GitBlitWebApp.properties b/src/com/gitblit/wicket/GitBlitWebApp.properties index 57ccd68f..b96a32ed 100644 --- a/src/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/com/gitblit/wicket/GitBlitWebApp.properties @@ -202,6 +202,8 @@ gb.mailingLists = mailing lists gb.preReceiveScripts = pre-receive scripts
gb.postReceiveScripts = post-receive scripts
gb.hookScripts = hook scripts
+gb.customDefinedProperties = custom defined properties
+gb.customDefinedPropertiesDescription = custom properties available to groovy hooks
gb.accessPermissions = access permissions
gb.filters = filters
gb.generalDescription = common settings
diff --git a/src/com/gitblit/wicket/pages/EditRepositoryPage.html b/src/com/gitblit/wicket/pages/EditRepositoryPage.html index d84573ec..e144f382 100644 --- a/src/com/gitblit/wicket/pages/EditRepositoryPage.html +++ b/src/com/gitblit/wicket/pages/EditRepositoryPage.html @@ -36,7 +36,11 @@ <tr><td colspan="2"><h3><wicket:message key="gb.hookScripts"></wicket:message> <small><wicket:message key="gb.hookScriptsDescription"></wicket:message></small></h3></td></tr>
<tr><th style="vertical-align: top;"><wicket:message key="gb.preReceiveScripts"></wicket:message><p></p><span wicket:id="inheritedPreReceive"></span></th><td style="padding:2px;"><span wicket:id="preReceiveScripts"></span></td></tr>
<tr><th style="vertical-align: top;"><wicket:message key="gb.postReceiveScripts"></wicket:message><p></p><span wicket:id="inheritedPostReceive"></span></th><td style="padding:2px;"><span wicket:id="postReceiveScripts"></span></td></tr>
- <tr><td colspan='2'><div class="form-actions"><input class="btn btn-primary" type="submit" value="Save" wicket:message="value:gb.save" wicket:id="save" tabindex="16" /> <input class="btn" type="submit" value="Cancel" wicket:message="value:gb.cancel" wicket:id="cancel" tabindex="17" /></div></td></tr>
+ <div wicket:id="customDefinedPropertiesSection">
+ <tr><td colspan="2"><h3><wicket:message key="gb.customDefinedProperties"></wicket:message> <small><wicket:message key="gb.customDefinedPropertiesDescription"></wicket:message></small></h3></td></tr>
+ <tr wicket:id="customDefinedProperties"><th style="vertical-align: top;"><span wicket:id="customLabel"></span></th><td class="edit"><input class="span8" type="text" wicket:id="customValue" size="30" tabindex="16" /></td></tr>
+ </div>
+ <tr><td colspan='2'><div class="form-actions"><input class="btn btn-primary" type="submit" value="Save" wicket:message="value:gb.save" wicket:id="save" tabindex="17" /> <input class="btn" type="submit" value="Cancel" wicket:message="value:gb.cancel" wicket:id="cancel" tabindex="18" /></div></td></tr>
</tbody>
</table>
</form>
diff --git a/src/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/com/gitblit/wicket/pages/EditRepositoryPage.java index af1b2b44..13b9e5a6 100644 --- a/src/com/gitblit/wicket/pages/EditRepositoryPage.java +++ b/src/com/gitblit/wicket/pages/EditRepositoryPage.java @@ -16,6 +16,7 @@ package com.gitblit.wicket.pages;
import java.text.MessageFormat;
+import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -23,26 +24,32 @@ import java.util.HashSet; import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import org.apache.wicket.PageParameters;
import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.extensions.markup.html.form.palette.Palette;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListItemModel;
+import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.util.CollectionModel;
import org.apache.wicket.model.util.ListModel;
+import com.gitblit.Constants;
import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.Constants.FederationStrategy;
-import com.gitblit.Constants;
import com.gitblit.GitBlit;
import com.gitblit.GitBlitException;
import com.gitblit.Keys;
@@ -149,6 +156,26 @@ public class EditRepositoryPage extends RootSubPage { new ListModel<String>(postReceiveScripts), new CollectionModel<String>(GitBlit
.self().getPostReceiveScriptsUnused(repositoryModel)),
new StringChoiceRenderer(), 12, true);
+
+ // Dynamic Custom Defined Properties Properties
+ final List<Entry<String, String>> definedProperties = new ArrayList<Entry<String, String>>();
+ List<String> customFields = GitBlit.getStrings(Keys.repository.customFields);
+ for (String customFieldDef : customFields) {
+ String[] customFieldProperty = customFieldDef.split("=");
+ definedProperties.add(new AbstractMap.SimpleEntry<String, String>(customFieldProperty[0], customFieldProperty[1]));
+ }
+
+ final ListView<Entry<String, String>> customDefinedProperties = new ListView<Entry<String, String>>("customDefinedProperties", definedProperties) {
+ @Override
+ protected void populateItem(ListItem<Entry<String, String>> item) {
+ String value = repositoryModel.customDefinedProperties.get(item.getModelObject().getKey());
+
+ item.add(new Label(item.getModelObject().getKey(), item.getModelObject().getValue())); // Used to get the key later
+ item.add(new Label("customLabel", item.getModelObject().getValue()));
+ item.add(new TextField<String>("customValue", new Model<String>(value)));
+ }
+ };
+ customDefinedProperties.setReuseItems(true);
CompoundPropertyModel<RepositoryModel> model = new CompoundPropertyModel<RepositoryModel>(
repositoryModel);
@@ -249,7 +276,16 @@ public class EditRepositoryPage extends RootSubPage { postReceiveScripts.add(post.next());
}
repositoryModel.postReceiveScripts = postReceiveScripts;
-
+
+ // Loop over each of the user defined properties
+ for (int i = 0; i < customDefinedProperties.size(); i++) {
+ ListItem<ListItemModel<String>> item = (ListItem<ListItemModel<String>>) customDefinedProperties.get(i);
+ String key = item.get(0).getId(); // Item 0 is our 'fake' label
+ String value = ((TextField<String>)item.get(2)).getValue(); // Item 2 is out text box
+
+ repositoryModel.customDefinedProperties.put(key, value);
+ }
+
// save the repository
GitBlit.self().updateRepositoryModel(oldName, repositoryModel, isCreate);
@@ -334,6 +370,14 @@ public class EditRepositoryPage extends RootSubPage { form.add(postReceivePalette);
form.add(new BulletListPanel("inheritedPostReceive", "inherited", GitBlit.self()
.getPostReceiveScriptsInherited(repositoryModel)));
+
+ WebMarkupContainer customDefinedPropertiesSection = new WebMarkupContainer("customDefinedPropertiesSection") {
+ public boolean isVisible() {
+ return GitBlit.getString(Keys.repository.customFields, "").isEmpty() == false;
+ };
+ };
+ customDefinedPropertiesSection.add(customDefinedProperties);
+ form.add(customDefinedPropertiesSection);
form.add(new Button("save"));
Button cancel = new Button("cancel") {
diff --git a/tests/com/gitblit/tests/RepositoryModelTest.java b/tests/com/gitblit/tests/RepositoryModelTest.java index f7418152..611ed295 100644 --- a/tests/com/gitblit/tests/RepositoryModelTest.java +++ b/tests/com/gitblit/tests/RepositoryModelTest.java @@ -67,8 +67,8 @@ public class RepositoryModelTest { RepositoryModel model = GitBlit.self().getRepositoryModel( GitBlitSuite.getHelloworldRepository().getDirectory().getName()); - assertEquals("\\d", model.userDefinedProperties.get("commitMessageRegEx")); - assertEquals("Hello", model.userDefinedProperties.get("anotherProperty")); + assertEquals("\\d", model.customDefinedProperties.get("commitMessageRegEx")); + assertEquals("Hello", model.customDefinedProperties.get("anotherProperty")); } @Test @@ -76,17 +76,17 @@ public class RepositoryModelTest { RepositoryModel model = GitBlit.self().getRepositoryModel( GitBlitSuite.getHelloworldRepository().getDirectory().getName()); - assertEquals("\\d", model.userDefinedProperties.get("commitMessageRegEx")); - assertEquals("Hello", model.userDefinedProperties.get("anotherProperty")); + assertEquals("\\d", model.customDefinedProperties.get("commitMessageRegEx")); + assertEquals("Hello", model.customDefinedProperties.get("anotherProperty")); - assertEquals("Hello", model.userDefinedProperties.put("anotherProperty", "GoodBye")); + assertEquals("Hello", model.customDefinedProperties.put("anotherProperty", "GoodBye")); GitBlit.self().updateRepositoryModel(model.name, model, false); model = GitBlit.self().getRepositoryModel( GitBlitSuite.getHelloworldRepository().getDirectory().getName()); - assertEquals("\\d", model.userDefinedProperties.get("commitMessageRegEx")); - assertEquals("GoodBye", model.userDefinedProperties.get("anotherProperty")); + assertEquals("\\d", model.customDefinedProperties.get("commitMessageRegEx")); + assertEquals("GoodBye", model.customDefinedProperties.get("anotherProperty")); } } |