Skip to content

Commit

Permalink
Added dragndrop for pipeline editor, resource index. (#1177)
Browse files Browse the repository at this point in the history
* added dragndrop for certain visualizers.

* WIP fixed indentation and commit msgs
  • Loading branch information
mnag1124 authored and brollb committed Aug 17, 2018
1 parent 1ccab4f commit 37a4edc
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/visualizers/panels/PipelineEditor/PipelineEditorControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/*jshint browser: true*/

define([
'js/DragDrop/DragHelper',
'deepforge/Constants',
'js/Constants',
'deepforge/viz/panels/ThumbnailControl',
Expand All @@ -13,6 +14,7 @@ define([
'q',
'underscore'
], function (
DragHelper,
CONSTANTS,
GME_CONSTANTS,
ThumbnailControl,
Expand Down Expand Up @@ -141,6 +143,22 @@ define([
this._widget.createConnection = this.createConnection.bind(this);
this._widget.removeConnection = this.removeConnection.bind(this);
this._widget.getDecorator = this.getDecorator.bind(this);

this._widget.onBackgroundDrop = (event, dragInfo) => {
if (!this._currentNodeId) { // no active node. Cannot add pipeline
return;
}
const effects = DragHelper.getDragEffects(dragInfo);
const items = DragHelper.getDragItems(dragInfo);

if (effects.includes(DragHelper.DRAG_EFFECTS.DRAG_CREATE_INSTANCE)) {
const parentId = this._currentNodeId;
const msg = `Creating ${items.length} new operation(s)`;
this._client.startTransaction(msg);
items.forEach(baseId => this._client.createNode({parentId, baseId}));
this._client.completeTransaction();
}
};
};

PipelineEditorControl.prototype.isContainedInActive = function (gmeId) {
Expand Down
18 changes: 18 additions & 0 deletions src/visualizers/panels/ResourceIndex/ResourceIndexControl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* globals define */
define([
'js/DragDrop/DragHelper',
'panels/PipelineIndex/PipelineIndexControl'
], function(
DragHelper,
PipelineIndexControl
) {
var ResourceIndexControl = function() {
Expand Down Expand Up @@ -50,6 +52,22 @@ define([
this._client.completeTransaction();
}
};

this._widget.onBackgroundDrop = (event, dragInfo) => {
if (!this._currentNodeId) { // no active node. Cannot add pipeline
return;
}
const effects = DragHelper.getDragEffects(dragInfo);
const items = DragHelper.getDragItems(dragInfo);

if (effects.includes(DragHelper.DRAG_EFFECTS.DRAG_CREATE_INSTANCE)) {
const parentId = this._currentNodeId;
const msg = `Creating ${items.length} new resource(s)`;
this._client.startTransaction(msg);
items.forEach(baseId => this._client.createNode({parentId, baseId}));
this._client.completeTransaction();
}
};
};
return ResourceIndexControl;
});
13 changes: 13 additions & 0 deletions src/visualizers/widgets/PipelineEditor/PipelineEditorWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/*jshint browser: true*/

define([
'js/DragDrop/DropTarget',
'deepforge/Constants',
'widgets/EasyDAG/AddNodeDialog',
'deepforge/viz/widgets/Thumbnail',
Expand All @@ -15,6 +16,7 @@ define([
'./klay',
'css!./styles/PipelineEditorWidget.css'
], function (
DropTarget,
CONSTANTS,
AddNodeDialog,
ThumbnailWidget,
Expand Down Expand Up @@ -46,6 +48,8 @@ define([
this.srcPortToConnectArgs = null;
this._connForPort = {};
this._itemsShowingPorts = [];
container.addClass(`${WIDGET_CLASS} container`);
this._initializeEventHandlers(container);

this.updateExecutions = _.debounce(this._updateExecutions, 50);
this.initExecs(execCntr);
Expand All @@ -60,6 +64,15 @@ define([
PipelineEditorWidget.prototype.onCreateInitialNode =
PipelineControl.prototype.onCreateInitialNode;

PipelineEditorWidget.prototype._initializeEventHandlers = function (container) {

DropTarget.makeDroppable(container, {
drop: (event, dragInfo) => {
this.onBackgroundDrop(event, dragInfo);
}
});
};

PipelineEditorWidget.prototype.getComponentId = function() {
return 'PipelineEditor';
};
Expand Down

0 comments on commit 37a4edc

Please sign in to comment.