浏览代码

HUE-7907 [dashboard] Removing a widget should automatically resize its siblings

Enrico Berti 7 年之前
父节点
当前提交
d54f0f4090
共有 1 个文件被更改,包括 17 次插入0 次删除
  1. 17 0
      desktop/libs/dashboard/src/dashboard/templates/common_search.mako

+ 17 - 0
desktop/libs/dashboard/src/dashboard/templates/common_search.mako

@@ -4068,6 +4068,23 @@ $(document).ready(function () {
   }, 'dashboard');
 
   huePubSub.subscribe('gridster.remove', function (gridElement) {
+    // resize the siblings to the max of the avail space
+    var siblings = [];
+    searchViewModel.gridItems().forEach(function (siblingWidget) {
+      if (siblingWidget.row() === gridElement.row() && gridElement.widgetId() !== siblingWidget.widgetId()) {
+        siblings.push(siblingWidget);
+      }
+    });
+    siblings.sort(function (a, b) {
+      return a.col() > b.col()
+    });
+    var optimalWidgetWidth = Math.floor(12 / siblings.length);
+    var $gridster = $(".gridster>ul").data('gridster');
+    for (var i = 1; i <= siblings.length; i++) {
+      var widget = siblings[i - 1];
+      $gridster.resize_widget($(widget.gridsterElement), optimalWidgetWidth, widget.size_y());
+      $gridster.move_widget($(widget.gridsterElement), ((i - 1) * optimalWidgetWidth) + 1, widget.row());
+    }
     searchViewModel.gridItems.remove(gridElement);
   }, 'dashboard')