mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-19 22:12:10 +01:00
merge with branch issue-156
This commit is contained in:
@@ -170,7 +170,7 @@ public class CreateRepositorySubCommand extends TemplateSubCommand
|
||||
|
||||
Map<String, Object> env = new HashMap<String, Object>();
|
||||
|
||||
env.put("repository", new RepositoryWrapper(repository));
|
||||
env.put("repository", new RepositoryWrapper(config, repository));
|
||||
renderTemplate(env, GetRepositorySubCommand.TEMPLATE);
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ public class GetRepositorySubCommand extends TemplateSubCommand
|
||||
{
|
||||
Map<String, Object> env = new HashMap<String, Object>();
|
||||
|
||||
env.put("repository", new RepositoryWrapper(repository));
|
||||
env.put("repository", new RepositoryWrapper(config, repository));
|
||||
renderTemplate(env, TEMPLATE);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -74,7 +74,7 @@ public class ListRepositoriesSubCommand extends TemplateSubCommand
|
||||
List<Repository> repositories = session.getRepositoryHandler().getAll();
|
||||
Map<String, Object> env = new HashMap<String, Object>();
|
||||
|
||||
env.put("repositories", WrapperUtil.wrapRepositories(repositories));
|
||||
env.put("repositories", WrapperUtil.wrapRepositories(config, repositories));
|
||||
renderTemplate(env, TEMPLATE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ public class ModifyRepositorySubCommand extends TemplateSubCommand
|
||||
|
||||
Map<String, Object> env = new HashMap<String, Object>();
|
||||
|
||||
env.put("repository", new RepositoryWrapper(repository));
|
||||
env.put("repository", new RepositoryWrapper(config, repository));
|
||||
renderTemplate(env, GetRepositorySubCommand.TEMPLATE);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -120,7 +120,7 @@ public abstract class PermissionSubCommand extends TemplateSubCommand
|
||||
|
||||
Map<String, Object> env = new HashMap<String, Object>();
|
||||
|
||||
env.put("repository", new RepositoryWrapper(repository));
|
||||
env.put("repository", new RepositoryWrapper(config, repository));
|
||||
renderTemplate(env, GetRepositorySubCommand.TEMPLATE);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -35,6 +35,7 @@ package sonia.scm.cli.wrapper;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.cli.config.ServerConfig;
|
||||
import sonia.scm.repository.Permission;
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
@@ -54,10 +55,25 @@ public class RepositoryWrapper extends AbstractWrapper
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param config
|
||||
* @param repository
|
||||
*/
|
||||
public RepositoryWrapper(Repository repository)
|
||||
public RepositoryWrapper(ServerConfig config, Repository repository)
|
||||
{
|
||||
this(config.getServerUrl(), repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param baseUrl
|
||||
* @param repository
|
||||
*/
|
||||
public RepositoryWrapper(String baseUrl, Repository repository)
|
||||
{
|
||||
this.baseUrl = baseUrl;
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@@ -159,7 +175,7 @@ public class RepositoryWrapper extends AbstractWrapper
|
||||
*/
|
||||
public String getUrl()
|
||||
{
|
||||
return repository.getUrl();
|
||||
return repository.createUrl(baseUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,6 +202,9 @@ public class RepositoryWrapper extends AbstractWrapper
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private String baseUrl;
|
||||
|
||||
/** Field description */
|
||||
private Repository repository;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ package sonia.scm.cli.wrapper;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.cli.config.ServerConfig;
|
||||
import sonia.scm.group.Group;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.user.User;
|
||||
@@ -76,18 +77,22 @@ public class WrapperUtil
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param baseUrl
|
||||
*
|
||||
* @param config
|
||||
* @param repositories
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static List<RepositoryWrapper> wrapRepositories(
|
||||
public static List<RepositoryWrapper> wrapRepositories(ServerConfig config,
|
||||
Collection<Repository> repositories)
|
||||
{
|
||||
List<RepositoryWrapper> wrappers = new ArrayList<RepositoryWrapper>();
|
||||
|
||||
for (Repository r : repositories)
|
||||
{
|
||||
wrappers.add(new RepositoryWrapper(r));
|
||||
wrappers.add(new RepositoryWrapper(config.getServerUrl(), r));
|
||||
}
|
||||
|
||||
return wrappers;
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.google.common.base.Objects;
|
||||
|
||||
import sonia.scm.BasicPropertiesAware;
|
||||
import sonia.scm.ModelObject;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.util.Util;
|
||||
import sonia.scm.util.ValidationUtil;
|
||||
|
||||
@@ -164,6 +165,22 @@ public class Repository extends BasicPropertiesAware implements ModelObject
|
||||
repository.setArchived(archived);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the url of the repository.
|
||||
*
|
||||
*
|
||||
* @param baseUrl base url of the server including the context path
|
||||
*
|
||||
* @return url of the repository
|
||||
* @since 1.17
|
||||
*/
|
||||
public String createUrl(String baseUrl)
|
||||
{
|
||||
String url = HttpUtil.append(baseUrl, type);
|
||||
|
||||
return HttpUtil.append(url, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the {@link Repository} is the same as the obj argument.
|
||||
*
|
||||
@@ -343,7 +360,9 @@ public class Repository extends BasicPropertiesAware implements ModelObject
|
||||
*
|
||||
*
|
||||
* @return base url
|
||||
* @deprecated use {@link #createUrl(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public String getUrl()
|
||||
{
|
||||
return url;
|
||||
@@ -511,7 +530,9 @@ public class Repository extends BasicPropertiesAware implements ModelObject
|
||||
*
|
||||
*
|
||||
* @param url base url
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public void setUrl(String url)
|
||||
{
|
||||
this.url = url;
|
||||
@@ -550,6 +571,8 @@ public class Repository extends BasicPropertiesAware implements ModelObject
|
||||
/** Field description */
|
||||
private String type;
|
||||
|
||||
/** Field description */
|
||||
/**
|
||||
* @deprecated use {@link #createUrl(java.lang.String)} instead
|
||||
*/
|
||||
private String url;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* 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.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class RepositoryTest
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCreateUrl()
|
||||
{
|
||||
Repository repository = new Repository("123", "hg", "test/repo");
|
||||
|
||||
assertEquals("http://localhost:8080/scm/hg/test/repo",
|
||||
repository.createUrl("http://localhost:8080/scm"));
|
||||
assertEquals("http://localhost:8080/scm/hg/test/repo",
|
||||
repository.createUrl("http://localhost:8080/scm/"));
|
||||
}
|
||||
}
|
||||
@@ -86,8 +86,6 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, {
|
||||
name: 'description'
|
||||
},{
|
||||
name: 'creationDate'
|
||||
},{
|
||||
name:'url'
|
||||
},{
|
||||
name: 'public'
|
||||
},{
|
||||
@@ -150,8 +148,9 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, {
|
||||
},{
|
||||
id: 'Url',
|
||||
header: this.colUrlText,
|
||||
dataIndex: 'url',
|
||||
renderer: this.renderUrl,
|
||||
dataIndex: 'name',
|
||||
renderer: this.renderRepositoryUrl,
|
||||
scope: this,
|
||||
width: 250
|
||||
},{
|
||||
id: 'Archive',
|
||||
@@ -219,6 +218,13 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, {
|
||||
}
|
||||
},
|
||||
|
||||
renderRepositoryUrl: function(name, meta, record){
|
||||
var type = record.get('type');
|
||||
return this.renderUrl(
|
||||
Sonia.repository.createUrl(type, name)
|
||||
);
|
||||
},
|
||||
|
||||
renderArchive: function(v){
|
||||
return v ? '<img src=' + this.archiveIcon + ' alt=' + v + '>' : '';
|
||||
},
|
||||
|
||||
@@ -74,7 +74,7 @@ Sonia.repository.InfoPanel = Ext.extend(Ext.Panel, {
|
||||
text: this.urlText
|
||||
},{
|
||||
xtype: 'box',
|
||||
html: String.format(this.linkTemplate, this.item.url)
|
||||
html: String.format(this.linkTemplate, Sonia.repository.createUrlFromObject(this.item))
|
||||
}];
|
||||
|
||||
var config = {
|
||||
@@ -105,7 +105,7 @@ Sonia.repository.InfoPanel = Ext.extend(Ext.Panel, {
|
||||
},
|
||||
|
||||
getRepositoryUrlWithUsername: function(){
|
||||
var uri = this.item.url;
|
||||
var uri = Sonia.repository.createUrlFromObject(this.item);
|
||||
if ( state.user.name != 'anonymous' ){
|
||||
var index = uri.indexOf("://");
|
||||
if ( index > 0 ){
|
||||
|
||||
@@ -78,6 +78,16 @@ Sonia.repository.setEditPanel = function(panels){
|
||||
editPanel.doLayout();
|
||||
}
|
||||
|
||||
Sonia.repository.createUrl = function(type, name){
|
||||
return Sonia.util.getBaseUrl() + '/' + type + '/' + name
|
||||
}
|
||||
|
||||
Sonia.repository.createUrlFromObject = function(repository){
|
||||
var url = Sonia.repository.createUrl(repository.type, repository.name);
|
||||
console.debug(url);
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* default panel
|
||||
*/
|
||||
|
||||
@@ -59,6 +59,21 @@ Sonia.util.getContextPath = function(){
|
||||
return path;
|
||||
}
|
||||
|
||||
Sonia.util.getBaseUrl = function(){
|
||||
var url = location.href;
|
||||
var i = url.indexOf('#');
|
||||
if ( i > 0 ){
|
||||
url = url.substring(0, i);
|
||||
}
|
||||
|
||||
if ( url.endsWith('/index.html') ){
|
||||
url = url.substring(0, url.length - '/index.html'.length);
|
||||
} else if ( url.endsWith('/') ){
|
||||
url = url.substring(0, url.length -1);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
Sonia.util.getName = function(path){
|
||||
var name = path;
|
||||
var index = path.lastIndexOf('/');
|
||||
|
||||
Reference in New Issue
Block a user