2014-08-06 08:57:40 -05:00
|
|
|
define([
|
|
|
|
'angular',
|
2014-08-07 07:35:19 -05:00
|
|
|
'lodash',
|
2014-08-06 08:57:40 -05:00
|
|
|
],
|
2014-08-13 08:02:57 -05:00
|
|
|
function (angular, _) {
|
2014-08-06 08:57:40 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var module = angular.module('grafana.services');
|
2014-08-13 03:07:32 -05:00
|
|
|
module.service('panelSrv', function($rootScope, $timeout, datasourceSrv) {
|
2014-08-06 08:57:40 -05:00
|
|
|
|
|
|
|
this.init = function($scope) {
|
2014-09-05 10:44:38 -05:00
|
|
|
if (!$scope.panel.span) { $scope.panel.span = 12; }
|
2014-08-06 08:57:40 -05:00
|
|
|
|
|
|
|
var menu = [
|
|
|
|
{
|
2014-09-23 09:11:31 -05:00
|
|
|
text: "view",
|
2014-09-24 04:58:02 -05:00
|
|
|
icon: "icon-eye-open",
|
2014-09-23 09:11:31 -05:00
|
|
|
click: 'toggleFullscreen(false)',
|
|
|
|
condition: $scope.panelMeta.fullscreenView
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'edit',
|
2014-09-24 04:58:02 -05:00
|
|
|
icon: 'icon-cogs',
|
2014-09-23 15:30:01 -05:00
|
|
|
click: 'editPanel()',
|
|
|
|
condition: true,
|
2014-08-06 08:57:40 -05:00
|
|
|
},
|
|
|
|
{
|
2014-09-23 09:11:31 -05:00
|
|
|
text: 'duplicate',
|
2014-09-24 04:58:02 -05:00
|
|
|
icon: 'icon-copy',
|
2014-08-06 08:57:40 -05:00
|
|
|
click: 'duplicatePanel(panel)',
|
|
|
|
condition: true
|
|
|
|
},
|
|
|
|
{
|
2014-09-23 15:10:10 -05:00
|
|
|
text: 'json',
|
2014-09-24 04:58:02 -05:00
|
|
|
icon: 'icon-code',
|
2014-09-23 15:10:10 -05:00
|
|
|
click: 'editPanelJson()',
|
2014-09-03 04:15:01 -05:00
|
|
|
condition: true
|
|
|
|
},
|
2014-09-24 04:58:02 -05:00
|
|
|
{
|
|
|
|
text: 'share',
|
|
|
|
icon: 'icon-share',
|
|
|
|
click: 'sharePanel()',
|
|
|
|
condition: true
|
|
|
|
},
|
2014-08-06 08:57:40 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
$scope.inspector = {};
|
|
|
|
$scope.panelMeta.menu = _.where(menu, { condition: true });
|
|
|
|
|
2014-09-23 15:30:01 -05:00
|
|
|
$scope.editPanel = function() {
|
|
|
|
if ($scope.panelMeta.fullscreenEdit) {
|
|
|
|
$scope.toggleFullscreen(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$scope.emitAppEvent('show-dash-editor', { src: 'app/partials/paneleditor.html', scope: $scope });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-03 04:15:01 -05:00
|
|
|
$scope.editPanelJson = function() {
|
|
|
|
$scope.emitAppEvent('show-json-editor', { object: $scope.panel, updateHandler: $scope.replacePanel });
|
|
|
|
};
|
|
|
|
|
2014-08-06 08:57:40 -05:00
|
|
|
$scope.updateColumnSpan = function(span) {
|
2014-09-23 09:11:31 -05:00
|
|
|
$scope.panel.span = Math.min(Math.max($scope.panel.span + span, 1), 12);
|
2014-08-06 08:57:40 -05:00
|
|
|
|
|
|
|
$timeout(function() {
|
|
|
|
$scope.$emit('render');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.addDataQuery = function() {
|
|
|
|
$scope.panel.targets.push({target: ''});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removeDataQuery = function (query) {
|
|
|
|
$scope.panel.targets = _.without($scope.panel.targets, query);
|
|
|
|
$scope.get_data();
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.setDatasource = function(datasource) {
|
|
|
|
$scope.panel.datasource = datasource;
|
|
|
|
$scope.datasource = datasourceSrv.get(datasource);
|
|
|
|
|
|
|
|
if (!$scope.datasource) {
|
2014-09-04 02:44:42 -05:00
|
|
|
$scope.panelMeta.error = "Cannot find datasource " + datasource;
|
2014-08-06 08:57:40 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.changeDatasource = function(datasource) {
|
|
|
|
$scope.setDatasource(datasource);
|
|
|
|
$scope.get_data();
|
|
|
|
};
|
|
|
|
|
2014-08-13 07:22:21 -05:00
|
|
|
$scope.toggleFullscreen = function(edit) {
|
|
|
|
$scope.dashboardViewState.update({ fullscreen: true, edit: edit, panelId: $scope.panel.id });
|
2014-08-06 08:57:40 -05:00
|
|
|
};
|
|
|
|
|
2014-08-12 11:21:48 -05:00
|
|
|
$scope.otherPanelInFullscreenMode = function() {
|
2014-08-13 03:07:32 -05:00
|
|
|
return $scope.dashboardViewState.fullscreen && !$scope.fullscreen;
|
2014-08-12 11:21:48 -05:00
|
|
|
};
|
|
|
|
|
2014-08-06 08:57:40 -05:00
|
|
|
// Post init phase
|
|
|
|
$scope.fullscreen = false;
|
2014-08-21 02:29:56 -05:00
|
|
|
$scope.editor = { index: 1 };
|
2014-08-06 08:57:40 -05:00
|
|
|
if ($scope.panelMeta.fullEditorTabs) {
|
|
|
|
$scope.editorTabs = _.pluck($scope.panelMeta.fullEditorTabs, 'title');
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.datasources = datasourceSrv.getMetricSources();
|
|
|
|
$scope.setDatasource($scope.panel.datasource);
|
2014-08-13 05:16:37 -05:00
|
|
|
$scope.dashboardViewState.registerPanel($scope);
|
2014-08-12 11:21:48 -05:00
|
|
|
|
|
|
|
if ($scope.get_data) {
|
|
|
|
var panel_get_data = $scope.get_data;
|
|
|
|
$scope.get_data = function() {
|
|
|
|
if ($scope.otherPanelInFullscreenMode()) { return; }
|
|
|
|
|
2014-09-04 02:44:42 -05:00
|
|
|
delete $scope.panelMeta.error;
|
2014-08-12 11:21:48 -05:00
|
|
|
$scope.panelMeta.loading = true;
|
|
|
|
|
|
|
|
panel_get_data();
|
|
|
|
};
|
2014-08-13 08:02:57 -05:00
|
|
|
|
2014-08-12 11:21:48 -05:00
|
|
|
if (!$scope.skipDataOnInit) {
|
|
|
|
$scope.get_data();
|
|
|
|
}
|
|
|
|
}
|
2014-08-06 08:57:40 -05:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|