Merge branch 'preferences' of github.com:grafana/grafana into preferences

This commit is contained in:
Torkel Ödegaard
2016-03-15 22:15:27 +01:00
7 changed files with 86 additions and 38 deletions

View File

@@ -7,7 +7,7 @@ import angular from 'angular';
export class DashNavCtrl {
/** @ngInject */
constructor($scope, $rootScope, alertSrv, $location, playlistSrv, backendSrv, $timeout) {
constructor($scope, $rootScope, alertSrv, $location, playlistSrv, backendSrv, contextSrv, $timeout) {
$scope.init = function() {
$scope.onAppEvent('save-dashboard', $scope.saveDashboard);
@@ -103,6 +103,26 @@ export class DashNavCtrl {
}, $scope.handleSaveDashError);
};
$scope.saveDashboardAsHome = function() {
var orgId = 'org-' + contextSrv.user.orgId;
backendSrv.get('/api/preferences').then(function(prefs) {
// Checking if the preferences already exists or not
if (prefs.userId === 0 && prefs.orgId === 0 && prefs.preference === null) {
prefs.preference = {};
}
if (prefs.preference == null) {
prefs.preference = {
home_dashboard_id: $scope.dashboard.id
};
} else {
var orgPrefs = prefs.preference;
orgPrefs.home_dashboard = $scope.dashboard.id;
}
backendSrv.put('api/preferences', prefs);
});
};
$scope.handleSaveDashError = function(err) {
if (err.data && err.data.status === "version-mismatch") {
err.isHandled = true;