From 7914f65f68ead6ad4afcf03a671d0b4f26712dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 13 Jun 2014 13:50:09 +0200 Subject: [PATCH] removed redundant load/save options --- src/app/controllers/dashLoader.js | 15 +- src/app/dashboards/default.json | 3 - src/app/dashboards/empty.json | 2 - src/app/partials/dashLoader.html | 2 +- src/app/partials/dasheditor.html | 14 +- src/app/services/dashboard/dashboardModel.js | 137 +------------------ 6 files changed, 13 insertions(+), 160 deletions(-) diff --git a/src/app/controllers/dashLoader.js b/src/app/controllers/dashLoader.js index 2f2edb4dcda..6b28ccc55d8 100644 --- a/src/app/controllers/dashLoader.js +++ b/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)) { diff --git a/src/app/dashboards/default.json b/src/app/dashboards/default.json index 68a71099931..f2a1c55a7bc 100644 --- a/src/app/dashboards/default.json +++ b/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 diff --git a/src/app/dashboards/empty.json b/src/app/dashboards/empty.json index 1cc249cfadd..588c476dd19 100644 --- a/src/app/dashboards/empty.json +++ b/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 diff --git a/src/app/partials/dashLoader.html b/src/app/partials/dashLoader.html index d65c5d33efd..9652a196fb8 100644 --- a/src/app/partials/dashLoader.html +++ b/src/app/partials/dashLoader.html @@ -45,7 +45,7 @@ Remove as favorite
  • - Export dashboard + Export dashboard
  • Share temp copy
  • diff --git a/src/app/partials/dasheditor.html b/src/app/partials/dasheditor.html index 9788fa10ba1..69ff346d1be 100644 --- a/src/app/partials/dasheditor.html +++ b/src/app/partials/dasheditor.html @@ -72,12 +72,6 @@
    Save to
    -
    - -
    -
    - -
    @@ -87,18 +81,12 @@
    Load from
    -
    - -
    -
    - -
    Sharing
    @@ -154,5 +142,5 @@
    - +
    \ No newline at end of file diff --git a/src/app/services/dashboard/dashboardModel.js b/src/app/services/dashboard/dashboardModel.js index a0908dd2ab5..15c94e55cbe 100644 --- a/src/app/services/dashboard/dashboardModel.js +++ b/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 here 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)) {