diff --git a/src/common/addlayers/AddServerDirective.js b/src/common/addlayers/AddServerDirective.js index 9b65432b..1bb24350 100644 --- a/src/common/addlayers/AddServerDirective.js +++ b/src/common/addlayers/AddServerDirective.js @@ -104,7 +104,7 @@ scope.server.authentication = $.base64.encode(credentials.username + ':' + credentials.password); - var serverBaseUrl = removeUrlLastRoute(scope.server.url); + var serverBaseUrl = urlRemoveLastRoute(scope.server.url); var serverAuthenticationUrl = serverBaseUrl + '/rest/settings.json'; serverAuthenticationUrl = serverAuthenticationUrl.replace('http://', 'http://null:null@'); ignoreNextScriptError = true; diff --git a/src/common/addlayers/ServerService.js b/src/common/addlayers/ServerService.js index 1ad5f7f7..9b3c38bc 100644 --- a/src/common/addlayers/ServerService.js +++ b/src/common/addlayers/ServerService.js @@ -201,7 +201,7 @@ var SERVER_SERVICE_USE_PROXY = true; server.config.alwaysAnonymous = false; // remove the 'wms endpoint' - var serverBaseUrl = removeUrlLastRoute(server.url); + var serverBaseUrl = urlRemoveLastRoute(server.url); var serverAuthenticationUrl = serverBaseUrl + '/rest/settings.json'; serverAuthenticationUrl = serverAuthenticationUrl.replace('http://', 'http://null:null@'); ignoreNextScriptError = true; @@ -314,7 +314,7 @@ var SERVER_SERVICE_USE_PROXY = true; server.config.alwaysAnonymous = false; // remove the 'wms endpoint' - var serverBaseUrl = removeUrlLastRoute(server.url); + var serverBaseUrl = urlRemoveLastRoute(server.url); var serverAuthenticationUrl = serverBaseUrl + '/rest/settings.json'; serverAuthenticationUrl = serverAuthenticationUrl.replace('http://', 'http://null:null@'); ignoreNextScriptError = true; diff --git a/src/common/sync/RemoteService.js b/src/common/sync/RemoteService.js index 6e8d50e3..26d816c9 100644 --- a/src/common/sync/RemoteService.js +++ b/src/common/sync/RemoteService.js @@ -10,8 +10,6 @@ var geogigService_; var synchronizationService_; - var counter = 0; - module.provider('remoteService', function() { this.remoteName = null; @@ -23,7 +21,6 @@ this.selectedText = ''; this.editing = false; this.verificationResult = null; - this.compatibleRepos = []; this.selectedRepoInitialCommit = null; this.$get = function($rootScope, $http, $q, $translate, dialogService, geogigService, synchronizationService) { @@ -46,7 +43,6 @@ service_.remoteURL = null; service_.remoteUsername = ''; service_.remotePassword = ''; - service_.compatibleRepos = []; if (goog.isDefAndNotNull(service_.selectedRemote)) { service_.remoteName = service_.selectedRemote.name; service_.remoteURL = service_.selectedRemote.url; @@ -78,19 +74,6 @@ }); }; - var multipleCompatibleRepos = function() { - counter--; - if (counter === 0) { - if (service_.compatibleRepos.length > 1) { - $('#remoteSelectDialog').modal('toggle'); - } else if (service_.compatibleRepos.length < 1) { - service_.verificationResult.reject(translate_.instant('no_compatible_repos')); - } else { - service_.verificationResult.resolve(service_.compatibleRepos[0]); - } - } - }; - this.reset = function() { this.selectedRepo = null; this.selectedRepoInitialCommit = null; @@ -164,7 +147,6 @@ if (!service_.editing) { resetForm(); } else { - service_.compatibleRepos = []; service_.selectedRemote.name = service_.remoteName; service_.selectedRemote.url = service_.remoteURL; service_.selectedRemote.username = service_.remoteUsername; @@ -210,55 +192,24 @@ options.newName = service_.remoteName; options.remoteName = service_.selectedRemote.name; } - var protocol = service_.remoteURL.substr(0, service_.remoteURL.indexOf('://') + '://'.length); - var url = service_.remoteURL.substr(protocol.length); - var index = url.lastIndexOf('/') + 1; - if (index === url.length) { - url = url.slice(0, url.length - 1); - index = url.lastIndexOf('/') + 1; - } - var splitinfo = []; - if (index > 0) { - var info = url.slice(index); - splitinfo = info.split(':'); - if (splitinfo.length > 1) { - console.log(splitinfo); - var temp = encodeURIComponent(encodeURIComponent(splitinfo[0])) + ':' + - encodeURIComponent(encodeURIComponent(splitinfo[1])); - url = url.replace(info, temp); - } - } - url = protocol + url; - var extraPath = ''; - if (splitinfo[0] === 'geoserver') { - extraPath = '/geogig'; - } else if (splitinfo[0] !== 'geogig') { - extraPath = '/geoserver/geogig'; - } + var url = urlRemoveTrailingSlash(service_.remoteURL); service_.verificationResult = q_.defer(); var config = {headers: {'Accept': 'text/json'}}; if (goog.isDefAndNotNull(service_.remoteUsername)) { config.headers['Authorization'] = 'Basic ' + $.base64.encode(service_.remoteUsername + ':' + service_.remotePassword); } - http_.get(url + extraPath, config).then(function(response) { - if (!goog.isDefAndNotNull(response.data.repositories)) { + http_.get(url + '.json', config).then(function(response) { + if (!goog.isDefAndNotNull(response.data.repository)) { checkCompatiblity(url, service_.verificationResult); } else { - counter = response.data.repositories.length; - var successFunc = function(url) { - service_.compatibleRepos.push(url); - multipleCompatibleRepos(); - }; - var rejectFunc = function() { - multipleCompatibleRepos(); - }; - for (var index = 0; index < response.data.repositories.length; index++) { - var repo = response.data.repositories[index]; - var compatibilityResult = q_.defer(); - checkCompatiblity(url + extraPath + '/' + repo, compatibilityResult); - compatibilityResult.promise.then(successFunc, rejectFunc); - } + var compatibilityResult = q_.defer(); + checkCompatiblity(url, compatibilityResult); + compatibilityResult.promise.then(function(url) { + service_.verificationResult.resolve(url); + }, function() { + service_.verificationResult.reject(translate_.instant('no_compatible_repos')); + }); } }, function(error) { // There was a problem connecting to the endpoint @@ -285,4 +236,3 @@ }; }); }()); - diff --git a/src/common/utils/Globals.js b/src/common/utils/Globals.js index 4324d19c..ba11299d 100644 --- a/src/common/utils/Globals.js +++ b/src/common/utils/Globals.js @@ -262,18 +262,27 @@ var sha1 = function(msg) { }; -// give http://myip/geoserver/wms, ir will return http://myip/geoserver +// given http://myip/geoserver/wms, it will return http://myip/geoserver // it handles extra slash at the end of the url if it has one -var removeUrlLastRoute = function(urlWithRoutes) { - var newUrl = null; - - if (goog.isDefAndNotNull(urlWithRoutes)) { - if (urlWithRoutes.lastIndexOf('/') === urlWithRoutes.length - 1) { - urlWithRoutes = urlWithRoutes.substring(0, urlWithRoutes.lastIndexOf('/')); +var urlRemoveLastRoute = function(url) { + url = urlRemoveTrailingSlash(url); + if (goog.isDefAndNotNull(url)) { + if (url.lastIndexOf('/') === url.length - 1) { + url = url.substring(0, url.lastIndexOf('/')); } - - newUrl = urlWithRoutes.substring(0, urlWithRoutes.lastIndexOf('/')); + return url.substring(0, url.lastIndexOf('/')); } + return url; +}; - return newUrl; +// given http://myip/geoserver/, it will return http://myip/geoserver +// if doesn't have training slash, it will return the url as it was passed in +var urlRemoveTrailingSlash = function(url) { + if (goog.isDefAndNotNull(url)) { + if (url.lastIndexOf('/') === url.length - 1) { + url = url.substring(0, url.lastIndexOf('/')); + } + } + return url; }; +