Răsfoiți Sursa

HUE-7776 [dashboard] Enable drop from assist in Gridster

Enrico Berti 8 ani în urmă
părinte
comite
e0717a3402

+ 4 - 0
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -552,6 +552,10 @@
           notifiedOnDragStarted = false;
         },
         drag: function (event) {
+          huePubSub.publish('draggable.text.drag', {
+            event: event,
+            meta: options.meta
+          });
           if (!notifiedOnDragStarted && Math.sqrt((dragStartX-event.clientX)*(dragStartX-event.clientX) + (dragStartY-event.clientY)*(dragStartY-event.clientY)) >= 10) {
             huePubSub.publish('draggable.text.started', options.meta);
             notifiedOnDragStarted = true;

+ 43 - 23
desktop/libs/dashboard/src/dashboard/templates/common_search.mako

@@ -3646,7 +3646,7 @@ $(document).ready(function () {
   });
 
   function addPreviewHolder() {
-    if (!$('.hue-preview-holder').length) {
+    if (!$('.hue-preview-holder').length && searchViewModel.columns().length > 0) {
       $('<li>').addClass('preview-holder hue-preview-holder').attr('data-sizex', '6').attr('data-sizey', '2').attr('data-row', '1').attr('data-col', '1').appendTo($('.gridster>ul'));
     }
   }
@@ -3655,6 +3655,13 @@ $(document).ready(function () {
     $('.hue-preview-holder').remove();
   }
 
+  function movePreviewHolder (options) {
+    if (!$('.gridster').hasClass('dragging')) {
+      $('.hue-preview-holder').attr('data-sizey', options.widgetHeight || 6);
+      $('.hue-preview-holder').attr('data-col', Math.max(1, Math.ceil((options.event.clientX - $('.gridster').offset().left) / (widgetGridWidth + 10))));
+      $('.hue-preview-holder').attr('data-row', Math.max(1, Math.ceil((options.event.pageY - $('.gridster').offset().top) / (widgetGridHeight + 10))));
+    }
+  }
 
   var widgetGridHeight = parseInt(hueUtils.getStyleFromCSSClass('[data-sizey="1"]').height);
   var widgetGridWidth = parseInt(hueUtils.getStyleFromCSSClass('[data-sizex="1"]').width);
@@ -3665,34 +3672,47 @@ $(document).ready(function () {
     addPreviewHolder();
   }, 'dashboard');
 
-  huePubSub.subscribe('top.widget.drag', function (options) {
-    if (!$('.gridster').hasClass('dragging')) {
-      $('.hue-preview-holder').attr('data-sizey', options.widgetHeight);
-      $('.hue-preview-holder').attr('data-col', Math.max(1, Math.ceil((options.event.clientX - $('.gridster').offset().left) / (widgetGridWidth + 10))));
-      $('.hue-preview-holder').attr('data-row', Math.max(1, Math.ceil((options.event.pageY - $('.gridster').offset().top) / (widgetGridHeight + 10))));
-    }
-  }, 'dashboard');
+  huePubSub.subscribe('top.widget.drag', movePreviewHolder, 'dashboard');
+  huePubSub.subscribe('draggable.text.drag', movePreviewHolder, 'dashboard');
+
+  huePubSub.subscribe('draggable.text.meta', addPreviewHolder, 'dashboard');
 
   huePubSub.subscribe('drop.on.page', function (options) {
-    removePreviewHolder();
-    if (tempDraggable) {
+    if (searchViewModel.columns().length > 0) {
+      removePreviewHolder();
       var dropPosition = {
         col: Math.max(1, Math.ceil((options.event.clientX - $('.gridster').offset().left) / (widgetGridWidth + 10))),
         row: Math.max(1, Math.ceil((options.event.pageY - $('.gridster').offset().top) / (widgetGridHeight + 10)))
       }
-      searchViewModel.gridItems.push(
-          ko.mapping.fromJS({
-            col: dropPosition.col,
-            row: dropPosition.row,
-            size_x: 6,
-            size_y: tempDraggable.gridsterHeight(),
-            widget: null,
-            callback: function (el) {
-              showAddFacetDemiModal(tempDraggable, searchViewModel.gridItems()[searchViewModel.gridItems().length - 1]);
-              tempDraggable = null;
-            }
-          })
-      );
+      if (tempDraggable) {
+        searchViewModel.gridItems.push(
+            ko.mapping.fromJS({
+              col: dropPosition.col,
+              row: dropPosition.row,
+              size_x: 6,
+              size_y: tempDraggable.gridsterHeight(),
+              widget: null,
+              callback: function (el) {
+                showAddFacetDemiModal(tempDraggable, searchViewModel.gridItems()[searchViewModel.gridItems().length - 1]);
+                tempDraggable = null;
+              }
+            })
+        );
+      }
+      else if (searchViewModel.lastDraggedMeta()) {
+        searchViewModel.gridItems.push(
+            ko.mapping.fromJS({
+              col: dropPosition.col,
+              row: dropPosition.row,
+              size_x: 6,
+              size_y: 6,
+              widget: null,
+              callback: function (el) {
+                showAddFacetDemiModal(null, searchViewModel.gridItems()[searchViewModel.gridItems().length - 1]);
+              }
+            })
+        );
+      }
     }
   }, 'dashboard');