Browse Source

HUE-8231 [dashboard] Auto resize widget height on window resize

Enrico Berti 7 years ago
parent
commit
1a73991399
1 changed files with 15 additions and 6 deletions
  1. 15 6
      desktop/libs/dashboard/src/dashboard/templates/common_search.mako

+ 15 - 6
desktop/libs/dashboard/src/dashboard/templates/common_search.mako

@@ -3913,6 +3913,7 @@ $(document).ready(function () {
       resizeFieldsList();
       resizeFieldsList();
     }, 200);
     }, 200);
     huePubSub.publish('dashboard.window.resize');
     huePubSub.publish('dashboard.window.resize');
+    huePubSub.publish('gridster.remove.scrollbars');
   });
   });
 
 
   var isDraggingOrResizingWidgets = false;
   var isDraggingOrResizingWidgets = false;
@@ -4304,15 +4305,23 @@ $(document).ready(function () {
   }, 'dashboard');
   }, 'dashboard');
 
 
   function removeInternalScroll(widget) {
   function removeInternalScroll(widget) {
-    var scrollDifference = widget.gridsterElement.scrollHeight - widget.gridsterElement.clientHeight;
-    if (scrollDifference > 0) { // avoid scrollbars inside the widget
-      widget.size_y(widget.size_y() + Math.ceil(scrollDifference / WIDGET_BASE_HEIGHT));
-      $gridster.resize_widget($(widget.gridsterElement), widget.size_x(), widget.size_y(), function () {
-        huePubSub.publish('gridster.clean.whitespace');
-      });
+    if (widget && widget.gridsterElement) {
+      var scrollDifference = widget.gridsterElement.scrollHeight - widget.gridsterElement.clientHeight;
+      if (scrollDifference > 0) { // avoid scrollbars inside the widget
+        widget.size_y(widget.size_y() + Math.ceil(scrollDifference / WIDGET_BASE_HEIGHT));
+        $gridster.resize_widget($(widget.gridsterElement), widget.size_x(), widget.size_y(), function () {
+          huePubSub.publish('gridster.clean.whitespace');
+        });
+      }
     }
     }
   }
   }
 
 
+  huePubSub.subscribe('gridster.remove.scrollbars', function () {
+    searchViewModel.gridItems().forEach(function (widget) {
+      removeInternalScroll(widget);
+    });
+  }, 'dashboard');
+
   huePubSub.subscribe('gridster.clean.grid.whitespace', function (options) {
   huePubSub.subscribe('gridster.clean.grid.whitespace', function (options) {
     var $gridsterWidget = $(options.event.target).parents('li.gs-w');
     var $gridsterWidget = $(options.event.target).parents('li.gs-w');
     var contentHeight = $gridsterWidget.find('.card-widget').height();
     var contentHeight = $gridsterWidget.find('.card-widget').height();