mirror of https://github.com/grafana/grafana
Dashboard: When saving a dashboard and another user has made changes inbetween, the user is promted with a warning if he really wants to overwrite the other's changes, Closes #718
parent
56c83cefe9
commit
04d25dc58a
@ -0,0 +1,116 @@ |
||||
define([ |
||||
'angular', |
||||
'./dashLoadControllers', |
||||
], function(angular) { |
||||
"use strict"; |
||||
|
||||
var module = angular.module('grafana.routes'); |
||||
|
||||
module.config(function($routeProvider, $locationProvider) { |
||||
$locationProvider.html5Mode(true); |
||||
|
||||
$routeProvider |
||||
.when('/', { |
||||
templateUrl: 'app/partials/dashboard.html', |
||||
controller : 'DashFromDBCtrl', |
||||
reloadOnSearch: false, |
||||
}) |
||||
.when('/dashboard/db/:slug', { |
||||
templateUrl: 'app/partials/dashboard.html', |
||||
controller : 'DashFromDBCtrl', |
||||
reloadOnSearch: false, |
||||
}) |
||||
.when('/dashboard/file/:jsonFile', { |
||||
templateUrl: 'app/partials/dashboard.html', |
||||
controller : 'DashFromFileCtrl', |
||||
reloadOnSearch: false, |
||||
}) |
||||
.when('/dashboard/script/:jsFile', { |
||||
templateUrl: 'app/partials/dashboard.html', |
||||
controller : 'DashFromScriptCtrl', |
||||
reloadOnSearch: false, |
||||
}) |
||||
.when('/dashboard/import/:file', { |
||||
templateUrl: 'app/partials/dashboard.html', |
||||
controller : 'DashFromImportCtrl', |
||||
reloadOnSearch: false, |
||||
}) |
||||
.when('/dashboard/new', { |
||||
templateUrl: 'app/partials/dashboard.html', |
||||
controller : 'NewDashboardCtrl', |
||||
reloadOnSearch: false, |
||||
}) |
||||
.when('/dashboard/import', { |
||||
templateUrl: 'app/features/dashboard/partials/import.html', |
||||
controller : 'DashboardImportCtrl', |
||||
}) |
||||
.when('/datasources', { |
||||
templateUrl: 'app/features/org/partials/datasources.html', |
||||
controller : 'DataSourcesCtrl', |
||||
}) |
||||
.when('/datasources/edit/:id', { |
||||
templateUrl: 'app/features/org/partials/datasourceEdit.html', |
||||
controller : 'DataSourceEditCtrl', |
||||
}) |
||||
.when('/datasources/new', { |
||||
templateUrl: 'app/features/org/partials/datasourceEdit.html', |
||||
controller : 'DataSourceEditCtrl', |
||||
}) |
||||
.when('/org', { |
||||
templateUrl: 'app/features/org/partials/orgDetails.html', |
||||
controller : 'OrgDetailsCtrl', |
||||
}) |
||||
.when('/org/new', { |
||||
templateUrl: 'app/features/org/partials/newOrg.html', |
||||
controller : 'NewOrgCtrl', |
||||
}) |
||||
.when('/org/users', { |
||||
templateUrl: 'app/features/org/partials/orgUsers.html', |
||||
controller : 'OrgUsersCtrl', |
||||
}) |
||||
.when('/org/apikeys', { |
||||
templateUrl: 'app/features/org/partials/orgApiKeys.html', |
||||
controller : 'OrgApiKeysCtrl', |
||||
}) |
||||
.when('/profile', { |
||||
templateUrl: 'app/features/profile/partials/profile.html', |
||||
controller : 'ProfileCtrl', |
||||
}) |
||||
.when('/profile/password', { |
||||
templateUrl: 'app/features/profile/partials/password.html', |
||||
controller : 'ChangePasswordCtrl', |
||||
}) |
||||
.when('/admin/settings', { |
||||
templateUrl: 'app/features/admin/partials/settings.html', |
||||
controller : 'AdminSettingsCtrl', |
||||
}) |
||||
.when('/admin/users', { |
||||
templateUrl: 'app/features/admin/partials/users.html', |
||||
controller : 'AdminUsersCtrl', |
||||
}) |
||||
.when('/admin/users/create', { |
||||
templateUrl: 'app/features/admin/partials/new_user.html', |
||||
controller : 'AdminEditUserCtrl', |
||||
}) |
||||
.when('/admin/users/edit/:id', { |
||||
templateUrl: 'app/features/admin/partials/edit_user.html', |
||||
controller : 'AdminEditUserCtrl', |
||||
}) |
||||
.when('/admin/orgs', { |
||||
templateUrl: 'app/features/admin/partials/orgs.html', |
||||
}) |
||||
.when('/login', { |
||||
templateUrl: 'app/partials/login.html', |
||||
controller : 'LoginCtrl', |
||||
}) |
||||
.when('/dashboard/solo/:slug/', { |
||||
templateUrl: 'app/features/panel/partials/soloPanel.html', |
||||
controller : 'SoloPanelCtrl', |
||||
}) |
||||
.otherwise({ |
||||
templateUrl: 'app/partials/error.html', |
||||
controller: 'ErrorCtrl' |
||||
}); |
||||
}); |
||||
|
||||
}); |
||||
@ -0,0 +1,126 @@ |
||||
define([ |
||||
'angular', |
||||
'lodash', |
||||
'kbn', |
||||
'moment', |
||||
'jquery', |
||||
], |
||||
function (angular, _, kbn, moment, $) { |
||||
"use strict"; |
||||
|
||||
var module = angular.module('grafana.routes'); |
||||
|
||||
module.controller('DashFromDBCtrl', function($scope, $routeParams, backendSrv) { |
||||
|
||||
if (!$routeParams.slug) { |
||||
backendSrv.get('/api/dashboards/home').then(function(result) { |
||||
$scope.initDashboard(result, $scope); |
||||
},function() { |
||||
$scope.initDashboard({}, $scope); |
||||
$scope.appEvent('alert-error', ['Load dashboard failed', '']); |
||||
}); |
||||
|
||||
return; |
||||
} |
||||
|
||||
return backendSrv.getDashboard($routeParams.slug).then(function(result) { |
||||
$scope.initDashboard(result, $scope); |
||||
}, function() { |
||||
$scope.initDashboard({ |
||||
meta: {}, |
||||
model: { title: 'Not found' } |
||||
}, $scope); |
||||
}); |
||||
}); |
||||
|
||||
module.controller('DashFromImportCtrl', function($scope, $location, alertSrv) { |
||||
if (!window.grafanaImportDashboard) { |
||||
alertSrv.set('Not found', 'Cannot reload page with unsaved imported dashboard', 'warning', 7000); |
||||
$location.path(''); |
||||
return; |
||||
} |
||||
$scope.initDashboard({ meta: {}, model: window.grafanaImportDashboard }, $scope); |
||||
}); |
||||
|
||||
module.controller('NewDashboardCtrl', function($scope) { |
||||
$scope.initDashboard({ |
||||
meta: {}, |
||||
model: { |
||||
title: "New dashboard", |
||||
rows: [{ height: '250px', panels:[] }] |
||||
}, |
||||
}, $scope); |
||||
}); |
||||
|
||||
module.controller('DashFromFileCtrl', function($scope, $rootScope, $http, $routeParams) { |
||||
|
||||
var file_load = function(file) { |
||||
return $http({ |
||||
url: "public/dashboards/"+file.replace(/\.(?!json)/,"/")+'?' + new Date().getTime(), |
||||
method: "GET", |
||||
transformResponse: function(response) { |
||||
return angular.fromJson(response); |
||||
} |
||||
}).then(function(result) { |
||||
if(!result) { |
||||
return false; |
||||
} |
||||
return result.data; |
||||
},function() { |
||||
$scope.appEvent('alert-error', ["Dashboard load failed", "Could not load <i>dashboards/"+file+"</i>. Please make sure it exists"]); |
||||
return false; |
||||
}); |
||||
}; |
||||
|
||||
file_load($routeParams.jsonFile).then(function(result) { |
||||
$scope.initDashboard({meta: {}, model: result}, $scope); |
||||
}); |
||||
|
||||
}); |
||||
|
||||
module.controller('DashFromScriptCtrl', function($scope, $rootScope, $http, $routeParams, $q, dashboardSrv, datasourceSrv, $timeout) { |
||||
|
||||
var execute_script = function(result) { |
||||
var services = { |
||||
dashboardSrv: dashboardSrv, |
||||
datasourceSrv: datasourceSrv, |
||||
$q: $q, |
||||
}; |
||||
|
||||
/*jshint -W054 */ |
||||
var script_func = new Function('ARGS','kbn','_','moment','window','document','$','jQuery', 'services', result.data); |
||||
var script_result = script_func($routeParams, kbn, _ , moment, window, document, $, $, services); |
||||
|
||||
// Handle async dashboard scripts
|
||||
if (_.isFunction(script_result)) { |
||||
var deferred = $q.defer(); |
||||
script_result(function(dashboard) { |
||||
$timeout(function() { |
||||
deferred.resolve({ data: dashboard }); |
||||
}); |
||||
}); |
||||
return deferred.promise; |
||||
} |
||||
|
||||
return { data: script_result }; |
||||
}; |
||||
|
||||
var script_load = function(file) { |
||||
var url = 'public/dashboards/'+file.replace(/\.(?!js)/,"/") + '?' + new Date().getTime(); |
||||
|
||||
return $http({ url: url, method: "GET" }) |
||||
.then(execute_script) |
||||
.then(null,function(err) { |
||||
console.log('Script dashboard error '+ err); |
||||
$scope.appEvent('alert-error', ["Script Error", "Please make sure it exists and returns a valid dashboard"]); |
||||
return false; |
||||
}); |
||||
}; |
||||
|
||||
script_load($routeParams.jsFile).then(function(result) { |
||||
$scope.initDashboard({meta: {}, model: result.data}, $scope); |
||||
}); |
||||
|
||||
}); |
||||
|
||||
}); |
||||
Loading…
Reference in new issue