module.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. group: ['default'],
  47. type: type,
  48. };
  49. };
  50. })
  51. .directive('columnEdit', function($compile,$timeout) {
  52. return {
  53. scope : {
  54. new_panel:"=panel",
  55. row:"=",
  56. config:"=",
  57. dashboards:"=",
  58. type:"=type"
  59. },
  60. link: function(scope, elem, attrs, ctrl) {
  61. scope.$on('render', function () {
  62. // Make sure the digest has completed and populated the attributes
  63. $timeout(function() {
  64. // Create a reference to the new_panel as panel so that the existing
  65. // editors work with our isolate scope
  66. scope.panel = scope.new_panel;
  67. var template = '<div ng-include src="\'panels/column/panelgeneral.html\'"></div>';
  68. if(!(_.isUndefined(scope.type)) && scope.type !== "") {
  69. template = template+'<div ng-include src="\'panels/'+scope.type+'/editor.html\'"></div>';
  70. }
  71. elem.html($compile(angular.element(template))(scope));
  72. });
  73. });
  74. }
  75. };
  76. }).filter('withoutColumn', function() {
  77. return function() {
  78. return _.without(config.modules,'column');
  79. };
  80. });