Skip to content

Commit

Permalink
Remove prepareWidgetsForDashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldutra committed Nov 14, 2019
1 parent 05e8b24 commit b434f03
Showing 1 changed file with 1 addition and 46 deletions.
47 changes: 1 addition & 46 deletions client/app/services/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,50 +33,6 @@ export function collectDashboardFilters(dashboard, queryResults, urlParams) {
return _.values(filters);
}

function prepareWidgetsForDashboard(widgets) {
// Default height for auto-height widgets.
// Compute biggest widget size and choose between it and some magic number.
// This value should be big enough so auto-height widgets will not overlap other ones.
const defaultWidgetSizeY =
Math.max(
_
.chain(widgets)
.map(w => w.options.position.sizeY)
.max()
.value(),
20,
) + 5;

// Fix layout:
// 1. sort and group widgets by row
// 2. update position of widgets in each row - place it right below
// biggest widget from previous row
_.chain(widgets)
.sortBy(widget => widget.options.position.row)
.groupBy(widget => widget.options.position.row)
.reduce((row, widgetsAtRow) => {
let height = 1;
_.each(widgetsAtRow, (widget) => {
height = Math.max(
height,
widget.options.position.autoHeight ? defaultWidgetSizeY : widget.options.position.sizeY,
);
widget.options.position.row = row;
if (widget.options.position.sizeY < 1) {
widget.options.position.sizeY = defaultWidgetSizeY;
}
});
return row + height;
}, 0)
.value();

// Sort widgets by updated column and row value
widgets = _.sortBy(widgets, widget => widget.options.position.col);
widgets = _.sortBy(widgets, widget => widget.options.position.row);

return widgets;
}

function calculateNewWidgetPosition(existingWidgets, newWidget) {
const width = _.extend({ sizeX: dashboardGridOptions.defaultSizeX }, _.extend({}, newWidget.options).position).sizeX;

Expand Down Expand Up @@ -125,7 +81,7 @@ function calculateNewWidgetPosition(existingWidgets, newWidget) {

function DashboardService($resource, $http, $location, currentUser) {
function prepareDashboardWidgets(widgets) {
return prepareWidgetsForDashboard(_.map(widgets, widget => new Widget(widget)));
return _.map(widgets, widget => new Widget(widget));
}

function transformSingle(dashboard) {
Expand Down Expand Up @@ -187,7 +143,6 @@ function DashboardService($resource, $http, $location, currentUser) {
};

resource.prepareDashboardWidgets = prepareDashboardWidgets;
resource.prepareWidgetsForDashboard = prepareWidgetsForDashboard;
resource.prototype.getParametersDefs = function getParametersDefs() {
const globalParams = {};
const queryParams = $location.search();
Expand Down

0 comments on commit b434f03

Please sign in to comment.