mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
worked on solo panel
This commit is contained in:
parent
c34d2f91cc
commit
de1de852fc
@ -1,7 +1,7 @@
|
||||
<div class="container-fluid main">
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
<div class="panel nospace" ng-if="panel" style="display:block;">
|
||||
<div class="panel nospace" ng-if="panel" style="width: 100%">
|
||||
<grafana-panel type="panel.type" ng-cloak></kibana-panel>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,6 +1,6 @@
|
||||
define([
|
||||
'./p_dashboard',
|
||||
'./p_solo-panel',
|
||||
'./pro/solo-panel',
|
||||
'./p_admin',
|
||||
'./p_login',
|
||||
],
|
||||
|
@ -14,17 +14,20 @@ function (angular) {
|
||||
});
|
||||
});
|
||||
|
||||
module.controller('SoloPanelCtrl', function($scope, $rootScope, datasourceSrv, $routeParams, alertSrv, dashboardSrv, filterSrv) {
|
||||
module.controller('SoloPanelCtrl', function($scope, $rootScope, datasourceSrv, $routeParams, dashboardSrv, timeSrv) {
|
||||
var panelId;
|
||||
|
||||
var db = datasourceSrv.getGrafanaDB();
|
||||
var panelId = parseInt($routeParams.panelId);
|
||||
$scope.init = function() {
|
||||
var db = datasourceSrv.getGrafanaDB();
|
||||
panelId = parseInt($routeParams.panelId);
|
||||
|
||||
db.getDashboard($routeParams.id, false)
|
||||
.then(function(dashboardData) {
|
||||
$scope.initPanelScope(dashboardData);
|
||||
}).then(null, function(error) {
|
||||
alertSrv.set('Error', error, 'error');
|
||||
});
|
||||
db.getDashboard($routeParams.id, false)
|
||||
.then(function(dashboardData) {
|
||||
$scope.initPanelScope(dashboardData);
|
||||
}).then(null, function(error) {
|
||||
$scope.appEvent('alert-error', ['Load panel error', error]);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.initPanelScope = function(dashboardData) {
|
||||
$scope.dashboard = dashboardSrv.create(dashboardData);
|
||||
@ -36,14 +39,18 @@ function (angular) {
|
||||
$scope.$index = 0;
|
||||
$scope.panel = $scope.getPanelById(panelId);
|
||||
|
||||
if (!$scope.panel) {
|
||||
$scope.appEvent('alert-error', ['Panel not found', '']);
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.panel.span = 12;
|
||||
$scope.dashboardViewState = {
|
||||
registerPanel: function() {
|
||||
}
|
||||
};
|
||||
|
||||
$scope.filter = filterSrv;
|
||||
$scope.filter.init($scope.dashboard);
|
||||
timeSrv.init($scope.dashboard);
|
||||
};
|
||||
|
||||
$scope.getPanelById = function(id) {
|
||||
@ -60,6 +67,10 @@ function (angular) {
|
||||
return null;
|
||||
};
|
||||
|
||||
if (!$scope.skipAutoInit) {
|
||||
$scope.init();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
0
src/test/specs/SoloPanelCtrl-specs.js
Normal file
0
src/test/specs/SoloPanelCtrl-specs.js
Normal file
@ -24,7 +24,7 @@ define([
|
||||
$provide.value('timeSrv', self.timeSrv);
|
||||
$provide.value('templateSrv', self.templateSrv);
|
||||
$provide.value('$element', self.$element);
|
||||
_.each(mocks, function(key, value) {
|
||||
_.each(mocks, function(value, key) {
|
||||
$provide.value(key, value);
|
||||
});
|
||||
});
|
||||
@ -34,16 +34,20 @@ define([
|
||||
return inject(function($controller, $rootScope, $q, $location) {
|
||||
self.scope = $rootScope.$new();
|
||||
self.$location = $location;
|
||||
self.scope.grafana = {};
|
||||
self.scope.panel = {};
|
||||
self.scope.row = { panels:[] };
|
||||
self.scope.dashboard = {};
|
||||
self.scope.dashboardViewState = new DashboardViewStateStub();
|
||||
self.scope.appEvent = sinon.spy();
|
||||
self.scope.onAppEvent = sinon.spy();
|
||||
|
||||
$rootScope.colors = [];
|
||||
for (var i = 0; i < 50; i++) { $rootScope.colors.push('#' + i); }
|
||||
|
||||
self.$q = $q;
|
||||
self.scope.skipDataOnInit = true;
|
||||
self.scope.skipAutoInit = true;
|
||||
self.controller = $controller(controllerName, {
|
||||
$scope: self.scope
|
||||
});
|
||||
@ -87,6 +91,7 @@ define([
|
||||
}
|
||||
|
||||
function TimeSrvStub() {
|
||||
this.init = sinon.spy();
|
||||
this.time = { from:'now-1h', to: 'now'};
|
||||
this.timeRange = function(parse) {
|
||||
if (parse === false) {
|
||||
|
57
src/test/specs/pro/soloPanelCtrl-specs.js
Normal file
57
src/test/specs/pro/soloPanelCtrl-specs.js
Normal file
@ -0,0 +1,57 @@
|
||||
define([
|
||||
'../helpers',
|
||||
'routes/pro/solo-panel',
|
||||
'services/dashboard/dashboardSrv',
|
||||
], function(helpers) {
|
||||
'use strict';
|
||||
|
||||
describe('SoloPanelCtrl', function() {
|
||||
var ctx = new helpers.ControllerTestContext();
|
||||
var datasource = {};
|
||||
var routeParams = {};
|
||||
|
||||
beforeEach(module('grafana.routes'));
|
||||
beforeEach(module('grafana.services'));
|
||||
beforeEach(ctx.providePhase({
|
||||
$routeParams: routeParams,
|
||||
datasourceSrv: {
|
||||
getGrafanaDB: sinon.stub().returns(datasource)
|
||||
}
|
||||
}));
|
||||
|
||||
beforeEach(ctx.createControllerPhase('SoloPanelCtrl'));
|
||||
|
||||
describe('setting up solo panel scope', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
var dashboard = {
|
||||
rows: [
|
||||
{
|
||||
panels: [
|
||||
{
|
||||
id: 23,
|
||||
some: 'prop'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
routeParams.id = 1;
|
||||
routeParams.panelId = 23;
|
||||
datasource.getDashboard = sinon.stub().returns(ctx.$q.when(dashboard));
|
||||
|
||||
ctx.scope.init();
|
||||
ctx.scope.$digest();
|
||||
});
|
||||
|
||||
it('should load dashboard and extract panel and setup panel scope', function() {
|
||||
expect(ctx.scope.panel.id).to.be(23);
|
||||
expect(ctx.scope.panel.some).to.be('prop');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
@ -114,6 +114,7 @@ require([
|
||||
angular.module('grafana', ['ngRoute']);
|
||||
angular.module('grafana.services', ['ngRoute', '$strap.directives']);
|
||||
angular.module('grafana.panels', []);
|
||||
angular.module('grafana.routes', ['ngRoute']);
|
||||
angular.module('grafana.filters', []);
|
||||
|
||||
require([
|
||||
@ -140,6 +141,7 @@ require([
|
||||
'specs/dashboardSrv-specs',
|
||||
'specs/dashboardViewStateSrv-specs',
|
||||
'specs/overview-ctrl-specs',
|
||||
'specs/pro/soloPanelCtrl-specs',
|
||||
], function () {
|
||||
window.__karma__.start();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user