improve mercurial configuration wizard

This commit is contained in:
Sebastian Sdorra
2011-04-27 10:02:25 +02:00
parent 190a63e6e9
commit 127f7fc09b
4 changed files with 78 additions and 56 deletions

View File

@@ -98,11 +98,33 @@ public class HgConfigResource
*/
@POST
@Path("auto-configuration")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public HgConfig autoConfiguration(@Context UriInfo uriInfo)
{
handler.setConfig(null);
handler.doAutoConfiguration();
return autoConfiguration(uriInfo, null);
}
/**
* Method description
*
*
* @param uriInfo
* @param config
*
* @return
*/
@POST
@Path("auto-configuration")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public HgConfig autoConfiguration(@Context UriInfo uriInfo, HgConfig config)
{
if (config == null)
{
config = new HgConfig();
}
handler.doAutoConfiguration(config);
return handler.getConfig();
}

View File

@@ -104,55 +104,35 @@ public class HgRepositoryHandler
/**
* Method description
*
*
* @param autoConfig
*/
public void doAutoConfiguration()
public void doAutoConfiguration(HgConfig autoConfig)
{
HgInstaller installer = HgInstallerFactory.createInstaller();
if (config == null)
try
{
config = new HgConfig();
try
if (logger.isDebugEnabled())
{
if (logger.isDebugEnabled())
{
logger.debug("installing mercurial with {}",
installer.getClass().getName());
}
installer.install(baseDirectory, config);
new HgWebConfigWriter(config).write();
logger.debug("installing mercurial with {}",
installer.getClass().getName());
}
catch (IOException ioe)
installer.install(baseDirectory, autoConfig);
config = autoConfig;
storeConfig();
new HgWebConfigWriter(config).write();
}
catch (IOException ioe)
{
if (logger.isErrorEnabled())
{
if (logger.isErrorEnabled())
{
logger.error(
"Could not write Hg CGI for inital config. "
+ "HgWeb may not function until a new Hg config is set", ioe);
}
logger.error(
"Could not write Hg CGI for inital config. "
+ "HgWeb may not function until a new Hg config is set", ioe);
}
}
else
{
try
{
if (logger.isDebugEnabled())
{
logger.debug("update mercurial with {}",
installer.getClass().getName());
}
installer.update(baseDirectory, config);
}
catch (IOException ex)
{
logger.error(ex.getMessage(), ex);
}
}
storeConfig();
}
/**
@@ -163,7 +143,11 @@ public class HgRepositoryHandler
public void loadConfig()
{
super.loadConfig();
doAutoConfiguration();
if (config == null)
{
doAutoConfiguration(new HgConfig());
}
}
//~--- get methods ----------------------------------------------------------

View File

@@ -170,13 +170,7 @@ Sonia.hg.ConfigWizardPanel = Ext.extend(Ext.Panel,{
},{
id: 'finish',
text: 'Finish',
handler: function(){
if ( debug ){
console.debug('finish');
console.debug( this.hgConfig );
}
this.fireEvent('finish', this.hgConfig);
},
handler: this.applyChanges,
scope: this,
disabled: true
}],
@@ -184,6 +178,7 @@ Sonia.hg.ConfigWizardPanel = Ext.extend(Ext.Panel,{
id: 'step-1',
layout: 'form',
items: [{
id: 'mercurial',
fieldLabel: 'Mercurial Installation',
name: 'mercurial',
xtype: 'combo',
@@ -195,8 +190,10 @@ Sonia.hg.ConfigWizardPanel = Ext.extend(Ext.Panel,{
store: hgInstallationStore,
valueField: 'path',
displayField: 'path',
allowBlank: false
allowBlank: false,
value: this.hgConfig.hgBinary
},{
id: 'python',
fieldLabel: 'Python Installation',
name: 'python',
xtype: 'combo',
@@ -208,7 +205,8 @@ Sonia.hg.ConfigWizardPanel = Ext.extend(Ext.Panel,{
store: pythonInstallationStore,
valueField: 'path',
displayField: 'path',
allowBlank: false
allowBlank: false,
value: this.hgConfig.pythonBinary
}]
},{
id: 'step-2',
@@ -221,6 +219,24 @@ Sonia.hg.ConfigWizardPanel = Ext.extend(Ext.Panel,{
Ext.apply(this, Ext.apply(this.initialConfig, config));
Sonia.hg.ConfigWizardPanel.superclass.initComponent.apply(this, arguments);
},
applyChanges: function(){
var mercurial = Ext.getCmp('mercurial').getValue();
var python = Ext.getCmp('python').getValue();
if (debug){
console.debug( 'configure mercurial=' + mercurial + " and python=" + python );
}
delete this.hgConfig.pythonPath;
delete this.hgConfig.useOptimizedBytecode;
this.hgConfig.hgBinary = mercurial;
this.hgConfig.pythonBinary = python;
if ( debug ){
console.debug( this.hgConfig );
}
this.fireEvent('finish', this.hgConfig);
}
});

View File

@@ -104,10 +104,9 @@ Sonia.hg.ConfigPanel = Ext.extend(Sonia.config.ConfigForm, {
wizard.on('finish', function(config){
if (debug){
console.debug( 'load config from wizard and submit to server' );
console.debug( config );
}
this.getForm().load(config);
this.onSubmit(config);
var self = Ext.getCmp('hgConfigForm');
self.loadConfig( self.el, 'config/repositories/hg/auto-configuration.json', 'POST', config );
}, this);
wizard.show();
},
@@ -141,11 +140,12 @@ Sonia.hg.ConfigPanel = Ext.extend(Sonia.config.ConfigForm, {
this.loadConfig(el, 'config/repositories/hg.json', 'GET');
},
loadConfig: function(el, url, method){
loadConfig: function(el, url, method, config){
var tid = setTimeout( function(){ el.mask(this.loadingText); }, 100);
Ext.Ajax.request({
url: restUrl + url,
method: method,
jsonData: config,
scope: this,
disableCaching: true,
success: function(response){