Commit 9be53f0a by Torkel Ödegaard

Updates to support sub url

parent 5feed234
......@@ -25,7 +25,8 @@ function (_, crypto) {
playlist_timespan : "1m",
unsaved_changes_warning : true,
search : { max_results: 100 },
admin : {}
admin : {},
appSubUrl: ""
};
// This initializes a new hash on purpose, to avoid adding parameters to
......
......@@ -16,6 +16,7 @@ function (angular, config, _, $, store) {
$rootScope.profilingEnabled = store.getBool('profilingEnabled');
$rootScope.performance = { loadStart: new Date().getTime() };
$rootScope.appSubUrl = config.appSubUrl;
$scope.init = function() {
$scope._ = _;
......
define([
'angular',
'config',
],
function (angular) {
function (angular, config) {
'use strict';
var module = angular.module('grafana.controllers');
module.controller('LoginCtrl', function($scope, $http, $location, $routeParams, alertSrv) {
module.controller('LoginCtrl', function($scope, backendSrv, $location, $routeParams, alertSrv) {
$scope.loginModel = {};
$scope.grafana.sidemenu = false;
......@@ -17,14 +18,10 @@ function (angular) {
};
$scope.logout = function() {
$http.post('/logout').then(function() {
backendSrv.post('/logout').then(function() {
alertSrv.set('Logged out!', '', 'success', 3000);
$scope.appEvent('logged-out');
$location.search({});
}, function() {
alertSrv.set('Logout failed:', 'Unexpected error', 'error', 3000);
});
};
......@@ -35,16 +32,9 @@ function (angular) {
return;
}
$http.post('/login', $scope.loginModel).then(function(results) {
$scope.appEvent('logged-in', results.data.user);
window.location.href = '/';
}, function(err) {
if (err.status === 401) {
$scope.loginError = "Username or password is incorrect";
}
else {
$scope.loginError = "Unexpected error";
}
backendSrv.post('/login', $scope.loginModel).then(function(results) {
$scope.appEvent('logged-in', results.user);
window.location.href = config.appSubUrl + '/';
});
};
......
......@@ -8,11 +8,11 @@
<li><a href="/login?logout">Logout</a></li>
</ul>
</div>
<a class="pro-sidemenu-link" href="/">
<a class="pro-sidemenu-link" ng-href="{{appSubUrl}}">
<i class="icon-th-large"></i>
Dashboards
</a>
<a class="pro-sidemenu-link" href="/charts">
<a class="pro-sidemenu-link" href="charts">
<i class="icon-signal"></i>
Graphs
</a>
......@@ -20,19 +20,19 @@
<i class="icon-bolt" style="padding-right: 23px"></i>
Alerts
</a>
<a class="pro-sidemenu-link" href="/admin/datasources">
<a class="pro-sidemenu-link" href="admin/datasources">
<i class="icon-sitemap"></i>
Data sources
</a>
<a class="pro-sidemenu-link" href="/admin">
<a class="pro-sidemenu-link" href="admin">
<i class="icon-tasks"></i>
Global options
</a>
<a class="pro-sidemenu-link" href="/account">
<a class="pro-sidemenu-link" href="account">
<i class="icon-user"></i>
Account settings
</a>
<a class="pro-sidemenu-link" href="/login?logout">
<a class="pro-sidemenu-link" href="login?logout">
<i class="icon-signout"></i>
Sign out
</a>
......
......@@ -12,17 +12,17 @@ function (angular, store) {
$routeProvider
.when('/', {
templateUrl: '/app/partials/dashboard.html',
templateUrl: 'app/partials/dashboard.html',
controller : 'DashFromDBProvider',
reloadOnSearch: false,
})
.when('/dashboard/db/:id', {
templateUrl: '/app/partials/dashboard.html',
templateUrl: 'app/partials/dashboard.html',
controller : 'DashFromDBProvider',
reloadOnSearch: false,
})
.when('/dashboard/temp/:id', {
templateUrl: '/app/partials/dashboard.html',
templateUrl: 'app/partials/dashboard.html',
controller : 'DashFromDBProvider',
reloadOnSearch: false,
})
......
define([
'angular',
'lodash',
'config',
],
function (angular, _) {
function (angular, _, config) {
'use strict';
var module = angular.module('grafana.services');
......@@ -27,7 +28,7 @@ function (angular, _) {
this.request = function(options) {
var httpOptions = {
url: options.url,
url: config.appSubUrl + options.url,
method: options.method,
data: options.data
};
......
......@@ -7,7 +7,7 @@ function (angular, _) {
var module = angular.module('grafana.services');
module.factory('GrafanaDatasource', function($q, $http) {
module.factory('GrafanaDatasource', function($q, backendSrv) {
function GrafanaDatasource() {
this.type = 'grafana';
......@@ -21,19 +21,13 @@ function (angular, _) {
url = '/temp/' + id;
}
return $http.get('/api/dashboards/' + id)
.then(function(result) {
if (result.data) {
return angular.fromJson(result.data);
return backendSrv.get('/api/dashboards/' + id)
.then(function(data) {
if (data) {
return angular.fromJson(data);
} else {
return false;
}
}, function(data) {
if(data.status === 0) {
throw "Could not contact Elasticsearch. Please ensure that Elasticsearch is reachable from your browser.";
} else {
throw "Could not find dashboard " + id;
}
});
};
......@@ -43,34 +37,28 @@ function (angular, _) {
dashboard.id = null;
}
return $http.post('/api/dashboard/', { dashboard: dashboard })
.then(function(result) {
return { title: dashboard.title, url: '/dashboard/db/' + result.data.slug };
}, function(data) {
throw "Failed to search: " + data;
return backendSrv.post('/api/dashboard/', { dashboard: dashboard })
.then(function(data) {
return { title: dashboard.title, url: '/dashboard/db/' + data.slug };
});
};
GrafanaDatasource.prototype.deleteDashboard = function(id) {
return $http({ method: 'DELETE', url: '/api/dashboard/' + id })
.then(function(result) {
return result.data.title;
}, function(err) {
throw err.data;
return backendSrv.delete('/api/dashboard/' + id)
.then(function(data) {
return data.title;
});
};
GrafanaDatasource.prototype.searchDashboards = function(query) {
return $http.get('/api/search/', { params: { q: query } })
.then(function(results) {
return backendSrv.get('/api/search/', { params: { q: query } })
.then(function(data) {
var hits = { dashboards: [], tags: [] };
hits.dashboards = _.map(results.data, function(item) {
hits.dashboards = _.map(data, function(item) {
item.id = item.slug;
return item;
});
return hits;
}, function(data) {
throw "Failed to search: " + data;
});
};
......
......@@ -52,7 +52,7 @@
<script>
window.grafanaBootData = {
user:[[.User]],
settings: [[.Settings]]
settings: [[.Settings]],
};
</script>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment