Skip to content

Commit

Permalink
improve conditional input type message
Browse files Browse the repository at this point in the history
  • Loading branch information
anatskiy committed Apr 25, 2017
1 parent d253d7a commit 65a31e0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 20 deletions.
65 changes: 49 additions & 16 deletions config/plugins/webhooks/demo/tour_generator/helper/__init__.py
Expand Up @@ -21,8 +21,8 @@ def __init__(self, trans, tool_id):
self._generate_tour()

def _upload_test_data(self):
"""
Upload test datasets, which are defined in the <test></test>
"""
Upload test datasets, which are defined in the <test></test>
section of the provided tool.
"""
if not self._tool.tests:
Expand All @@ -37,18 +37,33 @@ def _upload_test_data(self):
]

if not input_datasets:
self._use_datasets = False
return
# raise ValueError('Test data is missing.')
not_supported_input_types = [
k for k, v in self._tool.inputs.data.items() if
v.type == 'repeat' or v.type == 'data_collection'
]
if not_supported_input_types:
raise ValueError('Cannot generate a tour.')
else:
self._use_datasets = False
return

test_data_paths = [os.path.abspath('test-data')]
test_data_cache_dir = os.path.abspath(
os.environ.get('GALAXY_TEST_DATA_REPO_CACHE', 'test-data-cache'))
test_data_paths.extend([
x[0] for x in os.walk(test_data_cache_dir) if '.git' not in x[0]])

# Upload all test datasets
for i, input in enumerate(input_datasets):
input_name = input[0]
input_path = os.path.abspath(os.path.join('test-data', input_name))

if not os.path.exists(input_path):
raise ValueError(
'Test dataset "%s" doesn\'t exist.' % input_name)
for j, data_path in enumerate(test_data_paths):
input_path = os.path.join(data_path, input_name)
if os.path.exists(input_path):
break
elif j + 1 == len(test_data_paths): # the last path
raise ValueError('Test dataset "%s" doesn\'t exist.' %
input_name)

upload_tool = self._trans.app.toolbox.get_tool('upload1')
filename = os.path.basename(input_path)
Expand Down Expand Up @@ -102,8 +117,8 @@ def _generate_tour(self):

# TODO@me: for ... in test.inputs?
for name, input in self._tool.inputs.items():
# Skip this type as Tours Framework doesn't add tour_id to the
# corresponding DOM element
cond_case_steps = []

if input.type == 'repeat':
continue

Expand Down Expand Up @@ -146,12 +161,9 @@ def _generate_tour(self):
hid, dataset
)

# elif input.type == 'repeat':
# step['title'] = input.title
# step['content'] = 'Select parameter <b>%s</b>' % input.title

elif input.type == 'conditional':
param_id = '%s|%s' % (input.name, input.test_param.name)
step['title'] = input.test_param.label
step['element'] = '[tour_id="%s"]' % param_id
cond_param = input.label
params = []
Expand All @@ -165,6 +177,25 @@ def _generate_tour(self):
step['content'] = 'Select parameter(s): <b>%s</b>' % \
cond_param

# Conditional param cases
cases = {}
for case in input.cases:
for key, value in case.inputs.items():
if key not in cases.keys():
cases[key] = value.label

for case_id, case_title in cases.items():
tour_id = '%s|%s' % (input.name, case_id)
if tour_id in self._test.inputs.keys():
case_params = ', '.join(self._test.inputs[tour_id])
cond_case_steps.append({
'title': case_title,
'element': '[tour_id="%s"]' % tour_id,
'placement': 'right',
'content': 'Select parameter(s): <b>%s</b>' %
case_params
})

elif input.type == 'data_column':
column_param = self._test.inputs[name][0]
step['content'] = 'Select <b>Column: %s</b>' % column_param
Expand All @@ -173,6 +204,8 @@ def _generate_tour(self):
step['content'] = 'Select parameter <b>%s</b>' % input.label

steps.append(step)
if cond_case_steps:
steps.extend(cond_case_steps) # add conditional input steps

# Add the last step
steps.append({
Expand All @@ -191,7 +224,7 @@ def _generate_tour(self):
}

def get_data(self):
"""
"""
Return a dictionary with the uploaded datasets' history ids and
the generated tour.
"""
Expand Down
5 changes: 2 additions & 3 deletions config/plugins/webhooks/demo/tour_generator/static/script.js
Expand Up @@ -9,7 +9,7 @@ $(document).ready(function() {
// Add attribute 'tour_id' to the execution button
$('#execute').attr('tour_id', 'execute');

Toastr.info('Tour generation will take some time.');
Toastr.info('Tour generation might take some time.');
$.getJSON('/api/webhooks/tour_generator/get_data/', {
tool_id: this.toolId
}, function(obj) {
Expand Down Expand Up @@ -41,14 +41,13 @@ $(document).ready(function() {
} else {
Toastr.error('Some of the test datasets cannot be found in the history.');
}
}, 500);
}, 1000);
} else {
me._main(obj.data);
}
} else {
Toastr.error(obj.error);
console.error('Tour Generator: ' + obj.error);
console.error(obj);
}
});
},
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/webapps/galaxy/api/webhooks.py
Expand Up @@ -56,7 +56,6 @@ def get_all_by_type(self, trans, webhook_type, **kwd):
]

@expose_api_anonymous_and_sessionless
# def get_data(self, trans, webhook_name, params, **kwd):
def get_data(self, trans, webhook_name, **kwd):
"""
*GET /api/webhooks/{webhook_name}/get_data/{params}
Expand All @@ -72,6 +71,7 @@ def get_data(self, trans, webhook_name, **kwd):
for webhook in self.app.webhooks_registry.webhooks
if webhook.name == webhook_name
]

return imp.load_source('helper', webhook[0].helper).main(
trans,
webhook[0],
Expand Down

0 comments on commit 65a31e0

Please sign in to comment.