Skip to content

Commit

Permalink
generate tool tours
Browse files Browse the repository at this point in the history
  • Loading branch information
anatskiy committed Apr 5, 2017
1 parent 5a83e56 commit 4fdb554
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -93,7 +93,7 @@ tool-data/genome/*
tool-data/*.sample
tool-data/testtoolshed.g2.bx.psu.edu/
tool-data/toolshed.g2.bx.psu.edu/
tool-data/**/*.fa
tool-data/**/*.fa

# Test output
test-data-cache
Expand Down Expand Up @@ -136,3 +136,4 @@ doc/source/dev/schema.rst
*.rej
*~
.idea/
.vscode/
1 change: 1 addition & 0 deletions config/galaxy.ini.sample
Expand Up @@ -346,6 +346,7 @@ paste.app_factory = galaxy.web.buildapp:app_factory
# demo webhooks. To use an absolute path begin the path with '/'. This is a comma
# separated list.
# webhooks_dir = config/plugins/webhooks
webhooks_dir = config/plugins/webhooks/demo

# Each job is given a unique empty directory as its current working directory.
# This option defines in what parent directory those directories will be
Expand Down
Expand Up @@ -63,24 +63,70 @@ def upload_test_data(trans, tests):
return result


def generate_tour(tool):
tour_name = tool.name + ' Tour'

steps = [{
'title': tour_name,
'content': 'This short tour will guide you through the <b>' +
tool.name + '</b> tool.',
'orphan': True
}]

for name, input in tool.inputs.items():
step = {
'title': input.label,
'element': '[tour_id=%s]' % name,
'placement': 'right',
}

if input.type == 'text':
step['content'] = 'Enter parameter <b>%s</b>.' % input.label
elif input.type == 'data':
step['content'] = 'Select dataset.'
else:
step['content'] = 'Select parameter <b>%s</b>.' % input.label,

steps.append(step)

# Add last step
steps.append({
'title': 'Execute tool',
'content': 'Click <b>Execute</b> button to run the tool.',
'element': '#execute',
'placement': 'bottom',
# 'postclick': ['#execute']
})

return {
'title_default': tour_name,
'name': tour_name,
'description': tool.name + ' ' + tool.description,
'steps': steps
}


def main(trans, webhook, params):
error = ''
data = {}

try:
if not params or 'tool_id' not in params.keys():
raise KeyError('Tool id is missing.')

tool_id = params['tool_id']
# tool_id = 'Cut1'
tool = trans.app.toolbox.get_tool(tool_id)
tests = tool.tests

upload_result = upload_test_data(trans, tests)
if upload_result['errors']:
raise ValueError(str(upload_result['errors']))
# Generate Tour
data = generate_tour(tool)

# tests = tool.tests
# upload_result = upload_test_data(trans, tests)
# if upload_result['errors']:
# raise ValueError(str(upload_result['errors']))

except Exception as e:
error = str(e)
log.exception(e)

return {'success': not error, 'error': error}
return {'success': not error, 'error': error, 'data': data}
Expand Up @@ -7,14 +7,24 @@ $(document).ready(function() {
var me = this;
this.toolId = options.toolId;

// Add attribute 'tour_id' to the execution button
$('#execute').attr('tour_id', 'execute');

var url = '/api/webhooks/tour_generator/get_data/' + JSON.stringify({
'tool_id': this.toolId
});

$.getJSON(url, function(obj) {
$('#history-refresh-button').click(); // Refresh history panel
// $('#history-refresh-button').click(); // Refresh history panel
if (obj.success) {
me._renderForm(obj);
// me._renderForm(obj);

var tour = me._generateTour(obj.data);

// Clean tour run
tour.init();
tour.goTo(0);
tour.restart();
} else {
console.error('Tour Generator: ' + obj.error);
}
Expand All @@ -23,7 +33,9 @@ $(document).ready(function() {

_renderForm: function(obj) {
var me = this,
tool = Galaxy.toolPanel.get('tools').get({id: this.toolId});
tool = Galaxy.toolPanel.get('tools').get({
id: this.toolId
});

// Method #1
// var toolForm = Galaxy.page.center.prev.form;
Expand Down Expand Up @@ -74,6 +86,15 @@ $(document).ready(function() {
process.reject();
}
});
},

_generateTour: function(data) {
var tourData = Tours.hooked_tour_from_data(data);
sessionStorage.setItem('activeGalaxyTour', JSON.stringify(data));

return new Tour(_.extend({
steps: tourData.steps
}));
}
});

Expand Down

0 comments on commit 4fdb554

Please sign in to comment.