Merge pull request #11276 from assuntad23/bugfix/8488/rule-builder-fails-for-one-bad-url

Bugfix/8488/rule builder fails for one bad url
This commit is contained in:
John Chilton
2021-03-25 10:06:27 -04:00
committed by GitHub
6 changed files with 129 additions and 7 deletions
+7 -1
View File
@@ -129,6 +129,7 @@ export default {
components: { BButton },
data() {
return {
uploadUrl: null,
topInfo: "",
showHelper: true,
extension: this.app.defaultExtension,
@@ -168,7 +169,12 @@ export default {
this.initFtpPopover();
// file upload
this.initUploadbox({
url: this.app.uploadPath,
initUrl: (index) => {
if (!this.uploadUrl) {
this.uploadUrl = this.getRequestUrl([this.collection.get(index)], this.history_id);
}
return this.uploadUrl;
},
announce: (index, file) => {
this._eventAnnounce(index, file);
},
+1 -1
View File
@@ -141,7 +141,7 @@ export default {
});
$.uploadpost({
url: this.app.uploadPath,
data: this.app.toData(this.collection.filter()),
data: this.app.toFileUploadData(this.collection.filter()),
success: (message) => {
this._eventSuccess(message);
},
+7 -1
View File
@@ -128,6 +128,7 @@ export default {
},
data() {
return {
uploadUrl: null,
topInfo: "",
highlightBox: false,
showHelper: true,
@@ -164,7 +165,12 @@ export default {
this.initFtpPopover();
// file upload
this.initUploadbox({
url: this.app.uploadPath,
initUrl: (index) => {
if (!this.uploadUrl) {
this.uploadUrl = this.getRequestUrl([this.collection.get(index)], this.history_id);
}
return this.uploadUrl;
},
multiple: this.multiple,
announce: (index, file) => {
this._eventAnnounce(index, file);
@@ -10,6 +10,7 @@ import UploadFtp from "mvc/upload/upload-ftp";
import LazyLimited from "mvc/lazy/lazy-limited";
import { findExtension } from "./utils";
import { filesDialog } from "utils/data";
import { getAppRoot } from "onload";
const localize = _l;
@@ -339,5 +340,10 @@ export default {
const models = allHids.map((hid) => Galaxy.currHistoryPanel.collection.getByHid(hid));
return models;
},
getRequestUrl: function (items, history_id) {
var data = this.app.toData(items, history_id);
const appRoot = getAppRoot();
return data.fetchRequest ? `${appRoot}api/tools/fetch` : this.app.uploadPath;
},
},
};
@@ -60,6 +60,7 @@ export default {
extensionsSet: false,
datatypesMapper: null,
datatypesMapperReady: true,
URI_PREFIXES: ["http", "https", "ftp", "file", "gxfiles", "gximport", "gxuserimport", "gxftp"],
};
},
created() {
@@ -173,12 +174,44 @@ export default {
currentFtp: function () {
return this.currentUserId && this.ftpUploadSite;
},
toData: function (items, history_id) {
const data = {
fetchRequest: null,
uploadRequest: null,
};
if (items && items.length > 0) {
const split = this.preprocess(items);
if (split.urls.length > 0) {
data.fetchRequest = this.toFetchData(split.urls, history_id);
} else {
data.uploadRequest = this.toFileUploadData(split.files, history_id);
}
}
return data;
},
preprocess: function (items) {
const data = {
urls: [],
files: [],
};
for (var index in items) {
var it = items[index];
if (it.get("file_mode") != "new" || !this.itemIsURL(it)) {
data.files.push(it);
} else {
data.urls.push(it);
}
}
return data;
},
itemIsURL: function (item) {
return this.URI_PREFIXES.some((prefix) => item.get("url_paste").startsWith(prefix));
},
/**
* Package API data from array of models
* @param{Array} items - Upload items/rows filtered from a collection
*/
toData: function (items, history_id) {
toFileUploadData: function (items, history_id) {
// create dictionary for data submission
var data = {
payload: {
@@ -244,6 +277,38 @@ export default {
}
return data;
},
toFetchData: function (items, history_id) {
var data = {
history_id: history_id,
space_to_tab: items[0].get("space_to_tab"),
to_posix_lines: items[0].get("to_posix_lines"),
targets: [
{
destination: { type: "hdas" },
elements: [],
name: "",
},
],
auto_decompress: true,
};
// Composite does not use the fetch API, so we can just
// index into the first element of items
const urls = items[0].get("url_paste").split("\n");
for (var index in urls) {
var url = urls[index].trim();
if (url != "") {
var element = {
url: urls[index].trim(),
src: "url",
dbkey: items[0].get("genome", "?"),
ext: items[0].get("extension", "auto"),
};
data.targets[0].elements.push(element);
}
}
return data;
},
},
};
</script>
+41 -2
View File
@@ -228,6 +228,41 @@ import { getAppRoot } from "onload/loadConfig";
},
});
};
/**
*
* @param {*} config
*/
$.datafetchpost = function (config) {
var cnf = $.extend(
{},
{
data: {},
success: () => {},
error: () => {},
progress: () => {},
url: null,
},
config
);
var data = cnf.data;
if (data.error_message) {
cnf.error(data.error_message);
return;
}
// submit request
_uploadrequest({
url: cnf.url,
data: JSON.stringify(cnf.data),
success: cnf.success,
error: cnf.error,
progress: (e) => {
if (e.lengthComputable) {
cnf.progress(Math.round((e.loaded * 100) / e.total));
}
},
});
};
/**
Handles the upload events drag/drop etc.
@@ -391,6 +426,7 @@ import { getAppRoot } from "onload/loadConfig";
// create and submit data
var submitter = $.uploadpost;
var requestData = opts.initialize(index);
if (
file.chunk_mode &&
session &&
@@ -399,10 +435,13 @@ import { getAppRoot } from "onload/loadConfig";
session.chunk_upload_size > 0
) {
submitter = $.uploadchunk;
} else if (requestData.fetchRequest) {
submitter = $.datafetchpost;
}
submitter({
url: opts.url,
data: opts.initialize(index),
url: opts.initUrl(index),
data: requestData.fetchRequest ? requestData.fetchRequest : requestData.uploadRequest,
session: session,
success: (message) => {
opts.success(index, message);