row_ctrl.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. ///<reference path="../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. export class DashboardRowCtrl {
  4. static template = `
  5. <a class="dashboard-row__title pointer" ng-click="ctrl.toggle()">
  6. <span class="dashboard-row__chevron">
  7. <i class="fa fa-chevron-down" ng-hide="ctrl.panel.collapse"></i>
  8. <i class="fa fa-chevron-right" ng-show="ctrl.panel.collapse"></i>
  9. </span>
  10. <span class="dashboard-row__title-text">
  11. {{ctrl.panel.title | interpolateTemplateVars:this}}
  12. </span>
  13. </a>
  14. <div class="dashboard-row__panel_count">
  15. ({{ctrl.panel.hiddenPanels.length}} hidden panels)
  16. </div>
  17. <div class="dashboard-row__actions">
  18. <a class="pointer" ng-click="ctrl.openSettings()"><span class="fa fa-cog"></i></a>
  19. </div>
  20. <div class="dashboard-row__drag grid-drag-handle">
  21. </div>
  22. `;
  23. dashboard: any;
  24. panel: any;
  25. constructor(private $rootScope) {
  26. this.panel.hiddenPanels = this.panel.hiddenPanels || [];
  27. }
  28. toggle() {
  29. if (this.panel.collapse) {
  30. let panelIndex = _.indexOf(this.dashboard.panels, this.panel);
  31. for (let child of this.panel.hiddenPanels) {
  32. this.dashboard.panels.splice(panelIndex+1, 0, child);
  33. child.y = this.panel.y+1;
  34. console.log('restoring child', child);
  35. }
  36. this.panel.hiddenPanels = [];
  37. this.panel.collapse = false;
  38. return;
  39. }
  40. this.panel.collapse = true;
  41. let foundRow = false;
  42. for (let i = 0; i < this.dashboard.panels.length; i++) {
  43. let panel = this.dashboard.panels[i];
  44. if (panel === this.panel) {
  45. console.log('found row');
  46. foundRow = true;
  47. continue;
  48. }
  49. if (!foundRow) {
  50. continue;
  51. }
  52. if (panel.type === 'row') {
  53. break;
  54. }
  55. this.panel.hiddenPanels.push(panel);
  56. console.log('hiding child', panel.id);
  57. }
  58. for (let hiddenPanel of this.panel.hiddenPanels) {
  59. this.dashboard.removePanel(hiddenPanel, false);
  60. }
  61. }
  62. moveUp() {
  63. // let panelIndex = _.indexOf(this.dashboard.panels, this.panel);
  64. // let rowAbove = null;
  65. // for (let index = panelIndex-1; index > 0; index--) {
  66. // panel = this.dashboard.panels[index];
  67. // if (panel.type === 'row') {
  68. // rowAbove = panel;
  69. // }
  70. // }
  71. //
  72. // if (rowAbove) {
  73. // this.panel.y = rowAbove.y;
  74. // }
  75. }
  76. link(scope, elem) {
  77. elem.addClass('dashboard-row');
  78. scope.$watch('ctrl.panel.collapse', () => {
  79. elem.toggleClass('dashboard-row--collapse', this.panel.collapse === true);
  80. });
  81. }
  82. }