Skip to content

Commit

Permalink
Merge pull request #5365 from jmchilton/rule_based_uploader
Browse files Browse the repository at this point in the history
Rule-based Uploader / Builder
  • Loading branch information
martenson authored Mar 31, 2018
2 parents ac74b7f + 1c04bbe commit e552bc4
Show file tree
Hide file tree
Showing 27 changed files with 3,348 additions and 124 deletions.
1 change: 1 addition & 0 deletions client/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"presets": ["env"],
"moduleIds": true,
"plugins": ["transform-vue-template"],
"ignore": [
"i18n.js",
"utils/localization.js",
Expand Down
2,217 changes: 2,217 additions & 0 deletions client/galaxy/scripts/components/RuleCollectionBuilder.vue

Large diffs are not rendered by default.

131 changes: 107 additions & 24 deletions client/galaxy/scripts/mvc/collection/list-collection-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import baseCreator from "mvc/collection/base-creator";
import UI_MODAL from "mvc/ui/ui-modal";
import naturalSort from "utils/natural-sort";
import _l from "utils/localization";
import RuleCollectionBuilder from "components/RuleCollectionBuilder.vue";
import Vue from "vue";

import "ui/hoverhighlight";

var logNamespace = "collections";
Expand Down Expand Up @@ -1011,17 +1014,11 @@ var ListCollectionCreator = Backbone.View.extend(BASE_MVC.LoggableMixin)
}
});

