make date format configurable

This commit is contained in:
Sebastian Sdorra
2011-04-05 08:20:55 +02:00
parent 2396430431
commit ef5f68a96c
6 changed files with 194 additions and 10 deletions

View File

@@ -61,6 +61,9 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
public class ScmConfiguration public class ScmConfiguration
{ {
/** Field description */
public static final String DEFAULT_DATEFORMAT = "Y-m-d H:i:s";
/** Field description */ /** Field description */
public static final String DEFAULT_PLUGINURL = public static final String DEFAULT_PLUGINURL =
"http://plugins.scm-manager.org/scm-plugin-backend/api/{version}/plugins?os={os}&arch={arch}&snapshot=false"; "http://plugins.scm-manager.org/scm-plugin-backend/api/{version}/plugins?os={os}&arch={arch}&snapshot=false";
@@ -84,6 +87,7 @@ public class ScmConfiguration
public void load(ScmConfiguration other) public void load(ScmConfiguration other)
{ {
this.servername = other.servername; this.servername = other.servername;
this.dateFormat = other.dateFormat;
this.pluginUrl = other.pluginUrl; this.pluginUrl = other.pluginUrl;
this.sslPort = other.sslPort; this.sslPort = other.sslPort;
this.enableSSL = other.enableSSL; this.enableSSL = other.enableSSL;
@@ -118,6 +122,17 @@ public class ScmConfiguration
return adminUsers; return adminUsers;
} }
/**
* Method description
*
*
* @return
*/
public String getDateFormat()
{
return dateFormat;
}
/** /**
* Method description * Method description
* *
@@ -230,6 +245,17 @@ public class ScmConfiguration
this.anonymousAccessEnabled = anonymousAccessEnabled; this.anonymousAccessEnabled = anonymousAccessEnabled;
} }
/**
* Method description
*
*
* @param dateFormat
*/
public void setDateFormat(String dateFormat)
{
this.dateFormat = dateFormat;
}
/** /**
* Method description * Method description
* *
@@ -327,6 +353,11 @@ public class ScmConfiguration
/** Field description */ /** Field description */
private int sslPort = 8181; private int sslPort = 8181;
/**
* JavaScript date format, see http://jacwright.com/projects/javascript/date_format
*/
private String dateFormat = DEFAULT_DATEFORMAT;
/** Field description */ /** Field description */
private boolean anonymousAccessEnabled = false; private boolean anonymousAccessEnabled = false;
} }

View File

@@ -0,0 +1,90 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm;
/**
*
* @author Sebastian Sdorra
*/
public class ScmClientConfig
{
/**
* Constructs ...
*
*/
public ScmClientConfig() {}
/**
* Constructs ...
*
*
* @param dateFormat
*/
public ScmClientConfig(String dateFormat)
{
this.dateFormat = dateFormat;
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public String getDateFormat()
{
return dateFormat;
}
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param dateFormat
*/
public void setDateFormat(String dateFormat)
{
this.dateFormat = dateFormat;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private String dateFormat;
}

View File

@@ -71,19 +71,33 @@ public class ScmState
* @param provider * @param provider
* @param securityContext * @param securityContext
* @param repositoryTypes * @param repositoryTypes
* @param clientConfig
*/ */
public ScmState(SCMContextProvider provider, public ScmState(SCMContextProvider provider,
WebSecurityContext securityContext, WebSecurityContext securityContext,
Collection<Type> repositoryTypes) Collection<Type> repositoryTypes,
ScmClientConfig clientConfig)
{ {
this.version = provider.getVersion(); this.version = provider.getVersion();
this.user = securityContext.getUser(); this.user = securityContext.getUser();
this.groups = securityContext.getGroups(); this.groups = securityContext.getGroups();
this.repositoryTypes = repositoryTypes; this.repositoryTypes = repositoryTypes;
this.clientConfig = clientConfig;
} }
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public ScmClientConfig getClientConfig()
{
return clientConfig;
}
/** /**
* Method description * Method description
* *
@@ -141,6 +155,17 @@ public class ScmState
//~--- set methods ---------------------------------------------------------- //~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param clientConfig
*/
public void setClientConfig(ScmClientConfig clientConfig)
{
this.clientConfig = clientConfig;
}
/** /**
* Method description * Method description
* *
@@ -198,6 +223,9 @@ public class ScmState
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */
private ScmClientConfig clientConfig;
/** Field description */ /** Field description */
private Collection<String> groups; private Collection<String> groups;

View File

@@ -44,7 +44,9 @@ import org.slf4j.LoggerFactory;
import sonia.scm.SCMContext; import sonia.scm.SCMContext;
import sonia.scm.SCMContextProvider; import sonia.scm.SCMContextProvider;
import sonia.scm.ScmClientConfig;
import sonia.scm.ScmState; import sonia.scm.ScmState;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.repository.RepositoryManager; import sonia.scm.repository.RepositoryManager;
import sonia.scm.user.User; import sonia.scm.user.User;
import sonia.scm.web.security.WebSecurityContext; import sonia.scm.web.security.WebSecurityContext;
@@ -85,16 +87,18 @@ public class AuthenticationResource
* *
* *
* @param contextProvider * @param contextProvider
* @param configuration
* @param repositoryManger * @param repositoryManger
* @param securityContextProvider * @param securityContextProvider
*/ */
@Inject @Inject
public AuthenticationResource( public AuthenticationResource(
SCMContextProvider contextProvider, SCMContextProvider contextProvider, ScmConfiguration configuration,
RepositoryManager repositoryManger, RepositoryManager repositoryManger,
Provider<WebSecurityContext> securityContextProvider) Provider<WebSecurityContext> securityContextProvider)
{ {
this.contextProvider = contextProvider; this.contextProvider = contextProvider;
this.configuration = configuration;
this.repositoryManger = repositoryManger; this.repositoryManger = repositoryManger;
this.securityContextProvider = securityContextProvider; this.securityContextProvider = securityContextProvider;
} }
@@ -126,8 +130,7 @@ public class AuthenticationResource
if ((user != null) &&!SCMContext.USER_ANONYMOUS.equals(user.getName())) if ((user != null) &&!SCMContext.USER_ANONYMOUS.equals(user.getName()))
{ {
state = new ScmState(contextProvider, securityContext, state = createState(securityContext);
repositoryManger.getConfiguredTypes());
} }
else else
{ {
@@ -160,8 +163,7 @@ public class AuthenticationResource
if (user != null) if (user != null)
{ {
ScmState state = new ScmState(contextProvider, securityContext, ScmState state = createState(securityContext);
repositoryManger.getConfiguredTypes());
resp = Response.ok(state).build(); resp = Response.ok(state).build();
} }
@@ -198,8 +200,7 @@ public class AuthenticationResource
logger.debug("return state for user {}", user.getName()); logger.debug("return state for user {}", user.getName());
} }
state = new ScmState(contextProvider, securityContext, state = createState(securityContext);
repositoryManger.getConfiguredTypes());
response = Response.ok(state).build(); response = Response.ok(state).build();
} }
else else
@@ -210,8 +211,28 @@ public class AuthenticationResource
return response; return response;
} }
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param securityContext
*
* @return
*/
private ScmState createState(WebSecurityContext securityContext)
{
return new ScmState(contextProvider, securityContext,
repositoryManger.getConfiguredTypes(),
new ScmClientConfig(configuration.getDateFormat()));
}
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */
private ScmConfiguration configuration;
/** Field description */ /** Field description */
private SCMContextProvider contextProvider; private SCMContextProvider contextProvider;

