Commit 257ea391 by Torkel Ödegaard

fixed issues with unsaved changes srv

parent 4c64bcfa
define([ define([
'./dashboard-from-es', './dashboard-from-es',
'./dashboard-from-file' './dashboard-from-file',
'./dashboard-from-script'
], ],
function () {}); function () {});
\ No newline at end of file
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 <i>scripts/"+file+"</i>. 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);
});
});
});
...@@ -9,7 +9,6 @@ function(angular, $) { ...@@ -9,7 +9,6 @@ function(angular, $) {
var module = angular.module('kibana.services'); var module = angular.module('kibana.services');
module.service('dashboardKeybindings', function($rootScope, keyboardManager) { module.service('dashboardKeybindings', function($rootScope, keyboardManager) {
this.hasRegistered = false;
this.shortcuts = function(scope) { this.shortcuts = function(scope) {
...@@ -28,7 +27,6 @@ function(angular, $) { ...@@ -28,7 +27,6 @@ function(angular, $) {
}); });
scope.$on('$destroy', function() { scope.$on('$destroy', function() {
console.log('unbind keyboardManager');
keyboardManager.unbind('ctrl+f'); keyboardManager.unbind('ctrl+f');
keyboardManager.unbind('ctrl+h'); keyboardManager.unbind('ctrl+h');
keyboardManager.unbind('ctrl+s'); keyboardManager.unbind('ctrl+s');
......
...@@ -94,7 +94,7 @@ define([ ...@@ -94,7 +94,7 @@ define([
this.dashboard = dashboard; this.dashboard = dashboard;
this.templateSettings = { interpolate : /\[\[([\s\S]+?)\]\]/g }; this.templateSettings = { interpolate : /\[\[([\s\S]+?)\]\]/g };
/* if (!this.dashboard.services.filter) { if (!this.dashboard.services.filter) {
this.dashboard.services.filter = { this.dashboard.services.filter = {
list: [], list: [],
time: { time: {
...@@ -103,7 +103,7 @@ define([ ...@@ -103,7 +103,7 @@ define([
} }
}; };
} }
*/
this.time = dashboard.services.filter.time; this.time = dashboard.services.filter.time;
this.templateParameters = dashboard.services.filter.list || []; this.templateParameters = dashboard.services.filter.list || [];
this.updateTemplateData(true); this.updateTemplateData(true);
......
...@@ -18,8 +18,11 @@ function(angular, _, config) { ...@@ -18,8 +18,11 @@ function(angular, _, config) {
var modalScope = $rootScope.$new(); var modalScope = $rootScope.$new();
$rootScope.$on("dashboard-loaded", function(event, newDashboard) { $rootScope.$on("dashboard-loaded", function(event, newDashboard) {
// wait for different services to patch the dashboard (missing properties)
$timeout(function() {
self.original = angular.copy(newDashboard); self.original = angular.copy(newDashboard);
self.current = newDashboard; self.current = newDashboard;
}, 1000);
}); });
$rootScope.$on("dashboard-saved", function(event, savedDashboard) { $rootScope.$on("dashboard-saved", function(event, savedDashboard) {
...@@ -42,7 +45,8 @@ function(angular, _, config) { ...@@ -42,7 +45,8 @@ function(angular, _, config) {
if (self.has_unsaved_changes()) { if (self.has_unsaved_changes()) {
event.preventDefault(); event.preventDefault();
self.next = next; self.next = next;
self.open_modal();
$timeout(self.open_modal);
} }
}); });
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment