/// import _ from 'lodash'; export class DashboardRowCtrl { static template = ` {{ctrl.panel.title | interpolateTemplateVars:this}}
`; dashboard: any; panel: any; constructor(private $rootScope) { this.panel.hiddenPanels = this.panel.hiddenPanels || []; } toggle() { if (this.panel.collapse) { let panelIndex = _.indexOf(this.dashboard.panels, this.panel); for (let child of this.panel.hiddenPanels) { this.dashboard.panels.splice(panelIndex+1, 0, child); child.y = this.panel.y+1; console.log('restoring child', child); } this.panel.hiddenPanels = []; this.panel.collapse = false; return; } this.panel.collapse = true; let foundRow = false; for (let i = 0; i < this.dashboard.panels.length; i++) { let panel = this.dashboard.panels[i]; if (panel === this.panel) { console.log('found row'); foundRow = true; continue; } if (!foundRow) { continue; } if (panel.type === 'row') { break; } this.panel.hiddenPanels.push(panel); console.log('hiding child', panel.id); } for (let hiddenPanel of this.panel.hiddenPanels) { this.dashboard.removePanel(hiddenPanel, false); } } link(scope, elem) { elem.addClass('dashboard-row'); scope.$watch('ctrl.panel.collapse', () => { elem.toggleClass('dashboard-row--collapse', this.panel.collapse === true); }); } }