row_ctrl.ts 2.5 KB

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