-
-
-
-
-
- All files you select will be imported into the current folder ignoring their folder structure.
-
-
- All files within the selected folders and their subfolders will be imported into the current folder.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
You can set extension type and genome for all imported datasets at once:
-
- Type:
- Genome:
-
-
-
-
-
-
`
- );
- },
- templateImportPathModal: function () {
- return _.template(
- ``
- );
- },
- renderSelectBoxes: function () {
- const Galaxy = getGalaxyInstance();
- // This won't work properly unlesss we already have the data fetched.
- // See this.fetchExtAndGenomes()
- this.select_genome = new mod_select.View({
- css: "library-genome-select",
- 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: this.list_extensions,
- container: Galaxy.modal.$el.find("#library_extension_select"),
- value: "auto",
- });
- },
- /**
- * Create modal for importing from given directory
- * on Galaxy. Bind jQuery events.
- */
- importFilesFromGalaxyFolderModal: function (options) {
- var template_modal = this.templateBrowserModal();
- const Galaxy = getGalaxyInstance();
- this.modal = Galaxy.modal;
- this.modal.show({
- closing_events: true,
- title: _l("Please select folders or files"),
- body: template_modal({}),
- buttons: {
- Import: () => {
- this.importFromJstreePath(this, options);
- },
- Close: () => {
- Galaxy.modal.hide();
- },
- },
- closing_callback: () => {
- // TODO update table without fetching new content from the server
- this.options.updateContent();
- // Galaxy.libraries.library_router.navigate(`folders/${this.id}`, {
- // trigger: true,
- // });
- },
- });
-
- $(".libimport-select-all").bind("click", () => {
- $("#jstree_browser").jstree("check_all");
- });
- $(".libimport-select-none").bind("click", () => {
- $("#jstree_browser").jstree("uncheck_all");
- });
-
- this.renderSelectBoxes();
- options.disabled_jstree_element = "folders";
- this.renderJstree(options);
-
- $("input[type=radio]").change((event) => {
- if (event.target.value === "jstree-disable-folders") {
- options.disabled_jstree_element = "folders";
- this.renderJstree(options);
- $(".jstree-folders-message").hide();
- $(".jstree-preserve-structure").hide();
- $(".jstree-files-message").show();
- } else if (event.target.value === "jstree-disable-files") {
- $(".jstree-files-message").hide();
- $(".jstree-folders-message").show();
- $(".jstree-preserve-structure").show();
- options.disabled_jstree_element = "files";
- this.renderJstree(options);
- }
- });
- },
- /**
- * Take the selected items from the jstree, create a request queue
- * and send them one by one to the server for importing into
- * the current folder.
- *
- * jstree.js has to be loaded before
- * @see renderJstree
- */
- importFromJstreePath: function (that, options) {
- var all_nodes = $("#jstree_browser").jstree().get_selected(true);
- // remove the disabled elements that could have been trigerred with the 'select all'
- var selected_nodes = _.filter(all_nodes, (node) => node.state.disabled == false);
- var preserve_dirs = this.modal.$el.find(".preserve-checkbox").is(":checked");
- var link_data = this.modal.$el.find(".link-checkbox").is(":checked");
- var space_to_tab = this.modal.$el.find(".spacetab-checkbox").is(":checked");
- var to_posix_lines = this.modal.$el.find(".posix-checkbox").is(":checked");
- var file_type = this.select_extension.value();
- var dbkey = this.select_genome.value();
- var tag_using_filenames = this.modal.$el.find(".tag-files").is(":checked");
- var selection_type = selected_nodes[0].type;
- var paths = [];
- if (selected_nodes.length < 1) {
- Toast.info("Please select some items first.");
- } else {
- this.modal.disableButton("Import");
- for (let i = selected_nodes.length - 1; i >= 0; i--) {
- if (selected_nodes[i].li_attr.full_path !== undefined) {
- // should be always String
- paths.push(`"${selected_nodes[i].li_attr.full_path}"`);
- }
- }
- this.initChainCallControlAddingDatasets({
- length: paths.length,
- });
- if (selection_type === "folder") {
- const full_source = `${options.source}_folder`;
- this.chainCallImportingFolders({
- paths: paths,
- preserve_dirs: preserve_dirs,
- link_data: link_data,
- space_to_tab: space_to_tab,
- to_posix_lines: to_posix_lines,
- source: full_source,
- file_type: file_type,
- dbkey: dbkey,
- tag_using_filenames: tag_using_filenames,
- });
- } else if (selection_type === "file") {
- const full_source = `${options.source}_file`;
- this.chainCallImportingUserdirFiles({
- paths: paths,
- file_type: file_type,
- dbkey: dbkey,
- link_data: link_data,
- space_to_tab: space_to_tab,
- to_posix_lines: to_posix_lines,
- source: full_source,
- tag_using_filenames: tag_using_filenames,
- });
- }
- }
- },
- /**
- * Take the array of paths and create a request for each of them
- * calling them in chain. Update the progress bar in between each.
- * @param {array} paths paths relative to user folder on Galaxy
- * @param {boolean} tag_using_filenames add tags to datasets using names of files
- */
- chainCallImportingUserdirFiles: function (options) {
- const Galaxy = getGalaxyInstance();
- const popped_item = options.paths.pop();
- if (typeof popped_item === "undefined") {
- if (this.options.chain_call_control.failed_number === 0) {
- Toast.success("Selected files imported into the current folder");
- Galaxy.modal.hide();
- } else {
- Toast.error("An error occurred.");
- }
- return true;
- }
- const post_url = `${getAppRoot()}api/libraries/datasets`;
- const post_data = {
- 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,
- };
- const promise = $.when($.post(post_url, post_data));
- promise
- .done((response) => {
- updateProgress();
- this.chainCallImportingUserdirFiles(options);
- })
- .fail(() => {
- this.options.chain_call_control.failed_number += 1;
- updateProgress();
- this.chainCallImportingUserdirFiles(options);
- });
- },
- /**
- * Fetch the contents of user directory on Galaxy
- * and render jstree component based on received
- * data.
- * @param {[type]} options [description]
- */
- renderJstree: function (options) {
- 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: (model, response) => {
- $("#jstree_browser").jstree("destroy");
- $("#jstree_browser").jstree({
- core: {
- data: model,
- },
- plugins: ["types", "checkbox"],
- types: {
- folder: {
- icon: "jstree-folder",
- },
- file: {
- icon: "jstree-file",
- },
- },
- checkbox: {
- three_state: false,
- },
- });
- },
- error: (model, response) => {
- if (typeof response.responseJSON !== "undefined") {
- if (response.responseJSON.err_code === 404001) {
- Toast.warning(response.responseJSON.err_msg);
- getGalaxyInstance().modal.hide();
- } else {
- Toast.error(response.responseJSON.err_msg);
- }
- } else {
- Toast.error("An error occurred.");
- }
- },
- });
- },
- /**
- * Create modal for importing from Galaxy path.
- */
- importFilesFromPathModal: function () {
- const Galaxy = getGalaxyInstance();
- this.modal = Galaxy.modal;
- var template_modal = this.templateImportPathModal();
- this.modal.show({
- closing_events: true,
- title: _l("Please enter paths to import"),
- body: template_modal({}),
- buttons: {
- Import: () => {
- this.importFromPathsClicked(this);
- },
- Close: () => {
- Galaxy.modal.hide();
- },
- },
- closing_callback: () => {
- // TODO update table without fetching new content from the server
- this.options.updateContent();
-
- // Galaxy.libraries.library_router.navigate(`folders/${this.id}`, {
- // trigger: true,
- // });
- },
- });
- this.renderSelectBoxes();
- },
- /**
- * Take the paths from the textarea, split it, create
- * a request queue and call a function that starts sending
- * one by one to be imported on the server.
- */
- importFromPathsClicked: function () {
- var preserve_dirs = this.modal.$el.find(".preserve-checkbox").is(":checked");
- var link_data = this.modal.$el.find(".link-checkbox").is(":checked");
- var space_to_tab = this.modal.$el.find(".spacetab-checkbox").is(":checked");
- var to_posix_lines = this.modal.$el.find(".posix-checkbox").is(":checked");
- var tag_using_filenames = this.modal.$el.find(".tag-files").is(":checked");
- var file_type = this.select_extension.value();
- var dbkey = this.select_genome.value();
- var paths = $("textarea#import_paths").val();
- var valid_paths = [];
- if (!paths) {
- Toast.info("Please enter a path relative to Galaxy root.");
- } else {
- this.modal.disableButton("Import");
- paths = paths.split("\n");
- for (let i = paths.length - 1; i >= 0; i--) {
- var trimmed = paths[i].trim();
- if (trimmed.length !== 0) {
- valid_paths.push(trimmed);
- }
- }
- this.initChainCallControlAddingDatasets({
- length: valid_paths.length,
- });
- this.chainCallImportingFolders({
- paths: valid_paths,
- preserve_dirs: preserve_dirs,
- link_data: link_data,
- space_to_tab: space_to_tab,
- to_posix_lines: to_posix_lines,
- source: "admin_path",
- file_type: file_type,
- tag_using_filenames: tag_using_filenames,
- dbkey: dbkey,
- });
- }
- },
- /**
- * Take the array of paths and create a request for each of them
- * calling them in series. Update the progress bar in between each.
- * @param {array} paths paths relative to Galaxy root folder
- * @param {boolean} preserve_dirs indicates whether to preserve folder structure
- * @param {boolean} link_data copy files to Galaxy or link instead
- * @param {boolean} to_posix_lines convert line endings to POSIX standard
- * @param {boolean} space_to_tab convert spaces to tabs
- * @param {str} source string representing what type of folder
- * is the source of import
- * @param {boolean} tag_using_filenames add tags to datasets using names of files
- */
- chainCallImportingFolders: function (options) {
- const Galaxy = getGalaxyInstance();
- // TODO need to check which paths to call
- const popped_item = options.paths.pop();
- if (typeof popped_item == "undefined") {
- if (this.options.chain_call_control.failed_number === 0) {
- Toast.success("Selected folders and their contents imported into the current folder.");
- Galaxy.modal.hide();
- } else {
- // TODO better error report
- Toast.error("An error occurred.");
- }
- return true;
- }
- const post_url = `${getAppRoot()}api/libraries/datasets`;
- const post_data = {
- 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,
- };
- const promise = $.when($.post(post_url, post_data));
- promise
- .done((response) => {
- updateProgress();
- this.chainCallImportingFolders(options);
- })
- .fail(() => {
- this.options.chain_call_control.failed_number += 1;
- updateProgress();
- this.chainCallImportingFolders(options);
- });
- },
- templateAddingDatasetsProgressBar: function () {
- return _.template(
- `