View File

@@ -101,6 +101,8 @@ Sonia.config.ScmConfigPanel = Ext.extend(Sonia.config.ConfigPanel,{
titleText: 'General Settings', titleText: 'General Settings',
servnameText: 'Servername', servnameText: 'Servername',
// TODO i18n
dateFormatText: 'Date format',
enableForwardingText: 'Enable forwarding (mod_proxy)', enableForwardingText: 'Enable forwarding (mod_proxy)',
forwardPortText: 'Forward Port', forwardPortText: 'Forward Port',
pluginRepositoryText: 'Plugin repository', pluginRepositoryText: 'Plugin repository',
@@ -116,6 +118,8 @@ Sonia.config.ScmConfigPanel = Ext.extend(Sonia.config.ConfigPanel,{
// help // help
servernameHelpText: 'The name of this server. This name will be part of the repository url.', servernameHelpText: 'The name of this server. This name will be part of the repository url.',
// TODO i18n
dateFormatHelpText: 'JavaScript date format.',
pluginRepositoryHelpText: 'The url of the plugin repository.<br />Explanation of the {placeholders}:\n\ pluginRepositoryHelpText: 'The url of the plugin repository.<br />Explanation of the {placeholders}:\n\
<br /><b>version</b> = SCM-Manager Version<br /><b>os</b> = Operation System<br /><b>arch</b> = Architecture', <br /><b>version</b> = SCM-Manager Version<br /><b>os</b> = Operation System<br /><b>arch</b> = Architecture',
enableForwardingHelpText: 'Enbale mod_proxy port forwarding.', enableForwardingHelpText: 'Enbale mod_proxy port forwarding.',
@@ -139,6 +143,12 @@ Sonia.config.ScmConfigPanel = Ext.extend(Sonia.config.ConfigPanel,{
name: 'servername', name: 'servername',
helpText: this.servernameHelpText, helpText: this.servernameHelpText,
allowBlank: false allowBlank: false
},{
xtype: 'textfield',
fieldLabel: this.dateFormatText,
name: 'dateFormat',
helpText: this.dateFormatHelpText,
allowBlank: false
},{ },{
xtype: 'checkbox', xtype: 'checkbox',
fieldLabel: this.enableForwardingText, fieldLabel: this.enableForwardingText,

View File

@@ -33,8 +33,12 @@
formatTimestamp: function(value){ formatTimestamp: function(value){
var result = ''; var result = '';
if ( value != null && (value > 0 ||value.length > 0)){ if ( value != null && (value > 0 || value.length > 0)){
result = Ext.util.Format.date(new Date(value), "Y-m-d H:i:s"); var df = state.clientConfig.dateFormat;
if ( df == null || df.length == 0 || ! Ext.isDefined(value) ){
df = "Y-m-d H:i:s";
}
result = Ext.util.Format.date(new Date(value), df);
} }
return result; return result;
}, },