Commit de1de852 by Torkel Ödegaard

worked on solo panel

parent c34d2f91
<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>
......
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();
}
});
});
......@@ -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) {
......
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();
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment