Browse Source

removed redundant load/save options

Torkel Ödegaard 11 năm trước cách đây
mục cha
commit
7914f65f68

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

@@ -1,7 +1,8 @@
 define([
   'angular',
   'underscore',
-  'moment'
+  'moment',
+  'filesaver'
 ],
 function (angular, _, moment) {
   'use strict';
@@ -36,13 +37,10 @@ function (angular, _, moment) {
 
       var _l = $scope.dashboard.loader;
       if(type === 'load') {
-        return (_l.load_elasticsearch || _l.load_gist || _l.load_local);
+        return (_l.load_elasticsearch || _l.load_gist);
       }
       if(type === 'save') {
-        return (_l.save_elasticsearch || _l.save_gist || _l.save_local || _l.save_default);
-      }
-      if(type === 'share') {
-        return (_l.save_temp);
+        return (_l.save_elasticsearch || _l.save_gist);
       }
       return false;
     };
@@ -94,6 +92,11 @@ function (angular, _, moment) {
       });
     };
 
+    $scope.exportDashboard = function() {
+      var blob = new Blob([angular.toJson($scope.dashboard, true)], { type: "application/json;charset=utf-8" });
+      window.saveAs(blob, $scope.dashboard.title + '-' + new Date().getTime());
+    };
+
     $scope.save_gist = function() {
       $scope.dashboard.save_gist($scope.gist.title).then(function(link) {
         if (!_.isUndefined(link)) {

+ 0 - 3
src/app/dashboards/default.json

@@ -137,15 +137,12 @@
   "loader": {
     "save_gist": false,
     "save_elasticsearch": true,
-    "save_local": true,
     "save_default": true,
     "save_temp": true,
     "save_temp_ttl_enable": true,
     "save_temp_ttl": "30d",
     "load_gist": false,
     "load_elasticsearch": true,
-    "load_elasticsearch_size": 20,
-    "load_local": false,
     "hide": false
   },
   "refresh": false

+ 0 - 2
src/app/dashboards/empty.json

@@ -68,7 +68,6 @@
   "loader": {
     "save_gist": false,
     "save_elasticsearch": true,
-    "save_local": true,
     "save_default": true,
     "save_temp": true,
     "save_temp_ttl_enable": true,
@@ -76,7 +75,6 @@
     "load_gist": false,
     "load_elasticsearch": true,
     "load_elasticsearch_size": 20,
-    "load_local": false,
     "hide": false
   },
   "refresh": false

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

@@ -45,7 +45,7 @@
       <a class="link" ng-click="removeAsFavorite()">Remove as favorite</a>
     </li>
     <li ng-show="dashboard.loader.save_local">
-      <a class="link" ng-click="dashboard.to_file()">Export dashboard</a>
+      <a class="link" ng-click="exportDashboard()">Export dashboard</a>
     </li>
     <li ng-show="showDropdown('share')"><a bs-tooltip="'Share'" data-placement="bottom" ng-click="saveForSharing()" config-modal="app/partials/dashLoaderShare.html">Share temp copy</i></a></li>
 

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

@@ -72,12 +72,6 @@
     <div class="editor-row">
       <div class="section">
         <h5>Save to</h5>
-        <div class="editor-option">
-          <label class="small">Export</label><input type="checkbox" ng-model="dashboard.loader.save_local" ng-checked="dashboard.loader.save_local">
-        </div>
-        <div class="editor-option">
-          <label class="small">Browser</label><input type="checkbox" ng-model="dashboard.loader.save_default" ng-checked="dashboard.loader.save_default">
-        </div>
         <div class="editor-option">
           <label class="small">Gist <tip>Requires your domain to be OAUTH registered with Github<tip></label><input type="checkbox" ng-model="dashboard.loader.save_gist" ng-checked="dashboard.loader.save_gist">
         </div>
@@ -87,18 +81,12 @@
       </div>
       <div class="section">
         <h5>Load from</h5>
-        <div class="editor-option">
-          <label class="small">Local file</label><input type="checkbox" ng-model="dashboard.loader.load_local" ng-checked="dashboard.loader.load_local">
-        </div>
         <div class="editor-option">
           <label class="small">Gist</label><input type="checkbox" ng-model="dashboard.loader.load_gist" ng-checked="dashboard.loader.load_gist">
         </div>
         <div class="editor-option">
           <label class="small">Elasticsearch</label><input type="checkbox" ng-model="dashboard.loader.load_elasticsearch" ng-checked="dashboard.loader.load_elasticsearch">
         </div>
-        <div class="editor-option" ng-show="dashboard.loader.load.elasticsearch">
-          <label class="small">ES list size</label><input class="input-mini" type="number" ng-model="dashboard.loader.load_elasticsearch_size">
-        </div>
       </div>
       <div class="section">
       <h5>Sharing</h5>
@@ -154,5 +142,5 @@
   </div>
 
   <button ng-click="add_row(dashboard,row); reset_row();" class="btn btn-success" ng-show="editor.index == 1">Create Row</button>
-  <button type="button" class="btn btn-info" ng-click="editor.index=0;dismiss();reset_panel();dashboard.refresh()">Close</button>
+  <button type="button" class="btn btn-info" ng-click="editor.index=0;dismiss();reset_panel();dashboard.emit_refresh()">Close</button>
 </div>

+ 2 - 135
src/app/services/dashboard/dashboardModel.js

@@ -2,11 +2,7 @@ define([
   'angular',
   'jquery',
   'kbn',
-  'underscore',
-  'config',
-  'moment',
-  'modernizr',
-  'filesaver'
+  'underscore'
 ],
 function (angular, $, kbn, _) {
   'use strict';
@@ -41,7 +37,6 @@ function (angular, $, kbn, _) {
         save_temp_ttl: '30d',
         load_gist: false,
         load_elasticsearch: true,
-        load_elasticsearch_size: 20,
         hide: false
       });
 
@@ -96,137 +91,9 @@ function (angular, $, kbn, _) {
       }
     };
 
-    /*// A hash of defaults to use when loading a dashboard
-
-    var _dash = {
-
-    };
-
-    // An elasticJS client to use
-    var ejs = ejsResource(config.elasticsearch, config.elasticsearchBasicAuth);
+    /*
     var gist_pattern = /(^\d{5,}$)|(^[a-z0-9]{10,}$)|(gist.github.com(\/*.*)\/[a-z0-9]{5,}\/*$)/;
 
-    // Store a reference to this
-    var self = this;
-
-    this.current = _.clone(_dash);
-    this.last = {};
-    this.availablePanels = [];
-
-    $rootScope.$on('$routeChangeSuccess',function() {
-      // Clear the current dashboard to prevent reloading
-      self.current = {};
-      self.indices = [];
-      route();
-    });
-
-    var route = function() {
-      // Is there a dashboard type and id in the URL?
-      if(!(_.isUndefined($routeParams.kbnType)) && !(_.isUndefined($routeParams.kbnId))) {
-        var _type = $routeParams.kbnType;
-        var _id = $routeParams.kbnId;
-
-        switch(_type) {
-        case ('elasticsearch'):
-          self.elasticsearch_load('dashboard',_id);
-          break;
-        case ('temp'):
-          self.elasticsearch_load('temp',_id);
-          break;
-        case ('file'):
-          self.file_load(_id);
-          break;
-        case('script'):
-          self.script_load(_id);
-          break;
-        case('local'):
-          self.local_load();
-          break;
-        default:
-          $location.path(config.default_route);
-        }
-      // No dashboard in the URL
-      } else {
-        // Check if browser supports localstorage, and if there's an old dashboard. If there is,
-        // inform the user that they should save their dashboard to Elasticsearch and then set that
-        // as their default
-        if (Modernizr.localstorage) {
-          if(!(_.isUndefined(window.localStorage['dashboard'])) && window.localStorage['dashboard'] !== '') {
-            $location.path(config.default_route);
-            alertSrv.set('Saving to browser storage has been replaced',' with saving to Elasticsearch.'+
-              ' Click <a href="#/dashboard/local/deprecated">here</a> to load your old dashboard anyway.');
-          } else if(!(_.isUndefined(window.localStorage.grafanaDashboardDefault))) {
-            $location.path(window.localStorage.grafanaDashboardDefault);
-          } else {
-            $location.path(config.default_route);
-          }
-        // No? Ok, grab the default route, its all we have now
-        } else {
-          $location.path(config.default_route);
-        }
-      }
-    };
-
-    this.refresh = function() {
-      $rootScope.$broadcast('refresh');
-    };
-
-    var dash_defaults = function(dashboard) {
-
-      _.defaults(dashboard, _dash);
-      _.defaults(dashboard.loader,_dash.loader);
-
-      var filtering = _.findWhere(dashboard.pulldowns, {type: 'filtering'});
-      if (!filtering) {
-        dashboard.pulldowns.push({
-          type: 'filtering',
-          enable: false
-        });
-      }
-
-      var annotations = _.findWhere(dashboard.pulldowns, {type: 'annotations'});
-      if (!annotations) {
-        dashboard.pulldowns.push({
-          type: 'annotations',
-          enable: false
-        });
-      }
-
-      _.each(dashboard.rows, function(row) {
-        _.each(row.panels, function(panel) {
-          if (panel.type === 'graphite') {
-            panel.type = 'graph';
-          }
-        });
-      });
-
-      return dashboard;
-    };
-
-    this.dash_load = function(dashboard) {
-      // Cancel all timers
-      timer.cancel_all();
-
-      // reset fullscreen flag
-      $rootScope.fullscreen = false;
-
-      // Make sure the dashboard being loaded has everything required
-      dashboard = dash_defaults(dashboard);
-
-      window.document.title = 'Grafana - ' + dashboard.title;
-
-      // Set the current dashboard
-      self.current = angular.copy(dashboard);
-      if(dashboard.refresh) {
-        self.set_interval(dashboard.refresh);
-      }
-
-      self.availablePanels = config.panels;
-
-      $rootScope.$emit('dashboard-loaded', self.current);
-
-      return true;
-    };
 
     this.gist_id = function(string) {
       if(self.is_gist(string)) {