Skip to content

Commit 9899eb1

Browse files
committed
WIP: implement field parameter type for CWL.
1 parent 9181949 commit 9899eb1

File tree

3 files changed

+112
-2
lines changed

3 files changed

+112
-2
lines changed

client/galaxy/scripts/mvc/form/form-parameters.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { getGalaxyInstance } from "app";
55
import Utils from "utils/utils";
66
import Ui from "mvc/ui/ui-misc";
7+
import UiField from "mvc/ui/ui-field";
78
import SelectContent from "mvc/ui/ui-select-content";
89
import SelectLibrary from "mvc/ui/ui-select-library";
910
import SelectFtp from "mvc/ui/ui-select-ftp";
@@ -34,6 +35,7 @@ export default Backbone.Model.extend({
3435
ftpfile: "_fieldFtp",
3536
upload: "_fieldUpload",
3637
rules: "_fieldRulesEdit",
38+
field: "_fieldField",
3739
genomespacefile: "_fieldGenomeSpace"
3840
},
3941

@@ -233,5 +235,13 @@ export default Backbone.Model.extend({
233235
id: `field-${input_def.id}`,
234236
onchange: input_def.onchange
235237
});
238+
},
239+
240+
_fieldField: function(input_def) {
241+
return new UiField({
242+
id: `field-${input_def.id}`,
243+
onchange: input_def.onchange
244+
});
236245
}
246+
237247
});
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/** Renders the color picker used e.g. in the tool form **/
2+
import Utils from "utils/utils";
3+
import Ui from "mvc/ui/ui-misc";
4+
5+
/** Renders an input element used e.g. in the tool form */
6+
export default Backbone.View.extend({
7+
initialize: function(options) {
8+
this.model =
9+
(options && options.model) ||
10+
new Backbone.Model({
11+
value: {"src": "json", "value": null, "representation": "null"},
12+
}).set(options);
13+
this.$el = $("<div><p>moo cow</p></div>").addClass("ui-field");
14+
console.log(this.model.get("value"));
15+
var menuButton = new Ui.ButtonMenu({
16+
id: "options",
17+
icon: "fa-caret-down",
18+
title: "Input Type",
19+
tooltip: "View available input type options"
20+
});
21+
menuButton.addMenu({
22+
title: "Integer",
23+
onclick: () => {
24+
this._changeType("integer")
25+
}
26+
});
27+
menuButton.addMenu({
28+
title: "Leave Unselected",
29+
onclick: () => {
30+
this._changeType("null")
31+
}
32+
});
33+
this.$menuButton = menuButton;
34+
this.$inputDiv = $("<div/>").addClass("select-input");
35+
36+
this.$el.append(menuButton.$el);
37+
this.$el.append(this.$inputDiv);
38+
this.setElement(this.$el);
39+
this.listenTo(this.model, "change", this.render, this);
40+
this.render();
41+
},
42+
value: function(new_val) {
43+
var options = this.model.attributes;
44+
if (new_val) {
45+
this.model.set("value", new_val);
46+
this.model.trigger("change");
47+
options.onchange(new_val);
48+
}
49+
return this.model.get("value");
50+
},
51+
render: function() {
52+
const value = this.model.get("value");
53+
const rep = value.representation;
54+
if ( rep == "null" ) {
55+
this.$inputDiv.html($("<p>No value selected (null)</p>"));
56+
} else if ( rep == "integer" ) {
57+
const tagName = this.model.get("area") ? "textarea" : "input";
58+
this.$inputDiv.html($(`<${tagName} value="${value.value}"/>`));
59+
console.log(this.$inputDiv.find("input"));
60+
this.$inputDiv.find("input").on("change", () => { this._onchange() });
61+
}
62+
return this;
63+
},
64+
_changeType: function(representation) {
65+
const previousValue = this.model.get("value");
66+
const previousRawValue = previousValue.value;
67+
if ( representation == "null" ) {
68+
this.model.set("value", {"src": "json", "value": null, "representation": "null"});
69+
} else if ( representation == "integer" ) {
70+
var value = parseInt(previousRawValue);
71+
if ( isNaN( value ) ) {
72+
value = 0;
73+
}
74+
this.model.set("value", {"src": "json", "value": 0, "representation": "integer"});
75+
}
76+
},
77+
_rawValue: function(previousValue) {
78+
const rep = previousValue.representation;
79+
let rawVal;
80+
if ( rep == "null" ) {
81+
rawVal = null;
82+
} else if ( rep == "integer" ) {
83+
rawVal = parseInt(this.$inputDiv.find("input").val());
84+
}
85+
console.log("_rawValue returning " + rawVal);
86+
return rawVal;
87+
88+
},
89+
_onchange: function() {
90+
const previousValue = this.model.get("value");
91+
const newValue = this._rawValue(previousValue);
92+
previousValue["value"] = newValue;
93+
this.value(previousValue);
94+
this.model.get("onchange") && this.model.get("onchange")(this.model.get("value"));
95+
}
96+
});

lib/galaxy/workflow/run_request.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,17 @@ def build_workflow_run_configs(trans, workflow, payload):
277277
if step.type == "parameter_input":
278278
if normalized_key in param_map:
279279
value = param_map.pop(normalized_key)
280-
normalized_inputs[normalized_key] = value["input"]
280+
input_value = value["input"]
281+
if isinstance(input_value, dict) and input_value.get("src") == "json":
282+
input_value = input_value.get("value")
283+
normalized_inputs[normalized_key] = input_value
284+
281285

282286
steps_by_id = workflow.steps_by_id
283287
# Set workflow inputs.
284288
for key, input_dict in normalized_inputs.items():
285289
step = steps_by_id[key]
286-
if step.type == 'parameter_input' and (step.tool_inputs["parameter_type"] != "field" or not isinstance(input_dict, dict)):
290+
if step.type == 'parameter_input' and (step.tool_inputs["parameter_type"] != "field" or not isinstance(input_dict, dict) or "id" not in input_dict):
287291
continue
288292
if 'src' not in input_dict:
289293
raise exceptions.RequestParameterInvalidException("Not input source type defined for input '%s'." % input_dict)

0 commit comments

Comments
 (0)