Skip to content

Commit

Permalink
fixes error when trying to add remote to geogig repo
Browse files Browse the repository at this point in the history
  • Loading branch information
smesdaghi committed Aug 28, 2015
1 parent a6157ff commit eb7c72d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/common/addlayers/AddServerDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/common/addlayers/ServerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
70 changes: 10 additions & 60 deletions src/common/sync/RemoteService.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
var geogigService_;
var synchronizationService_;

var counter = 0;

module.provider('remoteService', function() {

this.remoteName = null;
Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -285,4 +236,3 @@
};
});
}());

29 changes: 19 additions & 10 deletions src/common/utils/Globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit eb7c72d

Please sign in to comment.