From 5fba36bf55245ef6563d32a1a9235c603cbd1d65 Mon Sep 17 00:00:00 2001 From: Brian Broll Date: Tue, 28 Jun 2016 16:42:29 -0500 Subject: [PATCH] Added 'Create Class' node in OperationEditor. Fixes #171 WIP #171 Adding support for new classes WIP #171. Fixed "New Class" tooltip WIP #171 Fixed eslint error --- .../EasyDAG/OpIntDecorator.EasyDAGWidget.js | 2 +- ...ionInterfaceEditorControl.EventHandlers.js | 16 +++++++++++ .../OperationInterfaceEditorWidget.js | 28 +++++++++---------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/decorators/OpIntDecorator/EasyDAG/OpIntDecorator.EasyDAGWidget.js b/src/decorators/OpIntDecorator/EasyDAG/OpIntDecorator.EasyDAGWidget.js index 5de635f2f..086b727c8 100644 --- a/src/decorators/OpIntDecorator/EasyDAG/OpIntDecorator.EasyDAGWidget.js +++ b/src/decorators/OpIntDecorator/EasyDAG/OpIntDecorator.EasyDAGWidget.js @@ -33,7 +33,7 @@ define([ OpIntDecorator.prototype.initialize = function() { if (this._node.baseName === 'Operation') { this.color = '#2196f3'; - } else { + } else if (this._node.baseName) { // On hover, show the type this.enableTooltip(this._node.baseName, 'dark'); } diff --git a/src/visualizers/panels/OperationInterfaceEditor/OperationInterfaceEditorControl.EventHandlers.js b/src/visualizers/panels/OperationInterfaceEditor/OperationInterfaceEditorControl.EventHandlers.js index f6404a66d..9418672bc 100644 --- a/src/visualizers/panels/OperationInterfaceEditor/OperationInterfaceEditorControl.EventHandlers.js +++ b/src/visualizers/panels/OperationInterfaceEditor/OperationInterfaceEditorControl.EventHandlers.js @@ -9,6 +9,22 @@ define([ this._widget.addRefTo = this.addRefTo.bind(this); this._widget.changePtrName = this.changePtrName.bind(this); this._widget.removePtr = this.removePtr.bind(this); + this._widget.getNewClassNode = this.getNewClassNode.bind(this); + }; + + OperationInterfaceEditorEvents.prototype.getNewClassNode = function(id) { + var Decorator = this._client.decoratorManager.getDecoratorForWidget( + this.DEFAULT_DECORATOR, 'EasyDAG'); + + return { + node: { + id: id, + class: 'create-node', + name: 'New Class...', + Decorator: Decorator, + attributes: {} + } + }; }; OperationInterfaceEditorEvents.prototype.allValidReferences = function() { diff --git a/src/visualizers/widgets/OperationInterfaceEditor/OperationInterfaceEditorWidget.js b/src/visualizers/widgets/OperationInterfaceEditor/OperationInterfaceEditorWidget.js index 68f384ba1..23a27e084 100644 --- a/src/visualizers/widgets/OperationInterfaceEditor/OperationInterfaceEditorWidget.js +++ b/src/visualizers/widgets/OperationInterfaceEditor/OperationInterfaceEditorWidget.js @@ -6,6 +6,7 @@ */ define([ + 'deepforge/globals', 'widgets/EasyDAG/EasyDAGWidget', 'widgets/EasyDAG/AddNodeDialog', './SelectionManager', @@ -13,6 +14,7 @@ define([ 'underscore', 'css!./styles/OperationInterfaceEditorWidget.css' ], function ( + DeepForge, EasyDAG, AddNodeDialog, SelectionManager, @@ -22,7 +24,8 @@ define([ 'use strict'; var OperationInterfaceEditorWidget, - WIDGET_CLASS = 'operation-interface-editor'; + WIDGET_CLASS = 'operation-interface-editor', + NEW_CLASS_ID = '__NEW_CLASS__'; OperationInterfaceEditorWidget = function (logger, container) { EasyDAG.call(this, logger, container); @@ -45,22 +48,19 @@ define([ OperationInterfaceEditorWidget.prototype.onAddButtonClicked = function(item, isInput) { var successorPairs = this.getValidSuccessorNodes(item.id), - successor = successorPairs[0]; + newClass = this.getNewClassNode(NEW_CLASS_ID); - if (successorPairs.length > 1) { - // Create the modal view with all possible subsequent nodes - var dialog = new AddNodeDialog(), - title = this._getAddSuccessorTitle(item); + // Add the 'Create Class' node + successorPairs.push(newClass); - dialog.show(title, successorPairs); - dialog.onSelect = pair => { - if (pair) { - this.onAddItemSelected(pair, isInput); + AddNodeDialog.prompt(successorPairs) + .then(selected => { + if (selected.node.id === NEW_CLASS_ID) { + DeepForge.create.Complex(); + } else { + this.onAddItemSelected(selected, isInput); } - }; - } else if (successor) { - this.onAddItemSelected(successor, isInput); - } + }); }; OperationInterfaceEditorWidget.prototype.onDeactivate = function() {