Merge remote-tracking branch 'tmcgowan/issue_3000' into dev

This commit is contained in:
Dannon Baker
2016-10-27 10:22:27 +02:00
5 changed files with 83 additions and 5 deletions
@@ -401,6 +401,7 @@ EditorFormView = Backbone.View.extend({
window.make_popupmenu && make_popupmenu( $("#workflow-options-button"), {
"Save" : save_current_workflow,
"Save As": workflow_save_as,
"Run": function() {
window.location = self.urls.run_workflow;
},
@@ -412,6 +413,35 @@ EditorFormView = Backbone.View.extend({
"Close": close_editor
});
/******************************************** Issue 3000*/
function workflow_save_as() {
var body = $('<form><label style="display:inline-block; width: 100%;">Save as name: </label><input type="text" id="workflow_rename" style="width: 80%;" autofocus/>' +
'<br><label style="display:inline-block; width: 100%;">Annotation: </label><input type="text" id="wf_annotation" style="width: 80%;" /></form>');
window.show_modal("Save As a New Workflow", body, {
"OK": function () {
var rename_name = $('#workflow_rename').val().length > 0 ? $('#workflow_rename').val() : "SavedAs_" + self.workflow.name;
var rename_annotation = $('#wf_annotation').val().length > 0 ? $('#wf_annotation').val() : "";
$.ajax({
url: self.urls.workflow_save_as,
type: "POST",
data: {
workflow_name: rename_name,
workflow_annotation: rename_annotation,
workflow_data: function() { return JSON.stringify( self.workflow.to_simple() ); }
}
}).done(function(id){
window.onbeforeunload = undefined;
window.location = "/workflow/editor?id=" + id;
hide_modal();
}).fail(function(){
hide_modal();
alert("Saving this workflow failed. Please contact this site's administrator.");
});
},
"Cancel": hide_modal
});
};
function edit_workflow_outputs(){
self.workflow.clear_active_node();
$('.right-content').hide();
@@ -526,7 +526,7 @@ class WorkflowController( BaseUIController, SharableMixin, UsesStoredWorkflowMix
@web.expose
@web.require_login( "use Galaxy workflows" )
def copy( self, trans, id ):
def copy( self, trans, id, save_as_name=None ):
# Get workflow to copy.
stored = self.get_stored_workflow( trans, id, check_ownership=False )
user = trans.get_user()
@@ -540,7 +540,10 @@ class WorkflowController( BaseUIController, SharableMixin, UsesStoredWorkflowMix
# Copy.
new_stored = model.StoredWorkflow()
new_stored.name = "Copy of '%s'" % stored.name
if (save_as_name):
new_stored.name = '%s' % save_as_name
else:
new_stored.name = "Copy of '%s'" % stored.name
new_stored.latest_workflow = stored.latest_workflow
# Copy annotation.
annotation_obj = self.get_item_annotation_obj( trans.sa_session, stored.user, stored )
@@ -592,6 +595,50 @@ class WorkflowController( BaseUIController, SharableMixin, UsesStoredWorkflowMix
value="",
help="A description of the workflow; annotation is shown alongside shared or published workflows." )
@web.json
def save_workflow_as(self, trans, workflow_name, workflow_data, workflow_annotation=""):
"""
Creates a new workflow based on Save As command. It is a new workflow, but
is created with workflow_data already present.
"""
user = trans.get_user()
if workflow_name is not None:
workflow_contents_manager = workflows.WorkflowContentsManager(trans.app)
stored_workflow = model.StoredWorkflow()
stored_workflow.name = workflow_name
stored_workflow.user = user
self.create_item_slug(trans.sa_session, stored_workflow)
workflow = model.Workflow()
workflow.name = workflow_name
workflow.stored_workflow = stored_workflow
stored_workflow.latest_workflow = workflow
# Add annotation.
workflow_annotation = sanitize_html( workflow_annotation, 'utf-8', 'text/html' )
self.add_item_annotation( trans.sa_session, trans.get_user(), stored_workflow, workflow_annotation )
# Persist
session = trans.sa_session
session.add( stored_workflow )
session.flush()
try:
workflow, errors = workflow_contents_manager.update_workflow_from_dict(
trans,
stored_workflow,
workflow_data,
)
except workflows.MissingToolsException as e:
return dict(
name=e.workflow.name,
message="This workflow includes missing or invalid tools. "
"It cannot be saved until the following steps are removed or the missing tools are enabled.",
errors=e.errors,
)
return (trans.security.encode_id(stored_workflow.id))
else:
#This is an error state, 'save as' must have a workflow_name
log.exception("Error in Save As workflow: no name.")
@web.expose
def delete( self, trans, id=None ):
"""
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -15,7 +15,8 @@
'annotate_async' : h.url_for( controller='workflow', action='annotate_async', id=trans.security.encode_id(stored.id) ),
'get_new_module_info' : h.url_for(controller='workflow', action='get_new_module_info' ),
'workflow_index' : h.url_for( controller='workflow', action='index' ),
'save_workflow' : h.url_for(controller='workflow', action='save_workflow' )
'save_workflow' : h.url_for(controller='workflow', action='save_workflow' ),
'workflow_save_as' : h.url_for(controller='workflow', action='save_workflow_as')
},
'workflows' : [{
'id' : trans.security.encode_id( workflow.id ),