3 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/b6c06c9db59b/ Changeset: b6c06c9db59b User: jmchilton Date: 2014-04-22 18:13:27 Summary: Workflow Editor: Rework InputTerminal to implement/use an update method (w/tests). This will enable replacing terminals instead of recreating them and reconnecting in subsequent changesets. Affected #: 2 files diff -r 008c26226230353a2440e6c7208de58575cfebff -r b6c06c9db59b3197a4f1c55327679ae6a6a08263 static/scripts/galaxy.workflow_editor.canvas.js --- a/static/scripts/galaxy.workflow_editor.canvas.js +++ b/static/scripts/galaxy.workflow_editor.canvas.js @@ -38,8 +38,11 @@ var InputTerminal = Terminal.extend( { initialize: function( attr ) { Terminal.prototype.initialize.call( this, attr ); - this.datatypes = attr.datatypes; - this.multiple = attr.multiple; + this.update( attr.input ); + }, + update: function( input ) { + this.datatypes = input.extensions; + this.multiple = input.multiple; }, canAccept: function ( other ) { if( this._inputFilled() ) { @@ -981,13 +984,9 @@ var input = options.input; var name = input.name; - var types = input.extensions; - var multiple = input.multiple; - - var terminal = this.el.terminal = new InputTerminal( { element: this.el, datatypes: types, multiple: multiple } ); + var terminal = this.el.terminal = new InputTerminal( { element: this.el, input: input } ); terminal.node = node; terminal.name = name; - node.input_terminals[name] = terminal; }, diff -r 008c26226230353a2440e6c7208de58575cfebff -r b6c06c9db59b3197a4f1c55327679ae6a6a08263 test/qunit/tests/workflow_editor_tests.js --- a/test/qunit/tests/workflow_editor_tests.js +++ b/test/qunit/tests/workflow_editor_tests.js @@ -63,7 +63,8 @@ setup: function() { this.node = { }; this.element = $( "<div>" ); - this.input_terminal = new InputTerminal( { element: this.element, datatypes: [ "txt" ] } ); + var input = { extensions: [ "txt" ], multiple: false }; + this.input_terminal = new InputTerminal( { element: this.element, input: input } ); this.input_terminal.node = this.node; }, test_connector: function( attr ) { @@ -90,6 +91,16 @@ } } ); + test( "test update", function() { + deepEqual( this.input_terminal.datatypes, [ 'txt' ] ); + equal( this.input_terminal.multiple, false ); + + this.input_terminal.update( { extensions: [ 'bam' ], multiple: true } ); + + deepEqual( this.input_terminal.datatypes, [ 'bam' ] ); + equal( this.input_terminal.multiple, true ); + } ); + test( "test connect", function() { this.node.markChanged = sinon.spy(); https://bitbucket.org/galaxy/galaxy-central/commits/47ff7cab1ab1/ Changeset: 47ff7cab1ab1 User: jmchilton Date: 2014-04-22 18:13:27 Summary: Workflow Editor: Replace instead of recreate terminal on update. This fixes at least one subtle bug related to multiple input data parameters (actually probably two bugs) because the old logic assumed there was only one connector per input terminal. This should be more efficient, lead to some code duplication deletion in subsequent changesets, and really help dataset collections where terminals are much more complex (there are data inputs and collection inputs, and each can be mapped over by collections) - this helps manage complexity downstream. Affected #: 2 files diff -r b6c06c9db59b3197a4f1c55327679ae6a6a08263 -r 47ff7cab1ab1b92bcbb0db06d6892bdad856f005 static/scripts/galaxy.workflow_editor.canvas.js --- a/static/scripts/galaxy.workflow_editor.canvas.js +++ b/static/scripts/galaxy.workflow_editor.canvas.js @@ -257,14 +257,17 @@ // Update input rows var old_body = nodeView.$( "div.inputs" ); var new_body = nodeView.newInputsDiv(); - $.each( data.data_inputs, function( i, input ) { - node.nodeView.replaceDataInput( input, new_body ); + var newTerminalViews = {}; + _.each( data.data_inputs, function( input ) { + var terminalView = node.nodeView.addDataInput( input, new_body ); + newTerminalViews[ input.name ] = terminalView; }); + // Cleanup any leftover terminals + _.each( _.difference( _.values( nodeView.terminalViews ), _.values( newTerminalViews ) ), function( unusedView ) { + unusedView.el.terminal.destroy(); + } ); + nodeView.terminalViews = newTerminalViews; old_body.replaceWith( new_body ); - // Cleanup any leftover terminals - old_body.find( "div.input-data-row > .terminal" ).each( function() { - this.terminal.destroy(); - }); // If active, reactivate with new form_html this.markChanged(); this.redraw(); @@ -754,6 +757,7 @@ this.tool_body = this.$el.find( ".toolFormBody" ); this.tool_body.find( "div" ).remove(); this.newInputsDiv().appendTo( this.tool_body ); + this.terminalViews = {}; }, render : function() { @@ -786,6 +790,7 @@ node: this.node, input: input } ); + this.terminalViews[ input.name ] = terminalView; var terminalElement = terminalView.el; var inputView = new DataInputView( { "terminalElement": terminalElement, @@ -798,29 +803,23 @@ }, replaceDataInput: function( input, new_body ) { - var terminalView = new InputTerminalView( { - node: this.node, - input: input - } ); + var terminalView = this.terminalViews[ input.name ]; + if( ! terminalView ) { + terminalView = new InputTerminalView( { + node: this.node, + input: input + } ); + } else { + var terminal = terminalView.el.terminal; + terminal.update( input ); + _.each( terminal.connectors, function( connector ) { + if( connector.handle1 && ! terminal.attachable( connector.handle1 ) ) { + connector.destroy(); + } + } ); + } + this.terminalViews[ input.name ] = terminalView; var t = terminalView.el; - - // If already connected save old connection - this.$( "div[name='" + input.name + "']" ).each( function() { - $(this).find( ".input-terminal" ).each( function() { - var c = this.terminal.connectors[0]; - if ( c ) { - var terminal = t.terminal; - if( c.handle1 && ! terminal.attachable( c.handle1 ) ) { - // connection no longer valid, destroy it - c.destroy(); - } else { - terminal.connectors[0] = c; - c.handle2 = terminal; - } - } - }); - $(this).remove(); - }); var inputView = new DataInputView( { "terminalElement": t, "input": input, @@ -831,7 +830,7 @@ // Append to new body new_body.append( ib.prepend( t ) ); - + return terminalView; }, addDataOutput: function( output ) { diff -r b6c06c9db59b3197a4f1c55327679ae6a6a08263 -r 47ff7cab1ab1b92bcbb0db06d6892bdad856f005 test/qunit/tests/workflow_editor_tests.js --- a/test/qunit/tests/workflow_editor_tests.js +++ b/test/qunit/tests/workflow_editor_tests.js @@ -385,11 +385,14 @@ var old_input_terminal = node.input_terminals.input1; old_input_terminal.connectors.push( connector ); + // Update node, make sure connector still the same... test.update_field_data_with_new_input(); - var new_input_terminal = node.input_terminals.input1; - equal( old_input_terminal, old_input_terminal ); - notEqual( old_input_terminal, new_input_terminal ); + equal( connector, new_input_terminal.connectors[ 0 ] ); + + // Update a second time, make sure connector still the same... + test.update_field_data_with_new_input(); + new_input_terminal = node.input_terminals.input1; equal( connector, new_input_terminal.connectors[ 0 ] ); } ); } ); https://bitbucket.org/galaxy/galaxy-central/commits/4a697eff1290/ Changeset: 4a697eff1290 User: jmchilton Date: 2014-04-22 18:13:27 Summary: Workflow Editor: Merge addDataInput and replaceDataInput into common method. Reduces some code duplication here and reduces even more code duplication downstream in dataset collections work. Affected #: 2 files diff -r 47ff7cab1ab1b92bcbb0db06d6892bdad856f005 -r 4a697eff12901cdb715667526bc097948646da86 static/scripts/galaxy.workflow_editor.canvas.js --- a/static/scripts/galaxy.workflow_editor.canvas.js +++ b/static/scripts/galaxy.workflow_editor.canvas.js @@ -785,24 +785,14 @@ this.tool_body.append( $( "<div class='rule'></div>" ) ); }, - addDataInput: function( input ) { - var terminalView = new InputTerminalView( { - node: this.node, - input: input - } ); - this.terminalViews[ input.name ] = terminalView; - var terminalElement = terminalView.el; - var inputView = new DataInputView( { - "terminalElement": terminalElement, - "input": input, - "nodeView": this, - } ); - var ib = inputView.$el; - var terminalElement = inputView.terminalElement; - this.$( ".inputs" ).append( ib.prepend( terminalElement ) ); - }, - - replaceDataInput: function( input, new_body ) { + addDataInput: function( input, body ) { + var skipResize = true; + if( ! body ) { + body = this.$( ".inputs" ); + // initial addition to node - resize input to help calculate node + // width. + skipResize = false; + } var terminalView = this.terminalViews[ input.name ]; if( ! terminalView ) { terminalView = new InputTerminalView( { @@ -819,17 +809,17 @@ } ); } this.terminalViews[ input.name ] = terminalView; - var t = terminalView.el; + var terminalElement = terminalView.el; var inputView = new DataInputView( { - "terminalElement": t, - "input": input, - "nodeView": this, - "skipResize": true, + terminalElement: terminalElement, + input: input, + nodeView: this, + skipResize: skipResize } ); var ib = inputView.$el; - // Append to new body - new_body.append( ib.prepend( t ) ); + var terminalElement = inputView.terminalElement; + body.append( ib.prepend( terminalElement ) ); return terminalView; }, diff -r 47ff7cab1ab1b92bcbb0db06d6892bdad856f005 -r 4a697eff12901cdb715667526bc097948646da86 test/qunit/tests/workflow_editor_tests.js --- a/test/qunit/tests/workflow_editor_tests.js +++ b/test/qunit/tests/workflow_editor_tests.js @@ -477,7 +477,7 @@ test( "replacing terminal on data input update preserves connections", function() { var connector = this.connectAttachedTerminal( "txt", "txt" ); var newElement = $("<div class='inputs'></div>"); - this.view.replaceDataInput( { name: "TestName", extensions: ["txt"] }, newElement ); + this.view.addDataInput( { name: "TestName", extensions: ["txt"] }, newElement ); var terminal = newElement.find(".input-terminal")[ 0 ].terminal; ok( connector.handle2 === terminal ); } ); @@ -487,7 +487,7 @@ var newElement = $("<div class='inputs'></div>"); var connector_destroy_spy = sinon.spy( connector, "destroy" ); // Replacing input with same name - but now of type bam should destroy connection. - this.view.replaceDataInput( { name: "TestName", extensions: ["bam"] }, newElement ); + this.view.addDataInput( { name: "TestName", extensions: ["bam"] }, newElement ); var terminal = newElement.find(".input-terminal")[ 0 ].terminal; ok( connector_destroy_spy.called ); } ); Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.