Просмотр исходного кода

Merge branch 'pro' into temp_test

Torkel Ödegaard 11 лет назад
Родитель
Сommit
2feab76a6f

+ 1 - 6
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('@');

+ 8 - 18
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 = {};

+ 4 - 0
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';

+ 2 - 1
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');
     };
 
   });

+ 44 - 24
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();

+ 1 - 0
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);
         }

+ 18 - 0
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();
+
+  });
+});

+ 11 - 0
src/app/features/admin/partials/settings.html

@@ -0,0 +1,11 @@
+<div ng-include="'app/partials/navbar.html'" ng-init="pageTitle='Admin > Settings'"></div>
+
+<div class="dashboard-edit-view" style="min-height: 500px">
+	<div class="dashboard-editor-body">
+		<div class="editor-row row">
+			<div class="section span6">
+
+			</div>
+		</div>
+	</div>
+</div>

+ 1 - 0
src/app/features/all.js

@@ -14,5 +14,6 @@ define([
   './account/importCtrl',
   './account/accountCtrl',
   './admin/adminUsersCtrl',
+  './admin/adminSettingsCtrl',
   './grafanaDatasource/datasource',
 ], function () {});

+ 1 - 1
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) {

+ 6 - 6
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;
           }

+ 0 - 1
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);
       }
 

+ 1 - 1
src/app/panels/graph/axisEditor.html

@@ -150,7 +150,7 @@
 				<li class="tight-form-item">
 					Show&nbsp;
 					<input class="cr1" id="panel.legend.show" type="checkbox"
-					ng-model="panel.legend.show" ng-checked="panel.legend.show" ng-change="render()">
+					ng-model="panel.legend.show" ng-checked="panel.legend.show" ng-change="get_data()">
 					<label for="panel.legend.show" class="cr1"></label>
 				</li>
 				<li class="tight-form-item">

+ 1 - 1
src/app/partials/dasheditor.html

@@ -96,7 +96,7 @@
 <div class="dashboard-editor-footer">
 	<div class="grafana-version-info" ng-show="editor.index === 0">
 		<span class="editor-option small">
-			Grafana version: {{grafanaVersion}} &nbsp;&nbsp;
+			Grafana version: {{grafana.version}} &nbsp;&nbsp;
 		</span>
 		<span grafana-version-check>
 		</span>

+ 2 - 2
src/app/partials/login.html

@@ -80,11 +80,11 @@
 			<div class="clearfix"></div>
 
 			<div class="login-oauth text-center">
-				<a class="btn btn-google" href="login/google" target="_self">
+				<a class="btn btn-google" href="login/google" target="_self" ng-if="googleAuthEnabled">
 					<i class="fa fa-google"></i>
 					with Google
 				</a>
-				<a class="btn btn-github" href="login/github" target="_self">
+				<a class="btn btn-github" href="login/github" target="_self" ng-if="githubAuthEnabled">
 					<i class="fa fa-github"></i>
 					with Github
 				</a>

+ 4 - 1
src/app/partials/sidemenu.html

@@ -1,6 +1,6 @@
 <div ng-controller="SideMenuCtrl" ng-init="init()">
 	<ul class="sidemenu">
-		<li class="dropdown">
+		<li class="dropdown" ng-if="grafana.user.isSignedIn">
 			<a class="sidemenu-user pointer" data-toggle="dropdown" title="{{grafana.user.email}}">
 				<span class="gravatar-missing">f</span>
 				<img ng-src="{{grafana.user.gravatarUrl}}" width="35">
@@ -10,6 +10,9 @@
 				<li><a href="{{appSubUrl}}/login?logout">Logout</a></li>
 			</ul>
 		</li>
+		<li ng-if="!grafana.user.isSignedIn">
+			<a href="login" class="sidemenu-item"><i class="fa fa-sign-in"></i>Sign in</a>
+		</li>
 		<li ng-repeat-start="item in menu" ng-class="{'active': item.active}">
 			<a href="{{item.href}}" class="sidemenu-item"><i class="{{item.icon}}"></i>{{item.text}}</a>
 		</li>

+ 8 - 4
src/app/routes/backend/all.js

@@ -20,14 +20,14 @@ define([
         controller : 'DashFromDBProvider',
         reloadOnSearch: false,
       })
-      .when('/dashboard/temp/:id', {
+      .when('/dashboard/import/:id', {
         templateUrl: 'app/partials/dashboard.html',
-        controller : 'DashFromDBProvider',
+        controller : 'DashFromImportCtrl',
         reloadOnSearch: false,
       })
-      .when('/dashboard/import/:id', {
+      .when('/dashboard/new', {
         templateUrl: 'app/partials/dashboard.html',
-        controller : 'DashFromImportCtrl',
+        controller : 'NewDashboardCtrl',
         reloadOnSearch: false,
       })
       .when('/account', {
@@ -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',

+ 8 - 5
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);
+  });
+
 });

+ 14 - 3
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 <i>dashboards/"+file+"</i>. Please make sure it exists" ,'error');
+        $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) {
+    var fileToLoad = $routeParams.jsonFile;
+    if ($route.current.newDashboard) {
+      fileToLoad = 'empty.json';
+    }
+
+    file_load(fileToLoad).then(function(result) {
       $scope.initDashboard(result, $scope);
     });
 

+ 1 - 0
src/app/services/all.js

@@ -2,6 +2,7 @@ define([
   './alertSrv',
   './utilSrv',
   './datasourceSrv',
+  './userSrv',
   './timer',
   './keyboardManager',
   './popoverSrv',

+ 24 - 0
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();
+    };
+
+  });
+
+});