mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
POC for repeating panels based on template variable options
This commit is contained in:
parent
3fe54894a5
commit
1b59fb5be9
@ -14,5 +14,6 @@ define([
|
||||
'./unsavedChangesSrv',
|
||||
'./directives/dashSearchView',
|
||||
'./graphiteImportCtrl',
|
||||
'./dynamicDashboardSrv',
|
||||
'./importCtrl',
|
||||
], function () {});
|
||||
|
@ -15,6 +15,7 @@ function (angular, $, config) {
|
||||
dashboardKeybindings,
|
||||
timeSrv,
|
||||
templateValuesSrv,
|
||||
dynamicDashboardSrv,
|
||||
dashboardSrv,
|
||||
dashboardViewStateSrv,
|
||||
$timeout) {
|
||||
@ -44,6 +45,8 @@ function (angular, $, config) {
|
||||
// template values service needs to initialize completely before
|
||||
// the rest of the dashboard can load
|
||||
templateValuesSrv.init(dashboard).then(function() {
|
||||
dynamicDashboardSrv.init(dashboard);
|
||||
|
||||
$scope.dashboard = dashboard;
|
||||
$scope.dashboardViewState = dashboardViewStateSrv.create($scope);
|
||||
$scope.dashboardMeta = data.meta;
|
||||
|
@ -126,6 +126,7 @@ function (angular, $, kbn, _, moment) {
|
||||
|
||||
var currentRow = this.rows[rowIndex];
|
||||
currentRow.panels.push(newPanel);
|
||||
return newPanel;
|
||||
};
|
||||
|
||||
p.formatDate = function(date, format) {
|
||||
|
48
src/app/features/dashboard/dynamicDashboardSrv.js
Normal file
48
src/app/features/dashboard/dynamicDashboardSrv.js
Normal file
@ -0,0 +1,48 @@
|
||||
define([
|
||||
'angular',
|
||||
'lodash',
|
||||
],
|
||||
function (angular, _) {
|
||||
'use strict';
|
||||
|
||||
var module = angular.module('grafana.services');
|
||||
|
||||
module.service('dynamicDashboardSrv', function() {
|
||||
|
||||
this.init = function(dashboard) {
|
||||
this.handlePanelRepeats(dashboard);
|
||||
};
|
||||
|
||||
this.handlePanelRepeats = function(dashboard) {
|
||||
var i, j, row, panel;
|
||||
for (i = 0; i < dashboard.rows.length; i++) {
|
||||
row = dashboard.rows[i];
|
||||
for (j = 0; j < row.panels.length; j++) {
|
||||
panel = row.panels[j];
|
||||
if (panel.repeat) {
|
||||
this.repeatPanel(panel, row, dashboard);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.repeatPanel = function(panel, row, dashboard) {
|
||||
var variables = dashboard.templating.list;
|
||||
var variable = _.findWhere(variables, {name: panel.repeat.replace('$', '')});
|
||||
if (!variable) {
|
||||
return;
|
||||
}
|
||||
|
||||
_.each(variable.options, function(option) {
|
||||
var copy = dashboard.duplicatePanel(panel, row);
|
||||
copy.repeat = null;
|
||||
console.log('duplicatePanel');
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
@ -11,6 +11,7 @@ function (angular, _, config) {
|
||||
module.service('panelSrv', function($rootScope, $timeout, datasourceSrv, $q) {
|
||||
|
||||
this.init = function($scope) {
|
||||
|
||||
if (!$scope.panel.span) { $scope.panel.span = 12; }
|
||||
|
||||
$scope.inspector = {};
|
||||
|
@ -10,6 +10,13 @@
|
||||
<div class="editor-option">
|
||||
<label class="small">Height</label><input type="text" class="input-small" ng-model='panel.height'></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h5>Templating options</h5>
|
||||
<div class="editor-option">
|
||||
<label class="small">Repeat Panel</label>
|
||||
<input type="text" class="input-medium" ng-model='panel.repeat'></input>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user