Commit 013f8cd8 by Torkel Ödegaard

refactor: moving code around a bit, refactoring PR #12796

parent f00b5eee
...@@ -4,7 +4,6 @@ import coreModule from 'app/core/core_module'; ...@@ -4,7 +4,6 @@ import coreModule from 'app/core/core_module';
import { PanelContainer } from './dashgrid/PanelContainer'; import { PanelContainer } from './dashgrid/PanelContainer';
import { DashboardModel } from './dashboard_model'; import { DashboardModel } from './dashboard_model';
import { PanelModel } from './panel_model'; import { PanelModel } from './panel_model';
import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN } from 'app/core/constants';
export class DashboardCtrl implements PanelContainer { export class DashboardCtrl implements PanelContainer {
dashboard: DashboardModel; dashboard: DashboardModel;
...@@ -24,8 +23,7 @@ export class DashboardCtrl implements PanelContainer { ...@@ -24,8 +23,7 @@ export class DashboardCtrl implements PanelContainer {
private unsavedChangesSrv, private unsavedChangesSrv,
private dashboardViewStateSrv, private dashboardViewStateSrv,
public playlistSrv, public playlistSrv,
private panelLoader, private panelLoader
private $location
) { ) {
// temp hack due to way dashboards are loaded // temp hack due to way dashboards are loaded
// can't use controllerAs on route yet // can't use controllerAs on route yet
...@@ -64,8 +62,8 @@ export class DashboardCtrl implements PanelContainer { ...@@ -64,8 +62,8 @@ export class DashboardCtrl implements PanelContainer {
.finally(() => { .finally(() => {
this.dashboard = dashboard; this.dashboard = dashboard;
this.dashboard.processRepeats(); this.dashboard.processRepeats();
this.dashboard.autoFitPanels(window.innerHeight);
this.autofitPanels();
this.unsavedChangesSrv.init(dashboard, this.$scope); this.unsavedChangesSrv.init(dashboard, this.$scope);
// TODO refactor ViewStateSrv // TODO refactor ViewStateSrv
...@@ -82,28 +80,6 @@ export class DashboardCtrl implements PanelContainer { ...@@ -82,28 +80,6 @@ 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 - 40;
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.dashboard.meta.autofitpanels = true;
console.log(this.dashboard);
}
}
onInitFailed(msg, fatal, err) { onInitFailed(msg, fatal, err) {
console.log(msg, err); console.log(msg, err);
......
import moment from 'moment'; import moment from 'moment';
import _ from 'lodash'; import _ from 'lodash';
import { GRID_COLUMN_COUNT, REPEAT_DIR_VERTICAL } from 'app/core/constants'; import { GRID_COLUMN_COUNT, REPEAT_DIR_VERTICAL, GRID_CELL_HEIGHT, GRID_CELL_VMARGIN } from 'app/core/constants';
import { DEFAULT_ANNOTATION_COLOR } from 'app/core/utils/colors'; import { DEFAULT_ANNOTATION_COLOR } from 'app/core/utils/colors';
import { Emitter } from 'app/core/utils/emitter'; import { Emitter } from 'app/core/utils/emitter';
import { contextSrv } from 'app/core/services/context_srv'; import { contextSrv } from 'app/core/services/context_srv';
...@@ -591,10 +591,6 @@ export class DashboardModel { ...@@ -591,10 +591,6 @@ export class DashboardModel {
updateSubmenuVisibility() { updateSubmenuVisibility() {
this.meta.submenuEnabled = (() => { this.meta.submenuEnabled = (() => {
if (this.meta.autofitpanels) {
return false;
}
if (this.links.length > 0) { if (this.links.length > 0) {
return true; return true;
} }
...@@ -834,4 +830,26 @@ export class DashboardModel { ...@@ -834,4 +830,26 @@ export class DashboardModel {
return !_.isEqual(updated, this.originalTemplating); return !_.isEqual(updated, this.originalTemplating);
} }
autoFitPanels(viewHeight: number) {
if (!this.meta.autofitpanels) {
return;
}
let maxRows = Math.max(
...this.panels.map(panel => {
return panel.gridPos.h + panel.gridPos.y;
})
);
//Consider navbar and submenu controls, padding and margin
let availableHeight = window.innerHeight - 55 - 20;
let availableRows = Math.floor(availableHeight / (GRID_CELL_HEIGHT + GRID_CELL_VMARGIN));
let scaleFactor = maxRows / availableRows;
this.panels.forEach((panel, i) => {
panel.gridPos.y = Math.round(panel.gridPos.y / scaleFactor) || 1;
panel.gridPos.h = Math.round(panel.gridPos.h / scaleFactor) || 1;
});
}
} }
...@@ -305,19 +305,6 @@ describe('DashboardModel', function() { ...@@ -305,19 +305,6 @@ describe('DashboardModel', function() {
}); });
}); });
describe('updateSubmenuVisibility with autofitpanels enabled', function() {
var model;
beforeEach(function() {
model = new DashboardModel({}, { autofitpanels: true });
model.updateSubmenuVisibility();
});
it('should not enable submmenu', function() {
expect(model.meta.submenuEnabled).toBe(false);
});
});
describe('updateSubmenuVisibility with hidden annotation toggle', function() { describe('updateSubmenuVisibility with hidden annotation toggle', function() {
var dashboard; var dashboard;
......
...@@ -38,9 +38,10 @@ export class LoadDashboardCtrl { ...@@ -38,9 +38,10 @@ export class LoadDashboardCtrl {
} }
} }
if ($routeParams.keepRows) { if ($routeParams.autofitpanels) {
result.meta.keepRows = true; result.meta.autofitpanels = true;
} }
$scope.initDashboard(result, $scope); $scope.initDashboard(result, $scope);
}); });
} }
......
.dashboard-container { .dashboard-container {
padding: $dashboard-padding; padding: $dashboard-padding $dashboard-padding 0 $dashboard-padding;
width: 100%; width: 100%;
min-height: 100%; min-height: 100%;
} }
......
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