Skip to content

Commit

Permalink
🔥: remove addFilesFromHistoryModal and related methods from `add-da…
Browse files Browse the repository at this point in the history
…tasets.js`
  • Loading branch information
itisAliRH committed Aug 2, 2024
1 parent 9c553c1 commit e67ee2f
Showing 1 changed file with 0 additions and 260 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ var AddDatasets = Backbone.View.extend({
*/
showImportModal: function (options) {
switch (options.source) {
case "history":
this.addFilesFromHistoryModal();
break;
case "importdir":
this.importFilesFromGalaxyFolderModal({
source: "importdir",
Expand Down Expand Up @@ -176,46 +173,6 @@ var AddDatasets = Backbone.View.extend({
value: "auto",
});
},
addFilesFromHistoryModal: function () {
const Galaxy = getGalaxyInstance();
this.histories = new mod_library_model.GalaxyHistories();
this.histories
.fetch()
.done(() => {
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: this.histories.models,
}),
buttons: {
Add: () => {
this.addAllDatasetsFromHistory();
},
Close: () => {
Galaxy.modal.hide();
},
},
closing_callback: () => {
// TODO update table without fetching new content from the server
// Galaxy.libraries.library_router.navigate(`folders/${this.id}`, { trigger: true });
},
});
this.fetchAndDisplayHistoryContents(this.histories.models[0].id);
$("#dataset_add_bulk").change((event) => {
this.fetchAndDisplayHistoryContents(event.target.value);
});
})
.fail((model, response) => {
if (typeof response.responseJSON !== "undefined") {
Toast.error(response.responseJSON.err_msg);
} else {
Toast.error("An error occurred.");
}
});
},
/**
* Create modal for importing from given directory
* on Galaxy. Bind jQuery events.
Expand Down Expand Up @@ -546,49 +503,6 @@ var AddDatasets = Backbone.View.extend({
this.chainCallImportingFolders(options);
});
},

fetchAndDisplayHistoryContents: function (history_id) {
var history_contents = new mod_library_model.HistoryContents({
id: history_id,
});
history_contents.fetch({
success: (history_contents) => {
var history_contents_template = this.templateHistoryContents();

if (history_contents.length > 0) {
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(),
})
);
this.modal.$el.find(".history-import-select-all").bind("click", () => {
$(".library_selected_history_content [type=checkbox]").prop("checked", true);
});
this.modal.$el.find(".history-import-unselect-all").bind("click", () => {
$(".library_selected_history_content [type=checkbox]").prop("checked", false);
});

this.modal.$el.find(".history-import-toggle-all").bind("click", (e) => {
this.selectAll(e);
});

this.modal.$el.find(".dataset_row").bind("click", (e) => {
this.selectClickedRow(e);
});
} else {
this.modal.$el.find(".library_selected_history_content").html(`<p>Selected history is empty.</p>`);
}
},
error: (model, response) => {
if (typeof response.responseJSON !== "undefined") {
Toast.error(response.responseJSON.err_msg);
} else {
Toast.error("An error occurred.");
}
},
});
},
templateAddingDatasetsProgressBar: function () {
return _.template(
`<div class="import_text">
Expand All @@ -602,180 +516,6 @@ var AddDatasets = Backbone.View.extend({
</div>`
);
},
templateAddFilesFromHistory: function () {
return _.template(
`<div id="add_files_modal">
<div class="form-group">
<label>1. Select history:</label>
<select id="dataset_add_bulk" name="dataset_add_bulk" class="form-control">
<% _.each(histories, function(history) { %> <!-- history select box -->
<option value="<%= _.escape(history.get("id")) %>">
<%= _.escape(history.get("name")) %>
</option>
<% }); %>
</select>
</div>
<div class="library_selected_history_content">
</div>
</div>`
);
},
templateHistoryContents: function () {
return _.template(
`<div class="form-group">
<label>2. Choose the datasets to import:</label>
<div class="library_style_container" style="width: 100%;" id="dataset_list">
<table class="grid table table-hover table-sm">
<thead>
<tr>
<th style="width: 30px;" class="mid" title="Check to select all datasets">
<input class="history-import-toggle-all" style="margin: 0;" type="checkbox" />
</th>
<th style="width: 30px;"></th>
<th>Name</th>
</tr>
</thead>
<tbody>
<% _.each(history_contents, function(history_item) { %>
<% if (history_item.get("deleted") != true ) { %>
<% var item_name = history_item.get("name") %>
<% if (history_item.get("type") === "collection") { %>
<% var collection_type = history_item.get("collection_type") %>
<% if (collection_type === "list") { %>
<tr class="dataset_row" data-id="<%= _.escape(history_item.get("id")) %>"
data-name="<%= _.escape(history_item.get("type")) %>">
<td><input style="margin: 0;" type="checkbox"></td>
<td><%= _.escape(history_item.get("hid")) %></td>
<td>
<%= item_name.length > 75 ? _.escape("...".concat(item_name.substr(-75))) : _.escape(item_name) %>
(Dataset Collection)
</td>
</tr>
<% } else { %>
<tr class="dataset_row" title="You can convert this collection into a collection of type list using the Collection Tools">
<td><input style="margin: 0;" type="checkbox" onclick="return false;" disabled="disabled" /></td>
<td><%= _.escape(history_item.get("hid")) %></td>
<td>
<%= item_name.length > 75 ? _.escape("...".concat(item_name.substr(-75))) : _.escape(item_name) %>
(Dataset Collection of type <%= _.escape(collection_type) %> not supported.)
</td>
</tr>
<% } %>
<% } else if (history_item.get("visible") === true && history_item.get("state") === "ok") { %>
<tr class="dataset_row" data-id="<%= _.escape(history_item.get("id")) %>"
data-name="<%= _.escape(history_item.get("type")) %>">
<td><input style="margin: 0;" type="checkbox"></td>
<td><%= _.escape(history_item.get("hid")) %></td>
<td>
<%= item_name.length > 75 ? _.escape("...".concat(item_name.substr(-75))) : _.escape(item_name) %>
</td>
</tr>
<% } %>
<% } %>
<% }); %>
</tbody>
</table>
</div>
</div>`
);
},
/**
* Check checkbox if user clicks on the whole row or
* on the checkbox itself
*/
selectClickedRow: function (event) {
var checkbox = "";
var $row;
var source;
$row = $(event.target).closest("tr");
if (event.target.localName === "input") {
checkbox = event.target;
source = "input";
} else if (event.target.localName === "td") {
checkbox = $row.find(":checkbox")[0];
source = "td";
}
if (checkbox.checked) {
if (source === "td") {
checkbox.checked = "";
this.makeWhiteRow($row);
} else if (source === "input") {
this.makeDarkRow($row);
}
} else {
if (source === "td") {
checkbox.checked = "selected";
this.makeDarkRow($row);
} else if (source === "input") {
this.makeWhiteRow($row);
}
}
},

/**
* User clicked the checkbox in the table heading
* @param {context} event
*/
selectAll: function (event) {
var selected = event.target.checked;
var self = this;
// Iterate each checkbox
$(":checkbox", "#dataset_list tbody").each(function () {
this.checked = selected;
var $row = $(this).closest("tr");
// Change color of selected/unselected
if (selected) {
self.makeDarkRow($row);
} else {
self.makeWhiteRow($row);
}
});
},

makeDarkRow: function ($row) {
$row.addClass("table-primary");
},

makeWhiteRow: function ($row) {
$row.removeClass("table-primary");
},
/**
* Import all selected datasets from history into the current folder.
*/
addAllDatasetsFromHistory: function () {
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 = [];
if (checked_hdas.length < 1) {
Toast.info("You must select some datasets first.");
} else {
this.modal.disableButton("Add");
checked_hdas.each(function () {
var hid = $(this).closest("tr").data("id");
if (hid) {
var item_type = $(this).closest("tr").data("name");
history_item_ids.push(hid);
history_item_types.push(item_type);
}
});
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 = `${getAppRoot()}api/folders/${this.options.id}/contents`;
if (history_item_types[i] === "collection") {
folder_item.set({ from_hdca_id: history_item_id });
} else {
folder_item.set({ from_hda_id: history_item_id });
}
items_to_add.push(folder_item);
}
this.initChainCallControlAddingDatasets({
length: items_to_add.length,
});
this.chainCallAddingHdas(items_to_add);
}
},
initChainCallControlAddingDatasets: function (options) {
var template;
template = this.templateAddingDatasetsProgressBar();
Expand Down

0 comments on commit e67ee2f

Please sign in to comment.