diff --git a/src/app/routes/all.js b/src/app/routes/all.js index 0f1d2fa7fb3..ccbd39cd166 100644 --- a/src/app/routes/all.js +++ b/src/app/routes/all.js @@ -1,5 +1,6 @@ define([ './dashboard-from-es', - './dashboard-from-file' + './dashboard-from-file', + './dashboard-from-script' ], function () {}); \ No newline at end of file diff --git a/src/app/routes/dashboard-from-script.js b/src/app/routes/dashboard-from-script.js new file mode 100644 index 00000000000..3cdd49e017a --- /dev/null +++ b/src/app/routes/dashboard-from-script.js @@ -0,0 +1,61 @@ +define([ + 'angular', + 'jquery', + 'config', + 'underscore', + 'kbn', + 'moment' +], +function (angular, $, config, _, kbn, moment) { + "use strict"; + + var module = angular.module('kibana.routes'); + + module.config(function($routeProvider) { + $routeProvider + .when('/dashboard/script/:jsFile', { + templateUrl: 'app/partials/dashboard.html', + controller : 'DashFromScriptProvider', + }); + }); + + module.controller('DashFromScriptProvider', function($scope, $rootScope, $http, $routeParams, alertSrv, $q) { + + var execute_script = function(result) { + /*jshint -W054 */ + var script_func = new Function('ARGS','kbn','_','moment','window','document','$','jQuery', result.data); + var script_result = script_func($routeParams, kbn, _ , moment, window, document, $, $); + + // Handle async dashboard scripts + if (_.isFunction(script_result)) { + var deferred = $q.defer(); + script_result(function(dashboard) { + $rootScope.$apply(function() { + deferred.resolve({ data: dashboard }); + }); + }); + return deferred.promise; + } + + return { data: script_result }; + }; + + var script_load = function(file) { + var url = 'app/dashboards/'+file.replace(/\.(?!js)/,"/") + '?' + new Date().getTime(); + + return $http({ url: url, method: "GET" }) + .then(execute_script) + .then(null,function(err) { + console.log('Script dashboard error '+ err); + alertSrv.set('Error', "Could not load scripts/"+file+". Please make sure it exists and returns a valid dashboard", 'error'); + return false; + }); + }; + + script_load($routeParams.jsFile).then(function(result) { + $scope.emitAppEvent('setup-dashboard', result.data); + }); + + }); + +}); diff --git a/src/app/services/dashboard/dashboardKeyBindings.js b/src/app/services/dashboard/dashboardKeyBindings.js index 4838565957d..6e8e0faaf36 100644 --- a/src/app/services/dashboard/dashboardKeyBindings.js +++ b/src/app/services/dashboard/dashboardKeyBindings.js @@ -9,7 +9,6 @@ function(angular, $) { var module = angular.module('kibana.services'); module.service('dashboardKeybindings', function($rootScope, keyboardManager) { - this.hasRegistered = false; this.shortcuts = function(scope) { @@ -28,7 +27,6 @@ function(angular, $) { }); scope.$on('$destroy', function() { - console.log('unbind keyboardManager'); keyboardManager.unbind('ctrl+f'); keyboardManager.unbind('ctrl+h'); keyboardManager.unbind('ctrl+s'); diff --git a/src/app/services/filterSrv.js b/src/app/services/filterSrv.js index f92c7b90a01..76b6c0c4051 100644 --- a/src/app/services/filterSrv.js +++ b/src/app/services/filterSrv.js @@ -94,7 +94,7 @@ define([ this.dashboard = dashboard; this.templateSettings = { interpolate : /\[\[([\s\S]+?)\]\]/g }; -/* if (!this.dashboard.services.filter) { + if (!this.dashboard.services.filter) { this.dashboard.services.filter = { list: [], time: { @@ -103,7 +103,7 @@ define([ } }; } -*/ + this.time = dashboard.services.filter.time; this.templateParameters = dashboard.services.filter.list || []; this.updateTemplateData(true); diff --git a/src/app/services/unsavedChangesSrv.js b/src/app/services/unsavedChangesSrv.js index e04ab365ab8..b52824172f7 100644 --- a/src/app/services/unsavedChangesSrv.js +++ b/src/app/services/unsavedChangesSrv.js @@ -18,8 +18,11 @@ function(angular, _, config) { var modalScope = $rootScope.$new(); $rootScope.$on("dashboard-loaded", function(event, newDashboard) { - self.original = angular.copy(newDashboard); - self.current = newDashboard; + // wait for different services to patch the dashboard (missing properties) + $timeout(function() { + self.original = angular.copy(newDashboard); + self.current = newDashboard; + }, 1000); }); $rootScope.$on("dashboard-saved", function(event, savedDashboard) { @@ -42,19 +45,20 @@ function(angular, _, config) { if (self.has_unsaved_changes()) { event.preventDefault(); self.next = next; - self.open_modal(); + + $timeout(self.open_modal); } }); }; this.open_modal = function() { var confirmModal = $modal({ - template: './app/partials/unsaved-changes.html', - persist: true, - show: false, - scope: modalScope, - keyboard: false - }); + template: './app/partials/unsaved-changes.html', + persist: true, + show: false, + scope: modalScope, + keyboard: false + }); $q.when(confirmModal).then(function(modalEl) { modalEl.modal('show');