row_ctrl.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.isCollapsed"></i>
  8. <i class="fa fa-chevron-right" ng-show="ctrl.isCollapsed"></i>
  9. </span>
  10. <span class="dashboard-row__title-text">{{ctrl.panel.title | interpolateTemplateVars:this}}</span>
  11. </a>
  12. <div class="dashboard-row__drag grid-drag-handle" ng-if="ctrl.isCollapsed">
  13. drag
  14. </div>
  15. <a class="dashboard-row__settings pointer">
  16. <i class="fa fa-cog"></i>
  17. </a>
  18. `;
  19. dashboard: any;
  20. panel: any;
  21. isCollapsed: boolean;
  22. constructor(private $rootScope) {
  23. console.log(this);
  24. this.panel.hiddenPanels = this.panel.hiddenPanels || [];
  25. this.isCollapsed = this.panel.hiddenPanels.length > 0;
  26. }
  27. toggle() {
  28. if (this.isCollapsed) {
  29. let panelIndex = _.indexOf(this.dashboard.panels, this.panel);
  30. for (let child of this.panel.hiddenPanels) {
  31. this.dashboard.panels.splice(panelIndex+1, 0, child);
  32. child.y = this.panel.y+1;
  33. console.log('restoring child', child);
  34. }
  35. this.panel.hiddenPanels = [];
  36. this.isCollapsed = false;
  37. return;
  38. }
  39. this.isCollapsed = true;
  40. let foundRow = false;
  41. for (let i = 0; i < this.dashboard.panels.length; i++) {
  42. let panel = this.dashboard.panels[i];
  43. if (panel === this.panel) {
  44. console.log('found row');
  45. foundRow = true;
  46. continue;
  47. }
  48. if (!foundRow) {
  49. continue;
  50. }
  51. if (panel.type === 'row') {
  52. break;
  53. }
  54. this.panel.hiddenPanels.push(panel);
  55. console.log('hiding child', panel.id);
  56. }
  57. for (let hiddenPanel of this.panel.hiddenPanels) {
  58. this.dashboard.removePanel(hiddenPanel, false);
  59. }
  60. }
  61. link(scope, elem) {
  62. elem.addClass('dashboard-row');
  63. scope.$watch('ctrl.isCollapsed', () => {
  64. elem.toggleClass('dashboard-row--collapse', this.isCollapsed);
  65. });
  66. }
  67. }