From 0f18a4a94d687b21f5d8c15e4c63e51dc27859b0 Mon Sep 17 00:00:00 2001 From: Victor Castell Date: Mon, 16 Nov 2015 22:53:49 +0100 Subject: [PATCH] API & UI relative paths This allows to work behind a http proxy --- dkron/dashboard.go | 5 ++++- static/js/dashboard.js | 12 ++++++------ templates/dashboard.html.tmpl | 30 +++++++++++++++++------------- templates/index.html.tmpl | 4 ---- templates/jobs.html.tmpl | 2 +- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/dkron/dashboard.go b/dkron/dashboard.go index 0b83df260..3107dd43c 100644 --- a/dkron/dashboard.go +++ b/dkron/dashboard.go @@ -12,6 +12,7 @@ import ( const ( tmplPath = "templates" dashboardPathPrefix = "dashboard" + apiPathPrefix = "v1" ) type commonDashboardData struct { @@ -20,6 +21,7 @@ type commonDashboardData struct { MemberName string Backend string Path string + APIPath string } func newCommonDashboardData(a *AgentCommand, nodeName, path string) *commonDashboardData { @@ -29,7 +31,8 @@ func newCommonDashboardData(a *AgentCommand, nodeName, path string) *commonDashb LeaderName: l.Name, MemberName: nodeName, Backend: a.config.Backend, - Path: fmt.Sprintf("%s/%s", dashboardPathPrefix, path), + Path: fmt.Sprintf("%s%s", path, dashboardPathPrefix), + APIPath: fmt.Sprintf("%s%s", path, apiPathPrefix), } } diff --git a/static/js/dashboard.js b/static/js/dashboard.js index 0d7fa48e0..8399eeb44 100644 --- a/static/js/dashboard.js +++ b/static/js/dashboard.js @@ -2,18 +2,18 @@ var dkron = angular.module('dkron', ['angular-rickshaw']); dkron.controller('JobListCtrl', function ($scope, $http, $interval) { $scope.click = function(jobName) { - var response = $http.put('/v1/jobs/' + jobName); + var response = $http.put(DKRON_API_PATH + '/jobs/' + jobName); response.success(function(data, status, headers, config) { - $('#message').html('
Success running jo ' + jobName + '
'); + $('#message').html('
Success running job ' + jobName + '
'); }); response.error(function(data, status, headers, config) { - $('#message').html('
Error running jo ' + jobName + '
'); + $('#message').html('
Error running job ' + jobName + '
'); }); }; var updateView = function() { - var response = $http.get('/v1/jobs/'); + var response = $http.get(DKRON_API_PATH + '/jobs'); response.success(function(data, status, headers, config) { $scope.updateStatus(data); }); @@ -97,7 +97,7 @@ dkron.controller('IndexCtrl', function ($scope, $http, $interval, $element) { }; updateView = function() { - var response = $http.get('/v1/jobs/'); + var response = $http.get(DKRON_API_PATH + '/jobs'); response.success(function(data, status, headers, config) { $scope.updateGraph(data); }); @@ -106,7 +106,7 @@ dkron.controller('IndexCtrl', function ($scope, $http, $interval, $element) { $('#message').html('
Error getting data
'); }); - var mq = $http.get('/v1/members/'); + var mq = $http.get(DKRON_API_PATH + '/members'); mq.success(function(data, status, headers, config) { $scope.members = data; }); diff --git a/templates/dashboard.html.tmpl b/templates/dashboard.html.tmpl index 50989c15d..0bc6c0b7f 100644 --- a/templates/dashboard.html.tmpl +++ b/templates/dashboard.html.tmpl @@ -3,22 +3,26 @@ Dkron - - - + + + - - - + + + - - + + - + - - - + + + + + @@ -51,7 +55,7 @@
  • - + Jobs diff --git a/templates/index.html.tmpl b/templates/index.html.tmpl index e579fd185..05b38f1bf 100644 --- a/templates/index.html.tmpl +++ b/templates/index.html.tmpl @@ -35,9 +35,5 @@ - -
    -

    Backend: {{ .Common.Backend }}

    -
    {{end}} diff --git a/templates/jobs.html.tmpl b/templates/jobs.html.tmpl index 0d2bdb644..1a35cdcd0 100644 --- a/templates/jobs.html.tmpl +++ b/templates/jobs.html.tmpl @@ -12,7 +12,7 @@ {{ range $job := .Jobs }} - {{ $job.Name }} + {{ $job.Name }} {{ $job.SuccessCount }} {{ $job.ErrorCount }}