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

+ 9 - 20
src/app/controllers/dashLoader.js

@@ -15,18 +15,18 @@ function (angular, _, moment) {
       $scope.gist = $scope.gist || {};
       $scope.elasticsearch = $scope.elasticsearch || {};
 
-      $rootScope.$on('save-dashboard', function() {
+      $scope.onAppEvent('save-dashboard', function() {
         $scope.elasticsearch_save('dashboard', false);
       });
 
-      $rootScope.$on('zoom-out', function() {
+      $scope.onAppEvent('zoom-out', function() {
         $scope.zoom(2);
       });
 
     };
 
     $scope.exitFullscreen = function() {
-      $rootScope.$emit('panel-fullscreen-exit');
+      $scope.emitAppEvent('panel-fullscreen-exit');
     };
 
     $scope.showDropdown = function(type) {
@@ -82,27 +82,16 @@ function (angular, _, moment) {
         });
     };
 
-    $scope.elasticsearch_delete = function(id) {
+    $scope.deleteDashboard = function(id) {
       if (!confirm('Are you sure you want to delete dashboard?')) {
         return;
       }
 
-      $scope.dashboard.elasticsearch_delete(id).then(
-        function(result) {
-          if(!_.isUndefined(result)) {
-            if(result.found) {
-              alertSrv.set('Dashboard Deleted',id+' has been deleted','success',5000);
-              // Find the deleted dashboard in the cached list and remove it
-              var toDelete = _.where($scope.elasticsearch.dashboards,{_id:id})[0];
-              $scope.elasticsearch.dashboards = _.without($scope.elasticsearch.dashboards,toDelete);
-            } else {
-              alertSrv.set('Dashboard Not Found','Could not find '+id+' in Elasticsearch','warning',5000);
-            }
-          } else {
-            alertSrv.set('Dashboard Not Deleted','An error occurred deleting the dashboard','error',5000);
-          }
-        }
-      );
+      elastic.deleteDashboard(id).then(function(id) {
+        alertSrv.set('Dashboard Deleted', id + ' has been deleted', 'success', 5000);
+      }, function() {
+        alertSrv.set('Dashboard Not Deleted', 'An error occurred deleting the dashboard', 'error', 5000);
+      });
     };
 
     $scope.save_gist = function() {

+ 0 - 1
src/app/partials/dashLoader.html

@@ -65,7 +65,6 @@
 
 </li>
 
-
 <li class="grafana-menu-home"><a bs-tooltip="'Goto saved default'" data-placement="bottom" href='#/'><i class='icon-home'></i></a></li>
 
 <li class="grafana-menu-edit" ng-show="dashboard.editable" bs-tooltip="'Configure dashboard'" data-placement="bottom"><a class="link" config-modal="app/partials/dasheditor.html"><i class='icon-cog pointer'></i></a></li>

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

@@ -77,7 +77,7 @@
           <tr bindonce
               ng-repeat="row in results.dashboards"
               ng-class="{'selected': $index === selectedIndex }">
-            <td><a confirm-click="elasticsearch_delete(row._id)" confirmation="Are you sure you want to delete the {{row._id}} dashboard"><i class="icon-remove"></i></a></td>
+            <td><a confirm-click="deleteDashboard(row._id)" confirmation="Are you sure you want to delete the {{row._id}} dashboard"><i class="icon-remove"></i></a></td>
             <td style="width:100%">
               <a href="#/dashboard/elasticsearch/{{row._id}}" bo-text="row._id"></a>
             </td>

+ 2 - 1
src/app/routes/all.js

@@ -1,6 +1,7 @@
 define([
   './dashboard-from-es',
   './dashboard-from-file',
-  './dashboard-from-script'
+  './dashboard-from-script',
+  './dashboard-default',
 ],
 function () {});

+ 24 - 0
src/app/routes/dashboard-default.js

@@ -0,0 +1,24 @@
+define([
+  'angular',
+  'config'
+],
+function (angular, config) {
+  "use strict";
+
+  var module = angular.module('kibana.routes');
+
+  module.config(function($routeProvider) {
+    $routeProvider
+      .when('/', {
+        redirectTo: function() {
+          if (window.localStorage && window.localStorage.grafanaDashboardDefault) {
+            return window.localStorage.grafanaDashboardDefault;
+          }
+          else {
+            return config.default_route;
+          }
+        }
+      });
+  });
+
+});

+ 0 - 10
src/app/routes/dashboard-from-file.js

@@ -14,16 +14,6 @@ function (angular, $, config, _) {
       .when('/dashboard/file/:jsonFile', {
         templateUrl: 'app/partials/dashboard.html',
         controller : 'DashFromFileProvider',
-      })
-      .when('/', {
-        redirectTo: function() {
-          if (window.localStorage && window.localStorage.grafanaDashboardDefault) {
-            return window.localStorage.grafanaDashboardDefault;
-          }
-          else {
-            return config.default_route;
-          }
-        }
       });
   });
 

+ 9 - 0
src/app/services/elasticsearch/es-client.js

@@ -39,6 +39,15 @@ function(angular, config) {
         });
     };
 
+    this.deleteDashboard = function(id) {
+      return this._request('DELETE', '/dashboard/' + id)
+        .then(function(result) {
+          return result.data._id;
+        }, function(err) {
+          throw err.data;
+        });
+    };
+
     this.saveForSharing = function(dashboard) {
       var data = {
         user: 'guest',