Browse Source

HUE-8183 [dashboard] Auto resize widget height when the content changes height

Enrico Berti 7 years ago
parent
commit
d0c0eeda89
1 changed files with 11 additions and 4 deletions
  1. 11 4
      desktop/libs/dashboard/src/dashboard/templates/common_search.mako

+ 11 - 4
desktop/libs/dashboard/src/dashboard/templates/common_search.mako

@@ -3876,11 +3876,10 @@ $(document).ready(function () {
   var $gridster = $('.gridster>ul').gridster({
   var $gridster = $('.gridster>ul').gridster({
     widget_margins: [10, 10],
     widget_margins: [10, 10],
     widget_base_dimensions: ['auto', WIDGET_BASE_HEIGHT],
     widget_base_dimensions: ['auto', WIDGET_BASE_HEIGHT],
-    autogenerate_stylesheet: true,
     scroll_container: '.page-content',
     scroll_container: '.page-content',
     avoid_overlapped_widgets: true,
     avoid_overlapped_widgets: true,
     max_cols: 12,
     max_cols: 12,
-    max_rows: 400,
+    max_rows: 200,
     resize: {
     resize: {
       axes: ['x'],
       axes: ['x'],
       enabled: true,
       enabled: true,
@@ -4131,15 +4130,23 @@ $(document).ready(function () {
 
 
   function equalizeWidgetsHeights() {
   function equalizeWidgetsHeights() {
     if (searchViewModel.isGridster() && !isDraggingOrResizingWidgets) {
     if (searchViewModel.isGridster() && !isDraggingOrResizingWidgets) {
-      // avoid scrollbars inside the widgets
       searchViewModel.gridItems().forEach(function (existingWidget) {
       searchViewModel.gridItems().forEach(function (existingWidget) {
         var scrollDifference = existingWidget.gridsterElement.scrollHeight - existingWidget.gridsterElement.clientHeight;
         var scrollDifference = existingWidget.gridsterElement.scrollHeight - existingWidget.gridsterElement.clientHeight;
-        if (scrollDifference > 0) {
+        if (scrollDifference > 0) { // avoid scrollbars inside the widgets
           existingWidget.size_y(existingWidget.size_y() + Math.ceil(scrollDifference / WIDGET_BASE_HEIGHT));
           existingWidget.size_y(existingWidget.size_y() + Math.ceil(scrollDifference / WIDGET_BASE_HEIGHT));
           $gridster.resize_widget($(existingWidget.gridsterElement), existingWidget.size_x(), existingWidget.size_y(), function () {
           $gridster.resize_widget($(existingWidget.gridsterElement), existingWidget.size_x(), existingWidget.size_y(), function () {
             huePubSub.publish('gridster.clean.whitespace');
             huePubSub.publish('gridster.clean.whitespace');
           });
           });
         }
         }
+        else { // or remove additional whitespace
+          var contentHeight = $(existingWidget.gridsterElement).find('.card-widget').height();
+          if (existingWidget.gridsterElement.clientHeight - contentHeight > (WIDGET_BASE_HEIGHT + 10)) {
+            existingWidget.size_y(Math.ceil(contentHeight / (WIDGET_BASE_HEIGHT + 10)));
+            $gridster.resize_widget($(existingWidget.gridsterElement), existingWidget.size_x(), existingWidget.size_y(), function () {
+              huePubSub.publish('gridster.clean.whitespace');
+            });
+          }
+        }
       });
       });
 
 
       // widgets on the same row should have the same height
       // widgets on the same row should have the same height