Skip to content

Commit 6ed07fb

Browse files
authored
Merge pull request #252 from girder/add-template-user
Add an option to include the user in a templated field
2 parents 51fa77b + 3f1041d commit 6ed07fb

File tree

5 files changed

+10
-3
lines changed

5 files changed

+10
-3
lines changed

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,12 @@ The following template values are handled identically for all parameters:
171171
- ``{{task}}``: the internal task name (this usually doesn't have spaces in it)
172172
- ``{{image}}``: the tag of the Docker image used for the task
173173
- ``{{now}}``: the local time the job started in the form yyyymmdd-HHMMSS. You can use ``yyyy``, ``mm``, ``dd``, ``HH``, ``MM``, ``SS`` for the four digit year, and two digit month, day, 24-hour, minute, and second.
174+
- ``{{user}}``: the login name of the current user.
174175
- ``{{parameter_<name of cli parameter>}}``: any parameter that isn't templated can be referenced by its name. For instance, in Example1 in the small-docker cli in this repo, ``{{parameter_stringChoice}}`` would get replaced by the value passed to the stringChoice parameter.
175176
- ``{{parameter_<name of cli parameter>_base}}`` is the same as the previous item except that if the right-most part of the parameter looks like a file extension, it is removed. This can be used to get the base name of file parameters.
176177

177178
The following template parameters are only handled on the web client:
179+
178180
- ``{#control:<selector>#}``: If specified for the value of a parameter, use the value of the selected field from the DOM. For instance, ``{#control:.h-zoom-value#}`` could get the current image zoom level.
179181

180182
There are also template values specific to individual parameters:

slicer_cli_web/rest_slicer_cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ def cliSubHandler(currentItem, params, user, token, datalist=None):
422422
'HH': time.strftime('%H', now),
423423
'MM': time.strftime('%M', now),
424424
'SS': time.strftime('%S', now),
425+
'user': user['login'] if user else '',
425426
}
426427

427428
sub_index_params, sub_opt_params = index_params, opt_params

slicer_cli_web/web_client/collections/WidgetCollection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const WidgetCollection = Backbone.Collection.extend({
2323
break;
2424
case 'multi':
2525
case 'new-file':
26-
if (m && m.value && m.value()) {
26+
if (m && m.value && m.value() && m.value().get) {
2727
params[m.id + '_folder'] = m.value().get('folderId');
2828
params[m.id] = m.value().get('name');
2929
}

slicer_cli_web/web_client/models/WidgetModel.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ const WidgetModel = Backbone.Model.extend({
225225
* the model on the server.
226226
*/
227227
_validateGirderModel(model) {
228-
if (!model.value || !model.value.get('name')) {
228+
if (!model.value || (model.value.get && !model.value.get('name'))) {
229229
if (!this.get('required')) {
230230
return;
231231
}
@@ -234,6 +234,9 @@ const WidgetModel = Backbone.Model.extend({
234234

235235
switch (this.get('type')) {
236236
case 'new-file':
237+
if (!model.value.get) {
238+
break;
239+
}
237240
if (!model.parent || model.parent.resourceName !== 'folder') {
238241
return 'Invalid parent model';
239242
}

slicer_cli_web/web_client/views/ControlWidget.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ const ControlWidget = View.extend({
336336
let modelType = 'folder'; // folder type by default, other types if necessary
337337
let modelId = null;
338338
// If it is an item it will have a folderId associated with it as a parent item
339-
if (resource.get('itemId')) {
339+
if (!resource.get) {
340+
} else if (resource.get('itemId')) {
340341
modelId = resource.get('itemId');
341342
modelType = 'item';
342343
} else if (resource.get('folderId')) {

0 commit comments

Comments
 (0)