Skip to content

Commit

Permalink
Partially address #557 and improve how added widgets are positioned
Browse files Browse the repository at this point in the history
  • Loading branch information
gashcrumb committed Sep 19, 2013
1 parent ad2c09a commit b457d49
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 15 deletions.
78 changes: 69 additions & 9 deletions hawtio-web/src/main/webapp/app/dashboard/js/editDashboards.ts
Expand Up @@ -177,31 +177,91 @@ module Dashboard {
if ($route && $route.routes) {
var value = $route.routes[text];
if (value) {
/*
angular.forEach($route.routes, (value, key) => {
if (key === text) {
*/
var templateUrl = value["templateUrl"];
if (templateUrl) {
if (!selectedItem.widgets) {
selectedItem.widgets = [];
}
var nextNumber = selectedItem.widgets.length + 1;
var widget = {
id: "w" + nextNumber, title: "", row: nextNumber, col: 1,
id: "w" + nextNumber, title: "",
row: 1,
col: 1,
size_x: 1,
size_y: 1,
path: Core.trimLeading(text, "/"),
include: templateUrl,
search: search,
hash: ""
};

// figure out the width of the dash
var gridWidth = 0;

selectedItem.widgets.forEach((w) => {
var rightSide = w.col + w.size_x;
if (rightSide > gridWidth) {
gridWidth = rightSide;
}
});

if ($scope.preferredSize) {
widget.size_x = parseInt($scope.preferredSize['size_x']);
widget.size_y = parseInt($scope.preferredSize['size_y']);
}

var found = false;

var left = (w) => {
return w.col;
};

var right = (w) => {
return w.col + w.size_x - 1;
};

var top = (w) => {
return w.row;
};

var bottom = (w) => {
return w.row + w.size_y - 1;
};

var collision = (w1, w2) => {
return !( left(w2) > right(w1) ||
right(w2) < left(w1) ||
top(w2) > bottom(w1) ||
bottom(w2) < top(w1));
};

if (selectedItem.widgets.isEmpty()) {
found = true;
}

while (!found) {
widget.col = 1;
for (; (widget.col + widget.size_x) <= gridWidth; widget.col++) {
if (!selectedItem.widgets.any((w) => {
var c = collision(w, widget);
return c
})) {
found = true;
break;
}
}
if (!found) {
widget.row = widget.row + 1
}
// just in case, keep the script from running away...
if (widget.row > 50) {
found = true;
}
}

if ($scope.routeParams) {
widget['routeParams'] = $scope.routeParams;
}
if ($scope.preferredSize) {
widget['size_x'] = $scope.preferredSize['size_x'];
widget['size_y'] = $scope.preferredSize['size_y'];
}
selectedItem.widgets.push(widget);

if (!nextHref && selectedItem.id) {
Expand Down
Expand Up @@ -202,7 +202,7 @@ module Dashboard {
var gridster = getGridster();
if (gridster) {
var data = gridster.serialize();
console.log("got data: " + JSON.stringify(data));
//console.log("got data: " + JSON.stringify(data));

var widgets = $scope.dashboard.widgets || [];
// console.log("Widgets: ", widgets);
Expand Down
13 changes: 8 additions & 5 deletions hawtio-web/src/main/webapp/app/dashboard/js/rectangleLocation.ts
Expand Up @@ -17,7 +17,8 @@ module Dashboard {

hash(newHash:string = null) {
if (newHash) {
this._hash = newHash;
return this.delegate.hash(newHash);
//this._hash = newHash;
}
return this._hash;
}
Expand All @@ -28,7 +29,7 @@ module Dashboard {

path(newPath:string = null) {
if (newPath) {
this._path = newPath;
return this.delegate.path(newPath);
}
return this._path;
}
Expand All @@ -47,7 +48,9 @@ module Dashboard {
}

search(parametersMap:any = null) {
// TODO deal with params...
if (parametersMap) {
return this.delegate.search(parametersMap);
}
return this._search;
}

Expand All @@ -60,10 +63,10 @@ module Dashboard {

url(newValue: string = null) {
if (newValue) {
// TODO!
return this.delegate.url(newValue);
}
return this.absUrl();
}

}
}
}

0 comments on commit b457d49

Please sign in to comment.