[feat] Reintroduced ordering column and remove search input box and related views

pull/7618/head
Shohan 2021-06-30 00:32:14 +05:30 zatwierdzone przez Matt Westcott
rodzic d2c09ec5af
commit e524ccb995
9 zmienionych plików z 40 dodań i 95 usunięć

Wyświetl plik

@ -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;
})()

Wyświetl plik

@ -52,7 +52,6 @@
<script src="{% versioned_static 'wagtailadmin/js/core.js' %}"></script>
<script src="{% versioned_static 'wagtailadmin/js/vendor.js' %}"></script>
<script src="{% versioned_static 'wagtailadmin/js/wagtailadmin.js' %}"></script>
<script src="{% versioned_static 'wagtailadmin/js/bulk-actions.js' %}"></script>
{% hook_output 'insert_global_admin_js' %}

Wyświetl plik

@ -9,13 +9,12 @@
{% explorer_breadcrumb parent_page %}
</header>
<form method="GET" id="filter_search"></form>
<form id="page-reorder-form">
{% 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 %}
<script src="{% versioned_static 'wagtailadmin/js/modal-workflow.js' %}"></script>
<script src="{% versioned_static 'wagtailadmin/js/privacy-switch.js' %}"></script>
{% if not show_ordering_column %}
<script defer src="{% versioned_static 'wagtailadmin/js/bulk-actions.js' %}"></script>
{% endif %}
<script type="text/javascript">
{% if ordering == 'ord' %}
$(function() {

Wyświetl plik

@ -18,7 +18,7 @@
{% if parent_page %}
{% page_permissions parent_page as parent_page_perms %}
<tr class="index {% if not parent_page.live %} unpublished{% endif %} {% block parent_page_row_classname %}{% endblock %}">
{% if is_moving %}<td></td>{% endif %}
<td></td>
<td class="title" {% if show_ordering_column %}colspan="2"{% endif %}>
{% block parent_page_title %}
{% endblock %}
@ -46,9 +46,13 @@
{% for page in pages %}
{% page_permissions page as page_perms %}
<tr {% if ordering == "ord" %}id="page_{{ page.id|unlocalize }}" data-page-title="{{ page.get_admin_display_title }}"{% endif %} class="{% if not page.live %}unpublished{% endif %} {% block page_row_classname %}{% endblock %}">
{% if show_ordering_column %}
<td class="ord">{% if orderable and ordering == "ord" %}<div class="handle icon icon-grip text-replace">{% trans 'Drag' %}</div>{% endif %}</td>
{% else %}
<td>
<input data-page-status="{% if page.live %}live{% else %}draft{% endif %}" data-page-id="{{page.id}}" class="bulk-action-checkbox" aria-label="Page select checkbox" type="checkbox" />
</td>
{% endif %}
<td class="title" valign="top" data-listing-page-title>
{% block page_title %}
{% endblock %}
@ -77,7 +81,4 @@
{% block no_results %}{% endblock %}
{% endif %}
</tbody>
</table>
<script>
window.AddBulkActionEventListeners()
</script>
</table>

Wyświetl plik

@ -17,6 +17,21 @@ ordering: the current sort parameter
{% endcomment %}
<tr class="table-headers">
{% if show_ordering_column %}
<th class="ord{% if orderable and ordering == 'ord' %} ord--active{% endif %}">
{% if orderable %}
{% if ordering == "ord" %}
<a href="{% url 'wagtailadmin_explore' parent_page.id %}" title="{% trans 'Disable ordering of child pages' %}">
{% icon name="order" %}{% trans 'Sort' %}
</a>
{% else %}
<a href="{% url 'wagtailadmin_explore' parent_page.id %}?ordering=ord" title="{% trans 'Enable ordering of child pages' %}">
{% icon name="order" %}{% trans 'Sort' %}
</a>
{% endif %}
{% endif %}
</th>
{% else %}
<th class="bulk-actions-filter-checkbox" data-parent-id="{{ parent_page.id }}">
<div>
<input type="checkbox" aria-label="Bulk action checkbox" />
@ -33,12 +48,9 @@ ordering: the current sort parameter
</div>
</div>
</th>
<th class="search">
<div class="nav-search">
<button class="button" form="filter_search" type="submit">{% trans "Search" %}</button>
<label for="page-search-q">Search</label>
<input aria-label='{% trans "Search text" %}' type="text" form="filter_search" value="{{filter_query}}" name="filters" placeholder='{% trans "Search" %}'>
</div>
{% endif %}
<th>
{% trans 'Page' %}
</th>
{% if show_parent %}
<th class="parent">

Wyświetl plik

@ -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/<int:parent_page_id>/', listing.index, name='wagtailadmin_explore'),
path('pages/filter-count/', filters.filter_count, name='wagtailadmin_filter_count'),
path('pages/<int:parent_page_id>/filter-count/', filters.filter_count, name='wagtailadmin_filter_count'),
# bulk actions
path('pages/multiple/<str:action>/', bulk_actions, name='wagtailadmin_bulk_action'),

Wyświetl plik

@ -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()))

Wyświetl plik

@ -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():

Wyświetl plik

@ -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():