mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +00:00
ui: tags: Minor refactoring in menu filtering and sorting
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
29d6cb2302
commit
9555697140
@ -171,17 +171,7 @@ def index(request):
|
||||
})
|
||||
|
||||
|
||||
class AppsIndexView(TemplateView):
|
||||
"""View for apps index.
|
||||
|
||||
This view supports filtering apps by one or more tags. If no tags are
|
||||
provided, it will show all the apps. If one or more tags are provided,
|
||||
it will select apps matching any of the provided tags.
|
||||
"""
|
||||
template_name = 'apps.html'
|
||||
|
||||
@staticmethod
|
||||
def _pick_menu_items(menu_items, selected_tags):
|
||||
def _pick_menu_items(menu_items, selected_tags):
|
||||
"""Return a sorted list of menu items filtered by tags."""
|
||||
|
||||
def _mismatch_map(menu_item) -> list[bool]:
|
||||
@ -201,9 +191,8 @@ class AppsIndexView(TemplateView):
|
||||
and then by the name of the menu item in current locale (by
|
||||
configured collation order).
|
||||
"""
|
||||
return (_mismatch_map(menu_item).count(True),
|
||||
_mismatch_map(menu_item), menu_item.order,
|
||||
menu_item.name.lower())
|
||||
return (_mismatch_map(menu_item).count(True), _mismatch_map(menu_item),
|
||||
menu_item.order, menu_item.name.lower())
|
||||
|
||||
# Filter out menu items that don't match any of the selected tags. If
|
||||
# no tags are selected, return all menu items. Otherwise, return all
|
||||
@ -215,6 +204,16 @@ class AppsIndexView(TemplateView):
|
||||
|
||||
return sorted(filtered_menu_items, key=_sort_key)
|
||||
|
||||
|
||||
class AppsIndexView(TemplateView):
|
||||
"""View for apps index.
|
||||
|
||||
This view supports filtering apps by one or more tags. If no tags are
|
||||
provided, it will show all the apps. If one or more tags are provided,
|
||||
it will select apps matching any of the provided tags.
|
||||
"""
|
||||
template_name = 'apps.html'
|
||||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
context = super().get_context_data(*args, **kwargs)
|
||||
context['show_disabled'] = True
|
||||
@ -229,8 +228,8 @@ class AppsIndexView(TemplateView):
|
||||
for menu_item in menu_items:
|
||||
all_tags.update(menu_item.tags or [])
|
||||
|
||||
context['all_tags'] = sorted(all_tags, key=lambda tag: _(tag))
|
||||
context['menu_items'] = self._pick_menu_items(menu_items, tags)
|
||||
context['all_tags'] = sorted(all_tags, key=_)
|
||||
context['menu_items'] = _pick_menu_items(menu_items, tags)
|
||||
|
||||
return context
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user