mirror of
https://github.com/ansible/awx.git
synced 2026-05-11 19:37:38 -02:30
Handle edge cases for auto resize module directive
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
angular.module('DashboardGraphs')
|
angular.module('DashboardGraphs')
|
||||||
.directive('autoSizeModule', ['$window', function($window) {
|
.directive('autoSizeModule', ['$window', '$timeout', function($window, $timeout) {
|
||||||
|
|
||||||
// Adjusts the size of the module so that all modules
|
// Adjusts the size of the module so that all modules
|
||||||
// fit into a single a page; assumes there are 2 rows
|
// fit into a single a page; assumes there are 2 rows
|
||||||
@@ -7,6 +7,21 @@ angular.module('DashboardGraphs')
|
|||||||
// by the navbar & the count summaries module
|
// by the navbar & the count summaries module
|
||||||
return function(scope, element, attr) {
|
return function(scope, element, attr) {
|
||||||
|
|
||||||
|
// We need to trigger a resize on the first call
|
||||||
|
// to this when the view things load; but we don't want
|
||||||
|
// to trigger a global window resize for everything that
|
||||||
|
// has an auto resize, since they'll all pick it up with
|
||||||
|
// a single call
|
||||||
|
var triggerResize =
|
||||||
|
_.throttle(function() {
|
||||||
|
$($window).resize();
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
function adjustSizeInitially() {
|
||||||
|
adjustSize();
|
||||||
|
triggerResize();
|
||||||
|
}
|
||||||
|
|
||||||
function adjustSize() {
|
function adjustSize() {
|
||||||
var winHeight = $($window).height(),
|
var winHeight = $($window).height(),
|
||||||
available_height = winHeight - $('#main-menu-container .navbar').outerHeight() - $('#count-container').outerHeight() - 120;
|
available_height = winHeight - $('#main-menu-container .navbar').outerHeight() - $('#count-container').outerHeight() - 120;
|
||||||
@@ -19,11 +34,18 @@ angular.module('DashboardGraphs')
|
|||||||
$($window).off('resize', adjustSize);
|
$($window).off('resize', adjustSize);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Wait a second or until dashboardReady triggers,
|
||||||
|
// whichever comes first. The timeout handles cases
|
||||||
|
// where dashboardReady never fires.
|
||||||
|
|
||||||
|
var dashboardReadyTimeout = $timeout(adjustSizeInitially, 500);
|
||||||
|
|
||||||
// This makes sure count-container div is loaded
|
// This makes sure count-container div is loaded
|
||||||
// by controllers/Home.js before we use it
|
// by controllers/Home.js before we use it
|
||||||
// to determine the available window height
|
// to determine the available window height
|
||||||
scope.$on('dashboardReady', function() {
|
scope.$on('dashboardReady', function() {
|
||||||
adjustSize();
|
$timeout.cancel(dashboardReadyTimeout);
|
||||||
|
adjustSizeInitially();
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user