Files
galaxy/static/scripts/mvc/workflow/workflow.js
T
2018-05-23 15:37:14 -04:00

1 line
8.6 KiB
JavaScript

define("mvc/workflow/workflow",["exports","libs/toastr","backbone","underscore","mvc/tag","mvc/workflow/workflow-model","utils/query-string-parsing","utils/localization","ui/loading-indicator"],function(o,e,t,r,n,l,i,s,a){"use strict";function d(o){return o&&o.__esModule?o:{default:o}}function c(o){if(o&&o.__esModule)return o;var e={};if(null!=o)for(var t in o)Object.prototype.hasOwnProperty.call(o,t)&&(e[t]=o[t]);return e.default=o,e}Object.defineProperty(o,"__esModule",{value:!0});var w=c(e),u=c(t),f=c(r),h=d(n),p=d(l),m=d(i),k=d(s),g=d(a),y=u.View.extend({tagName:"tr",initialize:function(){f.bindAll(this,"render","_rowTemplate","renderTagEditor","_templateActions","removeWorkflow","copyWorkflow"),w.options.timeOut=1500},events:{"click #show-in-tool-panel":"showInToolPanel","click #delete-workflow":"removeWorkflow","click #rename-workflow":"renameWorkflow","click #copy-workflow":"copyWorkflow"},render:function(){return $(this.el).html(this._rowTemplate()),this},showInToolPanel:function(){this.model.save({show_in_tool_panel:!this.model.get("show_in_tool_panel")},{success:function(){window.location=Galaxy.root+"workflows/list"}})},removeWorkflow:function(){var o=this.model.get("name");window.confirm("Are you sure you want to delete workflow '"+o+"'?")&&(this.model.destroy({success:function(){w.success("Successfully deleted workflow '"+o+"'")}}),this.remove())},renameWorkflow:function(){var o=this.model.get("name"),e=window.prompt("Enter a new Name for workflow '"+o+"'",o);e&&(this.model.save({name:e},{success:function(){w.success("Successfully renamed workflow '"+o+"' to '"+e+"'")}}),this.render())},copyWorkflow:function(){var o=this,e=this.model.get("name");$.getJSON(this.model.urlRoot+"/"+this.model.id+"/download",function(t){var r="Copy of "+e,n=o.model.get("owner");n!=Galaxy.user.attributes.username&&(r+=" shared by user "+n),t.name=r,o.collection.create(t,{at:0,wait:!0,success:function(){w.success("Successfully copied workflow '"+e+"' to '"+r+"'")},error:function(o,e,t){w.error(t.errorThrown)}})}).error(function(o,e,t){w.error(o.responseJSON.err_msg)})},_rowTemplate:function(){var o=this.model.get("show_in_tool_panel"),e=this.model.id,t='<input id="show-in-tool-panel" type="checkbox" class="show-in-tool-panel" '+(o?'checked="'+o+'"':"")+' value="'+e+'">';return'\n <td>\n <div class="btn-group">\n <a href="'+Galaxy.root+"workflow/editor?id="+this.model.id+'" class="btn btn-secondary">\n '+f.escape(this.model.get("name"))+'\n </a>\n <button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n <span class="sr-only">Toggle Dropdown</span>\n </button>\n '+this._templateActions()+'\n </div>\n </td>\n <td>\n <div class="'+e+' tags-display">\n </div>\n </td>\n <td>\n '+(this.model.get("owner")===Galaxy.user.attributes.username?"You":this.model.get("owner"))+"\n </td>\n <td>"+this.model.get("number_of_steps")+"</td>\n <td>"+(this.model.get("published")?"Yes":"No")+"</td>\n <td>"+t+"</td>"},renderTagEditor:function(){var o=new h.default.TagsEditor({model:this.model,el:$.find("."+this.model.id+".tags-display"),workflow_mode:!0});o.toggle(!0),o.render()},_templateActions:function(){return this.model.get("owner")===Galaxy.user.attributes.username?'<div class="dropdown-menu">\n <a class="dropdown-item" href="'+Galaxy.root+"workflow/editor?id="+this.model.id+'">Edit</a>\n <a class="dropdown-item" href="'+Galaxy.root+"workflows/run?id="+this.model.id+'">Run</a>\n <a class="dropdown-item" href="'+Galaxy.root+"workflow/sharing?id="+this.model.id+'">Share</a>\n <a class="dropdown-item" href="'+Galaxy.root+"api/workflows/"+this.model.id+'/download?format=json-download">Download</a>\n <a class="dropdown-item" id="copy-workflow" style="cursor: pointer;">Copy</a>\n <a class="dropdown-item" id="rename-workflow" style="cursor: pointer;">Rename</a>\n <a class="dropdown-item" href="'+Galaxy.root+"workflow/display_by_id?id="+this.model.id+'">View</a>\n <a class="dropdown-item" id="delete-workflow" style="cursor: pointer;">Delete</a>\n </div>':'<ul class="dropdown-menu">\n <li><a href="'+Galaxy.root+"workflow/display_by_username_and_slug?username="+this.model.get("owner")+"&slug="+this.model.get("slug")+'">View</a></li>\n <li><a href="'+Galaxy.root+"workflows/run?id="+this.model.id+'">Run</a></li>\n <li><a id="copy-workflow" style="cursor: pointer;">Copy</a></li>\n <li><a class="link-confirm-shared-'+this.model.id+'" href="'+Galaxy.root+"workflow/sharing?unshare_me=True&id="+this.model.id+'">Remove</a></li>\n </ul>'}}),v=u.View.extend({title:(0,k.default)("Workflows"),active_tab:"workflow",initialize:function(){g.default.markViewAsLoading(this),f.bindAll(this,"adjustActiondropdown"),this.collection=new p.default.WorkflowCollection,this.collection.fetch().done(this.render()),this.collection.bind("add",this.appendItem),this.collection.on("sync",this.render,this)},events:{dragleave:"unhighlightDropZone",drop:"drop",dragover:function(o){$(".hidden_description_layer").addClass("dragover"),$(".menubutton").addClass("background-none"),o.preventDefault()}},unhighlightDropZone:function(){$(".hidden_description_layer").removeClass("dragover"),$(".menubutton").removeClass("background-none")},drop:function(o){this.unhighlightDropZone(),o.preventDefault();for(var e,t=o.dataTransfer.files,r=0;e=t[r];r++)this.readWorkflowFiles(e)},readWorkflowFiles:function(o){var e=this,t=new FileReader;t.onload=function(r){var n=void 0;try{n=JSON.parse(t.result)}catch(e){w.error("Could not read file '"+o.name+"'. Verify it is a valid Galaxy workflow"),n=null}n&&e.collection.create(n,{at:0,wait:!0,success:function(){w.success("Successfully imported workflow '"+n.name+"'")},error:function(o,e,t){w.error(t.errorThrown)}})},t.readAsText(o,"utf-8")},_showArgErrors:f.once(function(){var o=m.default.get("message");"error"===m.default.get("status")?w.error(f.escape(o||"Unknown Error, please report this to an administrator.")):o&&w.info(f.escape(o))}),render:function(){var o=this,e=this._templateHeader(),t=this._templateActionButtons(),r=this._templateWorkflowTable();this.$el.html(e+t+r),f.each(this.collection.models,function(e){o.appendItem(e),o.confirmDelete(e)});return this.searchWorkflow(this.$(".search-wf"),this.$(".workflow-search tr"),3),this.adjustActiondropdown(),this._showArgErrors(),this},appendItem:function(o){var e=new y({model:o,collection:this.collection});$(".workflow-search").append(e.render().el),e.renderTagEditor()},confirmDelete:function(o){this.$(".link-confirm-shared-"+o.id).click(function(){return window.confirm("Are you sure you want to remove the shared workflow '"+o.attributes.name+"'?")})},searchWorkflow:function(o,e,t){o.on("keyup",function(){var o=$(this).val();if(o.length>=t){var r=new RegExp(o,"i");e.hide(),e.filter(function(){return r.test($(this).text())}).show()}else e.show()})},adjustActiondropdown:function(){$(this.el).on("show.bs.dropdown",function(){$(this.el).css("overflow","inherit")}),$(this.el).on("hide.bs.dropdown",function(){$(this.el).css("overflow","auto")})},_templateNoWorkflow:function(){return'<div class="wf-nodata"> You have no workflows. </div>'},_templateActionButtons:function(){return'<ul class="manage-table-actions"><li><input class="search-wf form-control" type="text" autocomplete="off" placeholder="search for workflow..."></li><li><a class="action-button fa fa-plus wf-action" id="new-workflow" title="Create new workflow" href="'+Galaxy.root+'workflows/create"></a></li><li><a class="action-button fa fa-upload wf-action" id="import-workflow" title="Upload or import workflow" href="'+Galaxy.root+'workflows/import"></a></li></ul>'},_templateWorkflowTable:function(){return'<table class="table colored"><thead><tr class="header"><th>Name</th><th>Tags</th><th>Owner</th><th># of Steps</th><th>Published</th><th>Show in tools panel</th></tr></thead><tbody class="workflow-search "><div class="hidden_description_layer"><p>Drop workflow files here to import</p></tbody></table></div>'},_templateHeader:function(){return'<div class="page-container"><div class="user-workflows wf"><div class="response-message"></div><h2>'+(0,k.default)("Your workflows")+"</h2></div></div>"}});o.default={View:v}});