diff --git a/public/app/core/components/search/search.html b/public/app/core/components/search/search.html index 35c4431d80c..953a769f7ee 100644 --- a/public/app/core/components/search/search.html +++ b/public/app/core/components/search/search.html @@ -64,12 +64,17 @@
- - - Import - + +
+ + +
+
diff --git a/public/app/core/core.ts b/public/app/core/core.ts index abebb5ce560..7c4ebc3d5ed 100644 --- a/public/app/core/core.ts +++ b/public/app/core/core.ts @@ -5,7 +5,6 @@ import "./directives/annotation_tooltip"; import "./directives/dash_class"; import "./directives/confirm_click"; import "./directives/dash_edit_link"; -import "./directives/dash_upload"; import "./directives/dropdown_typeahead"; import "./directives/grafana_version_check"; import "./directives/metric_segment"; diff --git a/public/app/core/directives/dash_upload.js b/public/app/core/directives/dash_upload.js deleted file mode 100644 index b03bc201e83..00000000000 --- a/public/app/core/directives/dash_upload.js +++ /dev/null @@ -1,46 +0,0 @@ -define([ - '../core_module', - 'app/core/utils/kbn', -], -function (coreModule, kbn) { - 'use strict'; - - coreModule.default.directive('dashUpload', function(timer, alertSrv, $location) { - return { - restrict: 'A', - link: function(scope) { - function file_selected(evt) { - var files = evt.target.files; // FileList object - var readerOnload = function() { - return function(e) { - scope.$apply(function() { - try { - window.grafanaImportDashboard = JSON.parse(e.target.result); - } catch (err) { - console.log(err); - scope.appEvent('alert-error', ['Import failed', 'JSON -> JS Serialization failed: ' + err.message]); - return; - } - var title = kbn.slugifyForUrl(window.grafanaImportDashboard.title); - window.grafanaImportDashboard.id = null; - $location.path('/dashboard-import/' + title); - }); - }; - }; - for (var i = 0, f; f = files[i]; i++) { - var reader = new FileReader(); - reader.onload = (readerOnload)(f); - reader.readAsText(f); - } - } - // Check for the various File API support. - if (window.File && window.FileReader && window.FileList && window.Blob) { - // Something - document.getElementById('dashupload').addEventListener('change', file_selected, false); - } else { - alertSrv.set('Oops','Sorry, the HTML5 File APIs are not fully supported in this browser.','error'); - } - } - }; - }); -}); diff --git a/public/app/features/dashboard/all.js b/public/app/features/dashboard/all.js index 9d370921332..926288a6e71 100644 --- a/public/app/features/dashboard/all.js +++ b/public/app/features/dashboard/all.js @@ -16,4 +16,5 @@ define([ './graphiteImportCtrl', './importCtrl', './impression_store', + './upload', ], function () {}); diff --git a/public/app/features/dashboard/upload.ts b/public/app/features/dashboard/upload.ts new file mode 100644 index 00000000000..90e811a43c1 --- /dev/null +++ b/public/app/features/dashboard/upload.ts @@ -0,0 +1,65 @@ +/// + +import kbn from 'app/core/utils/kbn'; +import coreModule from 'app/core/core_module'; + +var wnd: any = window; + +class DashboardImporter { + + prepareForImport(dash) { + dash.id = null; + return Promise.resolve(dash); + } + +} + + +/** @ngInject */ +function uploadDashboardDirective(timer, alertSrv, $location) { + return { + restrict: 'A', + link: function(scope) { + function file_selected(evt) { + var files = evt.target.files; // FileList object + var readerOnload = function() { + return function(e) { + var dash; + try { + dash = JSON.parse(e.target.result); + } catch (err) { + console.log(err); + scope.appEvent('alert-error', ['Import failed', 'JSON -> JS Serialization failed: ' + err.message]); + return; + } + + var importer = new DashboardImporter(); + importer.prepareForImport(dash).then(modified => { + wnd.grafanaImportDashboard = modified; + var title = kbn.slugifyForUrl(dash.title); + + scope.$apply(function() { + $location.path('/dashboard-import/' + title); + }); + }); + }; + }; + + for (var i = 0, f; f = files[i]; i++) { + var reader = new FileReader(); + reader.onload = readerOnload(); + reader.readAsText(f); + } + } + // Check for the various File API support. + if (wnd.File && wnd.FileReader && wnd.FileList && wnd.Blob) { + // Something + document.getElementById('dashupload').addEventListener('change', file_selected, false); + } else { + alertSrv.set('Oops','Sorry, the HTML5 File APIs are not fully supported in this browser.','error'); + } + } + }; +} + +coreModule.directive('dashUpload', uploadDashboardDirective);