mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fixed issues with unsaved changes srv
This commit is contained in:
parent
4c64bcfae7
commit
257ea391da
@ -1,5 +1,6 @@
|
||||
define([
|
||||
'./dashboard-from-es',
|
||||
'./dashboard-from-file'
|
||||
'./dashboard-from-file',
|
||||
'./dashboard-from-script'
|
||||
],
|
||||
function () {});
|
61
src/app/routes/dashboard-from-script.js
Normal file
61
src/app/routes/dashboard-from-script.js
Normal file
@ -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 <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, $) {
|
||||
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');
|
||||
|
@ -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);
|
||||
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user