mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
using next_positions inside add_widget method
This commit is contained in:
@@ -148,11 +148,13 @@
|
|||||||
* the widget that was just created.
|
* the widget that was just created.
|
||||||
*/
|
*/
|
||||||
fn.add_widget = function(html, size_x, size_y) {
|
fn.add_widget = function(html, size_x, size_y) {
|
||||||
|
var next_pos = this.next_position(size_x, size_y);
|
||||||
|
|
||||||
var $w = $(html).attr({
|
var $w = $(html).attr({
|
||||||
'data-col': this.highest_occupied_cell.col,
|
'data-col': next_pos.col,
|
||||||
'data-row': this.highest_occupied_cell.row + 1,
|
'data-row': next_pos.row,
|
||||||
'data-sizex' : size_x || 1,
|
'data-sizex' : next_pos.size_x,
|
||||||
'data-sizey' : size_y || 1
|
'data-sizey' : next_pos.size_y
|
||||||
}).addClass('gs_w').appendTo(this.$el).hide();
|
}).addClass('gs_w').appendTo(this.$el).hide();
|
||||||
|
|
||||||
this.$widgets = this.$widgets.add($w);
|
this.$widgets = this.$widgets.add($w);
|
||||||
@@ -178,6 +180,8 @@
|
|||||||
* widget coords.
|
* widget coords.
|
||||||
*/
|
*/
|
||||||
fn.next_position = function(size_x, size_y) {
|
fn.next_position = function(size_x, size_y) {
|
||||||
|
size_x || (size_x = 1);
|
||||||
|
size_y || (size_y = 1);
|
||||||
var ga = this.gridmap;
|
var ga = this.gridmap;
|
||||||
var cols_l = ga.length;
|
var cols_l = ga.length;
|
||||||
var valid_pos = [];
|
var valid_pos = [];
|
||||||
@@ -202,7 +206,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (valid_pos.length) {
|
if (valid_pos.length) {
|
||||||
var next_position = this.sort_by_row_asc(valid_pos)[0];
|
var next_position = this.sort_by_row_asc(valid_pos);
|
||||||
|
next_position = this.sort_by_row_asc(next_position)[0];
|
||||||
return next_position;
|
return next_position;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -695,6 +700,26 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sorts an Array of grid coords objects by column (representing the grid
|
||||||
|
* coords of each widget) in ascending way.
|
||||||
|
*
|
||||||
|
* @method sort_by_row_asc
|
||||||
|
* @param {Array} widgets Array of grid coords objects
|
||||||
|
* @return {Array} Returns the array sorted.
|
||||||
|
*/
|
||||||
|
fn.sort_by_col_asc = function(widgets) {
|
||||||
|
widgets = widgets.sort(function(a, b){
|
||||||
|
if (a.col > b.col) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
});
|
||||||
|
|
||||||
|
return widgets;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts an Array of grid coords objects (representing the grid coords of
|
* Sorts an Array of grid coords objects (representing the grid coords of
|
||||||
* each widget) in descending way.
|
* each widget) in descending way.
|
||||||
@@ -1819,6 +1844,7 @@
|
|||||||
fn.set_dom_grid_height = function() {
|
fn.set_dom_grid_height = function() {
|
||||||
var r = this.get_highest_occupied_cell().row;
|
var r = this.get_highest_occupied_cell().row;
|
||||||
this.$el.css('height', r * this.min_widget_height);
|
this.$el.css('height', r * this.min_widget_height);
|
||||||
|
// this.$widgets.draggable("option", "containment", this.$el);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user