diff --git a/src/app/components/settings.js b/src/app/components/settings.js index 9bef2757d9f..98c57d40084 100644 --- a/src/app/components/settings.js +++ b/src/app/components/settings.js @@ -34,12 +34,7 @@ function (_, crypto) { } }; - // This initializes a new hash on purpose, to avoid adding parameters to - // config.js without providing sane defaults - var settings = {}; - _.each(defaults, function(value, key) { - settings[key] = typeof options[key] !== 'undefined' ? options[key] : defaults[key]; - }); + var settings = _.extend({}, defaults, options); var parseBasicAuth = function(datasource) { var passwordEnd = datasource.url.indexOf('@'); diff --git a/src/app/controllers/grafanaCtrl.js b/src/app/controllers/grafanaCtrl.js index d2047cfef30..8df9b4155d6 100644 --- a/src/app/controllers/grafanaCtrl.js +++ b/src/app/controllers/grafanaCtrl.js @@ -10,17 +10,17 @@ function (angular, config, _, $, store) { var module = angular.module('grafana.controllers'); - module.controller('GrafanaCtrl', function($scope, alertSrv, utilSrv, grafanaVersion, $rootScope, $controller) { - $scope.grafanaVersion = grafanaVersion[0] === '@' ? 'master' : grafanaVersion; - $scope.grafana = {}; - - $rootScope.profilingEnabled = store.getBool('profilingEnabled'); - $rootScope.performance = { loadStart: new Date().getTime() }; - $rootScope.appSubUrl = config.appSubUrl; + module.controller('GrafanaCtrl', function($scope, alertSrv, utilSrv, grafanaVersion, $rootScope, $controller, userSrv) { $scope.init = function() { + $scope.grafana = {}; + $scope.grafana.version = grafanaVersion; $scope._ = _; + $rootScope.profilingEnabled = store.getBool('profilingEnabled'); + $rootScope.performance = { loadStart: new Date().getTime() }; + $rootScope.appSubUrl = config.appSubUrl; + if ($rootScope.profilingEnabled) { $scope.initProfiling(); } alertSrv.init(); @@ -28,19 +28,9 @@ function (angular, config, _, $, store) { $scope.dashAlerts = alertSrv; $scope.grafana.style = 'dark'; - - if (window.grafanaBackend) { - $scope.initBackendFeatures(); - } - }; - - $scope.initBackendFeatures = function() { + $scope.grafana.user = userSrv.getSignedInUser(); $scope.grafana.sidemenu = store.getBool('grafana.sidemenu'); - if (window.grafanaBootData.user.login) { - $scope.grafana.user = window.grafanaBootData.user; - } - $scope.onAppEvent('logged-out', function() { $scope.grafana.sidemenu = false; $scope.grafana.user = {}; diff --git a/src/app/controllers/loginCtrl.js b/src/app/controllers/loginCtrl.js index c3696d55124..e6b0f99f867 100644 --- a/src/app/controllers/loginCtrl.js +++ b/src/app/controllers/loginCtrl.js @@ -16,6 +16,10 @@ function (angular, config) { }; $scope.grafana.sidemenu = false; + + $scope.googleAuthEnabled = config.googleAuthEnabled; + $scope.githubAuthEnabled = config.githubAuthEnabled; + $scope.loginMode = true; $scope.submitBtnClass = 'btn-inverse'; $scope.submitBtnText = 'Log in'; diff --git a/src/app/controllers/search.js b/src/app/controllers/search.js index 3abcf4ec0a3..0b755ccbdb7 100644 --- a/src/app/controllers/search.js +++ b/src/app/controllers/search.js @@ -154,7 +154,8 @@ function (angular, _, config, $) { }; $scope.newDashboard = function() { - $location.url('/dashboard/file/empty.json'); + //$location.path('/dashboard/file/empty.json'); + $location.url('dashboard/new'); }; }); diff --git a/src/app/controllers/sidemenuCtrl.js b/src/app/controllers/sidemenuCtrl.js index 10b73e2458a..28e826646e8 100644 --- a/src/app/controllers/sidemenuCtrl.js +++ b/src/app/controllers/sidemenuCtrl.js @@ -15,39 +15,59 @@ function (angular, _, $, config) { return config.appSubUrl + url; }; - $scope.menu = [ - { - text: "Dashbord", - href: $scope.getUrl("/"), - startsWith: config.appSubUrl + '/dashboard/', - icon: "fa fa-th-large", - links: [ - { text: 'Settings', editview: 'settings', icon: "fa fa-cogs" }, - { text: 'Templating', editview: 'templating', icon: "fa fa-cogs" }, - { text: 'Annotations', editview: 'annotations', icon: "fa fa-bolt" }, - { text: 'Export', href:"", icon: "fa fa-bolt" }, - { text: 'JSON', href:"", icon: "fa fa-bolt" }, - ] - }, - { + $scope.menu = []; + $scope.menu.push({ + text: "Dashbord", + href: $scope.getUrl("/"), + startsWith: config.appSubUrl + '/dashboard/', + icon: "fa fa-th-large", + links: [ + { text: 'Settings', editview: 'settings'}, + { text: 'Templating', editview: 'templating'}, + { text: 'Annotations', editview: 'annotations'}, + { text: 'Export', href:""}, + { text: 'JSON', href:""}, + ] + }); + + if ($scope.grafana.user.accountRole === 'Admin') { + $scope.menu.push({ text: "Account", href: $scope.getUrl("/account"), + requireRole: "Admin", icon: "fa fa-shield", links: [ - { text: 'Info', href: $scope.getUrl("/account"), icon: "fa fa-sitemap" }, - { text: 'Data sources', href: $scope.getUrl("/account/datasources"), icon: "fa fa-sitemap" }, - { text: 'Users', href: $scope.getUrl("/account/users"), icon: "fa fa-users" }, - { text: 'API Keys', href: $scope.getUrl("/account/apikeys"), icon: "fa fa-key" }, + { text: 'Info', href: $scope.getUrl("/account")}, + { text: 'Data sources', href: $scope.getUrl("/account/datasources")}, + { text: 'Users', href: $scope.getUrl("/account/users")}, + { text: 'API Keys', href: $scope.getUrl("/account/apikeys")}, ] - }, - { + }); + } + + if ($scope.grafana.user.isSignedIn) { + $scope.menu.push({ text: "Profile", href: $scope.getUrl("/profile"), icon: "fa fa-user", + requireSignedIn: true, links: [ - { text: 'Info', href: $scope.getUrl("/profile"), icon: "fa fa-sitemap" }, + { text: 'Info', href: $scope.getUrl("/profile"), icon: "fa fa-sitemap" }, { text: 'Password', href:"", icon: "fa fa-lock" }, ] - } - ]; + }); + } + + if ($scope.grafana.user.isGrafanaAdmin) { + $scope.menu.push({ + text: "Admin", href: $scope.getUrl("/admin/users"), + icon: "fa fa-cube", + requireSignedIn: true, + links: [ + { text: 'Settings', href: $scope.getUrl("/admin/settings")}, + { text: 'Users', href: $scope.getUrl("/admin/users"), icon: "fa fa-lock" }, + { text: 'Log', href: "", icon: "fa fa-lock" }, + ] + }); + } $scope.onAppEvent('$routeUpdate', function() { $scope.updateState(); diff --git a/src/app/directives/dashEditLink.js b/src/app/directives/dashEditLink.js index dbafebae35c..b44b048f9d4 100644 --- a/src/app/directives/dashEditLink.js +++ b/src/app/directives/dashEditLink.js @@ -102,6 +102,7 @@ function (angular, $) { } }); + scope.$on("$destroy", hideEditorPane); scope.onAppEvent('hide-dash-editor', hideEditorPane); scope.onAppEvent('show-dash-editor', showEditorPane); } diff --git a/src/app/features/admin/adminSettingsCtrl.js b/src/app/features/admin/adminSettingsCtrl.js new file mode 100644 index 00000000000..736e5ce55d2 --- /dev/null +++ b/src/app/features/admin/adminSettingsCtrl.js @@ -0,0 +1,18 @@ +define([ + 'angular', +], +function (angular) { + 'use strict'; + + var module = angular.module('grafana.controllers'); + + module.controller('AdminSettingsCtrl', function($scope) { + + $scope.init = function() { + + }; + + $scope.init(); + + }); +}); diff --git a/src/app/features/admin/partials/settings.html b/src/app/features/admin/partials/settings.html new file mode 100644 index 00000000000..bea1f5fd4c7 --- /dev/null +++ b/src/app/features/admin/partials/settings.html @@ -0,0 +1,11 @@ +
+ +
+
+
+
+ +
+
+
+
diff --git a/src/app/features/all.js b/src/app/features/all.js index de8e1ac3a32..263c3acecb8 100644 --- a/src/app/features/all.js +++ b/src/app/features/all.js @@ -14,5 +14,6 @@ define([ './account/importCtrl', './account/accountCtrl', './admin/adminUsersCtrl', + './admin/adminSettingsCtrl', './grafanaDatasource/datasource', ], function () {}); diff --git a/src/app/features/dashboard/dashboardCtrl.js b/src/app/features/dashboard/dashboardCtrl.js index 0aee19d82e4..c88d6dfa725 100644 --- a/src/app/features/dashboard/dashboardCtrl.js +++ b/src/app/features/dashboard/dashboardCtrl.js @@ -105,7 +105,7 @@ function (angular, $, config, _) { }; $scope.checkFeatureToggles = function() { - $scope.submenuEnabled = $scope.dashboard.templating.enable || $scope.dashboard.annotations.enable; + $scope.submenuEnabled = $scope.dashboard.templating.enable || $scope.dashboard.annotations.enable || false; }; $scope.onDrop = function(panelId, row, dropTarget) { diff --git a/src/app/features/grafanaDatasource/datasource.js b/src/app/features/grafanaDatasource/datasource.js index 329b430985c..b52068e464f 100644 --- a/src/app/features/grafanaDatasource/datasource.js +++ b/src/app/features/grafanaDatasource/datasource.js @@ -18,17 +18,17 @@ function (angular, _, kbn) { this.editorSrc = 'app/features/grafanaDatasource/partials/query.editor.html'; } - GrafanaDatasource.prototype.getDashboard = function(id, isTemp) { - var url = '/dashboard/' + id; + GrafanaDatasource.prototype.getDashboard = function(slug, isTemp) { + var url = '/dashboard/' + slug; if (isTemp) { - url = '/temp/' + id; + url = '/temp/' + slug; } - return backendSrv.get('/api/dashboard/' + id) + return backendSrv.get('/api/dashboard/' + slug) .then(function(data) { - if (data) { - return angular.fromJson(data); + if (data && data.dashboard) { + return data.dashboard; } else { return false; } diff --git a/src/app/features/graphite/datasource.js b/src/app/features/graphite/datasource.js index a486250ac74..1b6c5007017 100644 --- a/src/app/features/graphite/datasource.js +++ b/src/app/features/graphite/datasource.js @@ -158,7 +158,6 @@ function (angular, _, $, config, kbn, moment) { date = date.replace('M', 'mon'); return date; } - date = kbn.parseDate(date); } diff --git a/src/app/panels/graph/axisEditor.html b/src/app/panels/graph/axisEditor.html index b2c2437e89b..34f624e28e4 100644 --- a/src/app/panels/graph/axisEditor.html +++ b/src/app/panels/graph/axisEditor.html @@ -150,7 +150,7 @@
  • Show  + ng-model="panel.legend.show" ng-checked="panel.legend.show" ng-change="get_data()">
  • diff --git a/src/app/partials/dasheditor.html b/src/app/partials/dasheditor.html index fdeb3a4db24..fd94432ba5f 100644 --- a/src/app/partials/dasheditor.html +++ b/src/app/partials/dasheditor.html @@ -96,7 +96,7 @@
  • +
  • + Sign in +
  • {{item.text}}
  • diff --git a/src/app/routes/backend/all.js b/src/app/routes/backend/all.js index f97ca90ba04..863be089243 100644 --- a/src/app/routes/backend/all.js +++ b/src/app/routes/backend/all.js @@ -20,16 +20,16 @@ define([ controller : 'DashFromDBProvider', reloadOnSearch: false, }) - .when('/dashboard/temp/:id', { - templateUrl: 'app/partials/dashboard.html', - controller : 'DashFromDBProvider', - reloadOnSearch: false, - }) .when('/dashboard/import/:id', { templateUrl: 'app/partials/dashboard.html', controller : 'DashFromImportCtrl', reloadOnSearch: false, }) + .when('/dashboard/new', { + templateUrl: 'app/partials/dashboard.html', + controller : 'NewDashboardCtrl', + reloadOnSearch: false, + }) .when('/account', { templateUrl: 'app/features/account/partials/account.html', controller : 'AccountCtrl', @@ -54,6 +54,10 @@ define([ templateUrl: 'app/features/profile/partials/profile.html', controller : 'ProfileCtrl', }) + .when('/admin/settings', { + templateUrl: 'app/features/admin/partials/settings.html', + controller : 'AdminSettingsCtrl', + }) .when('/admin/users', { templateUrl: 'app/features/admin/partials/users.html', controller : 'AdminUsersCtrl', diff --git a/src/app/routes/backend/dashboard.js b/src/app/routes/backend/dashboard.js index 63e22cd7117..919151c2aca 100644 --- a/src/app/routes/backend/dashboard.js +++ b/src/app/routes/backend/dashboard.js @@ -45,22 +45,25 @@ function (angular, store) { .then(function(dashboard) { prevDashPath = $location.path(); $scope.initDashboard(dashboard, $scope); - }).then(null, function(err) { - $scope.appEvent('alert-error', ['Load dashboard failed', err]); + }).then(null, function() { $scope.initDashboard({}, $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(window.grafanaImportDashboard, $scope); }); + module.controller('NewDashboardCtrl', function($scope) { + $scope.initDashboard({ + title: "New dashboard", + rows: [{ height: '250px', panels:[] }] + }, $scope); + }); + }); diff --git a/src/app/routes/standalone/fromFile.js b/src/app/routes/standalone/fromFile.js index fce9394789a..0eafa0ed650 100644 --- a/src/app/routes/standalone/fromFile.js +++ b/src/app/routes/standalone/fromFile.js @@ -15,10 +15,16 @@ function (angular, $, config, _) { templateUrl: 'app/partials/dashboard.html', controller : 'DashFromFileProvider', reloadOnSearch: false, + }) + .when('/dashboard/new', { + templateUrl: 'app/partials/dashboard.html', + controller : 'DashFromFileProvider', + reloadOnSearch: false, + newDashboard: true, }); }); - module.controller('DashFromFileProvider', function($scope, $rootScope, $http, $routeParams, alertSrv) { + module.controller('DashFromFileProvider', function($scope, $rootScope, $http, $routeParams, $route) { var renderTemplate = function(json,params) { var _r; @@ -46,12 +52,17 @@ function (angular, $, config, _) { } return result.data; },function() { - alertSrv.set('Error',"Could not load dashboards/"+file+". Please make sure it exists" ,'error'); + $scope.appEvent('alert-error', ["Dashboard load failed", "Could not load dashboards/"+file+". Please make sure it exists"]); return false; }); }; - file_load($routeParams.jsonFile).then(function(result) { + var fileToLoad = $routeParams.jsonFile; + if ($route.current.newDashboard) { + fileToLoad = 'empty.json'; + } + + file_load(fileToLoad).then(function(result) { $scope.initDashboard(result, $scope); }); diff --git a/src/app/services/all.js b/src/app/services/all.js index c4067274dd2..4d76a2e0957 100644 --- a/src/app/services/all.js +++ b/src/app/services/all.js @@ -2,6 +2,7 @@ define([ './alertSrv', './utilSrv', './datasourceSrv', + './userSrv', './timer', './keyboardManager', './popoverSrv', diff --git a/src/app/services/userSrv.js b/src/app/services/userSrv.js new file mode 100644 index 00000000000..14f373f7b1b --- /dev/null +++ b/src/app/services/userSrv.js @@ -0,0 +1,24 @@ +define([ + 'angular', + 'lodash', +], +function (angular, _) { + 'use strict'; + + var module = angular.module('grafana.services'); + + module.service('userSrv', function() { + + function User() { + if (window.grafanaBootData.user) { + _.extend(this, window.grafanaBootData.user); + } + } + + this.getSignedInUser = function() { + return new User(); + }; + + }); + +});