How to use system variables in `data-file_picker_favorites` for File Picker?

Hi,

I was wondering what is the recommended way to use system variables in the data-file_picker_favorites field from JS File Picker (GitHub - OSC/bc_js_filepicker: A file picker for Batch Connect applications)?

Using system variable for the default search directory:

data-default-directory: "$HOME"

works as expected.

However, I would like to expand the search directory to include multiple file-systems we support with per-user unique directories that are stored in system variables.
To do this, I use data-file_picker_favorites, but since this field is in JSON format, system variables or Ruby syntax such as:

data-file_picker_favorites: '[{"title": "HOME", "href": "${HOME}"}, {"title": "WORK", "href": "/work/#{g}/#{User.new.name}"}]'

are not recognized.

Based on this, what would be your suggested way to use system variables in the data-file_picker_favorites field?
Should we modify the files_api.js script and recompile form.js in order to support system variables for the File Picker?

I also understand that many of the File Picker features have been already incorporated in the newer OOD releases, so please let me know if there is some other solution we can consider.

We have Open OnDemand 3.1.10 on our cluster and we use the newest release of form.js from JS File Picker.
Please let me know if you need any additional information.

Thank you,
Natasha

If your form.yml is in ERB format (i.e., form.yml.erb)

Then I think this is more what you’re looking for. Note that I’m pulling User.new.group.to_s from memory/what I assume will work so that may not be 100% correct.

data-file_picker_favorites: '[{"title": "HOME", "href": "${HOME}"}, {"title": "WORK", "href": "/work/<%= User.new.group.to_s %>/<%= User.new.name %>"}]'

But I think the issue you have with ruby variables is they’re not being evaluated. this syntax in ERB <%= %> actually evaluates the variables.

Jeff, thank you so much - the exact command you provided worked as expected!

Thank you always for the prompt and great support!

Thank you,
Natasha

1 Like