grafana/src/app/directives/grafanaSimplePanel.js

68 lines
2.0 KiB
JavaScript
Raw Normal View History

define([
'angular',
2014-08-07 07:35:19 -05:00
'lodash'
],
function (angular, _) {
'use strict';
angular
2014-07-28 11:11:52 -05:00
.module('grafana.directives')
.directive('grafanaSimplePanel', function($compile) {
var panelLoading = '<span ng-show="panelMeta.loading == true">' +
'<span style="font-size:72px;font-weight:200">'+
'<i class="icon-spinner icon-spin"></i> loading ...' +
'</span>'+
'</span>';
return {
restrict: 'E',
link: function($scope, elem, attr) {
// once we have the template, scan it for controllers and
// load the module.js if we have any
// compile the module and uncloack. We're done
function loadModule($module) {
$module.appendTo(elem);
/* jshint indent:false */
$compile(elem.contents())($scope);
elem.removeClass("ng-cloak");
}
function loadController(name) {
elem.addClass("ng-cloak");
// load the panels module file, then render it in the dom.
var nameAsPath = name.replace(".", "/");
$scope.require([
'jquery',
'text!panels/'+nameAsPath+'/module.html'
], function ($, moduleTemplate) {
var $module = $(moduleTemplate);
// top level controllers
var $controllers = $module.filter('ngcontroller, [ng-controller], .ng-controller');
// add child controllers
$controllers = $controllers.add($module.find('ngcontroller, [ng-controller], .ng-controller'));
if ($controllers.length) {
$controllers.first().prepend(panelLoading);
$scope.require([
'panels/'+nameAsPath+'/module'
], function() {
loadModule($module);
});
} else {
loadModule($module);
}
});
}
$scope.$watch(attr.type, function (name) {
loadController(name);
});
}
};
});
2014-08-13 14:26:33 -05:00
});