//=============================================================================
/** Create a modal and load its body with the given CreatorClass creator type
* @returns {Deferred} resolved when creator has built a collection.
*/
var collectionCreatorModal = function _collectionCreatorModal(elements, options, CreatorClass) {
var deferred = jQuery.Deferred();
var modal = Galaxy.modal || new UI_MODAL.View();
var creator;
const collectionCreatorModalSetup = function _collectionCreatorModalSetup(options) {
const deferred = jQuery.Deferred();
const modal = Galaxy.modal || new UI_MODAL.View();

options = _.defaults(options || {}, {
elements: elements,
const creatorOptions = _.defaults(options || {}, {
oncancel: function() {
modal.hide();
deferred.reject("cancelled");
Expand All @@ -1032,18 +1029,67 @@ var collectionCreatorModal = function _collectionCreatorModal(elements, options,
}
});

creator = new CreatorClass(options);
modal.show({
title: options.title || _l("Create a collection"),
body: creator.$el,
width: "80%",
height: "100%",
closing_events: true
const showEl = function(el) {
modal.show({
title: options.title || _l("Create a collection"),
body: el,
width: "80%",
height: "100%",
closing_events: true
});
};

return { deferred, creatorOptions, showEl };
};

//=============================================================================
/** Create a modal and load its body with the given CreatorClass creator type
* @returns {Deferred} resolved when creator has built a collection.
*/
var collectionCreatorModal = function _collectionCreatorModal(elements, options, CreatorClass) {
options = _.defaults(options || {}, {
elements: elements
});
const { deferred, creatorOptions, showEl } = collectionCreatorModalSetup(options);
var creator = new CreatorClass(creatorOptions);
showEl(creator.$el);
creator.render();
window._collectionCreator = creator;
return deferred;
};

//TODO: remove modal header
var ruleBasedCollectionCreatorModal = function _ruleBasedCollectionCreatorModal(
elements,
elementsType,
importType,
options
) {
let title;
if (importType == "datasets") {
title = _l("Build Rules for Uploading Datasets");
} else if (elementsType == "datasets") {
title = _l("Build Rules for Creating Collection");
} else {
title = _l("Build Rules for Uploading Collections");
}
options = _.defaults(options || {}, {
title: title
});
const { deferred, creatorOptions, showEl } = collectionCreatorModalSetup(options);
var ruleCollectionBuilderInstance = Vue.extend(RuleCollectionBuilder);
var vm = document.createElement("div");
showEl(vm);
new ruleCollectionBuilderInstance({
propsData: {
initialElements: elements,
elementsType: elementsType,
importType: importType,
ftpUploadSite: options.ftpUploadSite,
creationFn: options.creationFn,
oncancel: options.oncancel,
oncreate: options.oncreate,
defaultHideSourceItems: options.defaultHideSourceItems
}
}).$mount(vm);
return deferred;
};

Expand All @@ -1059,15 +1105,14 @@ var listCollectionCreatorModal = function _listCollectionCreatorModal(elements,
* @returns {Deferred} resolved when the collection is added to the history.
*/
function createListCollection(contents, defaultHideSourceItems) {
var elements = contents.toJSON();
const elements = contents.toJSON();

var promise = listCollectionCreatorModal(elements, {
const promise = listCollectionCreatorModal(elements, {
defaultHideSourceItems: defaultHideSourceItems,
creationFn: function(elements, name, hideSourceItems) {
elements = elements.map(element => ({
id: element.id,
name: element.name,

//TODO: this allows for list:list even if the filter above does not - reconcile
src: element.history_content_type === "dataset" ? "hda" : "hdca"
}));
Expand All @@ -1078,12 +1123,50 @@ function createListCollection(contents, defaultHideSourceItems) {
return promise;
}

function createCollectionViaRules(selection, defaultHideSourceItems) {
let elements, elementsType, importType;
if (!selection.selectionType) {
// Have HDAs from the history panel.
elements = selection.toJSON();
elementsType = "datasets";
importType = "collections";
} else {
const hasNonWhitespaceChars = RegExp(/[^\s]/);
// Have pasted data, data from a history dataset, or FTP list.
const lines = selection.content
.split(/[\n\r]/)
.filter(line => line.length > 0 && hasNonWhitespaceChars.exec(line));

// Really poor tabular parser - we should get a library for this or expose options? I'm not
// sure.
let hasTabs = false;
if (lines.length > 0) {
const firstLine = lines[0];
if (firstLine.indexOf("\t") >= 0) {
hasTabs = true;
}
}
const regex = hasTabs ? /\t/ : /\s+/;
elements = lines.map(line => line.split(regex));
elementsType = selection.selectionType;
importType = selection.dataType || "collections";
}
const promise = ruleBasedCollectionCreatorModal(elements, elementsType, importType, {
ftpUploadSite: selection.ftpUploadSite,
defaultHideSourceItems: defaultHideSourceItems,
creationFn: function(elements, collectionType, name, hideSourceItems) {
return selection.createHDCA(elements, collectionType, name, hideSourceItems);
}
});
return promise;
}

//==============================================================================
export default {
DatasetCollectionElementView: DatasetCollectionElementView,
ListCollectionCreator: ListCollectionCreator,

collectionCreatorModal: collectionCreatorModal,
listCollectionCreatorModal: listCollectionCreatorModal,
createListCollection: createListCollection
createListCollection: createListCollection,
createCollectionViaRules: createCollectionViaRules
};
18 changes: 9 additions & 9 deletions client/galaxy/scripts/mvc/history/history-view-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,22 +294,20 @@ var HistoryViewEdit = _super.extend(
return [
{
html: _l("Build Dataset List"),
func: function() {
panel.buildCollection("list");
}
func: () => panel.buildCollection("list")
},
// TODO: Only show quick pair if two things selected.
{
html: _l("Build Dataset Pair"),
func: function() {
panel.buildCollection("paired");
}
func: () => panel.buildCollection("paired")
},
{
html: _l("Build List of Dataset Pairs"),
func: function() {
panel.buildCollection("list:paired");
}
func: () => panel.buildCollection("list:paired")
},
{
html: _l("Build Collection from Rules"),
func: () => panel.buildCollection("rules")
}
];
},
Expand All @@ -325,6 +323,8 @@ var HistoryViewEdit = _super.extend(
createFunc = PAIR_COLLECTION_CREATOR.createPairCollection;
} else if (collectionType == "list:paired") {
createFunc = LIST_OF_PAIRS_COLLECTION_CREATOR.createListOfPairsCollection;
} else if (collectionType.startsWith("rules")) {
createFunc = LIST_COLLECTION_CREATOR.createCollectionViaRules;
} else {
console.warn(`Unknown collectionType encountered ${collectionType}`);
}
Expand Down
2 changes: 1 addition & 1 deletion client/galaxy/scripts/mvc/history/job-states-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,4 @@ var JobStatesSummaryCollection = Backbone.Collection.extend({
}
});

export default { JobStatesSummary, JobStatesSummaryCollection, FETCH_STATE_ON_ADD };
export default { JobStatesSummary, JobStatesSummaryCollection, FETCH_STATE_ON_ADD, NON_TERMINAL_STATES, ERROR_STATES };
Loading

0 comments on commit e552bc4

Please sign in to comment.