Skip to content

Commit

Permalink
Merge pull request #2031 from uktrade/uat
Browse files Browse the repository at this point in the history
PROD release
  • Loading branch information
hnryjmes authored Jun 17, 2024
2 parents ff1d940 + a8ac747 commit 6b44ba4
Show file tree
Hide file tree
Showing 28 changed files with 403 additions and 185 deletions.
79 changes: 30 additions & 49 deletions caseworker/cases/views/denials.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def parties_to_search(self):
)
return parties_to_search

def get_search_params(self):
def get_initial_search_params(self):
"""
This is building the query_string that will be executed directly by the backend
The field query is contained within () without this ES gets confused and searches
Expand All @@ -56,6 +56,7 @@ def get_search_params(self):
search_filter.append(f'name:({party["name"]})')
search_filter.append(f'address:({party["address"]})')
country_list.add(party["country"]["name"])

return (" ".join(search_filter), country_list)

def get_form_action(self):
Expand Down Expand Up @@ -86,69 +87,49 @@ def get_form_action(self):
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()

_, session_countries_list, _ = self.get_search_params_from_session()
_, country_list = self.get_search_params()
kwargs["countries"] = session_countries_list or country_list
_, country_list = self.get_initial_search_params()
kwargs["countries"] = country_list

kwargs["form_action"] = self.get_form_action()

return kwargs

def get_initial(self):
session_search_string, _, session_selected_countries = self.get_search_params_from_session()
default_search_string, default_country_list = self.get_search_params()
search_string, selected_countries = self.get_initial_search_params()

return {
"search_string": session_search_string or default_search_string,
"country_filter": session_selected_countries or default_country_list,
"search_string": search_string,
"country_filter": selected_countries,
}

def form_valid(self, form):
search_id = self.request.GET.get("search_id", 1)
countries_list = set(c[0] for c in form.fields["country_filter"].choices)
search_string = form.cleaned_data["search_string"]
selected_countries = form.cleaned_data["country_filter"]
def get_search_params(self, form):
try:
form_data = form.cleaned_data
except AttributeError:
form_data = form.initial

self.request.session["search_params"] = {search_id: (search_string, countries_list, selected_countries)}
return self.render_to_response(self.get_context_data(form=form))
return form_data["search_string"], {"country": form_data["country_filter"]}

def get_search_params_from_session(self):
# This is required since the search_string shouldn't be sent in the query string due to sensative data
# so we require a search_string to be sent via post. Since the pagination currently works as a get only
# the query_string set by the user gets lost we should aim to move away from sessions once we have
# pagination that works with a post
search_id = self.request.GET.get("search_id", 1)

if self.request.session.get("search_params") and self.request.session.get("search_params").get(search_id):
return self.request.session["search_params"][search_id]
# We store a tuble of 3 values if nothing is found return all 3 as None.
return (None, None, None)
def form_valid(self, form):
return self.render_to_response(self.get_context_data(form=form))

def get_context_data(self, **kwargs):
total_pages = 0
search_results = []

default_search_string, country_list = self.get_search_params()

session_search_string, _, session_selected_countries = self.get_search_params_from_session()
search = session_search_string or default_search_string
country_filter = country_list if session_selected_countries is None else session_selected_countries

if search:
filter = {
"country": set(country_filter),
context = super().get_context_data(**kwargs)

form = context["form"]
search, country_filter = self.get_search_params(form)
search_results, _ = search_denials(request=self.request, search=search, filter=country_filter)
total_pages = search_results.get("total_pages", 0)

context.update(
{
"search_string": search,
"case": self.case,
"total_pages": total_pages,
"search_results": search_results,
"parties": self.parties_to_search,
"search_score_feature_flag": settings.FEATURE_FLAG_DENIALS_SEARCH_SCORE,
}
search_results, _ = search_denials(request=self.request, search=search, filter=filter)
total_pages = search_results.get("total_pages", 0)

context = super().get_context_data(
search_string=search,
case=self.case,
total_pages=total_pages,
search_results=search_results,
parties=self.parties_to_search,
search_score_feature_flag=settings.FEATURE_FLAG_DENIALS_SEARCH_SCORE,
**kwargs,
)

return context
2 changes: 1 addition & 1 deletion caseworker/templates/case/denial-for-case.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ <h2 class="govuk-heading-l govuk-!-margin-top-6 govuk-!-margin-bottom-3">
<div><p class="govuk-label">No matching denials</p></div>
{% endif %}
</form>
{% pagination %}
{% pagination link_type="form" form_id="denials-search-form" %}
</div>
</div>
{% endblock %}
1 change: 0 additions & 1 deletion caseworker/templates/case/slices/destinations.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ <h2 class="govuk-heading-m">{{ destinations|length }} destination{{ destinations
<div class="lite-buttons-row">

<button class="govuk-button" formaction="{% url 'cases:denials' queue_pk=queue.id pk=case.id %}" >View related denials</button>
<input type="hidden" id="search_id" name="search_id" value="{% now "U" %}">
<!--<button id="button-edit-destinations-flags" class="govuk-button govuk-button--secondary" data-module="govuk-button">
{% lcs 'cases.ApplicationPage.EDIT_DESTINATION_FLAGS' %}
</button>-->
Expand Down
60 changes: 36 additions & 24 deletions core/assets/styles/components/_pagination.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ $item-size: govuk-spacing(7);
justify-content: center;
list-style-type: none;
margin: 0;
margin-right: govuk-spacing(6); // Visually center the list
padding: 0;

@include govuk-media-query($until: tablet) {
Expand All @@ -71,33 +70,13 @@ $item-size: govuk-spacing(7);

&__list-item {
@include govuk-font($size: 19);
display: flex;
justify-content: center;
line-height: $item-size !important;
position: relative;
text-align: center;
width: $item-size;

a {
@extend .govuk-link;
@extend .govuk-link--no-visited-state;
display: inline-block;
line-height: $item-size !important;
position: relative;
text-decoration: none;
width: $item-size;

&:hover {
&::after {
background: currentColor;
bottom: 0;
content: "";
height: 2px;
left: govuk-spacing(1);
position: absolute;
right: govuk-spacing(1);
}
}
}

&--selected {
font-weight: bold;

Expand All @@ -111,6 +90,39 @@ $item-size: govuk-spacing(7);
right: govuk-spacing(1);
}
}

.lite-pagination__link {
width: 100%;
}
}

&__link {
@extend .govuk-link;
@extend .govuk-link--no-visited-state;
@include govuk-font($size: 19);
align-items: center;
background-color: inherit;
border: 0;
color: $govuk-link-colour;
cursor: pointer;
display: flex;
justify-content: center;
line-height: $item-size !important;
position: relative;
text-decoration: none;
white-space: nowrap;

&:hover {
&::after {
background: currentColor;
bottom: 0;
content: "";
position: absolute;
left: 0;
right: 0;
height: 2px;
}
}
}

&__list-ellipsis {
Expand All @@ -120,7 +132,7 @@ $item-size: govuk-spacing(7);
display: flex;
justify-content: center;
letter-spacing: 3px;
line-height: $item-size!important;
line-height: $item-size !important;
margin: 0 govuk-spacing(2);
position: relative;
text-align: center;
Expand Down
10 changes: 9 additions & 1 deletion core/builtins/custom_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,8 +1026,14 @@ def pagination_params(url, page):
return urlparse.urlunparse(url_parts)


PAGINATION_LINK_TYPES = ["anchor", "form"]


@register.inclusion_tag("components/pagination.html", takes_context=True)
def pagination(context, *args, **kwargs):
def pagination(context, *args, link_type="anchor", form_id=None, **kwargs):
if link_type not in PAGINATION_LINK_TYPES:
raise ValueError(f"Incorrect `link_type`. Choose either {' or '.join(PAGINATION_LINK_TYPES)}.")

class PageItem:
def __init__(self, number, url, selected=False):
self.number = number
Expand Down Expand Up @@ -1090,5 +1096,7 @@ def __init__(self, text="..."):
context["pages"] = pages
context["previous_page_number"] = current_page - 1
context["next_page_number"] = current_page + 1
context["paging_link_type"] = link_type
context["paging_form_id"] = form_id

return context
54 changes: 43 additions & 11 deletions core/templates/components/pagination.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@
<nav role="navigation" aria-label="Pagination Navigation">
<div class="lite-pagination__container">
{% if previous_link_url %}
<a id="link-previous-page" href="{{ previous_link_url }}" id="link-previous-page" class="lite-pagination__navigation-link lite-pagination__link">
{% svg 'previous' %}
<span data-number="{{ previous_page_number }}">Previous page</span>
</a>
{% if paging_link_type == "anchor" %}
<a id="link-previous-page" href="{{ previous_link_url }}" id="link-previous-page" class="lite-pagination__navigation-link lite-pagination__link">
{% svg 'previous' %}
<span data-number="{{ previous_page_number }}">Previous page</span>
</a>
{% elif paging_link_type == "form" %}
<button
class="lite-pagination__navigation-link lite-pagination__link"
form="{{ paging_form_id }}"
formaction="{{ previous_link_url }}"
>
{% svg 'previous' %}
<span data-number="{{ previous_page_number }}">Previous page</span>
</button>
{% endif %}
{% else %}
<p id="link-previous-page" class="lite-pagination__navigation-link lite-pagination__navigation-link--disabled">
{% svg 'previous' %}
Expand All @@ -23,9 +34,19 @@
{% if item.selected %}
{{ item.number }}
{% else %}
<a href="{{ item.url }}" {% if not item.selected %}aria-label="Goto Page {{ item.number}}" {% endif %} class="lite-pagination__link" data-number="{{ item.number }}">
{{ item.number }}
</a>
{% if paging_link_type == "anchor" %}
<a href="{{ item.url }}" {% if not item.selected %}aria-label="Goto Page {{ item.number}}" {% endif %} class="lite-pagination__link" data-number="{{ item.number }}">
{{ item.number }}
</a>
{% elif paging_link_type == "form" %}
<button
class="lite-pagination__navigation-link lite-pagination__link"
form="{{ paging_form_id }}"
formaction="{{ item.url }}"
>
{{ item.number }}
</button>
{% endif %}
{% endif %}
</li>
{% elif item.type == 'page_ellipsis' %}
Expand All @@ -38,10 +59,21 @@
{% endif %}

{% if next_link_url %}
<a id="link-next-page" href="{{ next_link_url }}" id="link-next-page" class="lite-pagination__navigation-link lite-pagination__link" >
<span data-number="{{ next_page_number }}">Next page</span>
{% svg 'next' %}
</a>
{% if paging_link_type == "anchor" %}
<a id="link-next-page" href="{{ next_link_url }}" id="link-next-page" class="lite-pagination__navigation-link lite-pagination__link" >
<span data-number="{{ next_page_number }}">Next page</span>
{% svg 'next' %}
</a>
{% elif paging_link_type == "form" %}
<button
class="lite-pagination__navigation-link lite-pagination__link"
form="{{ paging_form_id }}"
formaction="{{ next_link_url }}"
>
<span data-number="{{ next_page_number }}">Next page</span>
{% svg 'next' %}
</button>
{% endif %}
{% else %}
<p id="link-next-page" class="lite-pagination__navigation-link lite-pagination__navigation-link--disabled">
<span>Next page</span>
Expand Down
4 changes: 2 additions & 2 deletions exporter/applications/forms/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def reference_name_form(application_id=None):
TextInput(name="name"),
],
back_link=back_to_task_list(application_id),
default_button_name=conditional(application_id, generic.SAVE_AND_RETURN, generic.CONTINUE),
default_button_name=conditional(application_id, generic.SAVE_AND_RETURN, generic.SAVE_AND_CONTINUE),
)


Expand Down Expand Up @@ -60,5 +60,5 @@ def told_by_an_official_form(application_id=None):
),
],
back_link=back_to_task_list(application_id),
default_button_name=conditional(application_id, generic.SAVE_AND_RETURN, generic.CONTINUE),
default_button_name=conditional(application_id, generic.SAVE_AND_RETURN, generic.SAVE_AND_CONTINUE),
)
6 changes: 4 additions & 2 deletions exporter/applications/views/end_use_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ def init(request, **kwargs):
pass

summary_list_form_view = SummaryListFormView()
summary_list_form_view.cancel_link_text = "cancel"
summary_list_form_view.cancel_link_url = self.success_url
summary_list_form_view.back_url = self.success_url
summary_list_form_view.back_link_text = "Back to application overview"

summary_list_form_view.instruction_text = "Review your answers below and make any amends you need to. Click 'Save and continue' to save your progress."

summary_list_form_view.init = init
summary_list_form_view.request = request
Expand Down
3 changes: 1 addition & 2 deletions exporter/applications/views/parties/consignees.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def get(self, request, **kwargs):
kwargs = {"pk": application_id, "obj_pk": application["consignee"]["id"]}
context = {
"application": application,
"title": ConsigneePage.TITLE,
"edit_url": reverse("applications:edit_consignee", kwargs=kwargs),
"remove_url": reverse("applications:remove_consignee", kwargs=kwargs),
"answers": convert_party(
Expand All @@ -28,7 +27,7 @@ def get(self, request, **kwargs):
editable=application["status"]["value"] == "draft",
),
}
return render(request, "applications/end-user.html", context)
return render(request, "applications/consignee.html", context)
else:
return redirect(reverse("applications:add_consignee", kwargs={"pk": application_id}))

Expand Down
2 changes: 1 addition & 1 deletion exporter/applications/views/security_approvals/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ class SecurityApprovalsSummaryView(LoginRequiredMixin, ApplicationMixin, Templat
def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs)
context["application"] = self.application
context["back_link_url"] = reverse("applications:security_approvals", kwargs={"pk": self.kwargs["pk"]})
context["back_link_url"] = reverse("applications:task_list", kwargs={"pk": self.kwargs["pk"]})
context["security_classified_approvals_types"] = SecurityClassifiedApprovalsType
return context
Loading

0 comments on commit 6b44ba4

Please sign in to comment.