瀏覽代碼

HUE-8120 [dashboard] Ensure correct serialization of widgets on save and reload

Enrico Berti 7 年之前
父節點
當前提交
d9e49e84c8

+ 6 - 0
desktop/core/src/desktop/static/desktop/js/gridster-knockout.js

@@ -122,6 +122,12 @@ ko.bindingHandlers.gridster = {
       }
     };
 
+    var syncSub = huePubSub.subscribe('gridster.sync.model', syncPositionsToModel);
+
+    ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
+      syncSub.remove();
+    });
+
     // Just in case the consumer set up their own resize handler, we need to chain the calls
     var oldOnResize = gridster.options.resize.stop;
     gridster.options.resize.stop = function (event, ui, $widget) {

+ 4 - 6
desktop/libs/dashboard/src/dashboard/static/dashboard/js/search.ko.js

@@ -44,6 +44,7 @@ function loadSearchLayout(viewModel, json_layout) {
           properties: widget.properties,
           offset: widget.offset,
           loading: true,
+          gridsterHeight: viewModel.draggableWidgets[widget.widgetType].gridsterHeight() || 6,
           vm: viewModel
         }));
       });
@@ -56,18 +57,15 @@ function loadSearchLayout(viewModel, json_layout) {
   viewModel.columns(_columns);
 }
 
-function loadDashboardLayout(viewModel, grister_layout) {
-  $.each(grister_layout, function(index, item) {
+function loadDashboardLayout(viewModel, gridster_layout) {
+  $.each(gridster_layout, function(index, item) {
     viewModel.gridItems.push(
       ko.mapping.fromJS({
         col: parseInt(item.col),
         row: parseInt(item.row),
         size_x: parseInt(item.size_x),
         size_y: parseInt(item.size_y),
-        widget: item.widget ? viewModel.getWidgetById(item.widget.id) : null,
-        callback: function (el) {
-          $('.gridster ul').data('gridster').move_widget(el, 1, 1);
-        }
+        widget: item.widget ? viewModel.getWidgetById(item.widget.id) : null
       }));
   });
 }

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

@@ -4199,6 +4199,7 @@ $(document).ready(function () {
           $gridster.remove_empty_cells(1, i, 12, 1);
         }
       }
+      huePubSub.publish('gridster.sync.model');
     }
   }, 'dashboard');