From c4380e6ce76fdf965d9371e64231d2ade977e53f Mon Sep 17 00:00:00 2001 From: guerler Date: Thu, 19 Dec 2024 16:40:06 +0300 Subject: [PATCH] Consolidate overlapping get_plugins/get_visualization helper --- lib/galaxy/visualization/plugins/registry.py | 27 ++++++++------------ lib/galaxy/webapps/galaxy/api/plugins.py | 9 +++---- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/lib/galaxy/visualization/plugins/registry.py b/lib/galaxy/visualization/plugins/registry.py index 9a4bf712b742..8d7141b3067b 100644 --- a/lib/galaxy/visualization/plugins/registry.py +++ b/lib/galaxy/visualization/plugins/registry.py @@ -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): """ diff --git a/lib/galaxy/webapps/galaxy/api/plugins.py b/lib/galaxy/webapps/galaxy/api/plugins.py index d8af00154ea1..d1f861b57cf2 100644 --- a/lib/galaxy/webapps/galaxy/api/plugins.py +++ b/lib/galaxy/webapps/galaxy/api/plugins.py @@ -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):