Skip to content

Commit

Permalink
Consolidate overlapping get_plugins/get_visualization helper
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Dec 19, 2024
1 parent 24faf70 commit c4380e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
27 changes: 11 additions & 16 deletions lib/galaxy/visualization/plugins/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,27 +225,22 @@ def get_plugin(self, key):
raise ObjectNotFound(f"Unknown or invalid visualization: {key}")
return self.plugins[key]

def get_plugins(self, embeddable=None):
result = []
for plugin in self.plugins.values():
if embeddable and not plugin.config.get("embeddable"):
continue
if plugin.config.get("visible"):
result.append(plugin.to_dict())
return sorted(result, key=lambda k: k.get("html"))

# -- building links to visualizations from objects --
def get_visualizations(self, trans, target_object):
def get_visualizations(self, trans, target_object=None, embeddable=None):
"""
Get the names of visualizations usable on the `target_object` and
the urls to call in order to render the visualizations.
"""
applicable_visualizations = []
for vis_name in self.plugins:
url_data = self.get_visualization(trans, vis_name, target_object)
if url_data:
applicable_visualizations.append(url_data)
return sorted(applicable_visualizations, key=lambda k: k.get("html"))
result = []
for vis_name, vis_plugin in self.plugins.items():
if not vis_plugin.config.get("visible"):
continue
if embeddable and not vis_plugin.config.get("embeddable"):
continue
if target_object is not None and self.get_visualization(trans, vis_name, target_object) is None:
continue
result.append(vis_plugin.to_dict())
return sorted(result, key=lambda k: k.get("html"))

def get_visualization(self, trans, visualization_name, target_object):
"""
Expand Down
9 changes: 4 additions & 5 deletions lib/galaxy/webapps/galaxy/api/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ def index(self, trans, **kwargs):
GET /api/plugins:
"""
registry = self._get_registry()
embeddable = asbool(kwargs.get("embeddable"))
target_object = None
if (dataset_id := kwargs.get("dataset_id")) is not None:
hda = self.hda_manager.get_accessible(self.decode_id(dataset_id), trans.user)
return registry.get_visualizations(trans, hda)
else:
embeddable = asbool(kwargs.get("embeddable"))
return registry.get_plugins(embeddable=embeddable)
target_object = self.hda_manager.get_accessible(self.decode_id(dataset_id), trans.user)
return registry.get_visualizations(trans, target_object=target_object, embeddable=embeddable)

@expose_api
def show(self, trans, id, **kwargs):
Expand Down

0 comments on commit c4380e6

Please sign in to comment.