Skip to content

Commit 1f8f1b9

Browse files
committed
DragWidget
1 parent 60037a2 commit 1f8f1b9

File tree

2 files changed

+58
-25
lines changed

2 files changed

+58
-25
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* ************************************************************************
2+
3+
osparc - the simcore frontend
4+
5+
https://osparc.io
6+
7+
Copyright:
8+
2024 IT'IS Foundation, https://itis.swiss
9+
10+
License:
11+
MIT: https://opensource.org/licenses/MIT
12+
13+
Authors:
14+
* Odei Maiz (odeimaiz)
15+
16+
************************************************************************ */
17+
18+
qx.Class.define("osparc.dashboard.DragWidget", {
19+
extend: qx.ui.basic.Atom,
20+
21+
construct: function() {
22+
this.base(arguments);
23+
24+
this.set({
25+
opacity: 0.9,
26+
padding: 10,
27+
zIndex: 1000,
28+
font: "text-14",
29+
backgroundColor: "strong-main",
30+
decorator: "rounded",
31+
visibility: "excluded",
32+
});
33+
34+
const root = qx.core.Init.getApplication().getRoot();
35+
root.add(this);
36+
},
37+
38+
members: {
39+
__onMouseMoveDragging: function(e) {
40+
const domEl = this.getContentElement().getDomElement();
41+
domEl.style.left = `${e.pageX + 15}px`; // Offset for better visibility
42+
domEl.style.top = `${e.pageY + 15}px`;
43+
},
44+
45+
start: function() {
46+
this.show();
47+
document.addEventListener("mousemove", this.__onMouseMoveDragging.bind(this), false);
48+
},
49+
50+
end: function() {
51+
this.exclude();
52+
document.removeEventListener("mousemove", this.__onMouseMoveDragging.bind(this), false);
53+
},
54+
}
55+
});

services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -648,17 +648,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
648648

649649
__configureStudyCards: function(cards) {
650650
// Create drag indicator
651-
this.__dragIndicator = new qx.ui.basic.Atom().set({
652-
opacity: 0.9,
653-
padding: 10,
654-
zIndex: 1000,
655-
font: "text-14",
656-
backgroundColor: "strong-main",
657-
decorator: "rounded",
658-
visibility: "excluded",
659-
});
660-
const root = qx.core.Init.getApplication().getRoot();
661-
root.add(this.__dragIndicator);
651+
this.__dragIndicator = new osparc.dashboard.DragWidget();
662652

663653
cards.forEach(card => {
664654
card.setMultiSelectionMode(this.getMultiSelection());
@@ -670,12 +660,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
670660
},
671661

672662
__attachDragHandlers: function(card) {
673-
const onMouseMoveDragging = e => {
674-
const dragWidget = this.__dragIndicator.getContentElement().getDomElement();
675-
dragWidget.style.left = `${e.pageX + 10}px`; // Offset for better visibility
676-
dragWidget.style.top = `${e.pageY + 10}px`;
677-
};
678-
679663
card.setDraggable(true);
680664

681665
card.addListener("dragstart", e => {
@@ -690,21 +674,15 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
690674
// init drag indicator
691675
this.__dragIndicator.set({
692676
label: card.getTitle(),
693-
visibility: "visible",
694677
});
695-
// listen to mousemove while dragging
696-
document.addEventListener("mousemove", onMouseMoveDragging, false);
678+
this.__dragIndicator.start();
697679
});
698680

699681
card.addListener("dragend", () => {
700682
// bring back opacity after drag
701683
card.setOpacity(1);
702684
// hide drag indicator
703-
this.__dragIndicator.set({
704-
visibility: "excluded",
705-
});
706-
// remove listener
707-
document.removeEventListener("mousemove", onMouseMoveDragging, false);
685+
this.__dragIndicator.end();
708686
});
709687
},
710688

0 commit comments

Comments
 (0)