From 51180099bc9dcd503faf34e0daca9aeb48815654 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Thu, 1 Dec 2011 20:15:55 +0100 Subject: [PATCH] implement links for sub repositories --- .../sonia.repository.repositorybrowser.js | 59 +++++++++++++++---- .../webapp/resources/js/util/sonia.util.js | 27 +++++++++ 2 files changed, 76 insertions(+), 10 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.repositorybrowser.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.repositorybrowser.js index 7ffc9a0613..684c030968 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.repositorybrowser.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.repositorybrowser.js @@ -185,10 +185,8 @@ Sonia.repository.RepositoryBrowser = Ext.extend(Ext.grid.GridPanel, { if ( index > 0 ){ var prefix = rel.substring(0, index); var path = rel.substring(index + 1); - - console.debug( path ); - - if ( prefix == 'subrepo' ){ + + if ( prefix == 'sub' ){ this.openSubRepository(path); } else if ( prefix == 'dir' ){ this.changeDirectory(path); @@ -203,6 +201,21 @@ Sonia.repository.RepositoryBrowser = Ext.extend(Ext.grid.GridPanel, { if (debug){ console.debug('open sub repository ' + subRepository); } + var id = 'repositoryBrowser;' + subRepository + ';null;null'; + Sonia.repository.get(subRepository, function(repository){ + var panel = Ext.getCmp(id); + if (! panel){ + panel = { + id: id, + xtype: 'repositoryBrowser', + repository : repository, + revision: null, + closable: true, + autoScroll: true + } + } + main.addTab(panel); + }); }, appendRepositoryProperties: function(bar){ @@ -298,18 +311,44 @@ Sonia.repository.RepositoryBrowser = Ext.extend(Ext.grid.GridPanel, { bbar.doLayout(); }, + getRepositoryPath: function(url){ + var ctxPath = Sonia.util.getContextPath(); + var i = url.indexOf(ctxPath); + if ( i > 0 ){ + url = url.substring( i + ctxPath.length ); + } + if ( url.indexOf('/') == 0 ){ + url = url.substring(1); + } + return url; + }, + + transformLink: function(url){ + var link = null; + var server = Sonia.util.getServername(url); + if ( server == window.location.hostname || server == 'localhost' ){ + var repositoryPath = this.getRepositoryPath( url ); + if (repositoryPath){ + link = 'sub:' + repositoryPath; + } + } + return link; + }, + renderName: function(name, p, record){ var subRepository = record.get('subRepositoryUrl'); var folder = record.get('directory'); var path = null; var template = null; if ( subRepository ){ - // path = 'subrepo:' + subRepository; - // TODO check for internal link - - // internal - path = subRepository; - template = this.templateExternalLink; + // get real revision (.hgsubstate)? + path = this.transformLink(subRepository); + if ( path ){ + template = this.templateInternalLink; + } else { + path = subRepository; + template = this.templateExternalLink; + } } else { if (folder){ path = 'dir:'; diff --git a/scm-webapp/src/main/webapp/resources/js/util/sonia.util.js b/scm-webapp/src/main/webapp/resources/js/util/sonia.util.js index cce8a1e3fc..5c56feaeb5 100644 --- a/scm-webapp/src/main/webapp/resources/js/util/sonia.util.js +++ b/scm-webapp/src/main/webapp/resources/js/util/sonia.util.js @@ -32,6 +32,33 @@ Ext.ns('Sonia.util'); // functions + +Sonia.util.getServername = function(url){ + var i = url.indexOf('://'); + if ( i > 0 ){ + url = url.substring(i+3); + i = url.indexOf(':'); + if ( i <= 0 ){ + i = url.indexof('/'); + } + if ( i > 0 ){ + url = url.substring(0, i); + } + } + return url; +} + +Sonia.util.getContextPath = function(){ + var path = window.location.pathname; + if ( path.indexOf('.html') > 0 ){ + var i = path.lastIndexOf('/'); + if ( i > 0 ){ + path = path.substring(0, i); + } + } + return path; +} + Sonia.util.getName = function(path){ var name = path; var index = path.lastIndexOf('/');