From 29eca5426d30847d027b54ea83fbf9a9703f53d6 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 28 Jul 2026 08:04:42 -0700 Subject: [PATCH] views: Link to apps-add page from a tag click in app page Tests: - On Coturn app page, clicking on a tag redirects to Add New App page with tag filter set to clicked tag. - On Names app page, clicking on a tag redirects to system page with tag filter set to clicked tag. - On Operations page such as when installing an app, clicking on a tag redirects to Add New App page with tag filter set to clicked tag. - On Index page such when OpenVPN is clicked description for OpenVPN is shown. Clicking on a tag in the description redirects to Add New App page with tag filter set to clicked tag. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/templates/app-header.html | 2 +- plinth/views.py | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/plinth/templates/app-header.html b/plinth/templates/app-header.html index e5c90d58b..1d6cc7de0 100644 --- a/plinth/templates/app-header.html +++ b/plinth/templates/app-header.html @@ -47,7 +47,7 @@
{% for tag in app_info.tags %} {% if not forloop.first %}•{% endif %} - {% trans tag %} diff --git a/plinth/views.py b/plinth/views.py index 7e1d20031..9ed0305e6 100644 --- a/plinth/views.py +++ b/plinth/views.py @@ -174,12 +174,16 @@ def index(request): shortcut for shortcut in shortcuts if shortcut.component_id == selected ] selected_shortcut = selected_shortcut[0] if selected_shortcut else None + tag_search_url = None + if selected_shortcut: + tag_search_url = _get_tag_search_url(selected_shortcut.app) return TemplateResponse( request, 'index.html', { 'title': _('FreedomBox'), 'shortcuts': shortcuts, 'selected_shortcut': selected_shortcut, + 'tag_search_url': tag_search_url, }) @@ -266,6 +270,34 @@ def _get_all_tags(menu_items: list[menu.Menu]) -> list[str]: return sorted(get_tags(menu_items), key=_) +def _get_tag_search_url(app: app_module.App) -> str: + """Return the URL to which clicking on tags to redirect to.""" + default_url = 'apps-add' + + menus = list(app.get_components_of_type(menu.Menu)) + if not menus: + return default_url # When app has no menu item. + + parent_section = menus[0] + for _index in range(10): + if parent_section.parent_url_name in ('index', None): + break + + try: + parent_section = menu.Menu.get_with_url_name( + parent_section.parent_url_name) + except LookupError: + return default_url + else: + # There was a loop in traversing to the parent menu item. + return default_url + + if parent_section.url_name == 'apps': + return default_url + + return parent_section.url_name + + class AppsView(TemplateView): """View for showing installed apps. @@ -507,6 +539,7 @@ class AppView(FormView): context['firewall'] = self.app.get_components_of_type(Firewall) context['has_backup_restore'] = _has_backup_restore(self.app) + context['tag_search_url'] = _get_tag_search_url(self.app) return context @@ -532,6 +565,7 @@ class AppOperationsView(TemplateView): context['operations'] = operation.manager.filter(self.app.app_id) # Refresh periodically while operations are running context['refresh_page_sec'] = 3 if context['operations'] else 0 + context['tag_search_url'] = _get_tag_search_url(self.app) return context @@ -569,6 +603,8 @@ class SetupView(TemplateView): elif context['setup_state'] == app_module.App.SetupState.UP_TO_DATE: context['refresh_page_sec'] = 0 + context['tag_search_url'] = _get_tag_search_url(app) + return context def dispatch(self, request, *args, **kwargs):