row_ctrl.ts 2.6 KB

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