plugin-manager: Use relative URL to access Gerrit base URL

The plugin-manager plugin was not working properly for setups
with a reverse-proxy with a non-root base path.

Use a relative URL for calculating the base path, so that
any reverse-proxy configuration with a non-root path can
automatically get to the main location correctly.

Rewrite of Change-Id: If382fe16 with a simplified
implementation.

Bug: Issue 13521
Change-Id: I5181098bfb2d4a27eef3b51fc8780cc8f294d1c3
diff --git a/src/main/resources/static/js/plugin-manager.js b/src/main/resources/static/js/plugin-manager.js
index 0fb97a2..d786e90 100644
--- a/src/main/resources/static/js/plugin-manager.js
+++ b/src/main/resources/static/js/plugin-manager.js
@@ -35,8 +35,19 @@
         return pluginIndex;
       }
 
+      $scope.getBaseUrl = function () {
+        // Using a relative URL for allowing to reach Gerrit base URL
+        // which could be a non-root path when behind a reverse proxy
+        // on a path location.
+        // The use of a relative URL is for allowing a flexible way
+        // to reach the root even when accessed outside the canonical web
+        // URL (e.g. accessing on node directly with the hostname instead
+        // of the FQDN)
+        return window.location.pathname + '/../../../..';
+      }
+
       $scope.refreshInstalled = function(refreshPluginId) {
-        $http.get('/plugins/?all', plugins.httpConfig).then(
+        $http.get($scope.getBaseUrl() + '/plugins/?all', plugins.httpConfig).then(
             function successCallback(response) {
 
               angular.forEach(response.data, function(plugin) {
@@ -74,7 +85,7 @@
       }
 
       $scope.refreshAvailable = function(refreshPluginId) {
-        $http.get('/plugins/plugin-manager/available', plugins.httpConfig)
+        $http.get($scope.getBaseUrl() + '/plugins/plugin-manager/available', plugins.httpConfig)
             .then(
                 function successCallback(response) {
 
@@ -118,7 +129,7 @@
         };
         $("button#" + id).addClass("hidden");
         $("span#installing-" + id).removeClass("hidden");
-        $http.put('/a/plugins/' + id + ".jar", pluginInstallData).then(
+        $http.put($scope.getBaseUrl() + '/a/plugins/' + id + ".jar", pluginInstallData).then(
             function successCallback(response) {
               $("span#installing-" + id).addClass("hidden");
               $("span#installed-" + id).removeClass("hidden");