Adding search bar to page listing header (not fully functional at this point)

pull/11032/head
Matt Westcott 2023-10-10 10:03:22 +01:00
rodzic 58d6c137b4
commit 30c68652c7
6 zmienionych plików z 148 dodań i 84 usunięć

Wyświetl plik

@ -6,67 +6,9 @@
{% block content %}
{% page_permissions parent_page as parent_page_perms %}
{% include 'wagtailadmin/pages/page_listing_header.html' with title=parent_page.get_admin_display_title page_perms=parent_page_perms %}
<form id="page-reorder-form">
{% csrf_token %}
{% if parent_page %}
{% if parent_page.is_root %}
<div class="nice-padding">
<div class="help-block help-info">
{% icon name='help' %}
{% if perms.wagtailcore.add_site %}
{% url 'wagtailsites:index' as wagtailsites_index_url %}
<p>
{% blocktrans trimmed %}
The root level is where you can add new sites to your Wagtail installation. Pages created here will not be accessible at any URL until they are associated with a site.
{% endblocktrans %}
{% if wagtailsites_index_url %}
<a href="{{ wagtailsites_index_url }}">{% trans "Configure a site now." %}</a>
{% endif %}
</p>
<p>
{% blocktrans trimmed %}
If you just want to add pages to an existing site, create them as children of the homepage instead.
{% endblocktrans %}
</p>
{% else %}
{% blocktrans trimmed %}
Pages created here will not be accessible at any URL. To add pages to an existing site, create them as children of the homepage.
{% endblocktrans %}
{% endif %}
</div>
</div>
{# get_url_parts will return None is the page has no site #}
{% elif not parent_page.get_url_parts %}
<div class="nice-padding">
<div class="help-block help-warning">
{% icon name='warning' %}
{% if perms.wagtailcore.add_site %}
{% url 'wagtailsites:index' as wagtailsites_index_url %}
{% blocktrans trimmed %}
There is no site set up for this location. Pages created here will not be accessible at any URL until a site is associated with this location.
{% endblocktrans %}
{% if wagtailsites_index_url %}
<a href="{{ wagtailsites_index_url }}">{% trans "Configure a site now." %}</a>
{% endif %}
{% else %}
{% blocktrans trimmed %}
There is no site record for this location. Pages created here will not be accessible at any URL.
{% endblocktrans %}
{% endif %}
</div>
</div>
{% endif %}
{% endif %}
{% component table %}
{% if is_paginated %}
{% include "wagtailadmin/shared/pagination_nav.html" with items=page_obj linkurl=index_url %}
{% endif %}
{% trans "Select all pages in listing" as select_all_text %}
{% include 'wagtailadmin/bulk_actions/footer.html' with select_all_obj_text=select_all_text app_label='wagtailcore' model_name='page' objects=pages %}
</form>
<div id="listing-results">
{% include 'wagtailadmin/pages/index_results.html' %}
</div>
{% endblock %}
{% block extra_js %}

Wyświetl plik

@ -0,0 +1,63 @@
{% load wagtailadmin_tags i18n %}
<form id="page-reorder-form">
{% csrf_token %}
{% if parent_page %}
{% if parent_page.is_root %}
<div class="nice-padding">
<div class="help-block help-info">
{% icon name='help' %}
{% if perms.wagtailcore.add_site %}
{% url 'wagtailsites:index' as wagtailsites_index_url %}
<p>
{% blocktrans trimmed %}
The root level is where you can add new sites to your Wagtail installation. Pages created here will not be accessible at any URL until they are associated with a site.
{% endblocktrans %}
{% if wagtailsites_index_url %}
<a href="{{ wagtailsites_index_url }}">{% trans "Configure a site now." %}</a>
{% endif %}
</p>
<p>
{% blocktrans trimmed %}
If you just want to add pages to an existing site, create them as children of the homepage instead.
{% endblocktrans %}
</p>
{% else %}
{% blocktrans trimmed %}
Pages created here will not be accessible at any URL. To add pages to an existing site, create them as children of the homepage.
{% endblocktrans %}
{% endif %}
</div>
</div>
{# get_url_parts will return None is the page has no site #}
{% elif not parent_page.get_url_parts %}
<div class="nice-padding">
<div class="help-block help-warning">
{% icon name='warning' %}
{% if perms.wagtailcore.add_site %}
{% url 'wagtailsites:index' as wagtailsites_index_url %}
{% blocktrans trimmed %}
There is no site set up for this location. Pages created here will not be accessible at any URL until a site is associated with this location.
{% endblocktrans %}
{% if wagtailsites_index_url %}
<a href="{{ wagtailsites_index_url }}">{% trans "Configure a site now." %}</a>
{% endif %}
{% else %}
{% blocktrans trimmed %}
There is no site record for this location. Pages created here will not be accessible at any URL.
{% endblocktrans %}
{% endif %}
</div>
</div>
{% endif %}
{% endif %}
{% component table %}
{% if is_paginated %}
{% include "wagtailadmin/shared/pagination_nav.html" with items=page_obj linkurl=index_url %}
{% endif %}
{% trans "Select all pages in listing" as select_all_text %}
{% include 'wagtailadmin/bulk_actions/footer.html' with select_all_obj_text=select_all_text app_label='wagtailcore' model_name='page' objects=pages %}
</form>

Wyświetl plik

@ -32,6 +32,27 @@
{% endif %}
{% endblock %}
{% block search_form %}
<form
class="search-form"
action="{{ index_url }}"
method="get"
novalidate
role="search"
data-controller="w-swap"
data-action="change->w-swap#searchLazy input->w-swap#searchLazy"
data-w-swap-src-value="{{ results_url }}"
data-w-swap-target-value="#listing-results"
>
{% for field in search_form %}
{% include "wagtailadmin/shared/field.html" with field=field classname="w-mb-0 -w-mt-2.5" sr_only_label=True icon="search" %}
{% endfor %}
{% comment %}Add an initial disabled & hidden submit button so that pressing 'enter' will not submit form. Reload not required as the content is dynamically loaded.{% endcomment %}
<div class="visuallyhidden"><input disabled type="submit" aria-hidden="true"/></div>
<div class="submit visuallyhidden"><input type="submit" value="Search" class="button" /></div>
</form>
{% endblock %}
{% block side_panels %}
{% include "wagtailadmin/shared/side_panels.html" with in_explorer=True %}
{% endblock side_panels %}

Wyświetl plik

@ -28,6 +28,7 @@
{% endblock %}
</div>
</header>
{% block search_form %}{% endblock %}
{% block side_panels %}
{% if side_panels %}

Wyświetl plik

@ -34,6 +34,11 @@ urlpatterns = [
listing.IndexView.as_view(),
name="wagtailadmin_explore",
),
path(
"pages/<int:parent_page_id>/results/",
listing.IndexResultsView.as_view(),
name="wagtailadmin_explore_results",
),
# bulk actions
path(
"bulk/<str:app_label>/<str:model_name>/<str:action>/",

Wyświetl plik

@ -6,6 +6,7 @@ from django.utils.translation import gettext
from django.utils.translation import gettext_lazy as _
from wagtail import hooks
from wagtail.admin.forms.search import SearchForm
from wagtail.admin.ui.components import MediaContainer
from wagtail.admin.ui.side_panels import (
PageStatusSidePanel,
@ -24,8 +25,7 @@ from wagtail.admin.views.generic.permissions import PermissionCheckedMixin
from wagtail.permission_policies.pages import Page, PagePermissionPolicy
class IndexView(PermissionCheckedMixin, BaseListingView):
template_name = "wagtailadmin/pages/index.html"
class BaseIndexView(PermissionCheckedMixin, BaseListingView):
permission_policy = PagePermissionPolicy()
any_permission_required = {
"add",
@ -103,6 +103,17 @@ class IndexView(PermissionCheckedMixin, BaseListingView):
self.locale = None
self.translations = []
# Search
self.query_string = None
if "q" in self.request.GET:
self.search_form = SearchForm(
self.request.GET, placeholder=_("Search pages…")
)
if self.search_form.is_valid():
self.query_string = self.search_form.cleaned_data["q"]
else:
self.search_form = SearchForm(placeholder=_("Search pages…"))
return super().get(request)
def get_ordering(self):
@ -178,6 +189,9 @@ class IndexView(PermissionCheckedMixin, BaseListingView):
def get_index_url(self):
return reverse("wagtailadmin_explore", args=[self.parent_page.id])
def get_results_url(self):
return reverse("wagtailadmin_explore_results", args=[self.parent_page.id])
def get_table_kwargs(self):
kwargs = super().get_table_kwargs()
kwargs["use_row_ordering_attributes"] = self.show_ordering_column
@ -192,6 +206,42 @@ class IndexView(PermissionCheckedMixin, BaseListingView):
}
return kwargs
def get_context_data(self, **kwargs):
self.show_ordering_column = self.ordering == "ord"
if self.show_ordering_column:
self.columns = self.columns.copy()
self.columns[0] = OrderingColumn("ordering", width="10px", sort_key="ord")
self.i18n_enabled = getattr(settings, "WAGTAIL_I18N_ENABLED", False)
context = super().get_context_data(**kwargs)
context.update(
{
"parent_page": self.parent_page,
"ordering": self.ordering,
"index_url": self.get_index_url(),
"results_url": self.get_results_url(),
"search_form": self.search_form,
}
)
return context
def get_translations(self):
return [
{
"locale": translation.locale,
"url": reverse("wagtailadmin_explore", args=[translation.id]),
}
for translation in self.parent_page.get_translations()
.only("id", "locale")
.select_related("locale")
]
class IndexView(BaseIndexView):
template_name = "wagtailadmin/pages/index.html"
def get_side_panels(self):
side_panels = [
PageStatusSidePanel(
@ -207,34 +257,16 @@ class IndexView(PermissionCheckedMixin, BaseListingView):
return MediaContainer(side_panels)
def get_context_data(self, **kwargs):
self.show_ordering_column = self.ordering == "ord"
if self.show_ordering_column:
self.columns = self.columns.copy()
self.columns[0] = OrderingColumn("ordering", width="10px", sort_key="ord")
self.i18n_enabled = getattr(settings, "WAGTAIL_I18N_ENABLED", False)
context = super().get_context_data(**kwargs)
side_panels = self.get_side_panels()
context.update(
{
"parent_page": self.parent_page,
"ordering": self.ordering,
"side_panels": side_panels,
"media": side_panels.media,
"index_url": self.get_index_url(),
}
)
return context
def get_translations(self):
return [
{
"locale": translation.locale,
"url": reverse("wagtailadmin_explore", args=[translation.id]),
}
for translation in self.parent_page.get_translations()
.only("id", "locale")
.select_related("locale")
]
class IndexResultsView(BaseIndexView):
template_name = "wagtailadmin/pages/index_results.html"