diff --git a/plugins/scm-git-plugin/src/main/java/sonia/scm/api/rest/resources/GitConfigResource.java b/plugins/scm-git-plugin/src/main/java/sonia/scm/api/rest/resources/GitConfigResource.java new file mode 100644 index 0000000000..60b24b3704 --- /dev/null +++ b/plugins/scm-git-plugin/src/main/java/sonia/scm/api/rest/resources/GitConfigResource.java @@ -0,0 +1,102 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + + + +package sonia.scm.api.rest.resources; + +//~--- non-JDK imports -------------------------------------------------------- + +import com.google.inject.Inject; +import com.google.inject.Singleton; + +import sonia.scm.repository.RepositoryManager; + + +//~--- JDK imports ------------------------------------------------------------ + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; +import sonia.scm.repository.GitConfig; +import sonia.scm.repository.GitRepositoryHandler; + +/** + * + * @author Sebastian Sdorra + */ +@Singleton +@Path("config/repositories/git") +@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) +public class GitConfigResource +{ + + /** + * Constructs ... + * + * + * @param repositoryManager + */ + @Inject + public GitConfigResource(RepositoryManager repositoryManager) + { + repositoryHandler = (GitRepositoryHandler) repositoryManager.getHandler( + GitRepositoryHandler.TYPE_NAME); + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + @GET + public GitConfig getConfig() + { + GitConfig config = repositoryHandler.getConfig(); + + if (config == null) + { + config = new GitConfig(); + repositoryHandler.setConfig(config); + } + + return config; + } + + //~--- set methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param uriInfo + * @param config + * + * @return + */ + @POST + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public Response setConfig(@Context UriInfo uriInfo, GitConfig config) + { + repositoryHandler.setConfig(config); + repositoryHandler.storeConfig(); + + return Response.created(uriInfo.getRequestUri()).build(); + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private GitRepositoryHandler repositoryHandler; +} diff --git a/plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitWebPlugin.java b/plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitWebPlugin.java index 8d8dab5eff..d55a202a31 100644 --- a/plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitWebPlugin.java +++ b/plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitWebPlugin.java @@ -14,6 +14,8 @@ package sonia.scm.web; public class GitWebPlugin implements ScmWebPlugin { + public static final String SCRIPT = "/sonia/scm/git.config.js"; + /** * Method description * @@ -34,5 +36,9 @@ public class GitWebPlugin implements ScmWebPlugin * @param context */ @Override - public void contextInitialized(ScmWebPluginContext context) {} + public void contextInitialized(ScmWebPluginContext context) + { + context.addScriptResource( new ClasspathWebResource(SCRIPT) ); + + } } diff --git a/plugins/scm-git-plugin/src/main/resources/sonia/scm/git.config.js b/plugins/scm-git-plugin/src/main/resources/sonia/scm/git.config.js new file mode 100644 index 0000000000..e5229a5508 --- /dev/null +++ b/plugins/scm-git-plugin/src/main/resources/sonia/scm/git.config.js @@ -0,0 +1,63 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +registerConfigPanel({ + xtype : 'configForm', + title : 'Git Settings', + items : [{ + xtype : 'textfield', + fieldLabel : 'Git Binary', + name : 'gitBinary', + allowBlank : false + },{ + xtype: 'textfield', + name: 'repositoryDirectory', + fieldLabel: 'Repository directory', + allowBlank : false + },{ + xtype: 'textfield', + name: 'baseUrl', + fieldLabel: 'Base URL', + allowBlank : false + }], + + onSubmit: function(values){ + this.el.mask('Submit ...'); + Ext.Ajax.request({ + url: restUrl + 'config/repositories/git.json', + method: 'POST', + jsonData: values, + scope: this, + disableCaching: true, + success: function(response){ + this.el.unmask(); + }, + failure: function(){ + this.el.unmask(); + } + }); + }, + + onLoad: function(el){ + var tid = setTimeout( function(){ el.mask('Loading ...'); }, 100); + Ext.Ajax.request({ + url: restUrl + 'config/repositories/git.json', + method: 'GET', + scope: this, + disableCaching: true, + success: function(response){ + var obj = Ext.decode(response.responseText); + this.load(obj); + clearTimeout(tid); + el.unmask(); + }, + failure: function(){ + el.unmask(); + clearTimeout(tid); + alert('failure'); + } + }); + } + +});