From e524ccb995c12562609d09f305609e7eb2f97abd Mon Sep 17 00:00:00 2001 From: Shohan Date: Wed, 30 Jun 2021 00:32:14 +0530 Subject: [PATCH] [feat] Reintroduced ordering column and remove search input box and related views --- client/src/entrypoints/admin/bulk-actions.js | 6 +- .../templates/wagtailadmin/admin_base.html | 1 - .../templates/wagtailadmin/pages/index.html | 7 +- .../wagtailadmin/pages/listing/_list.html | 11 ++-- .../pages/listing/_table_headers_explore.html | 24 +++++-- wagtail/admin/urls/__init__.py | 4 +- wagtail/admin/views/filters.py | 64 ------------------- wagtail/admin/views/pages/listing.py | 10 +-- wagtail/admin/wagtail_hooks.py | 8 +++ 9 files changed, 40 insertions(+), 95 deletions(-) delete mode 100644 wagtail/admin/views/filters.py diff --git a/client/src/entrypoints/admin/bulk-actions.js b/client/src/entrypoints/admin/bulk-actions.js index 7470b36091..822848e5c0 100644 --- a/client/src/entrypoints/admin/bulk-actions.js +++ b/client/src/entrypoints/admin/bulk-actions.js @@ -129,7 +129,7 @@ function BulkActionEventListeners(e) { /* Adds all event listeners */ -function AddBulkActionEventListeners() { +(function AddBulkActionEventListeners() { document.querySelectorAll(`.${BULK_ACTION_PAGE_CHECKBOX_INPUT}`) .forEach(el => { checkedState.numPages++; @@ -144,6 +144,4 @@ function AddBulkActionEventListeners() { ); parentPageId = document.querySelector(`.${BULK_ACTION_SELECT_ALL_CHECKBOX_TH}`).dataset.parentId; updateNumPagesInListing(getParameterByName('filters')); -} - -window.AddBulkActionEventListeners = AddBulkActionEventListeners; +})() diff --git a/wagtail/admin/templates/wagtailadmin/admin_base.html b/wagtail/admin/templates/wagtailadmin/admin_base.html index 6ed8427ae2..4a233b18e4 100644 --- a/wagtail/admin/templates/wagtailadmin/admin_base.html +++ b/wagtail/admin/templates/wagtailadmin/admin_base.html @@ -52,7 +52,6 @@ - {% hook_output 'insert_global_admin_js' %} diff --git a/wagtail/admin/templates/wagtailadmin/pages/index.html b/wagtail/admin/templates/wagtailadmin/pages/index.html index 05a450a6aa..ac09c4a13a 100644 --- a/wagtail/admin/templates/wagtailadmin/pages/index.html +++ b/wagtail/admin/templates/wagtailadmin/pages/index.html @@ -9,13 +9,12 @@ {% explorer_breadcrumb parent_page %} -
{% csrf_token %} {% page_permissions parent_page as parent_page_perms %} - {% include "wagtailadmin/pages/listing/_list_explore.html" with sortable=1 sortable_by_type=1 full_width=1 show_ordering_column=1 parent_page=parent_page orderable=parent_page_perms.can_reorder_children %} + {% include "wagtailadmin/pages/listing/_list_explore.html" with sortable=1 sortable_by_type=1 full_width=1 show_ordering_column=show_ordering_column parent_page=parent_page orderable=parent_page_perms.can_reorder_children %} {% if do_paginate %} {% url 'wagtailadmin_explore' parent_page.id as pagination_base_url %} @@ -30,7 +29,9 @@ {% comment %} modal-workflow is required by the view restrictions interface {% endcomment %} - + {% if not show_ordering_column %} + + {% endif %} \ No newline at end of file + \ No newline at end of file diff --git a/wagtail/admin/templates/wagtailadmin/pages/listing/_table_headers_explore.html b/wagtail/admin/templates/wagtailadmin/pages/listing/_table_headers_explore.html index 3099d28a78..83d7019b38 100644 --- a/wagtail/admin/templates/wagtailadmin/pages/listing/_table_headers_explore.html +++ b/wagtail/admin/templates/wagtailadmin/pages/listing/_table_headers_explore.html @@ -17,6 +17,21 @@ ordering: the current sort parameter {% endcomment %} + {% if show_ordering_column %} + + {% if orderable %} + {% if ordering == "ord" %} + + {% icon name="order" %}{% trans 'Sort' %} + + {% else %} + + {% icon name="order" %}{% trans 'Sort' %} + + {% endif %} + {% endif %} + + {% else %}
@@ -33,12 +48,9 @@ ordering: the current sort parameter
- - + {% endif %} + + {% trans 'Page' %} {% if show_parent %} diff --git a/wagtail/admin/urls/__init__.py b/wagtail/admin/urls/__init__.py index 7449c79216..9a8a4be6e2 100644 --- a/wagtail/admin/urls/__init__.py +++ b/wagtail/admin/urls/__init__.py @@ -15,7 +15,7 @@ from wagtail.admin.urls import pages as wagtailadmin_pages_urls from wagtail.admin.urls import password_reset as wagtailadmin_password_reset_urls from wagtail.admin.urls import reports as wagtailadmin_reports_urls from wagtail.admin.urls import workflows as wagtailadmin_workflows_urls -from wagtail.admin.views import account, chooser, filters, home, tags, userbar +from wagtail.admin.views import account, chooser, home, tags, userbar from wagtail.admin.views.pages import listing from wagtail.admin.views.pages.bulk_actions import index as bulk_actions from wagtail.core import hooks @@ -34,8 +34,6 @@ urlpatterns = [ # TODO: Move into wagtailadmin_pages namespace path('pages/', listing.index, name='wagtailadmin_explore_root'), path('pages//', listing.index, name='wagtailadmin_explore'), - path('pages/filter-count/', filters.filter_count, name='wagtailadmin_filter_count'), - path('pages//filter-count/', filters.filter_count, name='wagtailadmin_filter_count'), # bulk actions path('pages/multiple//', bulk_actions, name='wagtailadmin_bulk_action'), diff --git a/wagtail/admin/views/filters.py b/wagtail/admin/views/filters.py deleted file mode 100644 index d483228fbb..0000000000 --- a/wagtail/admin/views/filters.py +++ /dev/null @@ -1,64 +0,0 @@ -from django.db.models import Q -from django.http.response import JsonResponse -from django.shortcuts import get_object_or_404, redirect - -from wagtail.admin.auth import user_has_any_page_permission, user_passes_test -from wagtail.admin.navigation import get_explorable_root_page -from wagtail.core.models import Page, UserPagePermissionsProxy -from wagtail.search.utils import parse_query_string - - -def apply_filters(filter_query): - filters_to_be_applied = Q() - - # filter_query should be of the format 'filter1:value1 filter2:value2' - filter_query = filter_query.strip() - if not filter_query: - return filters_to_be_applied - filter_args = parse_query_string(filter_query)[0] - filters = { - 'status': { - 'live': Q(live=True), - 'draft': Q(live=False), - } - } - - for _arg, filter_value in filter_args.items(): - if _arg not in filters: - continue - if filter_value not in filters[_arg]: - continue - filters_to_be_applied = filters_to_be_applied & filters[_arg][filter_value] - - return filters_to_be_applied - - -@user_passes_test(user_has_any_page_permission) -def filter_count(request, parent_page_id=None): - if parent_page_id: - parent_page = get_object_or_404(Page, id=parent_page_id) - # This will always succeed because of the @user_passes_test above. - root_page = get_explorable_root_page(request.user) - - # If this page isn't a descendant of the user's explorable root page, - # then redirect to that explorable root page instead. - if not ( - parent_page.pk == root_page.pk - or parent_page.is_descendant_of(root_page) - ): - return redirect('wagtailadmin_explore', root_page.pk) - - parent_page = parent_page.specific - - user_perms = UserPagePermissionsProxy(request.user) - pages = ( - parent_page.get_children().prefetch_related( - "content_type", "sites_rooted_here" - ) - & user_perms.explorable_pages() - ) - else: - pages = Page.objects.all().prefetch_related('content_type').specific() - filter_query = request.GET.dict().get('filters', '') - filters_to_be_applied = apply_filters(filter_query) - return JsonResponse(dict(count=pages.filter(filters_to_be_applied).count())) diff --git a/wagtail/admin/views/pages/listing.py b/wagtail/admin/views/pages/listing.py index bb11153597..4f0cfdc8e8 100644 --- a/wagtail/admin/views/pages/listing.py +++ b/wagtail/admin/views/pages/listing.py @@ -7,7 +7,6 @@ from django.urls import reverse from wagtail.admin.auth import user_has_any_page_permission, user_passes_test from wagtail.admin.navigation import get_explorable_root_page -from wagtail.admin.views.filters import apply_filters from wagtail.core import hooks from wagtail.core.models import Page, UserPagePermissionsProxy @@ -40,13 +39,6 @@ def index(request, parent_page_id=None): & user_perms.explorable_pages() ) - # filter pages - # the query should be ?filters=filter1:value1 filter2:value2.... If there are duplicate filters, the filter value of the - # latter will be considered by design - filter_query = request.GET.get('filters', '') - filters_to_be_applied = apply_filters(filter_query) - pages = pages.filter(filters_to_be_applied) - # Get page ordering ordering = request.GET.get('ordering', '-latest_revision_created_at') if ordering not in [ @@ -111,7 +103,7 @@ def index(request, parent_page_id=None): 'do_paginate': do_paginate, 'locale': None, 'translations': [], - 'filter_query': filter_query, + 'show_ordering_column': 'ordering' in request.GET.dict() } if getattr(settings, 'WAGTAIL_I18N_ENABLED', False) and not parent_page.is_root(): diff --git a/wagtail/admin/wagtail_hooks.py b/wagtail/admin/wagtail_hooks.py index 5e9aa0ff52..8eef7bd01d 100644 --- a/wagtail/admin/wagtail_hooks.py +++ b/wagtail/admin/wagtail_hooks.py @@ -302,6 +302,14 @@ def page_listing_more_buttons(page, page_perms, is_parent=False, next_url=None): priority=50 ) + if is_parent: + yield Button( + _('Sort menu order'), + '?ordering=ord', + attrs={'title': _("Change ordering of child pages of '%(title)s'") % {'title': page.get_admin_display_title()}}, + priority=60 + ) + @hooks.register('register_admin_urls') def register_viewsets_urls():