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

1 line
5.3 KiB
JavaScript

define("mvc/user/user-custom-builds",["exports","utils/localization","utils/utils","mvc/ui/ui-misc","mvc/form/form-view","mvc/ui/ui-table"],function(e,t,a,l,i,s){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(e,"__esModule",{value:!0});var o=n(t),r=(n(a),n(l)),d=n(i),u=n(s),c=Backbone.Collection.extend({comparator:function(e,t){return e=e.get("name"),t=t.get("name"),e>t?1:e<t?-1:0}}),m=Backbone.View.extend({initialize:function(e){var t=this;this.active_tab="user";var a=Galaxy.currHistoryPanel&&Galaxy.currHistoryPanel.model.id;this.model=new Backbone.Model,this.model.url=Galaxy.root+"api/histories/"+a+"/custom_builds_metadata",this.collection=new c,this.collection.url=Galaxy.root+"api/users/"+Galaxy.user.id+"/custom_builds",this.message=new r.default.Message({}),this.installed_builds=new r.default.Select.View({optional:!0,onchange:function(){t.installed_builds.value(null)},empty_text:"List of available builds:",error_text:"No system installed builds available."}),this.table=new u.default.View({cls:"grid",selectable:!1}),this.table.addHeader("Name"),this.table.addHeader("Key"),this.table.addHeader("Number of chroms/contigs"),this.table.addHeader(""),this.table.appendHeader(),this.setElement($("<div/>").append($("<h4/>").text("Current Custom Builds")).append(this.table.$el).append(this.$installed=$("<div/>").append($("<h4/>").text("System Installed Builds").addClass("ui-margin-top")).append(this.installed_builds.$el)).append($("<h4/>").text("Add a Custom Build").addClass("ui-margin-top")).append($("<span/>").addClass("ui-column").append($("<div/>").addClass("ui-column-left").append(this.message.$el).append(this.$form=$("<div/>").addClass("ui-margin-top"))).append(this.$help=$("<div/>").addClass("ui-column-right")))),this.listenTo(this.collection,"add remove reset",function(){t._renderTable()}),this.listenTo(this.model,"change",function(){t._renderForm()}),this.collection.fetch(),this.model.fetch()},render:function(){this._renderTable(),this._renderForm()},_renderTable:function(){var e=this;this.table.delAll(),this.collection.sort(),this.collection.each(function(t){e.table.add(t.get("name")),e.table.add(t.id),e.table.add(void 0!==t.get("count")?t.get("count"):"Processing..."),e.table.add(new r.default.ButtonIcon({icon:"fa-trash-o",cls:"ui-button-icon-plain",tooltip:(0,o.default)("Delete custom build."),onclick:function(){t.destroy()}}).$el),e.table.append(t.id)})},_renderForm:function(){var e=this,t=new d.default({inputs:[{type:"text",name:"name",label:"Name",help:"Specify a build name e.g. Hamster."},{type:"text",name:"id",label:"Key",help:"Specify a build key e.g. hamster_v1."},{name:"len",type:"conditional",test_param:{name:"type",label:"Definition",help:(0,o.default)("Provide the data source."),type:"select",value:"fasta",data:[{value:"fasta",label:"FASTA-file from history"},{value:"file",label:"Len-file from disk"},{value:"text",label:"Len-file by copy/paste"}]},cases:[{value:"fasta",inputs:[{type:"select",name:"value",label:"FASTA-file",data:this.model.get("fasta_hdas")}]},{value:"file",inputs:[{type:"upload",name:"value",label:"Len-file",data:this.model.get("len_hdas")}]},{value:"text",inputs:[{type:"text",area:!0,name:"value",label:"Edit/Paste"}]}]}],buttons:{save:new r.default.Button({icon:"fa-save",tooltip:(0,o.default)("Create new Build"),title:(0,o.default)("Save"),cls:"btn btn-primary ui-clear-float",onclick:function(){var a=t.data.create();a.id&&a.name?e.collection.create(a,{wait:!0,success:function(t){t.get("message")?e.message.update({message:t.get("message"),status:"warning"}):e.message.update({message:"Successfully added a new custom build.",status:"success"})},error:function(t,a){var l=a&&a.responseJSON&&a.responseJSON.err_msg;e.message.update({message:l||"Failed to create custom build.",status:"danger"})}}):e.message.update({message:"All inputs are required.",status:"danger"})}})},onchange:function(){var a=t.data.match("len|type");if(a){var l=t.field_list[a];e._renderHelp(l.value())}}});this.$form.empty().append(t.$el);var a=this.model.get("installed_builds");a&&a.length?(this.$installed.show(),this.installed_builds.update(this.model.get("installed_builds"))):this.$installed.hide(),this._renderHelp("fasta")},_renderHelp:function(e){this.$help.empty().addClass("alert alert-info").html("fasta"==e?this._templateFasta():this._templateLen())},_templateLen:function(){return"<h4>Length Format</h4><p>The length format is two-column, separated by whitespace, of the form:<pre>chrom/contig length of chrom/contig</pre></p><p>For example, the first few entries of <em>mm9.len</em> are as follows:<pre>chr1 197195432\nchr2 181748087\nchr3 159599783\nchr4 155630120\nchr5 152537259</pre></p><p>Trackster uses this information to populate the select box for chrom/contig, andto set the maximum basepair of the track browser. You may either upload a .len fileof this format (Len File option), or directly enter the information into the box (Len Entry option).</p>"},_templateFasta:function(){return"<h4>FASTA format</h4><p>This is a multi-fasta file from your current history that provides the genomesequences for each chromosome/contig in your build.</p><p>Here is a snippet from an example multi-fasta file:<pre>>chr1\nATTATATATAAGACCACAGAGAGAATATTTTGCCCGG...\n\n>chr2\nGGCGGCCGCGGCGATATAGAACTACTCATTATATATA...\n\n...</pre></p>"}});e.default={View:m}});