module.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*jshint globalstrict:true */
  2. /*global angular:true */
  3. /*
  4. ## Column
  5. ### Parameters
  6. * panels :: an array of panel objects. All of their spans should be set to 12
  7. */
  8. 'use strict';
  9. angular.module('kibana.column', [])
  10. .controller('column', function($scope, $rootScope, $timeout) {
  11. $scope.panelMeta = {
  12. status : "Stable",
  13. description : "A pseudo panel that lets you add other panels to be arranged in a column with"+
  14. "defined heights."
  15. };
  16. // Set and populate defaults
  17. var _d = {
  18. panels : []
  19. };
  20. _.defaults($scope.panel,_d);
  21. $scope.init = function(){
  22. $scope.reset_panel();
  23. };
  24. $scope.toggle_row = function(panel) {
  25. panel.collapse = panel.collapse ? false : true;
  26. if (!panel.collapse) {
  27. $timeout(function() {
  28. $scope.send_render();
  29. });
  30. }
  31. };
  32. $scope.send_render = function() {
  33. $scope.$broadcast('render');
  34. };
  35. $scope.add_panel = function(panel) {
  36. $scope.panel.panels.push(panel);
  37. };
  38. $scope.reset_panel = function(type) {
  39. $scope.new_panel = {
  40. loading: false,
  41. error: false,
  42. sizeable: false,
  43. span: 12,
  44. height: "150px",
  45. editable: true,
  46. type: type,
  47. };
  48. };
  49. })
  50. .directive('columnEdit', function($compile,$timeout) {
  51. return {
  52. scope : {
  53. new_panel:"=panel",
  54. row:"=",
  55. config:"=",
  56. dashboards:"=",
  57. type:"=type"
  58. },
  59. link: function(scope, elem, attrs, ctrl) {
  60. scope.$on('render', function () {
  61. // Make sure the digest has completed and populated the attributes
  62. $timeout(function() {
  63. // Create a reference to the new_panel as panel so that the existing
  64. // editors work with our isolate scope
  65. scope.panel = scope.new_panel;
  66. var template = '<div ng-include src="\'panels/column/panelgeneral.html\'"></div>';
  67. if(!(_.isUndefined(scope.type)) && scope.type !== "") {
  68. template = template+'<div ng-include src="\'panels/'+scope.type+'/editor.html\'"></div>';
  69. }
  70. elem.html($compile(angular.element(template))(scope));
  71. });
  72. });
  73. }
  74. };
  75. }).filter('withoutColumn', function() {
  76. return function() {
  77. return _.without(config.modules,'column');
  78. };
  79. });