diff --git a/client/galaxy/scripts/galaxy.library.js b/client/galaxy/scripts/galaxy.library.js index a94300bbd39..55f2745e8a9 100644 --- a/client/galaxy/scripts/galaxy.library.js +++ b/client/galaxy/scripts/galaxy.library.js @@ -176,7 +176,7 @@ var GalaxyLibrary = Backbone.View.extend({ mod_toastr.info("You must select at least one dataset to download"); Galaxy.libraries.library_router.navigate(`folders/${folder_id}`, { trigger: true, replace: true }); } else { - Galaxy.libraries.folderToolbarView.download(folder_id, format); + Galaxy.libraries.folderToolbarView.download(format); Galaxy.libraries.library_router.navigate(`folders/${folder_id}`, { trigger: false, replace: true }); } }); diff --git a/client/galaxy/scripts/mvc/collection/list-collection-creator.js b/client/galaxy/scripts/mvc/collection/list-collection-creator.js index ed99b659ca1..5a0072d0503 100644 --- a/client/galaxy/scripts/mvc/collection/list-collection-creator.js +++ b/client/galaxy/scripts/mvc/collection/list-collection-creator.js @@ -278,8 +278,8 @@ var ListCollectionCreator = Backbone.View.extend(BASE_MVC.LoggableMixin) /** describe what is wrong with a particular element if anything */ _isElementInvalid: function(element) { - if (element.history_content_type !== "dataset") { - return _l("is not a dataset"); + if (element.history_content_type === "dataset_collection") { + return _l("is a collection, this is not allowed"); } var validState = element.state === STATES.OK || _.contains(STATES.NOT_READY_STATES, element.state); if (!validState) { diff --git a/client/galaxy/scripts/mvc/collection/list-of-pairs-collection-creator.js b/client/galaxy/scripts/mvc/collection/list-of-pairs-collection-creator.js index d2754caae16..15a2998f08a 100644 --- a/client/galaxy/scripts/mvc/collection/list-of-pairs-collection-creator.js +++ b/client/galaxy/scripts/mvc/collection/list-of-pairs-collection-creator.js @@ -1796,7 +1796,8 @@ var pairedCollectionCreatorModal = function _pairedCollectionCreatorModal(datase oncreate: function(creator, response) { Galaxy.modal.hide(); deferred.resolve(response); - } + }, + title: _l("Create a collection of paired datasets") }); if (!window.Galaxy || !Galaxy.modal) { @@ -1805,7 +1806,7 @@ var pairedCollectionCreatorModal = function _pairedCollectionCreatorModal(datase creator = new PairedCollectionCreator(options); Galaxy.modal.show({ - title: _l("Create a collection of paired datasets"), + title: options.title, body: creator.$el, width: "80%", height: "800px", diff --git a/client/galaxy/scripts/mvc/library/library-foldertoolbar-view.js b/client/galaxy/scripts/mvc/library/library-foldertoolbar-view.js index 5e0f92a68bb..9f4c9d2726c 100644 --- a/client/galaxy/scripts/mvc/library/library-foldertoolbar-view.js +++ b/client/galaxy/scripts/mvc/library/library-foldertoolbar-view.js @@ -3,17 +3,23 @@ import mod_utils from "utils/utils"; import mod_toastr from "libs/toastr"; import mod_library_model from "mvc/library/library-model"; import mod_select from "mvc/ui/ui-select"; +import LIST_CREATOR from "mvc/collection/list-collection-creator"; +import PAIR_CREATOR from "mvc/collection/pair-collection-creator"; +import PAIRED_CREATOR from "mvc/collection/list-of-pairs-collection-creator"; +import HDCA_MODEL from "mvc/history/hdca-model"; import "libs/jquery/jstree"; + var FolderToolbarView = Backbone.View.extend({ el: "#center", events: { - "click #toolbtn_create_folder": "createFolderFromModal", - "click #toolbtn_bulk_import": "modalBulkImport", - "click #include_deleted_datasets_chk": "checkIncludeDeleted", - "click #toolbtn_bulk_delete": "deleteSelectedItems", + "click .toolbtn-create-folder": "createFolderFromModal", + "click .toolbtn-bulk-import": "importToHistoryModal", + "click .include-deleted-datasets-chk": "checkIncludeDeleted", + "click .toolbtn-bulk-delete": "deleteSelectedItems", "click .toolbtn-show-locinfo": "showLocInfo", - "click .page_size_prompt": "showPageSizePrompt" + "click .page-size-prompt": "showPageSizePrompt", + "click .toolbtn-collection-import": "showCollectionSelect" }, defaults: { @@ -137,13 +143,9 @@ var FolderToolbarView = Backbone.View.extend({ this.$el.find("[data-toggle]").tooltip(); }, - // shows modal for creating folder createFolderFromModal: function(event) { event.preventDefault(); event.stopPropagation(); - - // create modal - var self = this; var template = this.templateNewFolderInModal(); this.modal = Galaxy.modal; this.modal.show({ @@ -151,20 +153,19 @@ var FolderToolbarView = Backbone.View.extend({ title: _l("Create New Folder"), body: template(), buttons: { - Create: function() { - self.create_new_folder_event(); + Create: () => { + this.createNewFolderEvent(); }, - Close: function() { + Close: () => { Galaxy.modal.hide(); } } }); }, - // create the new folder from modal - create_new_folder_event: function() { - var folderDetails = this.serialize_new_folder(); - if (this.validate_new_folder(folderDetails)) { + createNewFolderEvent: function() { + var folderDetails = this.serializeNewFolder(); + if (this.validateNewFolder(folderDetails)) { var folder = new mod_library_model.FolderAsModel(); var url_items = Backbone.history.fragment.split("/"); var current_folder_id; @@ -197,43 +198,39 @@ var FolderToolbarView = Backbone.View.extend({ return false; }, - // serialize data from the modal - serialize_new_folder: function() { + serializeNewFolder: function() { return { name: $("input[name='Name']").val(), description: $("input[name='Description']").val() }; }, - // validate new folder info - validate_new_folder: function(folderDetails) { + validateNewFolder: function(folderDetails) { return folderDetails.name !== ""; }, - // show bulk import modal - modalBulkImport: function() { + importToHistoryModal: function(e) { + e.preventDefault(); var $checkedValues = this.findCheckedRows(); + var template = this.templateImportIntoHistoryModal(); if ($checkedValues.length === 0) { mod_toastr.info("You must select some datasets first."); } else { - var that = this; - this.histories = new mod_library_model.GalaxyHistories(); - this.histories - .fetch() + var promise = this.fetchUserHistories(); + promise .done(() => { - var template = that.templateBulkImportInModal(); - that.modal = Galaxy.modal; - that.modal.show({ + this.modal = Galaxy.modal; + this.modal.show({ closing_events: true, title: _l("Import into History"), body: template({ - histories: that.histories.models + histories: this.histories.models }), buttons: { - Import: function() { - that.importAllIntoHistory(); + Import: () => { + this.importAllIntoHistory(); }, - Close: function() { + Close: () => { Galaxy.modal.hide(); } } @@ -249,84 +246,73 @@ var FolderToolbarView = Backbone.View.extend({ } }, - /** - * Import all selected datasets into history. - */ + fetchUserHistories: function() { + this.histories = new mod_library_model.GalaxyHistories(); + var promise = this.histories.fetch(); + return promise; + }, + importAllIntoHistory: function() { this.modal.disableButton("Import"); var new_history_name = this.modal.$("input[name=history_name]").val(); - var that = this; if (new_history_name !== "") { - $.post(`${Galaxy.root}api/histories`, { - name: new_history_name - }) + this.createNewHistory(new_history_name) .done(new_history => { - that.options.last_used_history_id = new_history.id; - that.processImportToHistory(new_history.id, new_history.name); + this.processImportToHistory(new_history.id, new_history.name); }) .fail((xhr, status, error) => { mod_toastr.error("An error occurred."); }) .always(() => { - that.modal.enableButton("Import"); + this.modal.enableButton("Import"); }); } else { - var history_id = $("select[name=dataset_import_bulk] option:selected").val(); - this.options.last_used_history_id = history_id; - var history_name = $("select[name=dataset_import_bulk] option:selected").text(); + var history_id = $("select[name=import_to_history] option:selected").val(); + var history_name = $("select[name=import_to_history] option:selected").text(); this.processImportToHistory(history_id, history_name); this.modal.enableButton("Import"); } }, + createNewHistory: function(new_history_name) { + var promise = $.post(`${Galaxy.root}api/histories`, { name: new_history_name }); + return promise; + }, + processImportToHistory: function(history_id, history_name) { - var dataset_ids = []; - var folder_ids = []; - this.findCheckedRows().each(function() { - var row_id = $(this) - .closest("tr") - .data("id"); - if (row_id.substring(0, 1) == "F") { - folder_ids.push(row_id); - } else { - dataset_ids.push(row_id); - } - }); + var checked_items = this.findCheckedItems(); + var items_to_import = []; // prepare the dataset objects to be imported - var datasets_to_import = []; - for (var i = dataset_ids.length - 1; i >= 0; i--) { - var library_dataset_id = dataset_ids[i]; + for (let i = checked_items.dataset_ids.length - 1; i >= 0; i--) { + var library_dataset_id = checked_items.dataset_ids[i]; var historyItem = new mod_library_model.HistoryItem(); historyItem.url = `${historyItem.urlRoot + history_id}/contents`; historyItem.content = library_dataset_id; historyItem.source = "library"; - datasets_to_import.push(historyItem); + items_to_import.push(historyItem); } - // prepare the folder objects to be imported - var folders_to_import = []; - for (var i = folder_ids.length - 1; i >= 0; i--) { - var library_folder_id = folder_ids[i]; + for (let i = checked_items.folder_ids.length - 1; i >= 0; i--) { + var library_folder_id = checked_items.folder_ids[i]; var historyItem = new mod_library_model.HistoryItem(); historyItem.url = `${historyItem.urlRoot + history_id}/contents`; historyItem.content = library_folder_id; historyItem.source = "library_folder"; - datasets_to_import.push(historyItem); + items_to_import.push(historyItem); } - this.initChainCallControl({ - length: datasets_to_import.length, + length: items_to_import.length, action: "to_history", history_name: history_name }); // set the used history as current so user will see the last one // that he imported into in the history panel on the 'analysis' page jQuery.getJSON(`${Galaxy.root}history/set_as_current?id=${history_id}`); - this.chainCallImportingIntoHistory(datasets_to_import, history_name); + this.chainCallImportingIntoHistory(items_to_import, history_name); }, /** - * Update the progress bar in modal window. + * Update progress bar in modal. */ updateProgress: function() { this.progress += this.progressStep; @@ -336,25 +322,13 @@ var FolderToolbarView = Backbone.View.extend({ }, /** - * download selected datasets - * @param {str} folder_id id of the current folder + * Download selected datasets. Called from the router. * @param {str} format requested archive format */ - download: function(folder_id, format) { - var dataset_ids = []; - var folder_ids = []; - this.findCheckedRows().each(function() { - var row_id = $(this) - .closest("tr") - .data("id"); - if (row_id.substring(0, 1) == "F") { - folder_ids.push(row_id); - } else { - dataset_ids.push(row_id); - } - }); + download: function(format) { + var checked_items = this.findCheckedItems(); var url = `${Galaxy.root}api/libraries/datasets/download/${format}`; - var data = { ld_ids: dataset_ids, folder_ids: folder_ids }; + var data = { ld_ids: checked_items.dataset_ids, folder_ids: checked_items.folder_ids }; this.processDownload(url, data, "get"); }, @@ -388,33 +362,32 @@ var FolderToolbarView = Backbone.View.extend({ addFilesFromHistoryModal: function() { this.histories = new mod_library_model.GalaxyHistories(); - var self = this; this.histories .fetch() .done(() => { - self.modal = Galaxy.modal; - var template_modal = self.templateAddFilesFromHistory(); - self.modal.show({ + this.modal = Galaxy.modal; + var template_modal = this.templateAddFilesFromHistory(); + this.modal.show({ closing_events: true, title: _l("Adding datasets from your history"), body: template_modal({ - histories: self.histories.models + histories: this.histories.models }), buttons: { - Add: function() { - self.addAllDatasetsFromHistory(); + Add: () => { + this.addAllDatasetsFromHistory(); }, - Close: function() { + Close: () => { Galaxy.modal.hide(); } }, - closing_callback: function() { - Galaxy.libraries.library_router.navigate(`folders/${self.id}`, { trigger: true }); + closing_callback: () => { + Galaxy.libraries.library_router.navigate(`folders/${this.id}`, { trigger: true }); } }); - self.fetchAndDisplayHistoryContents(self.histories.models[0].id); + this.fetchAndDisplayHistoryContents(this.histories.models[0].id); $("#dataset_add_bulk").change(event => { - self.fetchAndDisplayHistoryContents(event.target.value); + this.fetchAndDisplayHistoryContents(event.target.value); }); }) .fail((model, response) => { @@ -428,10 +401,8 @@ var FolderToolbarView = Backbone.View.extend({ /** * Create modal for importing from Galaxy path. - * This feature is admin-only. */ importFilesFromPathModal: function() { - var that = this; this.modal = Galaxy.modal; var template_modal = this.templateImportPathModal(); this.modal.show({ @@ -439,16 +410,16 @@ var FolderToolbarView = Backbone.View.extend({ title: _l("Please enter paths to import"), body: template_modal({}), buttons: { - Import: function() { - that.importFromPathsClicked(that); + Import: () => { + this.importFromPathsClicked(this); }, - Close: function() { + Close: () => { Galaxy.modal.hide(); } }, - closing_callback: function() { + closing_callback: () => { // TODO: should not trigger routes outside of the router - Galaxy.libraries.library_router.navigate(`folders/${that.id}`, { + Galaxy.libraries.library_router.navigate(`folders/${this.id}`, { trigger: true }); } @@ -458,38 +429,37 @@ var FolderToolbarView = Backbone.View.extend({ /** * Request all extensions and genomes from Galaxy - * and save them sorted in arrays. + * and save them in sorted arrays. */ fetchExtAndGenomes: function() { - var that = this; mod_utils.get({ url: `${Galaxy.root}api/datatypes?extension_only=False`, - success: function(datatypes) { - that.list_extensions = []; - for (var key in datatypes) { - that.list_extensions.push({ + success: datatypes => { + this.list_extensions = []; + for (let key in datatypes) { + this.list_extensions.push({ id: datatypes[key].extension, text: datatypes[key].extension, description: datatypes[key].description, description_url: datatypes[key].description_url }); } - that.list_extensions.sort((a, b) => (a.id > b.id ? 1 : a.id < b.id ? -1 : 0)); - that.list_extensions.unshift(that.auto); + this.list_extensions.sort((a, b) => (a.id > b.id ? 1 : a.id < b.id ? -1 : 0)); + this.list_extensions.unshift(this.auto); }, cache: true }); mod_utils.get({ url: `${Galaxy.root}api/genomes`, - success: function(genomes) { - that.list_genomes = []; - for (var key in genomes) { - that.list_genomes.push({ + success: genomes => { + this.list_genomes = []; + for (let key in genomes) { + this.list_genomes.push({ id: genomes[key][1], text: genomes[key][0] }); } - that.list_genomes.sort((a, b) => (a.id > b.id ? 1 : a.id < b.id ? -1 : 0)); + this.list_genomes.sort((a, b) => (a.id > b.id ? 1 : a.id < b.id ? -1 : 0)); }, cache: true }); @@ -498,18 +468,15 @@ var FolderToolbarView = Backbone.View.extend({ renderSelectBoxes: function() { // This won't work properly unlesss we already have the data fetched. // See this.fetchExtAndGenomes() - // TODO switch to common resources: - // https://trello.com/c/dIUE9YPl/1933-ui-common-resources-and-data-into-galaxy-object - var that = this; this.select_genome = new mod_select.View({ css: "library-genome-select", - data: that.list_genomes, + data: this.list_genomes, container: Galaxy.modal.$el.find("#library_genome_select"), value: "?" }); this.select_extension = new mod_select.View({ css: "library-extension-select", - data: that.list_extensions, + data: this.list_extensions, container: Galaxy.modal.$el.find("#library_extension_select"), value: "auto" }); @@ -520,7 +487,6 @@ var FolderToolbarView = Backbone.View.extend({ * on Galaxy. Bind jQuery events. */ importFilesFromGalaxyFolderModal: function(options) { - var that = this; var template_modal = this.templateBrowserModal(); this.modal = Galaxy.modal; this.modal.show({ @@ -528,16 +494,16 @@ var FolderToolbarView = Backbone.View.extend({ title: _l("Please select folders or files"), body: template_modal({}), buttons: { - Import: function() { - that.importFromJstreePath(that, options); + Import: () => { + this.importFromJstreePath(this, options); }, - Close: function() { + Close: () => { Galaxy.modal.hide(); } }, - closing_callback: function() { + closing_callback: () => { // TODO: should not trigger routes outside of the router - Galaxy.libraries.library_router.navigate(`folders/${that.id}`, { + Galaxy.libraries.library_router.navigate(`folders/${this.id}`, { trigger: true }); } @@ -557,7 +523,7 @@ var FolderToolbarView = Backbone.View.extend({ $("input[type=radio]").change(event => { if (event.target.value === "jstree-disable-folders") { options.disabled_jstree_element = "folders"; - that.renderJstree(options); + this.renderJstree(options); $(".jstree-folders-message").hide(); $(".jstree-preserve-structure").hide(); $(".jstree-files-message").show(); @@ -566,7 +532,7 @@ var FolderToolbarView = Backbone.View.extend({ $(".jstree-folders-message").show(); $(".jstree-preserve-structure").show(); options.disabled_jstree_element = "files"; - that.renderJstree(options); + this.renderJstree(options); } }); }, @@ -578,14 +544,13 @@ var FolderToolbarView = Backbone.View.extend({ * @param {[type]} options [description] */ renderJstree: function(options) { - var that = this; this.options = _.extend(this.options, options); var target = options.source || "userdir"; var disabled_jstree_element = this.options.disabled_jstree_element; this.jstree = new mod_library_model.Jstree(); this.jstree.url = `${this.jstree.urlRoot}?target=${target}&format=jstree&disable=${disabled_jstree_element}`; this.jstree.fetch({ - success: function(model, response) { + success: (model, response) => { $("#jstree_browser").jstree("destroy"); $("#jstree_browser").jstree({ core: { @@ -605,7 +570,7 @@ var FolderToolbarView = Backbone.View.extend({ } }); }, - error: function(model, response) { + error: (model, response) => { if (typeof response.responseJSON !== "undefined") { if (response.responseJSON.err_code === 404001) { mod_toastr.warning(response.responseJSON.err_msg); @@ -639,7 +604,7 @@ var FolderToolbarView = Backbone.View.extend({ } else { this.modal.disableButton("Import"); paths = paths.split("\n"); - for (var i = paths.length - 1; i >= 0; i--) { + for (let i = paths.length - 1; i >= 0; i--) { var trimmed = paths[i].trim(); if (trimmed.length !== 0) { valid_paths.push(trimmed); @@ -727,7 +692,7 @@ var FolderToolbarView = Backbone.View.extend({ mod_toastr.info("Please select some items first."); } else { this.modal.disableButton("Import"); - for (var i = selected_nodes.length - 1; i >= 0; i--) { + for (let i = selected_nodes.length - 1; i >= 0; i--) { if (selected_nodes[i].li_attr.full_path !== undefined) { paths.push(selected_nodes[i].li_attr.full_path); } @@ -769,24 +734,23 @@ var FolderToolbarView = Backbone.View.extend({ var history_contents = new mod_library_model.HistoryContents({ id: history_id }); - var self = this; history_contents.fetch({ - success: function(history_contents) { - var history_contents_template = self.templateHistoryContents(); - self.histories.get(history_id).set({ contents: history_contents }); - self.modal.$el.find("#selected_history_content").html( + success: history_contents => { + var history_contents_template = this.templateHistoryContents(); + this.histories.get(history_id).set({ contents: history_contents }); + this.modal.$el.find(".library_selected_history_content").html( history_contents_template({ history_contents: history_contents.models.reverse() }) ); - self.modal.$el.find(".history-import-select-all").bind("click", () => { - $("#selected_history_content [type=checkbox]").prop("checked", true); + this.modal.$el.find(".history-import-select-all").bind("click", () => { + $(".library_selected_history_content [type=checkbox]").prop("checked", true); }); - self.modal.$el.find(".history-import-unselect-all").bind("click", () => { - $("#selected_history_content [type=checkbox]").prop("checked", false); + this.modal.$el.find(".history-import-unselect-all").bind("click", () => { + $(".library_selected_history_content [type=checkbox]").prop("checked", false); }); }, - error: function(model, response) { + error: (model, response) => { if (typeof response.responseJSON !== "undefined") { mod_toastr.error(response.responseJSON.err_msg); } else { @@ -800,7 +764,7 @@ var FolderToolbarView = Backbone.View.extend({ * Import all selected datasets from history into the current folder. */ addAllDatasetsFromHistory: function() { - var checked_hdas = this.modal.$el.find("#selected_history_content").find(":checked"); + var checked_hdas = this.modal.$el.find(".library_selected_history_content").find(":checked"); var history_item_ids = []; // can be hda or hdca var history_item_types = []; var items_to_add = []; @@ -820,7 +784,7 @@ var FolderToolbarView = Backbone.View.extend({ history_item_types.push(item_type); } }); - for (var i = history_item_ids.length - 1; i >= 0; i--) { + for (let i = history_item_ids.length - 1; i >= 0; i--) { var history_item_id = history_item_ids[i]; var folder_item = new mod_library_model.Item(); folder_item.url = `${Galaxy.root}api/folders/${this.options.id}/contents`; @@ -846,12 +810,11 @@ var FolderToolbarView = Backbone.View.extend({ * @param {str} history_name name of the history to import to */ chainCallImportingIntoHistory: function(history_item_set, history_name) { - var self = this; var popped_item = history_item_set.pop(); if (typeof popped_item == "undefined") { if (this.options.chain_call_control.failed_number === 0) { mod_toastr.success("Selected datasets imported into history. Click this to start analyzing it.", "", { - onclick: function() { + onclick: () => { window.location = Galaxy.root; } }); @@ -862,7 +825,7 @@ var FolderToolbarView = Backbone.View.extend({ "Some of the datasets could not be imported into history. Click this to see what was imported.", "", { - onclick: function() { + onclick: () => { window.location = Galaxy.root; } } @@ -880,13 +843,13 @@ var FolderToolbarView = Backbone.View.extend({ promise .done(() => { - self.updateProgress(); - self.chainCallImportingIntoHistory(history_item_set, history_name); + this.updateProgress(); + this.chainCallImportingIntoHistory(history_item_set, history_name); }) .fail(() => { - self.options.chain_call_control.failed_number += 1; - self.updateProgress(); - self.chainCallImportingIntoHistory(history_item_set, history_name); + this.options.chain_call_control.failed_number += 1; + this.updateProgress(); + this.chainCallImportingIntoHistory(history_item_set, history_name); }); }, @@ -897,7 +860,6 @@ var FolderToolbarView = Backbone.View.extend({ * @param {boolean} tag_using_filenames add tags to datasets using names of files */ chainCallImportingUserdirFiles: function(options) { - var that = this; var popped_item = options.paths.pop(); if (typeof popped_item === "undefined") { if (this.options.chain_call_control.failed_number === 0) { @@ -910,9 +872,9 @@ var FolderToolbarView = Backbone.View.extend({ } var promise = $.when( $.post( - `${Galaxy.root}api/libraries/datasets?encoded_folder_id=${that.id}&source=${ - options.source - }&path=${popped_item}&file_type=${options.file_type}&link_data=${options.link_data}&space_to_tab=${ + `${Galaxy.root}api/libraries/datasets?encoded_folder_id=${this.id}&source=${options.source}&path=${ + popped_item + }&file_type=${options.file_type}&link_data=${options.link_data}&space_to_tab=${ options.space_to_tab }&to_posix_lines=${options.to_posix_lines}&dbkey=${options.dbkey}&tag_using_filenames=${ options.tag_using_filenames @@ -921,13 +883,13 @@ var FolderToolbarView = Backbone.View.extend({ ); promise .done(response => { - that.updateProgress(); - that.chainCallImportingUserdirFiles(options); + this.updateProgress(); + this.chainCallImportingUserdirFiles(options); }) .fail(() => { - that.options.chain_call_control.failed_number += 1; - that.updateProgress(); - that.chainCallImportingUserdirFiles(options); + this.options.chain_call_control.failed_number += 1; + this.updateProgress(); + this.chainCallImportingUserdirFiles(options); }); }, @@ -945,7 +907,6 @@ var FolderToolbarView = Backbone.View.extend({ */ chainCallImportingFolders: function(options) { // TODO need to check which paths to call - var that = this; var popped_item = options.paths.pop(); if (typeof popped_item == "undefined") { if (this.options.chain_call_control.failed_number === 0) { @@ -959,24 +920,24 @@ var FolderToolbarView = Backbone.View.extend({ } var promise = $.when( $.post( - `${Galaxy.root}api/libraries/datasets?encoded_folder_id=${that.id}&source=${ - options.source - }&path=${popped_item}&preserve_dirs=${options.preserve_dirs}&link_data=${ - options.link_data - }&to_posix_lines=${options.to_posix_lines}&space_to_tab=${options.space_to_tab}&file_type=${ - options.file_type - }&dbkey=${options.dbkey}&tag_using_filenames=${options.tag_using_filenames}` + `${Galaxy.root}api/libraries/datasets?encoded_folder_id=${this.id}&source=${options.source}&path=${ + popped_item + }&preserve_dirs=${options.preserve_dirs}&link_data=${options.link_data}&to_posix_lines=${ + options.to_posix_lines + }&space_to_tab=${options.space_to_tab}&file_type=${options.file_type}&dbkey=${ + options.dbkey + }&tag_using_filenames=${options.tag_using_filenames}` ) ); promise .done(response => { - that.updateProgress(); - that.chainCallImportingFolders(options); + this.updateProgress(); + this.chainCallImportingFolders(options); }) .fail(() => { - that.options.chain_call_control.failed_number += 1; - that.updateProgress(); - that.chainCallImportingFolders(options); + this.options.chain_call_control.failed_number += 1; + this.updateProgress(); + this.chainCallImportingFolders(options); }); }, @@ -986,7 +947,6 @@ var FolderToolbarView = Backbone.View.extend({ * @param {array} hdas_set array of empty hda objects */ chainCallAddingHdas: function(hdas_set) { - var self = this; this.added_hdas = new mod_library_model.Folder(); var popped_item = hdas_set.pop(); if (typeof popped_item == "undefined") { @@ -1009,13 +969,13 @@ var FolderToolbarView = Backbone.View.extend({ promise .done(model => { Galaxy.libraries.folderListView.collection.add(model); - self.updateProgress(); - self.chainCallAddingHdas(hdas_set); + this.updateProgress(); + this.chainCallAddingHdas(hdas_set); }) .fail(() => { - self.options.chain_call_control.failed_number += 1; - self.updateProgress(); - self.chainCallAddingHdas(hdas_set); + this.options.chain_call_control.failed_number += 1; + this.updateProgress(); + this.chainCallAddingHdas(hdas_set); }); }, @@ -1025,7 +985,6 @@ var FolderToolbarView = Backbone.View.extend({ * @param {array} lddas_set array of lddas to delete */ chainCallDeletingItems: function(items_to_delete) { - var self = this; this.deleted_items = new mod_library_model.Folder(); var item_to_delete = items_to_delete.pop(); if (typeof item_to_delete === "undefined") { @@ -1047,7 +1006,7 @@ var FolderToolbarView = Backbone.View.extend({ .destroy() .done(item => { Galaxy.libraries.folderListView.collection.remove(item_to_delete.id); - self.updateProgress(); + this.updateProgress(); // add the deleted item to collection, triggers rendering if (Galaxy.libraries.folderListView.options.include_deleted) { var updated_item = null; @@ -1061,12 +1020,12 @@ var FolderToolbarView = Backbone.View.extend({ } Galaxy.libraries.folderListView.collection.add(updated_item); } - self.chainCallDeletingItems(items_to_delete); + this.chainCallDeletingItems(items_to_delete); }) .fail(() => { - self.options.chain_call_control.failed_number += 1; - self.updateProgress(); - self.chainCallDeletingItems(items_to_delete); + this.options.chain_call_control.failed_number += 1; + this.updateProgress(); + this.chainCallDeletingItems(items_to_delete); }); }, @@ -1102,7 +1061,7 @@ var FolderToolbarView = Backbone.View.extend({ title: _l("Deleting selected items"), body: template({}), buttons: { - Close: function() { + Close: () => { Galaxy.modal.hide(); } } @@ -1129,13 +1088,13 @@ var FolderToolbarView = Backbone.View.extend({ // prepare the dataset items to be added var items_to_delete = []; - for (var i = dataset_ids.length - 1; i >= 0; i--) { + for (let i = dataset_ids.length - 1; i >= 0; i--) { var dataset = new mod_library_model.Item({ id: dataset_ids[i] }); items_to_delete.push(dataset); } - for (var i = folder_ids.length - 1; i >= 0; i--) { + for (let i = folder_ids.length - 1; i >= 0; i--) { var folder = new mod_library_model.FolderAsModel({ id: folder_ids[i] }); @@ -1150,7 +1109,6 @@ var FolderToolbarView = Backbone.View.extend({ showLocInfo: function() { var library = null; - var that = this; if (Galaxy.libraries.libraryListView !== null) { library = Galaxy.libraries.libraryListView.collection.get(this.options.parent_library_id); this.showLocInfoModal(library); @@ -1159,8 +1117,8 @@ var FolderToolbarView = Backbone.View.extend({ id: this.options.parent_library_id }); library.fetch({ - success: function() { - that.showLocInfoModal(library); + success: () => { + this.showLocInfoModal(library); }, error: function(model, response) { if (typeof response.responseJSON !== "undefined") { @@ -1174,15 +1132,14 @@ var FolderToolbarView = Backbone.View.extend({ }, showLocInfoModal: function(library) { - var that = this; var template = this.templateLocInfoInModal(); this.modal = Galaxy.modal; this.modal.show({ closing_events: true, title: _l("Location Details"), - body: template({ library: library, options: that.options }), + body: template({ library: library, options: this.options }), buttons: { - Close: function() { + Close: () => { Galaxy.modal.hide(); } } @@ -1238,6 +1195,175 @@ var FolderToolbarView = Backbone.View.extend({ return $("#folder_list_body").find(":checked"); }, + findCheckedItems: function() { + var folder_ids = []; + var dataset_ids = []; + this.findCheckedRows().each(function() { + var row_id = $(this) + .closest("tr") + .data("id"); + if (row_id.substring(0, 1) == "F") { + folder_ids.push(row_id); + } else { + dataset_ids.push(row_id); + } + }); + return { folder_ids: folder_ids, dataset_ids: dataset_ids }; + }, + + showCollectionSelect: function(e) { + e.preventDefault(); + var checked_items = this.findCheckedItems(); + var template = this.templateCollectionSelectModal(); + this.modal = Galaxy.modal; + this.modal.show({ + closing_events: true, + title: "Create History Collection from Datasets", + body: template({selected_datasets: checked_items.dataset_ids.length}), + buttons: { + Continue: () => { + this.showColectionBuilder(checked_items.dataset_ids); + }, + Close: () => { + Galaxy.modal.hide(); + } + } + }); + this.prepareCollectionTypeSelect(); + this.prepareHistoryTypeSelect(); + }, + + prepareCollectionTypeSelect: function() { + this.collectionType = "list"; + this.select_collection_type = new mod_select.View({ + css: "library-collection-type-select", + container: this.modal.$el.find(".library-collection-type-select"), + data: [ + { id: "list", text: "List" }, + { id: "paired", text: "Paired" }, + { id: "list:paired", text: "List of Pairs" } + ], + value: "list", + onchange: collectionType => { + this.updateCollectionType(collectionType); + } + }); + }, + + prepareHistoryTypeSelect: function() { + var promise = this.fetchUserHistories(); + promise.done(() => { + var history_options = []; + for (let i = this.histories.length - 1; i >= 0; i--) { + history_options.unshift({ + id: this.histories.models[i].id, + text: this.histories.models[i].get("name") + }); + } + this.select_collection_history = new mod_select.View({ + css: "library-collection-history-select", + container: this.modal.$el.find(".library-collection-history-select"), + data: history_options, + value: history_options[0].id + }); + }); + }, + + /** Update collection type */ + updateCollectionType: function(collectionType) { + this.collectionType = collectionType; + }, + + showColectionBuilder: function(checked_items) { + let collection_elements = []; + let elements_source = this.modal.$('input[type="radio"]:checked').val(); + if (elements_source === "selection") { + for (let i = checked_items.length - 1; i >= 0; i--) { + let collection_item = {}; + let dataset = Galaxy.libraries.folderListView.folder_container.get("folder").get(checked_items[i]); + collection_item.id = checked_items[i]; + collection_item.name = dataset.get("name"); + collection_item.deleted = dataset.get("deleted"); + collection_item.state = dataset.get("state"); + collection_elements.push(collection_item); + } + } else if (elements_source === "folder") { + collection_elements = new Backbone.Collection( + Galaxy.libraries.folderListView.folder_container.get("folder").where({type: "file"}) + ).toJSON(); + } + let new_history_name = this.modal.$("input[name=history_name]").val(); + if (new_history_name !== "") { + this.createNewHistory(new_history_name) + .done(new_history => { + mod_toastr.success("History created"); + this.collectionImport(collection_elements, new_history.id, new_history.name); + }) + .fail((xhr, status, error) => { + mod_toastr.error("An error occurred."); + }); + } else { + let selected_history_id = this.select_collection_history.value(); + let selected_history_name = this.select_collection_history.text(); + this.collectionImport(collection_elements, selected_history_id, selected_history_name); + } + }, + + collectionImport: function(collection_elements, history_id, history_name) { + let modal_title = `Creating Collection in ${history_name}`; + let creator_class; + let creationFn; + if (this.collectionType === "list"){ + creator_class = LIST_CREATOR.ListCollectionCreator; + creationFn = (elements, name, hideSourceItems) => { + elements = elements.map(element => ({ + id: element.id, + name: element.name, + src: "ldda" + })); + return this.createHDCA(elements, this.collectionType, name, hideSourceItems, history_id); + }; + LIST_CREATOR.collectionCreatorModal( + collection_elements, + {creationFn: creationFn, title: modal_title, defaultHideSourceItems: true}, + creator_class + ); + } else if (this.collectionType === "paired"){ + creator_class = PAIR_CREATOR.PairCollectionCreator; + creationFn = (elements, name, hideSourceItems) => { + elements = [ + { name: "forward", src: "ldda", id: elements[0].id }, + { name: "reverse", src: "ldda", id: elements[1].id } + ]; + return this.createHDCA(elements, this.collectionType, name, hideSourceItems, history_id); + }; + LIST_CREATOR.collectionCreatorModal( + collection_elements, + {creationFn: creationFn, title: modal_title, defaultHideSourceItems: true}, + creator_class + ); + } else if (this.collectionType === "list:paired"){ + let elements = collection_elements.map(element => ({ + id: element.id, + name: element.name, + src: "ldda" + })); + PAIRED_CREATOR.pairedCollectionCreatorModal(elements, {historyId: history_id, title: modal_title, defaultHideSourceItems: true}); + } + }, + + createHDCA: function(elementIdentifiers, collectionType, name, hideSourceItems, history_id, options) { + let hdca = new HDCA_MODEL.HistoryDatasetCollection({ + history_content_type: "dataset_collection", + collection_type: collectionType, + history_id: history_id, + name: name, + hide_source_items: hideSourceItems || false, + element_identifiers: elementIdentifiers + }); + return hdca.save(options); + }, + templateToolBar: function() { return _.template( [ @@ -1249,18 +1375,21 @@ var FolderToolbarView = Backbone.View.extend({ "DATA LIBRARIES", // paginator will append here '', + // include deleted checkbox '
", - '