Change from manual URL construction to using a lib

Makes the code cleaner to read and more resilient to changes

Fixes https://jira.coreos.com/browse/QUAY-940
This commit is contained in:
Joseph Schorr 2018-05-22 13:09:48 -04:00
parent e33760fcd2
commit 648590c356
13 changed files with 85 additions and 56 deletions

View file

@ -1,3 +1,23 @@
var urlParseURL = require('url-parse');
var UrlBuilder = function(initial_url) {
this.url = urlParseURL(initial_url || '', '/');
};
UrlBuilder.prototype.setQueryParameter = function(paramName, paramValue) {
if (paramValue == null) {
return;
}
this.url.query = this.url.query || {};
this.url.query[paramName] = paramValue;
};
UrlBuilder.prototype.toString = function() {
return this.url.toString();
};
/**
* Service which exposes various utility methods.
*/
@ -98,19 +118,23 @@ angular.module('quay').factory('UtilService', ['$sanitize', 'markdownConverter',
};
utilService.getRestUrl = function(args) {
var url = '';
var path = '';
for (var i = 0; i < arguments.length; ++i) {
if (i > 0) {
url += '/';
path += '/';
}
url += encodeURI(arguments[i])
path += encodeURI(arguments[i])
}
return url;
return new UrlBuilder(path);
};
utilService.textToSafeHtml = function(text) {
return $sanitize(utilService.escapeHtmlString(text));
};
utilService.UrlBuilder = UrlBuilder;
return utilService;
}]);