Commit 36c406ee by Tobias Skarhed Committed by Torkel Ödegaard

Extract to own method

parent 1618b095
...@@ -65,24 +65,7 @@ export class DashboardCtrl implements PanelContainer { ...@@ -65,24 +65,7 @@ export class DashboardCtrl implements PanelContainer {
this.dashboard = dashboard; this.dashboard = dashboard;
this.dashboard.processRepeats(); this.dashboard.processRepeats();
if (this.$location.search().autofitpanels) { this.autofitPanels();
let maxRows = Math.max(
...this.dashboard.panels.map(panel => {
return panel.gridPos.h + panel.gridPos.y;
})
);
//Consider navbar and submenu controls, padding and margin
let availableHeight = window.innerHeight - 80;
let availableRows = Math.floor(availableHeight / (GRID_CELL_HEIGHT + GRID_CELL_VMARGIN));
let scaleFactor = maxRows / availableRows;
this.dashboard.panels.forEach((panel, i) => {
panel.gridPos.y = Math.round(panel.gridPos.y / scaleFactor) || 1;
panel.gridPos.h = Math.round(panel.gridPos.h / scaleFactor) || 1;
});
}
this.unsavedChangesSrv.init(dashboard, this.$scope); this.unsavedChangesSrv.init(dashboard, this.$scope);
// TODO refactor ViewStateSrv // TODO refactor ViewStateSrv
...@@ -99,6 +82,26 @@ export class DashboardCtrl implements PanelContainer { ...@@ -99,6 +82,26 @@ export class DashboardCtrl implements PanelContainer {
.catch(this.onInitFailed.bind(this, 'Dashboard init failed', true)); .catch(this.onInitFailed.bind(this, 'Dashboard init failed', true));
} }
autofitPanels() {
if (this.$location.search().autofitpanels) {
let maxRows = Math.max(
...this.dashboard.panels.map(panel => {
return panel.gridPos.h + panel.gridPos.y;
})
);
//Consider navbar and submenu controls, padding and margin
let availableHeight = window.innerHeight - 80;
let availableRows = Math.floor(availableHeight / (GRID_CELL_HEIGHT + GRID_CELL_VMARGIN));
let scaleFactor = maxRows / availableRows;
this.dashboard.panels.forEach((panel, i) => {
panel.gridPos.y = Math.round(panel.gridPos.y / scaleFactor) || 1;
panel.gridPos.h = Math.round(panel.gridPos.h / scaleFactor) || 1;
});
}
}
onInitFailed(msg, fatal, err) { onInitFailed(msg, fatal, err) {
console.log(msg, err); console.log(msg, err);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment