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:
@@ -14,5 +14,6 @@ define([
|
|||||||
'./unsavedChangesSrv',
|
'./unsavedChangesSrv',
|
||||||
'./directives/dashSearchView',
|
'./directives/dashSearchView',
|
||||||
'./graphiteImportCtrl',
|
'./graphiteImportCtrl',
|
||||||
|
'./dynamicDashboardSrv',
|
||||||
'./importCtrl',
|
'./importCtrl',
|
||||||
], function () {});
|
], function () {});
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ function (angular, $, config) {
|
|||||||
dashboardKeybindings,
|
dashboardKeybindings,
|
||||||
timeSrv,
|
timeSrv,
|
||||||
templateValuesSrv,
|
templateValuesSrv,
|
||||||
|
dynamicDashboardSrv,
|
||||||
dashboardSrv,
|
dashboardSrv,
|
||||||
dashboardViewStateSrv,
|
dashboardViewStateSrv,
|
||||||
$timeout) {
|
$timeout) {
|
||||||
@@ -44,6 +45,8 @@ function (angular, $, config) {
|
|||||||
// template values service needs to initialize completely before
|
// template values service needs to initialize completely before
|
||||||
// the rest of the dashboard can load
|
// the rest of the dashboard can load
|
||||||
templateValuesSrv.init(dashboard).then(function() {
|
templateValuesSrv.init(dashboard).then(function() {
|
||||||
|
dynamicDashboardSrv.init(dashboard);
|
||||||
|
|
||||||
$scope.dashboard = dashboard;
|
$scope.dashboard = dashboard;
|
||||||
$scope.dashboardViewState = dashboardViewStateSrv.create($scope);
|
$scope.dashboardViewState = dashboardViewStateSrv.create($scope);
|
||||||
$scope.dashboardMeta = data.meta;
|
$scope.dashboardMeta = data.meta;
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ function (angular, $, kbn, _, moment) {
|
|||||||
|
|
||||||
var currentRow = this.rows[rowIndex];
|
var currentRow = this.rows[rowIndex];
|
||||||
currentRow.panels.push(newPanel);
|
currentRow.panels.push(newPanel);
|
||||||
|
return newPanel;
|
||||||
};
|
};
|
||||||
|
|
||||||
p.formatDate = function(date, format) {
|
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) {
|
module.service('panelSrv', function($rootScope, $timeout, datasourceSrv, $q) {
|
||||||
|
|
||||||
this.init = function($scope) {
|
this.init = function($scope) {
|
||||||
|
|
||||||
if (!$scope.panel.span) { $scope.panel.span = 12; }
|
if (!$scope.panel.span) { $scope.panel.span = 12; }
|
||||||
|
|
||||||
$scope.inspector = {};
|
$scope.inspector = {};
|
||||||
|
|||||||
@@ -10,6 +10,13 @@
|
|||||||
<div class="editor-option">
|
<div class="editor-option">
|
||||||
<label class="small">Height</label><input type="text" class="input-small" ng-model='panel.height'></select>
|
<label class="small">Height</label><input type="text" class="input-small" ng-model='panel.height'></select>
|
||||||
</div>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user