1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/c6d9b2f1b26b/ Changeset: c6d9b2f1b26b User: martenson Date: 2014-04-10 21:07:01 Summary: forgotten files for previous commit data libraries: API refactoring and improvements; backbone decoupling; role UI first implementation Affected #: 4 files diff -r a70f236803f7d398b4f486342e864add77e9ad3f -r c6d9b2f1b26b219b03a74c321202dc68160e9a15 static/scripts/mvc/library/library-folderrow-view.js --- /dev/null +++ b/static/scripts/mvc/library/library-folderrow-view.js @@ -0,0 +1,310 @@ +// dependencies +define([ + "galaxy.masthead", + "utils/utils", + "libs/toastr", + "mvc/library/library-model"], +function(mod_masthead, + mod_utils, + mod_toastr, + mod_library_model) { + +// galaxy library row view +var FolderRowView = Backbone.View.extend({ + // last selected history in modal for UX + lastSelectedHistory: '', + + events: { + 'click .library-dataset' : 'showDatasetDetails' + }, + + options: { + type: null + }, + + initialize : function(folder_item){ + this.render(folder_item); + }, + + render: function(folder_item){ + // if (typeof folder_item === 'undefined'){ + // folder_item = Galaxy.libraries.libraryFolderView.collection.get(this.$el.data('id')); + // } + var template = null; + if (folder_item.get('type') === 'folder'){ + this.options.type = 'folder'; + template = this.templateRowFolder(); + } else { + this.options.type = 'file'; + template = this.templateRowFile(); + } + this.setElement(template({content_item:folder_item})); + this.$el.show(); + return this; + }, + + //show modal with current dataset info + showDatasetDetails : function(event){ + // prevent default + event.preventDefault(); + + var id = this.id; + + //create new item + var item = new mod_library_model.Item(); + var histories = new mod_library_model.GalaxyHistories(); + item.id = id; + var self = this; + + //fetch the dataset info + item.fetch({ + success: function (item) { + // TODO can start rendering here already + //fetch user histories for import purposes + histories.fetch({ + success: function (histories){ + self.renderModalAfterFetch(item, histories); + }, + error: function(){ + mod_toastr.error('An error occured during fetching histories:('); + self.renderModalAfterFetch(item); + } + }); + }, + error: function(){ + mod_toastr.error('An error occured during loading dataset details :('); + } + }); +}, + + // show the current dataset in a modal + renderModalAfterFetch : function(item, histories){ + var size = this.size_to_string(item.get('file_size')); + var template = _.template(this.templateDatasetModal(), { item : item, size : size }); + // make modal + var self = this; + this.modal = Galaxy.modal; + this.modal.show({ + closing_events : true, + title : 'Dataset Details', + body : template, + buttons : { + 'Import' : function() { self.importCurrentIntoHistory(); }, + 'Download' : function() { self.downloadCurrent(); }, + 'Close' : function() { self.modal.hide(); } + } + }); + + $(".peek").html(item.get("peek")); + + // show the import-into-history footer only if the request for histories succeeded + if (typeof history.models !== undefined){ + var history_footer_tmpl = _.template(this.templateHistorySelectInModal(), {histories : histories.models}); + $(this.modal.elMain).find('.buttons').prepend(history_footer_tmpl); + // preset last selected history if we know it + if (self.lastSelectedHistory.length > 0) { + $(this.modal.elMain).find('#dataset_import_single').val(self.lastSelectedHistory); + } + } + }, + + // TODO this is dup func, unify + // convert size to nice string + size_to_string : function (size){ + // identify unit + var unit = ""; + if (size >= 100000000000) { size = size / 100000000000; unit = "TB"; } else + if (size >= 100000000) { size = size / 100000000; unit = "GB"; } else + if (size >= 100000) { size = size / 100000; unit = "MB"; } else + if (size >= 100) { size = size / 100; unit = "KB"; } else + { size = size * 10; unit = "b"; } + // return formatted string + return (Math.round(size) / 10) + unit; + }, + + // download dataset shown currently in modal + downloadCurrent : function(){ + //disable the buttons + this.modal.disableButton('Import'); + this.modal.disableButton('Download'); + + var library_dataset_id = []; + library_dataset_id.push($('#id_row').attr('data-id')); + var url = '/api/libraries/datasets/download/uncompressed'; + var data = {'ldda_ids' : library_dataset_id}; + + this.processDownload(url, data); + this.modal.enableButton('Import'); + this.modal.enableButton('Download'); + }, + + // TODO this is dup func, unify + // create hidden form and submit through POST to initialize download + processDownload: function(url, data, method){ + //url and data options required + if( url && data ){ + //data can be string of parameters or array/object + data = typeof data == 'string' ? data : $.param(data); + //split params into form inputs + var inputs = ''; + $.each(data.split('&'), function(){ + var pair = this.split('='); + inputs+='<input type="hidden" name="'+ pair[0] +'" value="'+ pair[1] +'" />'; + }); + //send request + $('<form action="'+ url +'" method="'+ (method||'post') +'">'+inputs+'</form>') + .appendTo('body').submit().remove(); + + mod_toastr.info('Your download will begin soon'); + } + }, + + // import dataset shown currently in modal into selected history + importCurrentIntoHistory : function(){ + //disable the buttons + this.modal.disableButton('Import'); + this.modal.disableButton('Download'); + + var history_id = $(this.modal.elMain).find('select[name=dataset_import_single] option:selected').val(); + this.lastSelectedHistory = history_id; //save selected history for further use + + var library_dataset_id = $('#id_row').attr('data-id'); + var historyItem = new mod_library_model.HistoryItem(); + var self = this; + historyItem.url = historyItem.urlRoot + history_id + '/contents'; + + // save the dataset into selected history + historyItem.save({ content : library_dataset_id, source : 'library' }, { success : function(){ + mod_toastr.success('Dataset imported'); + //enable the buttons + self.modal.enableButton('Import'); + self.modal.enableButton('Download'); + }, error : function(){ + mod_toastr.error('An error occured! Dataset not imported. Please try again.'); + //enable the buttons + self.modal.enableButton('Import'); + self.modal.enableButton('Download'); + } + }); + }, + + templateRowFolder: function() { + tmpl_array = []; + + tmpl_array.push('<tr class="folder_row light" id="<%- content_item.id %>">'); + tmpl_array.push(' <td>'); + tmpl_array.push(' <span title="Folder" class="fa fa-folder-o"></span>'); + tmpl_array.push(' </td>'); + tmpl_array.push(' <td></td>'); + tmpl_array.push(' <td>'); + tmpl_array.push(' <a href="#folders/<%- content_item.id %>"><%- content_item.get("name") %></a>'); + tmpl_array.push(' <% if (content_item.get("item_count") === 0) { %>'); // empty folder + tmpl_array.push(' <span>(empty folder)</span>'); + tmpl_array.push(' <% } %>'); + tmpl_array.push(' </td>'); + tmpl_array.push(' <td>folder</td>'); + tmpl_array.push(' <td><%= _.escape(content_item.get("item_count")) %> item(s)</td>'); // size + tmpl_array.push(' <td><%= _.escape(content_item.get("time_updated")) %></td>'); // time updated + tmpl_array.push('</tr>'); + + return _.template(tmpl_array.join('')); + }, + + templateRowFile: function(){ + tmpl_array = []; + + tmpl_array.push('<tr class="dataset_row light" id="<%- content_item.id %>">'); + tmpl_array.push(' <td>'); + tmpl_array.push(' <span title="Dataset" class="fa fa-file-o"></span>'); + tmpl_array.push(' </td>'); + tmpl_array.push(' <td style="text-align: center; "><input style="margin: 0;" type="checkbox"></td>'); + tmpl_array.push(' <td><a href="#" class="library-dataset"><%- content_item.get("name") %><a></td>'); // dataset + tmpl_array.push(' <td><%= _.escape(content_item.get("data_type")) %></td>'); // data type + tmpl_array.push(' <td><%= _.escape(content_item.get("readable_size")) %></td>'); // size + tmpl_array.push(' <td><%= _.escape(content_item.get("time_updated")) %></td>'); // time updated + tmpl_array.push('</tr>'); + + return _.template(tmpl_array.join('')); + }, + +templateDatasetModal : function(){ + var tmpl_array = []; + + tmpl_array.push('<div class="modal_table">'); + tmpl_array.push(' <table class="grid table table-striped table-condensed">'); + tmpl_array.push(' <tr>'); + tmpl_array.push(' <th scope="row" id="id_row" data-id="<%= _.escape(item.get("ldda_id")) %>">Name</th>'); + tmpl_array.push(' <td><%= _.escape(item.get("name")) %></td>'); + tmpl_array.push(' </tr>'); + tmpl_array.push(' <tr>'); + tmpl_array.push(' <th scope="row">Data type</th>'); + tmpl_array.push(' <td><%= _.escape(item.get("data_type")) %></td>'); + tmpl_array.push(' </tr>'); + tmpl_array.push(' <tr>'); + tmpl_array.push(' <th scope="row">Genome build</th>'); + tmpl_array.push(' <td><%= _.escape(item.get("genome_build")) %></td>'); + tmpl_array.push(' </tr>'); + tmpl_array.push(' <th scope="row">Size</th>'); + tmpl_array.push(' <td><%= _.escape(size) %></td>'); + tmpl_array.push(' </tr>'); + tmpl_array.push(' <tr>'); + tmpl_array.push(' <th scope="row">Date uploaded (UTC)</th>'); + tmpl_array.push(' <td><%= _.escape(item.get("date_uploaded")) %></td>'); + tmpl_array.push(' </tr>'); + tmpl_array.push(' <tr>'); + tmpl_array.push(' <th scope="row">Uploaded by</th>'); + tmpl_array.push(' <td><%= _.escape(item.get("uploaded_by")) %></td>'); + tmpl_array.push(' </tr>'); + tmpl_array.push(' <tr scope="row">'); + tmpl_array.push(' <th scope="row">Data Lines</th>'); + tmpl_array.push(' <td scope="row"><%= _.escape(item.get("metadata_data_lines")) %></td>'); + tmpl_array.push(' </tr>'); + tmpl_array.push(' <th scope="row">Comment Lines</th>'); + tmpl_array.push(' <% if (item.get("metadata_comment_lines") === "") { %>'); + tmpl_array.push(' <td scope="row"><%= _.escape(item.get("metadata_comment_lines")) %></td>'); + tmpl_array.push(' <% } else { %>'); + tmpl_array.push(' <td scope="row">unknown</td>'); + tmpl_array.push(' <% } %>'); + tmpl_array.push(' </tr>'); + tmpl_array.push(' <tr>'); + tmpl_array.push(' <th scope="row">Number of Columns</th>'); + tmpl_array.push(' <td scope="row"><%= _.escape(item.get("metadata_columns")) %></td>'); + tmpl_array.push(' </tr>'); + tmpl_array.push(' <tr>'); + tmpl_array.push(' <th scope="row">Column Types</th>'); + tmpl_array.push(' <td scope="row"><%= _.escape(item.get("metadata_column_types")) %></td>'); + tmpl_array.push(' </tr>'); + tmpl_array.push(' <tr>'); + tmpl_array.push(' <th scope="row">Miscellaneous information</th>'); + tmpl_array.push(' <td scope="row"><%= _.escape(item.get("misc_blurb")) %></td>'); + tmpl_array.push(' </tr>'); + tmpl_array.push(' </table>'); + tmpl_array.push(' <pre class="peek">'); + tmpl_array.push(' </pre>'); + tmpl_array.push('</div>'); + + return tmpl_array.join(''); +}, + +templateHistorySelectInModal : function(){ + var tmpl_array = []; + + tmpl_array.push('<span id="history_modal_combo" style="width:100%; margin-left: 1em; margin-right: 1em; ">'); + tmpl_array.push('Select history: '); + tmpl_array.push('<select id="dataset_import_single" name="dataset_import_single" style="width:40%; margin-bottom: 1em; "> '); + tmpl_array.push(' <% _.each(histories, function(history) { %>'); //history select box + tmpl_array.push(' <option value="<%= _.escape(history.get("id")) %>"><%= _.escape(history.get("name")) %></option>'); + tmpl_array.push(' <% }); %>'); + tmpl_array.push('</select>'); + tmpl_array.push('</span>'); + + return tmpl_array.join(''); +} + +}); + +return { + FolderRowView: FolderRowView +}; + +}); diff -r a70f236803f7d398b4f486342e864add77e9ad3f -r c6d9b2f1b26b219b03a74c321202dc68160e9a15 static/scripts/mvc/library/library-foldertoolbar-view.js --- /dev/null +++ b/static/scripts/mvc/library/library-foldertoolbar-view.js @@ -0,0 +1,320 @@ +// dependencies +define([ + "galaxy.masthead", + "utils/utils", + "libs/toastr", + "mvc/library/library-model"], +function(mod_masthead, + mod_utils, + mod_toastr, + mod_library_model) { + +var FolderToolbarView = Backbone.View.extend({ + el: '#center', + + events: { + 'click #toolbtn_create_folder' : 'createFolderFromModal', + 'click #toolbtn_bulk_import' : 'modalBulkImport' + }, + + defaults: { + 'can_add_library_item' : false, + 'contains_file' : false + }, + + modal : null, + + initialize: function(options){ + this.options = _.defaults(options || {}, this.defaults); + this.render(); + }, + + render: function(options){ + this.options = _.extend(this.options, options); + var toolbar_template = this.templateToolBar(); + var is_admin = Galaxy.currUser.isAdmin(); + this.$el.html(toolbar_template({id: this.options.id, admin_user: is_admin})); + }, + + configureElements: function(options){ + this.options = _.extend(this.options, options); + if (this.options.can_add_library_item === true){ + $('#toolbtn_create_folder').show(); + $('#toolbtn_upload_files').show(); + } + if (this.options.contains_file === true){ + $('#toolbtn_bulk_import').show(); + $('#toolbtn_dl').show(); + } + this.$el.find('[data-toggle]').tooltip(); + }, + + // shows modal for creating folder + createFolderFromModal: function(){ + event.preventDefault(); + event.stopPropagation(); + + // create modal + var self = this; + var template = this.templateNewFolderInModal(); + this.modal = Galaxy.modal; + this.modal.show({ + closing_events : true, + title : 'Create New Folder', + body : template(), + buttons : { + 'Create' : function() {self.create_new_folder_event();}, + 'Close' : function() {self.modal.hide(); self.modal = null;} + } + }); + }, + + // create the new folder from modal + create_new_folder_event: function(){ + var folderDetails = this.serialize_new_folder(); + if (this.validate_new_folder(folderDetails)){ + var folder = new mod_library_model.FolderAsModel(); + url_items = Backbone.history.fragment.split('/'); + current_folder_id = url_items[url_items.length-1]; + folder.url = folder.urlRoot + '/' + current_folder_id ; + + var self = this; + folder.save(folderDetails, { + success: function (folder) { + self.modal.hide(); + mod_toastr.success('Folder created'); + Galaxy.libraries.folderListView.render({id: current_folder_id}); + }, + error: function(){ + mod_toastr.error('An error occured :('); + } + }); + } else { + mod_toastr.error('Folder\'s name is missing'); + } + return false; + }, + + // serialize data from the modal + serialize_new_folder : function(){ + return { + name: $("input[name='Name']").val(), + description: $("input[name='Description']").val() + }; + }, + + // validate new folder info + validate_new_folder: function(folderDetails){ + return folderDetails.name !== ''; + }, + + + // show bulk import modal + modalBulkImport : function(){ + var checkedValues = $('#folder_table').find(':checked'); + if(checkedValues.length === 0){ + mod_toastr.info('You have to select some datasets first'); + } else { + var self = this; + // fetch histories + var template = this.templateBulkImportInModal(); + var histories = new mod_library_model.GalaxyHistories(); + histories.fetch({ + success: function (histories){ + // make modal + // var history_modal_tmpl = template({histories : histories.models}); + self.modal = Galaxy.modal; + self.modal.show({ + closing_events : true, + title : 'Import into History', + body : template({histories : histories.models}), + buttons : { + 'Import' : function() {self.importAllIntoHistory();}, + 'Close' : function() {self.modal.hide();} + } + }); + }, + error: function(){ + mod_toastr.error('An error occured :('); + } + }); + } + }, + + // import all selected datasets into history + importAllIntoHistory : function (){ + //disable the button to prevent multiple submission + this.modal.disableButton('Import'); + + var history_id = $("select[name=dataset_import_bulk] option:selected").val(); + var history_name = $("select[name=dataset_import_bulk] option:selected").text(); + + var dataset_ids = []; + $('#folder_table').find(':checked').each(function(){ + if (this.parentElement.parentElement.id !== '') { + dataset_ids.push(this.parentElement.parentElement.id); + } + }); + var progress_bar_tmpl = this.templateProgressBar(); + $(this.modal.elMain).find('.modal-body').html(progress_bar_tmpl({ history_name : history_name })); + + // init the progress bar + var progressStep = 100 / dataset_ids.length; + this.initProgress(progressStep); + + // prepare the dataset objects to be imported + var datasets_to_import = []; + for (var i = dataset_ids.length - 1; i >= 0; i--) { + library_dataset_id = dataset_ids[i]; + var historyItem = new mod_library_model.HistoryItem(); + var self = this; + historyItem.url = historyItem.urlRoot + history_id + '/contents'; + historyItem.content = library_dataset_id; + historyItem.source = 'library'; + datasets_to_import.push(historyItem); + } + // call the recursive function to call ajax one after each other (request FIFO queue) + this.chainCall(datasets_to_import); + }, + + chainCall: function(history_item_set){ + var self = this; + var popped_item = history_item_set.pop(); + if (typeof popped_item === "undefined") { + mod_toastr.success('All datasets imported'); + this.modal.hide(); + return; + } + var promise = $.when(popped_item.save({content: popped_item.content, source: popped_item.source})).done(function(a1){ + self.updateProgress(); + self.chainCall(history_item_set); + }); + }, + + initProgress: function(progressStep){ + this.progress = 0; + this.progressStep = progressStep; + }, + + updateProgress: function(){ + this.progress += this.progressStep; + $('.progress-bar-import').width(Math.round(this.progress) + '%'); + txt_representation = Math.round(this.progress) + '% Complete'; + $('.completion_span').text(txt_representation); + }, + + // download selected datasets + download : function(folder_id, format){ + var dataset_ids = []; + $('#folder_table').find(':checked').each(function(){ + if (this.parentElement.parentElement.id !== '') { + dataset_ids.push(this.parentElement.parentElement.id); + } + }); + + var url = '/api/libraries/datasets/download/' + format; + var data = {'ldda_ids' : dataset_ids}; + this.processDownload(url, data, 'get'); + }, + + // create hidden form and submit through POST to initialize download + processDownload: function(url, data, method){ + //url and data options required + if( url && data ){ + //data can be string of parameters or array/object + data = typeof data == 'string' ? data : $.param(data); + //split params into form inputs + var inputs = ''; + $.each(data.split('&'), function(){ + var pair = this.split('='); + inputs+='<input type="hidden" name="'+ pair[0] +'" value="'+ pair[1] +'" />'; + }); + //send request + $('<form action="'+ url +'" method="'+ (method||'post') +'">'+inputs+'</form>') + .appendTo('body').submit().remove(); + + mod_toastr.info('Your download will begin soon'); + } + }, + + templateToolBar: function(){ + tmpl_array = []; + + // CONTAINER + tmpl_array.push('<div class="library_style_container">'); + tmpl_array.push('<h3>Data Libraries Beta Test. This is work in progress. Please report problems & ideas via <a href="mailto:galaxy-bugs@bx.psu.edu?Subject=DataLibrariesBeta_Feedback" target="_blank">email</a> and <a href="https://trello.com/c/nwYQNFPK/56-data-library-ui-progressive-display-of-fold..." target="_blank">Trello</a>.</h3>'); + // TOOLBAR + tmpl_array.push('<div id="library_folder_toolbar" >'); + tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Create New Folder" id="toolbtn_create_folder" class="primary-button" type="button" style="display:none;"><span class="fa fa-plus"></span><span class="fa fa-folder-close"></span> folder</button>'); + tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Upload Files to Current Folder" id="toolbtn_upload_files" class="primary-button" type="button" style="display:none;"><span class="fa fa-upload"></span> upload</button>'); + tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Import selected datasets into history" id="toolbtn_bulk_import" class="primary-button" style="margin-left: 0.5em; display:none;" type="button"><span class="fa fa-book"></span> to history</button>'); + tmpl_array.push(' <div id="toolbtn_dl" class="btn-group" style="margin-left: 0.5em; display:none; ">'); + tmpl_array.push(' <button title="Download selected datasets" id="drop_toggle" type="button" class="primary-button dropdown-toggle" data-toggle="dropdown">'); + tmpl_array.push(' <span class="fa fa-download"></span> download <span class="caret"></span>'); + tmpl_array.push(' </button>'); + tmpl_array.push(' <ul class="dropdown-menu" role="menu">'); + tmpl_array.push(' <li id="download_archive"><a href="#/folders/<%= id %>/download/tgz">.tar.gz</a></li>'); + tmpl_array.push(' <li id="download_archive"><a href="#/folders/<%= id %>/download/tbz">.tar.bz</a></li>'); + tmpl_array.push(' <li id="download_archive"><a href="#/folders/<%= id %>/download/zip">.zip</a></li>'); + tmpl_array.push(' </ul>'); + tmpl_array.push(' </div>'); + tmpl_array.push(' </div>'); + tmpl_array.push(' <div id="folder_items_element">'); + // library items will append here + tmpl_array.push(' </div>'); + tmpl_array.push('</div>'); + + return _.template(tmpl_array.join('')); + }, + + templateNewFolderInModal: function(){ + tmpl_array = []; + + tmpl_array.push('<div id="new_folder_modal">'); + tmpl_array.push('<form>'); + tmpl_array.push('<input type="text" name="Name" value="" placeholder="Name">'); + tmpl_array.push('<input type="text" name="Description" value="" placeholder="Description">'); + tmpl_array.push('</form>'); + tmpl_array.push('</div>'); + + return _.template(tmpl_array.join('')); + }, + + + templateBulkImportInModal : function(){ + var tmpl_array = []; + + tmpl_array.push('<span id="history_modal_combo_bulk" style="width:90%; margin-left: 1em; margin-right: 1em; ">'); + tmpl_array.push('Select history: '); + tmpl_array.push('<select id="dataset_import_bulk" name="dataset_import_bulk" style="width:50%; margin-bottom: 1em; "> '); + tmpl_array.push(' <% _.each(histories, function(history) { %>'); //history select box + tmpl_array.push(' <option value="<%= _.escape(history.get("id")) %>"><%= _.escape(history.get("name")) %></option>'); + tmpl_array.push(' <% }); %>'); + tmpl_array.push('</select>'); + tmpl_array.push('</span>'); + + return _.template(tmpl_array.join('')); + }, + + templateProgressBar : function (){ + var tmpl_array = []; + + tmpl_array.push('<div class="import_text">'); + tmpl_array.push('Importing selected datasets to history <b><%= _.escape(history_name) %></b>'); + tmpl_array.push('</div>'); + tmpl_array.push('<div class="progress">'); + tmpl_array.push(' <div class="progress-bar progress-bar-import" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 00%;">'); + tmpl_array.push(' <span class="completion_span">0% Complete</span>'); + tmpl_array.push(' </div>'); + tmpl_array.push('</div>'); + tmpl_array.push(''); + + return _.template(tmpl_array.join('')); + } +}); + +return { + FolderToolbarView: FolderToolbarView +}; + +}); diff -r a70f236803f7d398b4f486342e864add77e9ad3f -r c6d9b2f1b26b219b03a74c321202dc68160e9a15 static/scripts/packed/mvc/library/library-folderrow-view.js --- /dev/null +++ b/static/scripts/packed/mvc/library/library-folderrow-view.js @@ -0,0 +1,1 @@ +define(["galaxy.masthead","utils/utils","libs/toastr","mvc/library/library-model"],function(b,d,e,c){var a=Backbone.View.extend({lastSelectedHistory:"",events:{"click .library-dataset":"showDatasetDetails"},options:{type:null},initialize:function(f){this.render(f)},render:function(f){var g=null;if(f.get("type")==="folder"){this.options.type="folder";g=this.templateRowFolder()}else{this.options.type="file";g=this.templateRowFile()}this.setElement(g({content_item:f}));this.$el.show();return this},showDatasetDetails:function(i){i.preventDefault();var j=this.id;var h=new c.Item();var g=new c.GalaxyHistories();h.id=j;var f=this;h.fetch({success:function(k){g.fetch({success:function(l){f.renderModalAfterFetch(k,l)},error:function(){e.error("An error occured during fetching histories:(");f.renderModalAfterFetch(k)}})},error:function(){e.error("An error occured during loading dataset details :(")}})},renderModalAfterFetch:function(k,h){var i=this.size_to_string(k.get("file_size"));var j=_.template(this.templateDatasetModal(),{item:k,size:i});var g=this;this.modal=Galaxy.modal;this.modal.show({closing_events:true,title:"Dataset Details",body:j,buttons:{Import:function(){g.importCurrentIntoHistory()},Download:function(){g.downloadCurrent()},Close:function(){g.modal.hide()}}});$(".peek").html(k.get("peek"));if(typeof history.models!==undefined){var f=_.template(this.templateHistorySelectInModal(),{histories:h.models});$(this.modal.elMain).find(".buttons").prepend(f);if(g.lastSelectedHistory.length>0){$(this.modal.elMain).find("#dataset_import_single").val(g.lastSelectedHistory)}}},size_to_string:function(f){var g="";if(f>=100000000000){f=f/100000000000;g="TB"}else{if(f>=100000000){f=f/100000000;g="GB"}else{if(f>=100000){f=f/100000;g="MB"}else{if(f>=100){f=f/100;g="KB"}else{f=f*10;g="b"}}}}return(Math.round(f)/10)+g},downloadCurrent:function(){this.modal.disableButton("Import");this.modal.disableButton("Download");var f=[];f.push($("#id_row").attr("data-id"));var g="/api/libraries/datasets/download/uncompressed";var h={ldda_ids:f};this.processDownload(g,h);this.modal.enableButton("Import");this.modal.enableButton("Download")},processDownload:function(g,h,i){if(g&&h){h=typeof h=="string"?h:$.param(h);var f="";$.each(h.split("&"),function(){var j=this.split("=");f+='<input type="hidden" name="'+j[0]+'" value="'+j[1]+'" />'});$('<form action="'+g+'" method="'+(i||"post")+'">'+f+"</form>").appendTo("body").submit().remove();e.info("Your download will begin soon")}},importCurrentIntoHistory:function(){this.modal.disableButton("Import");this.modal.disableButton("Download");var h=$(this.modal.elMain).find("select[name=dataset_import_single] option:selected").val();this.lastSelectedHistory=h;var f=$("#id_row").attr("data-id");var i=new c.HistoryItem();var g=this;i.url=i.urlRoot+h+"/contents";i.save({content:f,source:"library"},{success:function(){e.success("Dataset imported");g.modal.enableButton("Import");g.modal.enableButton("Download")},error:function(){e.error("An error occured! Dataset not imported. Please try again.");g.modal.enableButton("Import");g.modal.enableButton("Download")}})},templateRowFolder:function(){tmpl_array=[];tmpl_array.push('<tr class="folder_row light" id="<%- content_item.id %>">');tmpl_array.push(" <td>");tmpl_array.push(' <span title="Folder" class="fa fa-folder-o"></span>');tmpl_array.push(" </td>");tmpl_array.push(" <td></td>");tmpl_array.push(" <td>");tmpl_array.push(' <a href="#folders/<%- content_item.id %>"><%- content_item.get("name") %></a>');tmpl_array.push(' <% if (content_item.get("item_count") === 0) { %>');tmpl_array.push(" <span>(empty folder)</span>");tmpl_array.push(" <% } %>");tmpl_array.push(" </td>");tmpl_array.push(" <td>folder</td>");tmpl_array.push(' <td><%= _.escape(content_item.get("item_count")) %> item(s)</td>');tmpl_array.push(' <td><%= _.escape(content_item.get("time_updated")) %></td>');tmpl_array.push("</tr>");return _.template(tmpl_array.join(""))},templateRowFile:function(){tmpl_array=[];tmpl_array.push('<tr class="dataset_row light" id="<%- content_item.id %>">');tmpl_array.push(" <td>");tmpl_array.push(' <span title="Dataset" class="fa fa-file-o"></span>');tmpl_array.push(" </td>");tmpl_array.push(' <td style="text-align: center; "><input style="margin: 0;" type="checkbox"></td>');tmpl_array.push(' <td><a href="#" class="library-dataset"><%- content_item.get("name") %><a></td>');tmpl_array.push(' <td><%= _.escape(content_item.get("data_type")) %></td>');tmpl_array.push(' <td><%= _.escape(content_item.get("readable_size")) %></td>');tmpl_array.push(' <td><%= _.escape(content_item.get("time_updated")) %></td>');tmpl_array.push("</tr>");return _.template(tmpl_array.join(""))},templateDatasetModal:function(){var f=[];f.push('<div class="modal_table">');f.push(' <table class="grid table table-striped table-condensed">');f.push(" <tr>");f.push(' <th scope="row" id="id_row" data-id="<%= _.escape(item.get("ldda_id")) %>">Name</th>');f.push(' <td><%= _.escape(item.get("name")) %></td>');f.push(" </tr>");f.push(" <tr>");f.push(' <th scope="row">Data type</th>');f.push(' <td><%= _.escape(item.get("data_type")) %></td>');f.push(" </tr>");f.push(" <tr>");f.push(' <th scope="row">Genome build</th>');f.push(' <td><%= _.escape(item.get("genome_build")) %></td>');f.push(" </tr>");f.push(' <th scope="row">Size</th>');f.push(" <td><%= _.escape(size) %></td>");f.push(" </tr>");f.push(" <tr>");f.push(' <th scope="row">Date uploaded (UTC)</th>');f.push(' <td><%= _.escape(item.get("date_uploaded")) %></td>');f.push(" </tr>");f.push(" <tr>");f.push(' <th scope="row">Uploaded by</th>');f.push(' <td><%= _.escape(item.get("uploaded_by")) %></td>');f.push(" </tr>");f.push(' <tr scope="row">');f.push(' <th scope="row">Data Lines</th>');f.push(' <td scope="row"><%= _.escape(item.get("metadata_data_lines")) %></td>');f.push(" </tr>");f.push(' <th scope="row">Comment Lines</th>');f.push(' <% if (item.get("metadata_comment_lines") === "") { %>');f.push(' <td scope="row"><%= _.escape(item.get("metadata_comment_lines")) %></td>');f.push(" <% } else { %>");f.push(' <td scope="row">unknown</td>');f.push(" <% } %>");f.push(" </tr>");f.push(" <tr>");f.push(' <th scope="row">Number of Columns</th>');f.push(' <td scope="row"><%= _.escape(item.get("metadata_columns")) %></td>');f.push(" </tr>");f.push(" <tr>");f.push(' <th scope="row">Column Types</th>');f.push(' <td scope="row"><%= _.escape(item.get("metadata_column_types")) %></td>');f.push(" </tr>");f.push(" <tr>");f.push(' <th scope="row">Miscellaneous information</th>');f.push(' <td scope="row"><%= _.escape(item.get("misc_blurb")) %></td>');f.push(" </tr>");f.push(" </table>");f.push(' <pre class="peek">');f.push(" </pre>");f.push("</div>");return f.join("")},templateHistorySelectInModal:function(){var f=[];f.push('<span id="history_modal_combo" style="width:100%; margin-left: 1em; margin-right: 1em; ">');f.push("Select history: ");f.push('<select id="dataset_import_single" name="dataset_import_single" style="width:40%; margin-bottom: 1em; "> ');f.push(" <% _.each(histories, function(history) { %>");f.push(' <option value="<%= _.escape(history.get("id")) %>"><%= _.escape(history.get("name")) %></option>');f.push(" <% }); %>");f.push("</select>");f.push("</span>");return f.join("")}});return{FolderRowView:a}}); \ No newline at end of file diff -r a70f236803f7d398b4f486342e864add77e9ad3f -r c6d9b2f1b26b219b03a74c321202dc68160e9a15 static/scripts/packed/mvc/library/library-foldertoolbar-view.js --- /dev/null +++ b/static/scripts/packed/mvc/library/library-foldertoolbar-view.js @@ -0,0 +1,1 @@ +define(["galaxy.masthead","utils/utils","libs/toastr","mvc/library/library-model"],function(b,d,e,c){var a=Backbone.View.extend({el:"#center",events:{"click #toolbtn_create_folder":"createFolderFromModal","click #toolbtn_bulk_import":"modalBulkImport"},defaults:{can_add_library_item:false,contains_file:false},modal:null,initialize:function(f){this.options=_.defaults(f||{},this.defaults);this.render()},render:function(f){this.options=_.extend(this.options,f);var h=this.templateToolBar();var g=Galaxy.currUser.isAdmin();this.$el.html(h({id:this.options.id,admin_user:g}))},configureElements:function(f){this.options=_.extend(this.options,f);if(this.options.can_add_library_item===true){$("#toolbtn_create_folder").show();$("#toolbtn_upload_files").show()}if(this.options.contains_file===true){$("#toolbtn_bulk_import").show();$("#toolbtn_dl").show()}this.$el.find("[data-toggle]").tooltip()},createFolderFromModal:function(){event.preventDefault();event.stopPropagation();var f=this;var g=this.templateNewFolderInModal();this.modal=Galaxy.modal;this.modal.show({closing_events:true,title:"Create New Folder",body:g(),buttons:{Create:function(){f.create_new_folder_event()},Close:function(){f.modal.hide();f.modal=null}}})},create_new_folder_event:function(){var f=this.serialize_new_folder();if(this.validate_new_folder(f)){var h=new c.FolderAsModel();url_items=Backbone.history.fragment.split("/");current_folder_id=url_items[url_items.length-1];h.url=h.urlRoot+"/"+current_folder_id;var g=this;h.save(f,{success:function(i){g.modal.hide();e.success("Folder created");Galaxy.libraries.folderListView.render({id:current_folder_id})},error:function(){e.error("An error occured :(")}})}else{e.error("Folder's name is missing")}return false},serialize_new_folder:function(){return{name:$("input[name='Name']").val(),description:$("input[name='Description']").val()}},validate_new_folder:function(f){return f.name!==""},modalBulkImport:function(){var f=$("#folder_table").find(":checked");if(f.length===0){e.info("You have to select some datasets first")}else{var h=this;var i=this.templateBulkImportInModal();var g=new c.GalaxyHistories();g.fetch({success:function(j){h.modal=Galaxy.modal;h.modal.show({closing_events:true,title:"Import into History",body:i({histories:j.models}),buttons:{Import:function(){h.importAllIntoHistory()},Close:function(){h.modal.hide()}}})},error:function(){e.error("An error occured :(")}})}},importAllIntoHistory:function(){this.modal.disableButton("Import");var h=$("select[name=dataset_import_bulk] option:selected").val();var m=$("select[name=dataset_import_bulk] option:selected").text();var o=[];$("#folder_table").find(":checked").each(function(){if(this.parentElement.parentElement.id!==""){o.push(this.parentElement.parentElement.id)}});var n=this.templateProgressBar();$(this.modal.elMain).find(".modal-body").html(n({history_name:m}));var j=100/o.length;this.initProgress(j);var f=[];for(var g=o.length-1;g>=0;g--){library_dataset_id=o[g];var k=new c.HistoryItem();var l=this;k.url=k.urlRoot+h+"/contents";k.content=library_dataset_id;k.source="library";f.push(k)}this.chainCall(f)},chainCall:function(g){var f=this;var h=g.pop();if(typeof h==="undefined"){e.success("All datasets imported");this.modal.hide();return}var i=$.when(h.save({content:h.content,source:h.source})).done(function(j){f.updateProgress();f.chainCall(g)})},initProgress:function(f){this.progress=0;this.progressStep=f},updateProgress:function(){this.progress+=this.progressStep;$(".progress-bar-import").width(Math.round(this.progress)+"%");txt_representation=Math.round(this.progress)+"% Complete";$(".completion_span").text(txt_representation)},download:function(f,j){var h=[];$("#folder_table").find(":checked").each(function(){if(this.parentElement.parentElement.id!==""){h.push(this.parentElement.parentElement.id)}});var g="/api/libraries/datasets/download/"+j;var i={ldda_ids:h};this.processDownload(g,i,"get")},processDownload:function(g,h,i){if(g&&h){h=typeof h=="string"?h:$.param(h);var f="";$.each(h.split("&"),function(){var j=this.split("=");f+='<input type="hidden" name="'+j[0]+'" value="'+j[1]+'" />'});$('<form action="'+g+'" method="'+(i||"post")+'">'+f+"</form>").appendTo("body").submit().remove();e.info("Your download will begin soon")}},templateToolBar:function(){tmpl_array=[];tmpl_array.push('<div class="library_style_container">');tmpl_array.push('<h3>Data Libraries Beta Test. This is work in progress. Please report problems & ideas via <a href="mailto:galaxy-bugs@bx.psu.edu?Subject=DataLibrariesBeta_Feedback" target="_blank">email</a> and <a href="https://trello.com/c/nwYQNFPK/56-data-library-ui-progressive-display-of-fold..." target="_blank">Trello</a>.</h3>');tmpl_array.push('<div id="library_folder_toolbar" >');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Create New Folder" id="toolbtn_create_folder" class="primary-button" type="button" style="display:none;"><span class="fa fa-plus"></span><span class="fa fa-folder-close"></span> folder</button>');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Upload Files to Current Folder" id="toolbtn_upload_files" class="primary-button" type="button" style="display:none;"><span class="fa fa-upload"></span> upload</button>');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Import selected datasets into history" id="toolbtn_bulk_import" class="primary-button" style="margin-left: 0.5em; display:none;" type="button"><span class="fa fa-book"></span> to history</button>');tmpl_array.push(' <div id="toolbtn_dl" class="btn-group" style="margin-left: 0.5em; display:none; ">');tmpl_array.push(' <button title="Download selected datasets" id="drop_toggle" type="button" class="primary-button dropdown-toggle" data-toggle="dropdown">');tmpl_array.push(' <span class="fa fa-download"></span> download <span class="caret"></span>');tmpl_array.push(" </button>");tmpl_array.push(' <ul class="dropdown-menu" role="menu">');tmpl_array.push(' <li id="download_archive"><a href="#/folders/<%= id %>/download/tgz">.tar.gz</a></li>');tmpl_array.push(' <li id="download_archive"><a href="#/folders/<%= id %>/download/tbz">.tar.bz</a></li>');tmpl_array.push(' <li id="download_archive"><a href="#/folders/<%= id %>/download/zip">.zip</a></li>');tmpl_array.push(" </ul>");tmpl_array.push(" </div>");tmpl_array.push(" </div>");tmpl_array.push(' <div id="folder_items_element">');tmpl_array.push(" </div>");tmpl_array.push("</div>");return _.template(tmpl_array.join(""))},templateNewFolderInModal:function(){tmpl_array=[];tmpl_array.push('<div id="new_folder_modal">');tmpl_array.push("<form>");tmpl_array.push('<input type="text" name="Name" value="" placeholder="Name">');tmpl_array.push('<input type="text" name="Description" value="" placeholder="Description">');tmpl_array.push("</form>");tmpl_array.push("</div>");return _.template(tmpl_array.join(""))},templateBulkImportInModal:function(){var f=[];f.push('<span id="history_modal_combo_bulk" style="width:90%; margin-left: 1em; margin-right: 1em; ">');f.push("Select history: ");f.push('<select id="dataset_import_bulk" name="dataset_import_bulk" style="width:50%; margin-bottom: 1em; "> ');f.push(" <% _.each(histories, function(history) { %>");f.push(' <option value="<%= _.escape(history.get("id")) %>"><%= _.escape(history.get("name")) %></option>');f.push(" <% }); %>");f.push("</select>");f.push("</span>");return _.template(f.join(""))},templateProgressBar:function(){var f=[];f.push('<div class="import_text">');f.push("Importing selected datasets to history <b><%= _.escape(history_name) %></b>");f.push("</div>");f.push('<div class="progress">');f.push(' <div class="progress-bar progress-bar-import" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 00%;">');f.push(' <span class="completion_span">0% Complete</span>');f.push(" </div>");f.push("</div>");f.push("");return _.template(f.join(""))}});return{FolderToolbarView:a}}); \ No newline at end of file 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.