panel_header.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ///<reference path="../../headers/common.d.ts" />
  2. import {coreModule} from 'app/core/core';
  3. var template = `
  4. <span class="panel-title">
  5. <span class="icon-gf panel-alert-icon"></span>
  6. <span class="panel-title-text">{{ctrl.panel.title | interpolateTemplateVars:this}}</span>
  7. <span class="panel-menu-container dropdown">
  8. <span class="fa fa-caret-down panel-menu-toggle" data-toggle="dropdown"></span>
  9. <ul class="dropdown-menu dropdown-menu--menu panel-menu" role="menu">
  10. <li>
  11. <a ng-click="ctrl.addDataQuery(datasource);">
  12. <i class="fa fa-cog"></i> Edit <span class="dropdown-menu-item-shortcut">e</span>
  13. </a>
  14. </li>
  15. <li class="dropdown-submenu">
  16. <a ng-click="ctrl.addDataQuery(datasource);"><i class="fa fa-cube"></i> Actions</a>
  17. <ul class="dropdown-menu panel-menu">
  18. <li><a ng-click="ctrl.addDataQuery(datasource);"><i class="fa fa-flash"></i> Add Annotation</a></li>
  19. <li><a ng-click="ctrl.addDataQuery(datasource);"><i class="fa fa-bullseye"></i> Toggle Legend</a></li>
  20. <li><a ng-click="ctrl.addDataQuery(datasource);"><i class="fa fa-download"></i> Export to CSV</a></li>
  21. <li><a ng-click="ctrl.addDataQuery(datasource);"><i class="fa fa-eye"></i> View JSON</a></li>
  22. </ul>
  23. </li>
  24. <li><a ng-click="ctrl.addDataQuery(datasource);"><i class="fa fa-trash"></i> Remove</a></li>
  25. </ul>
  26. </span>
  27. <span class="panel-time-info" ng-show="ctrl.timeInfo"><i class="fa fa-clock-o"></i> {{ctrl.timeInfo}}</span>
  28. </span>`;
  29. function renderMenuItem(item, ctrl) {
  30. let html = '';
  31. let listItemClass = '';
  32. if (item.divider) {
  33. return '<li class="divider"></li>';
  34. }
  35. if (item.submenu) {
  36. listItemClass = 'dropdown-submenu';
  37. }
  38. html += `<li class="${listItemClass}"><a `;
  39. if (item.click) { html += ` ng-click="${item.click}"`; }
  40. if (item.href) { html += ` href="${item.href}"`; }
  41. html += `><i class="${item.icon}"></i>`;
  42. html += `<span class="dropdown-item-text">${item.text}</span>`;
  43. if (item.shortcut) {
  44. html += `<span class="dropdown-menu-item-shortcut">${item.shortcut}</span>`;
  45. }
  46. html += `</a>`;
  47. if (item.submenu) {
  48. html += '<ul class="dropdown-menu dropdown-menu--menu panel-menu">';
  49. for (let subitem of item.submenu) {
  50. html += renderMenuItem(subitem, ctrl);
  51. }
  52. html += '</ul>';
  53. }
  54. html += `</li>`;
  55. return html;
  56. }
  57. function createMenuTemplate(ctrl) {
  58. let html = '';
  59. for (let item of ctrl.getMenu()) {
  60. html += renderMenuItem(item, ctrl);
  61. }
  62. return html;
  63. }
  64. /** @ngInject **/
  65. function panelHeader($compile) {
  66. return {
  67. restrict: 'E',
  68. template: template,
  69. link: function(scope, elem, attrs) {
  70. let menuElem = elem.find('.panel-menu');
  71. let menuScope;
  72. elem.click(function(evt) {
  73. //const targetClass = evt.target.className;
  74. // remove existing scope
  75. if (menuScope) {
  76. menuScope.$destroy();
  77. }
  78. menuScope = scope.$new();
  79. let menuHtml = createMenuTemplate(scope.ctrl);
  80. menuElem.html(menuHtml);
  81. $compile(menuElem)(menuScope);
  82. // if (targetClass === 'panel-title-text' || targetClass === 'panel-title') {
  83. // evt.stopPropagation();
  84. // elem.find('[data-toggle=dropdown]').dropdown('toggle');
  85. // }
  86. });
  87. }
  88. };
  89. }
  90. coreModule.directive('panelHeader', panelHeader);