2 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/84c88d3644c0/ Changeset: 84c88d3644c0 User: jgoecks Date: 2013-08-14 21:15:13 Summary: Update Backbone to v1.0.0 and Backbone-relational to v0.8.5 Affected #: 4 files This diff is so big that we needed to truncate the remainder. https://bitbucket.org/galaxy/galaxy-central/commits/ebf6033a1cd4/ Changeset: ebf6033a1cd4 User: jgoecks Date: 2013-08-14 21:20:23 Summary: Tool panel refactoring: (a) make client-side code compatible with newest Backbone and Backbone-relational libraries; (b) use mixin rather than a base model on client; (c) add spacing between methods of server-side definition. Pack scripts. Affected #: 4 files diff -r 84c88d3644c0edc925fe2583276fbd32711f30a9 -r ebf6033a1cd4416602294b674628eb73da6fa663 lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -94,6 +94,7 @@ class ToolBox( object ): """Container for a collection of tools""" + def __init__( self, config_filenames, tool_root_dir, app ): """ Create a toolbox from the config files named by `config_filenames`, using @@ -144,6 +145,7 @@ # config files, adding or removing locally developed tools or workflows. The value of integrated_tool_panel # will be False when things like functional tests are the caller. self.write_integrated_tool_panel_config_file() + def init_tools( self, config_filename ): """ Read the configuration file and load each tool. The following tags are currently supported: @@ -199,11 +201,13 @@ tool_path=tool_path, config_elems=config_elems ) self.shed_tool_confs.append( shed_tool_conf_dict ) + def get_shed_config_dict_by_filename( self, filename, default=None ): for shed_config_dict in self.shed_tool_confs: if shed_config_dict[ 'config_filename' ] == filename: return shed_config_dict return default + def __add_tool_to_tool_panel( self, tool_id, panel_component, section=False ): # See if a version of this tool is already loaded into the tool panel. The value of panel_component # will be a ToolSection (if the value of section=True) or self.tool_panel (if section=False). @@ -239,6 +243,7 @@ del panel_dict[ loaded_version_key ] panel_dict.insert( index, key, tool ) log.debug( "Loaded tool id: %s, version: %s into tool panel." % ( tool.id, tool.version ) ) + def load_tool_panel( self ): for key, val in self.integrated_tool_panel.items(): if key.startswith( 'tool_' ): @@ -276,6 +281,7 @@ section.elems[ section_key ] = section_val log.debug( "Loaded label: %s" % ( section_val.text ) ) self.tool_panel[ key ] = section + def load_integrated_tool_panel_keys( self ): """ Load the integrated tool panel keys, setting values for tools and workflows to None. The values will @@ -308,6 +314,7 @@ elif elem.tag == 'label': key = 'label_%s' % elem.get( 'id' ) self.integrated_tool_panel[ key ] = None + def write_integrated_tool_panel_config_file( self ): """ Write the current in-memory version of the integrated_tool_panel.xml file to disk. Since Galaxy administrators @@ -350,6 +357,7 @@ os.close( fd ) shutil.move( filename, os.path.abspath( self.integrated_tool_panel_config ) ) os.chmod( self.integrated_tool_panel_config, 0644 ) + def get_tool( self, tool_id, tool_version=None, get_all_versions=False ): """Attempt to locate a tool in the tool box.""" if tool_id in self.tools_by_id and not get_all_versions: @@ -380,6 +388,7 @@ #No tool matches by version, simply return the first available tool found return rval[0] return None + def get_loaded_tools_by_lineage( self, tool_id ): """Get all loaded tools associated by lineage to the tool whose id is tool_id.""" tv = self.__get_tool_version( tool_id ) @@ -395,6 +404,7 @@ tool = self.tools_by_id[ tool_id ] return [ tool ] return [] + def __get_tool_version( self, tool_id ): """Return a ToolVersion if one exists for the tool_id""" return self.sa_session.query( self.app.model.ToolVersion ) \ @@ -527,6 +537,7 @@ integrated_panel_dict.insert( index, key, tool ) except: log.exception( "Error reading tool from path: %s" % path ) + def load_workflow_tag_set( self, elem, panel_dict, integrated_panel_dict, load_panel_dict, index=None ): try: # TODO: should id be encoded? @@ -543,6 +554,7 @@ integrated_panel_dict.insert( index, key, workflow ) except: log.exception( "Error loading workflow: %s" % workflow_id ) + def load_label_tag_set( self, elem, panel_dict, integrated_panel_dict, load_panel_dict, index=None ): label = ToolSectionLabel( elem ) key = 'label_' + label.id @@ -552,6 +564,7 @@ integrated_panel_dict[ key ] = label else: integrated_panel_dict.insert( index, key, label ) + def load_section_tag_set( self, elem, tool_path, load_panel_dict, index=None ): key = 'section_' + elem.get( "id" ) if key in self.tool_panel: @@ -580,6 +593,7 @@ self.integrated_tool_panel[ key ] = integrated_section else: self.integrated_tool_panel.insert( index, key, integrated_section ) + def load_tool( self, config_file, guid=None, repository_id=None, **kwds ): """Load a single tool from the file named by `config_file` and return an instance of `Tool`.""" # Parse XML configuration file and get the root element @@ -597,6 +611,7 @@ else: ToolClass = Tool return ToolClass( config_file, root, self.app, guid=guid, repository_id=repository_id, **kwds ) + def reload_tool_by_id( self, tool_id ): """ Attempt to reload the tool identified by 'tool_id', if successful @@ -634,6 +649,7 @@ message += "<b>version:</b> %s" % old_tool.version status = 'done' return message, status + def remove_tool_by_id( self, tool_id ): """ Attempt to remove the tool identified by 'tool_id'. @@ -662,6 +678,7 @@ message += "<b>version:</b> %s" % tool.version status = 'done' return message, status + def load_workflow( self, workflow_id ): """ Return an instance of 'Workflow' identified by `id`, @@ -670,11 +687,13 @@ id = self.app.security.decode_id( workflow_id ) stored = self.app.model.context.query( self.app.model.StoredWorkflow ).get( id ) return stored.latest_workflow + def init_dependency_manager( self ): if self.app.config.use_tool_dependencies: self.dependency_manager = DependencyManager( [ self.app.config.tool_dependency_dir ] ) else: self.dependency_manager = None + @property def sa_session( self ): """ @@ -683,9 +702,10 @@ return self.app.model.context def to_dict( self, trans, in_panel=True, **kwds ): - # - # Dictify toolbox. - # + """ + Dictify toolbox. + """ + context = Bunch( toolbox=self, trans=trans, **kwds ) if in_panel: panel_elts = [ val for val in self.tool_panel.itervalues() ] @@ -705,8 +725,8 @@ rval.append( elt.to_dict( trans, for_link=True ) ) else: tools = [] - for id, tool in self.toolbox.tools_by_id.items(): - tools.append( tool.to_dict( trans ) ) + for id, tool in self.tools_by_id.items(): + tools.append( tool.to_dict( trans, for_link=True ) ) rval = tools return rval diff -r 84c88d3644c0edc925fe2583276fbd32711f30a9 -r ebf6033a1cd4416602294b674628eb73da6fa663 static/scripts/mvc/tools.js --- a/static/scripts/mvc/tools.js +++ b/static/scripts/mvc/tools.js @@ -8,17 +8,13 @@ define( ["libs/underscore", "viz/trackster/util", "mvc/data", "libs/backbone/backbone-relational" ], function(_, util, data) { - + /** - * Simple base model for any visible element. Includes useful attributes and ability - * to set and track visibility. + * Mixin to enable model to track visibility. */ -var BaseModel = Backbone.RelationalModel.extend({ - defaults: { - name: null, - hidden: false - }, - +var VisibilityMixin = { + hidden: false, + show: function() { this.set("hidden", false); }, @@ -30,7 +26,8 @@ is_visible: function() { return !this.attributes.hidden; } -}); + +}; /** * A tool parameter. @@ -121,7 +118,7 @@ /** * A Galaxy tool. */ -var Tool = BaseModel.extend({ +var Tool = Backbone.RelationalModel.extend({ // Default attributes. defaults: { id: null, @@ -252,6 +249,7 @@ return run_deferred; } }); +_.extend(Tool.prototype, VisibilityMixin); /** * Tool view. @@ -270,12 +268,12 @@ /** * Label or section header in tool panel. */ -var ToolPanelLabel = BaseModel.extend({}); +var ToolPanelLabel = Backbone.Model.extend(VisibilityMixin); /** * Section of tool panel with elements (labels and tools). */ -var ToolPanelSection = BaseModel.extend({ +var ToolPanelSection = Backbone.Model.extend({ defaults: { elems: [], open: false @@ -317,13 +315,14 @@ } } }); +_.extend(ToolPanelSection.prototype, VisibilityMixin); /** * Tool search that updates results when query is changed. Result value of null * indicates that query was not run; if not null, results are from search using * query. */ -var ToolSearch = BaseModel.extend({ +var ToolSearch = Backbone.Model.extend({ defaults: { search_hint_string: "search tools", min_chars_for_search: 3, @@ -378,65 +377,48 @@ } }); +_.extend(ToolSearch.prototype, VisibilityMixin); /** - * A collection of ToolPanelSections, Tools, and ToolPanelLabels. Collection - * applies search results as they become available. + * Tool Panel. */ -var ToolPanel = Backbone.Collection.extend({ - // TODO: need to generate this using url_for - url: "/tools", - tools: new ToolCollection(), - +var ToolPanel = Backbone.Model.extend({ + + initialize: function(options) { + this.attributes.tool_search = options.tool_search; + this.attributes.tool_search.on("change:results", this.apply_search_results, this); + this.attributes.tools = options.tools; + this.attributes.layout = new Backbone.Collection( this.parse(options.layout) ); + }, + + /** + * Parse tool panel dictionary and return collection of tool panel elements. + */ parse: function(response) { // Recursive function to parse tool panel elements. - var parse_elt = function(elt_dict) { - var type = elt_dict.type; - if (type === 'tool') { - return new Tool(elt_dict); - } - else if (type === 'section') { - // Parse elements. - var elems = _.map(elt_dict.elems, parse_elt); - elt_dict.elems = elems; - return new ToolPanelSection(elt_dict); - } - else if (type === 'label') { - return new ToolPanelLabel(elt_dict); - } - }; + var self = this, + // Helper to recursively parse tool panel. + parse_elt = function(elt_dict) { + var type = elt_dict.type; + if (type === 'tool') { + return self.attributes.tools.get(elt_dict.id); + } + else if (type === 'section') { + // Parse elements. + var elems = _.map(elt_dict.elems, parse_elt); + elt_dict.elems = elems; + return new ToolPanelSection(elt_dict); + } + else if (type === 'label') { + return new ToolPanelLabel(elt_dict); + } + }; return _.map(response, parse_elt); }, - - initialize: function(options) { - this.tool_search = options.tool_search; - this.tool_search.on("change:results", this.apply_search_results, this); - this.on("reset", this.populate_tools, this); - }, - - /** - * Populate tool collection from panel elements. - */ - populate_tools: function() { - var self = this; - self.tools = new ToolCollection(); - this.each(function(panel_elt) { - if (panel_elt instanceof ToolPanelSection) { - _.each(panel_elt.attributes.elems, function (section_elt) { - if (section_elt instanceof Tool) { - self.tools.push(section_elt); - } - }); - } - else if (panel_elt instanceof Tool) { - self.tools.push(panel_elt); - } - }); - }, - + clear_search_results: function() { - this.each(function(panel_elt) { + this.get('layout').each(function(panel_elt) { if (panel_elt instanceof ToolPanelSection) { panel_elt.clear_search_results(); } @@ -448,14 +430,14 @@ }, apply_search_results: function() { - var results = this.tool_search.attributes.results; + var results = this.get('tool_search').get('results'); if (results === null) { this.clear_search_results(); return; } var cur_label = null; - this.each(function(panel_elt) { + this.get('layout').each(function(panel_elt) { if (panel_elt instanceof ToolPanelLabel) { cur_label = panel_elt; cur_label.hide(); @@ -635,19 +617,19 @@ * Set up view. */ initialize: function() { - this.collection.tool_search.on("change:results", this.handle_search_results, this); + this.model.get('tool_search').on("change:results", this.handle_search_results, this); }, render: function() { var self = this; // Render search. - var search_view = new ToolSearchView( {model: this.collection.tool_search} ); + var search_view = new ToolSearchView( { model: this.model.get('tool_search') } ); search_view.render(); self.$el.append(search_view.$el); // Render panel. - this.collection.each(function(panel_elt) { + this.model.get('layout').each(function(panel_elt) { if (panel_elt instanceof ToolPanelSection) { var section_title_view = new ToolPanelSectionView({model: panel_elt}); section_title_view.render(); @@ -670,7 +652,7 @@ // Tool id is always the first class. var tool_id = $(this).attr('class').split(/\s+/)[0], - tool = self.collection.tools.get(tool_id); + tool = self.model.get('tools').get(tool_id); self.trigger("tool_link_click", e, tool); }); @@ -679,7 +661,7 @@ }, handle_search_results: function() { - var results = this.collection.tool_search.attributes.results; + var results = this.model.get('tool_search').get('results'); if (results && results.length === 0) { $("#search-no-results").show(); } @@ -752,6 +734,7 @@ ToolParameter: ToolParameter, IntegerToolParameter: IntegerToolParameter, Tool: Tool, + ToolCollection: ToolCollection, ToolSearch: ToolSearch, ToolPanel: ToolPanel, ToolPanelView: ToolPanelView, diff -r 84c88d3644c0edc925fe2583276fbd32711f30a9 -r ebf6033a1cd4416602294b674628eb73da6fa663 static/scripts/packed/mvc/tools.js --- a/static/scripts/packed/mvc/tools.js +++ b/static/scripts/packed/mvc/tools.js @@ -1,1 +1,1 @@ -define(["libs/underscore","viz/trackster/util","mvc/data","libs/backbone/backbone-relational"],function(t,a,u){var h=Backbone.RelationalModel.extend({defaults:{name:null,hidden:false},show:function(){this.set("hidden",false)},hide:function(){this.set("hidden",true)},is_visible:function(){return !this.attributes.hidden}});var d=Backbone.RelationalModel.extend({defaults:{name:null,label:null,type:null,value:null,html:null,num_samples:5},initialize:function(){this.attributes.html=unescape(this.attributes.html)},copy:function(){return new d(this.toJSON())},get_samples:function(){var w=this.get("type"),v=null;if(w==="number"){v=d3.scale.linear().domain([this.get("min"),this.get("max")]).ticks(this.get("num_samples"))}else{if(w==="select"){v=t.map(this.get("options"),function(x){return x[0]})}}return v},set_value:function(v){this.set("value",v||"")}},{TYPE_DICT:{number:c},create:function(v){var w=d.TYPE_DICT[v.type]||d;return new w(v)}});var c=d.extend({defaults:t.extend({},d.prototype.defaults,{min:null,max:null}),initialize:function(){d.prototype.initialize.call(this);if(this.attributes.min){this.attributes.min=parseInt(this.attributes.min,10)}if(this.attributes.max){this.attributes.max=parseInt(this.attributes.max,10)}},set_value:function(v){this.set("value",parseInt(v,10))}});var g=h.extend({defaults:{id:null,name:null,description:null,target:null,inputs:[]},initialize:function(v){this.attributes.inputs=new Backbone.Collection(t.map(v.inputs,function(w){return d.create(w)}))},urlRoot:galaxy_paths.get("tool_url"),copy:function(w){var x=new g(this.toJSON());if(w){var v=new Backbone.Collection();x.get("inputs").each(function(y){if(y.get_samples()){v.push(y)}});x.set("inputs",v)}return x},apply_search_results:function(v){(t.indexOf(v,this.attributes.id)!==-1?this.show():this.hide());return this.is_visible()},set_input_value:function(v,w){this.get("inputs").find(function(x){return x.get("name")===v}).set("value",w)},set_input_values:function(w){var v=this;t.each(t.keys(w),function(x){v.set_input_value(x,w[x])})},run:function(){return this._run()},rerun:function(w,v){return this._run({action:"rerun",target_dataset_id:w.id,regions:v})},get_inputs_dict:function(){var v={};this.get("inputs").each(function(w){v[w.get("name")]=w.get("value")});return v},_run:function(x){var y=t.extend({tool_id:this.id,inputs:this.get_inputs_dict()},x);var w=$.Deferred(),v=new a.ServerStateDeferred({ajax_settings:{url:this.urlRoot,data:JSON.stringify(y),dataType:"json",contentType:"application/json",type:"POST"},interval:2000,success_fn:function(z){return z!=="pending"}});$.when(v.go()).then(function(z){w.resolve(new u.DatasetCollection().reset(z))});return w}});var n=Backbone.View.extend({});var k=Backbone.Collection.extend({model:g});var o=h.extend({});var r=h.extend({defaults:{elems:[],open:false},clear_search_results:function(){t.each(this.attributes.elems,function(v){v.show()});this.show();this.set("open",false)},apply_search_results:function(w){var x=true,v;t.each(this.attributes.elems,function(y){if(y instanceof o){v=y;v.hide()}else{if(y instanceof g){if(y.apply_search_results(w)){x=false;if(v){v.show()}}}}});if(x){this.hide()}else{this.show();this.set("open",true)}}});var b=h.extend({defaults:{search_hint_string:"search tools",min_chars_for_search:3,spinner_url:"",clear_btn_url:"",search_url:"",visible:true,query:"",results:null,clear_key:27},initialize:function(){this.on("change:query",this.do_search)},do_search:function(){var x=this.attributes.query;if(x.length<this.attributes.min_chars_for_search){this.set("results",null);return}var w=x+"*";if(this.timer){clearTimeout(this.timer)}$("#search-clear-btn").hide();$("#search-spinner").show();var v=this;this.timer=setTimeout(function(){$.get(v.attributes.search_url,{query:w},function(y){v.set("results",y);$("#search-spinner").hide();$("#search-clear-btn").show()},"json")},200)},clear_search:function(){this.set("query","");this.set("results",null)}});var l=Backbone.Collection.extend({url:"/tools",tools:new k(),parse:function(v){var w=function(z){var y=z.type;if(y==="tool"){return new g(z)}else{if(y==="section"){var x=t.map(z.elems,w);z.elems=x;return new r(z)}else{if(y==="label"){return new o(z)}}}};return t.map(v,w)},initialize:function(v){this.tool_search=v.tool_search;this.tool_search.on("change:results",this.apply_search_results,this);this.on("reset",this.populate_tools,this)},populate_tools:function(){var v=this;v.tools=new k();this.each(function(w){if(w instanceof r){t.each(w.attributes.elems,function(x){if(x instanceof g){v.tools.push(x)}})}else{if(w instanceof g){v.tools.push(w)}}})},clear_search_results:function(){this.each(function(v){if(v instanceof r){v.clear_search_results()}else{v.show()}})},apply_search_results:function(){var w=this.tool_search.attributes.results;if(w===null){this.clear_search_results();return}var v=null;this.each(function(x){if(x instanceof o){v=x;v.hide()}else{if(x instanceof g){if(x.apply_search_results(w)){if(v){v.show()}}}else{v=null;x.apply_search_results(w)}}})}});var p=Backbone.View.extend({initialize:function(){this.model.on("change:hidden",this.update_visible,this);this.update_visible()},update_visible:function(){(this.model.attributes.hidden?this.$el.hide():this.$el.show())}});var j=p.extend({tagName:"div",template:Handlebars.templates.tool_link,render:function(){this.$el.append(this.template(this.model.toJSON()));return this}});var e=p.extend({tagName:"div",className:"toolPanelLabel",render:function(){this.$el.append($("<span/>").text(this.model.attributes.name));return this}});var i=p.extend({tagName:"div",className:"toolSectionWrapper",template:Handlebars.templates.panel_section,initialize:function(){p.prototype.initialize.call(this);this.model.on("change:open",this.update_open,this)},render:function(){this.$el.append(this.template(this.model.toJSON()));var v=this.$el.find(".toolSectionBody");t.each(this.model.attributes.elems,function(w){if(w instanceof g){var x=new j({model:w,className:"toolTitle"});x.render();v.append(x.$el)}else{if(w instanceof o){var y=new e({model:w});y.render();v.append(y.$el)}else{}}});return this},events:{"click .toolSectionTitle > a":"toggle"},toggle:function(){this.model.set("open",!this.model.attributes.open)},update_open:function(){(this.model.attributes.open?this.$el.children(".toolSectionBody").slideDown("fast"):this.$el.children(".toolSectionBody").slideUp("fast"))}});var m=Backbone.View.extend({tagName:"div",id:"tool-search",className:"bar",template:Handlebars.templates.tool_search,events:{click:"focus_and_select","keyup :input":"query_changed","click #search-clear-btn":"clear"},render:function(){this.$el.append(this.template(this.model.toJSON()));if(!this.model.is_visible()){this.$el.hide()}this.$el.find(".tooltip").tooltip();return this},focus_and_select:function(){this.$el.find(":input").focus().select()},clear:function(){this.model.clear_search();this.$el.find(":input").val(this.model.attributes.search_hint_string);this.focus_and_select();return false},query_changed:function(v){if((this.model.attributes.clear_key)&&(this.model.attributes.clear_key===v.which)){this.clear();return false}this.model.set("query",this.$el.find(":input").val())}});var s=Backbone.View.extend({tagName:"div",className:"toolMenu",initialize:function(){this.collection.tool_search.on("change:results",this.handle_search_results,this)},render:function(){var v=this;var w=new m({model:this.collection.tool_search});w.render();v.$el.append(w.$el);this.collection.each(function(y){if(y instanceof r){var x=new i({model:y});x.render();v.$el.append(x.$el)}else{if(y instanceof g){var z=new j({model:y,className:"toolTitleNoSection"});z.render();v.$el.append(z.$el)}else{if(y instanceof o){var A=new e({model:y});A.render();v.$el.append(A.$el)}}}});v.$el.find("a.tool-link").click(function(z){var y=$(this).attr("class").split(/\s+/)[0],x=v.collection.tools.get(y);v.trigger("tool_link_click",z,x)});return this},handle_search_results:function(){var v=this.collection.tool_search.attributes.results;if(v&&v.length===0){$("#search-no-results").show()}else{$("#search-no-results").hide()}}});var q=Backbone.View.extend({className:"toolForm",template:Handlebars.templates.tool_form,render:function(){this.$el.children().remove();this.$el.append(this.template(this.model.toJSON()))}});var f=Backbone.View.extend({className:"toolMenuAndView",initialize:function(){this.tool_panel_view=new s({collection:this.collection});this.tool_form_view=new q()},render:function(){this.tool_panel_view.render();this.tool_panel_view.$el.css("float","left");this.$el.append(this.tool_panel_view.$el);this.tool_form_view.$el.hide();this.$el.append(this.tool_form_view.$el);var v=this;this.tool_panel_view.on("tool_link_click",function(x,w){x.preventDefault();v.show_tool(w)})},show_tool:function(w){var v=this;w.fetch().done(function(){v.tool_form_view.model=w;v.tool_form_view.render();v.tool_form_view.$el.show();$("#left").width("650px")})}});return{ToolParameter:d,IntegerToolParameter:c,Tool:g,ToolSearch:b,ToolPanel:l,ToolPanelView:s,ToolFormView:q}}); \ No newline at end of file +define(["libs/underscore","viz/trackster/util","mvc/data","libs/backbone/backbone-relational"],function(t,a,u){var e={hidden:false,show:function(){this.set("hidden",false)},hide:function(){this.set("hidden",true)},is_visible:function(){return !this.attributes.hidden}};var d=Backbone.RelationalModel.extend({defaults:{name:null,label:null,type:null,value:null,html:null,num_samples:5},initialize:function(){this.attributes.html=unescape(this.attributes.html)},copy:function(){return new d(this.toJSON())},get_samples:function(){var w=this.get("type"),v=null;if(w==="number"){v=d3.scale.linear().domain([this.get("min"),this.get("max")]).ticks(this.get("num_samples"))}else{if(w==="select"){v=t.map(this.get("options"),function(x){return x[0]})}}return v},set_value:function(v){this.set("value",v||"")}},{TYPE_DICT:{number:c},create:function(v){var w=d.TYPE_DICT[v.type]||d;return new w(v)}});var c=d.extend({defaults:t.extend({},d.prototype.defaults,{min:null,max:null}),initialize:function(){d.prototype.initialize.call(this);if(this.attributes.min){this.attributes.min=parseInt(this.attributes.min,10)}if(this.attributes.max){this.attributes.max=parseInt(this.attributes.max,10)}},set_value:function(v){this.set("value",parseInt(v,10))}});var h=Backbone.RelationalModel.extend({defaults:{id:null,name:null,description:null,target:null,inputs:[]},initialize:function(v){this.attributes.inputs=new Backbone.Collection(t.map(v.inputs,function(w){return d.create(w)}))},urlRoot:galaxy_paths.get("tool_url"),copy:function(w){var x=new h(this.toJSON());if(w){var v=new Backbone.Collection();x.get("inputs").each(function(y){if(y.get_samples()){v.push(y)}});x.set("inputs",v)}return x},apply_search_results:function(v){(t.indexOf(v,this.attributes.id)!==-1?this.show():this.hide());return this.is_visible()},set_input_value:function(v,w){this.get("inputs").find(function(x){return x.get("name")===v}).set("value",w)},set_input_values:function(w){var v=this;t.each(t.keys(w),function(x){v.set_input_value(x,w[x])})},run:function(){return this._run()},rerun:function(w,v){return this._run({action:"rerun",target_dataset_id:w.id,regions:v})},get_inputs_dict:function(){var v={};this.get("inputs").each(function(w){v[w.get("name")]=w.get("value")});return v},_run:function(x){var y=t.extend({tool_id:this.id,inputs:this.get_inputs_dict()},x);var w=$.Deferred(),v=new a.ServerStateDeferred({ajax_settings:{url:this.urlRoot,data:JSON.stringify(y),dataType:"json",contentType:"application/json",type:"POST"},interval:2000,success_fn:function(z){return z!=="pending"}});$.when(v.go()).then(function(z){w.resolve(new u.DatasetCollection().reset(z))});return w}});t.extend(h.prototype,e);var n=Backbone.View.extend({});var k=Backbone.Collection.extend({model:h});var o=Backbone.Model.extend(e);var r=Backbone.Model.extend({defaults:{elems:[],open:false},clear_search_results:function(){t.each(this.attributes.elems,function(v){v.show()});this.show();this.set("open",false)},apply_search_results:function(w){var x=true,v;t.each(this.attributes.elems,function(y){if(y instanceof o){v=y;v.hide()}else{if(y instanceof h){if(y.apply_search_results(w)){x=false;if(v){v.show()}}}}});if(x){this.hide()}else{this.show();this.set("open",true)}}});t.extend(r.prototype,e);var b=Backbone.Model.extend({defaults:{search_hint_string:"search tools",min_chars_for_search:3,spinner_url:"",clear_btn_url:"",search_url:"",visible:true,query:"",results:null,clear_key:27},initialize:function(){this.on("change:query",this.do_search)},do_search:function(){var x=this.attributes.query;if(x.length<this.attributes.min_chars_for_search){this.set("results",null);return}var w=x+"*";if(this.timer){clearTimeout(this.timer)}$("#search-clear-btn").hide();$("#search-spinner").show();var v=this;this.timer=setTimeout(function(){$.get(v.attributes.search_url,{query:w},function(y){v.set("results",y);$("#search-spinner").hide();$("#search-clear-btn").show()},"json")},200)},clear_search:function(){this.set("query","");this.set("results",null)}});t.extend(b.prototype,e);var l=Backbone.Model.extend({initialize:function(v){this.attributes.tool_search=v.tool_search;this.attributes.tool_search.on("change:results",this.apply_search_results,this);this.attributes.tools=v.tools;this.attributes.layout=new Backbone.Collection(this.parse(v.layout))},parse:function(w){var v=this,x=function(A){var z=A.type;if(z==="tool"){return v.attributes.tools.get(A.id)}else{if(z==="section"){var y=t.map(A.elems,x);A.elems=y;return new r(A)}else{if(z==="label"){return new o(A)}}}};return t.map(w,x)},clear_search_results:function(){this.get("layout").each(function(v){if(v instanceof r){v.clear_search_results()}else{v.show()}})},apply_search_results:function(){var w=this.get("tool_search").get("results");if(w===null){this.clear_search_results();return}var v=null;this.get("layout").each(function(x){if(x instanceof o){v=x;v.hide()}else{if(x instanceof h){if(x.apply_search_results(w)){if(v){v.show()}}}else{v=null;x.apply_search_results(w)}}})}});var p=Backbone.View.extend({initialize:function(){this.model.on("change:hidden",this.update_visible,this);this.update_visible()},update_visible:function(){(this.model.attributes.hidden?this.$el.hide():this.$el.show())}});var j=p.extend({tagName:"div",template:Handlebars.templates.tool_link,render:function(){this.$el.append(this.template(this.model.toJSON()));return this}});var f=p.extend({tagName:"div",className:"toolPanelLabel",render:function(){this.$el.append($("<span/>").text(this.model.attributes.name));return this}});var i=p.extend({tagName:"div",className:"toolSectionWrapper",template:Handlebars.templates.panel_section,initialize:function(){p.prototype.initialize.call(this);this.model.on("change:open",this.update_open,this)},render:function(){this.$el.append(this.template(this.model.toJSON()));var v=this.$el.find(".toolSectionBody");t.each(this.model.attributes.elems,function(w){if(w instanceof h){var x=new j({model:w,className:"toolTitle"});x.render();v.append(x.$el)}else{if(w instanceof o){var y=new f({model:w});y.render();v.append(y.$el)}else{}}});return this},events:{"click .toolSectionTitle > a":"toggle"},toggle:function(){this.model.set("open",!this.model.attributes.open)},update_open:function(){(this.model.attributes.open?this.$el.children(".toolSectionBody").slideDown("fast"):this.$el.children(".toolSectionBody").slideUp("fast"))}});var m=Backbone.View.extend({tagName:"div",id:"tool-search",className:"bar",template:Handlebars.templates.tool_search,events:{click:"focus_and_select","keyup :input":"query_changed","click #search-clear-btn":"clear"},render:function(){this.$el.append(this.template(this.model.toJSON()));if(!this.model.is_visible()){this.$el.hide()}this.$el.find(".tooltip").tooltip();return this},focus_and_select:function(){this.$el.find(":input").focus().select()},clear:function(){this.model.clear_search();this.$el.find(":input").val(this.model.attributes.search_hint_string);this.focus_and_select();return false},query_changed:function(v){if((this.model.attributes.clear_key)&&(this.model.attributes.clear_key===v.which)){this.clear();return false}this.model.set("query",this.$el.find(":input").val())}});var s=Backbone.View.extend({tagName:"div",className:"toolMenu",initialize:function(){this.model.get("tool_search").on("change:results",this.handle_search_results,this)},render:function(){var v=this;var w=new m({model:this.model.get("tool_search")});w.render();v.$el.append(w.$el);this.model.get("layout").each(function(y){if(y instanceof r){var x=new i({model:y});x.render();v.$el.append(x.$el)}else{if(y instanceof h){var z=new j({model:y,className:"toolTitleNoSection"});z.render();v.$el.append(z.$el)}else{if(y instanceof o){var A=new f({model:y});A.render();v.$el.append(A.$el)}}}});v.$el.find("a.tool-link").click(function(z){var y=$(this).attr("class").split(/\s+/)[0],x=v.model.get("tools").get(y);v.trigger("tool_link_click",z,x)});return this},handle_search_results:function(){var v=this.model.get("tool_search").get("results");if(v&&v.length===0){$("#search-no-results").show()}else{$("#search-no-results").hide()}}});var q=Backbone.View.extend({className:"toolForm",template:Handlebars.templates.tool_form,render:function(){this.$el.children().remove();this.$el.append(this.template(this.model.toJSON()))}});var g=Backbone.View.extend({className:"toolMenuAndView",initialize:function(){this.tool_panel_view=new s({collection:this.collection});this.tool_form_view=new q()},render:function(){this.tool_panel_view.render();this.tool_panel_view.$el.css("float","left");this.$el.append(this.tool_panel_view.$el);this.tool_form_view.$el.hide();this.$el.append(this.tool_form_view.$el);var v=this;this.tool_panel_view.on("tool_link_click",function(x,w){x.preventDefault();v.show_tool(w)})},show_tool:function(w){var v=this;w.fetch().done(function(){v.tool_form_view.model=w;v.tool_form_view.render();v.tool_form_view.$el.show();$("#left").width("650px")})}});return{ToolParameter:d,IntegerToolParameter:c,Tool:h,ToolCollection:k,ToolSearch:b,ToolPanel:l,ToolPanelView:s,ToolFormView:q}}); \ No newline at end of file diff -r 84c88d3644c0edc925fe2583276fbd32711f30a9 -r ebf6033a1cd4416602294b674628eb73da6fa663 templates/webapps/galaxy/root/tool_menu.mako --- a/templates/webapps/galaxy/root/tool_menu.mako +++ b/templates/webapps/galaxy/root/tool_menu.mako @@ -12,40 +12,45 @@ } }); - require(["mvc/tools"], function(tools) { + require(["mvc/tools"], function(tools_mod) { // Init. on document load. $(function() { - // Create tool search, tool panel, and tool panel view. - var tool_search = new tools.ToolSearch({ - spinner_url: "${h.url_for('/static/images/loading_small_white_bg.gif')}", - search_url: "${h.url_for( controller='root', action='tool_search' )}", - hidden: false - }), - tool_panel = new tools.ToolPanel({ tool_search: tool_search }), - tool_panel_view = new tools.ToolPanelView({ collection: tool_panel }); - - // Add tool panel to Galaxy object. - Galaxy.toolPanel = tool_panel; - ## Populate tool panel if (a) anonymous use possible or (b) user is logged in. %if trans.user or not trans.app.config.require_login: - tool_panel.reset( tool_panel.parse( ${h.to_json_string( trans.app.toolbox.to_dict( trans ) )} ) ); + // Create tool search, tool panel, and tool panel view. + var tool_search = new tools_mod.ToolSearch({ + spinner_url: "${h.url_for('/static/images/loading_small_white_bg.gif')}", + search_url: "${h.url_for( controller='root', action='tool_search' )}", + hidden: false + }), + tools = new tools_mod.ToolCollection( + ${ h.to_json_string( trans.app.toolbox.to_dict( trans, in_panel=False ) ) } + ), + tool_panel = new tools_mod.ToolPanel({ + tool_search: tool_search, + tools: tools, + layout: ${h.to_json_string( trans.app.toolbox.to_dict( trans ) )} + }), + tool_panel_view = new tools_mod.ToolPanelView({ model: tool_panel }); + + // Add tool panel to Galaxy object. + Galaxy.toolPanel = tool_panel; + + // If there are tools, render panel and display everything. + if (tool_panel.get('layout').size() > 1) { + tool_panel_view.render(); + $('.toolMenu').show(); + } + $('.toolMenuContainer').prepend(tool_panel_view.$el); + + // Minsize init hint. + $( "a[minsizehint]" ).click( function() { + if ( parent.handle_minwidth_hint ) { + parent.handle_minwidth_hint( $(this).attr( "minsizehint" ) ); + } + }); %endif - - // If there are tools, render panel and display everything. - if (tool_panel.length > 1) { // > 1 because tool_search counts as a model - tool_panel_view.render(); - $('.toolMenu').show(); - } - $('.toolMenuContainer').prepend(tool_panel_view.$el); - - // Minsize init hint. - $( "a[minsizehint]" ).click( function() { - if ( parent.handle_minwidth_hint ) { - parent.handle_minwidth_hint( $(this).attr( "minsizehint" ) ); - } - }); }); }); 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.