Skip to content

Commit

Permalink
Tp2000 1517 implement improved quota views for users (#1307)
Browse files Browse the repository at this point in the history
* working through current/approved up to transaction issues

* updating to use .all() on querysearch; adding actions column on QuotaDetail view

* fixing broken test

* adding title caption

* copy changes requested by UR team

* tidying up tabs/sub_quotas.jinja

* alligning tab headings with tab names

* fixing conditional headings

* changing query to .current

* fix
  • Loading branch information
CPrich905 authored Oct 21, 2024
1 parent 874f05b commit 534d4da
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 54 deletions.
7 changes: 7 additions & 0 deletions common/jinja2/layouts/detail.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
{% if title_caption %}
{% block page_subtitle%}
<span class="govuk-caption-xl">
{{ title_caption }}
</span>
{% endblock %}
{% endif %}
<h1 class="govuk-heading-xl">{{ page_title }}</h1>
</div>
</div>
Expand Down
23 changes: 12 additions & 11 deletions quotas/jinja2/includes/quotas/actions.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@
<div class="app-related-items" role="complementary">
<h2 class="govuk-heading-s" id="subsection-title">Actions</h2>
<ul class="govuk-list govuk-!-font-size-16">
<li><a class="govuk-link" href="{{ url('quota_definition-ui-list', args=[object.sid]) }}">View and edit quota data</a></li>
<li><a class="govuk-link" href="{{ url('quota_definition-ui-create', args=[object.sid]) }}">Create definition period</a></li>
<br>
<li><a class="govuk-link" href="{{ url('sub_quota_definitions-ui-create') }}">Create quota associations</a></li>
<br>
<li><a class="govuk-link" href="{{ url('quota_suspension_or_blocking-ui-create', args=[object.sid]) }}">Create suspension or blocking period</a></li>
<br>
<li><a class="govuk-link" href="{{ measures_url }}">View all measures</a></li>
<br>
<strong class=govuk-heading-xs">Edit and delete quota</strong>
{% set edit_url = object.get_url('edit') %}
{% if edit_url %}
<li><a class="govuk-link" href="{{ edit_url }}">Edit this {{object._meta.verbose_name}}</a></li>
Expand All @@ -19,8 +11,17 @@
{% if delete_url %}
<li><a class="govuk-link" href="{{ delete_url }}">Delete this {{object._meta.verbose_name}}</a></li>
{% endif %}
<br><br>
<li><a class="govuk-link" href="{{ uk_tariff_url }}" target="_blank" noopener noreferrer>View this quota on the UK Integrated Online Tariff </a></li>
<br>
<strong class=govuk-heading-xs">Create quota data</strong>
<li><a class="govuk-link" href="{{ url('quota_definition-ui-create', args=[object.sid]) }}">Create definition period</a></li>
<li><a class="govuk-link" href="{{ url('sub_quota_definitions-ui-create') }}">Create quota associations</a></li>
<li><a class="govuk-link" href="{{ url('quota_suspension_or_blocking-ui-create', args=[object.sid]) }}">Create suspension or blocking period</a></li>
<br>
<strong class=govuk-heading-xs">View and edit quota data</strong>
<li><a class="govuk-link" href="{{ url('quota_definition-ui-list', args=[object.sid]) }}">View and edit quota data</a></li>
<li><a class="govuk-link" href="{{ measures_url }}">View all measures</a></li>
<li><a class="govuk-link" href="{{ uk_tariff_url }}" target="_blank" noopener noreferrer>View this quota on the UK Integrated Online Tariff </a></li>
</ul>
</div>
</div>
2 changes: 1 addition & 1 deletion quotas/jinja2/includes/quotas/tabs/blocking_periods.jinja
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="quota__blocking-periods govuk-grid-row">
<div class="quota__blocking-periods__content govuk-grid-column-three-quarters">
<h2 class="govuk-heading-l">Details</h2>
<h2 class="govuk-heading-l">Blocking periods</h2>
{% if blocking_period %}
{{ govukSummaryList({
"rows": [
Expand Down
4 changes: 2 additions & 2 deletions quotas/jinja2/includes/quotas/tabs/core_data.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

<div class="quota__core-data govuk-grid-row">
<div class="quota__core-data__content govuk-grid-column-three-quarters">
<h2 class="govuk-heading-l">Details</h2>
<h2 class="govuk-heading-l">Order number details</h2>
{{ govukSummaryList({
"rows": [
{
"key": {"text": "Order Number"},
"key": {"text": "Order number"},
"value": {"text": object.order_number},
"actions": {"items": []}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="quota__definition-details govuk-grid-row">
<div class="quota__definition-details__content govuk-grid-column-three-quarters">
<h2 class="govuk-heading-l">Details</h2>
<h2 class="govuk-heading-l">Definition details</h2>
{% if current_definition %}
{{ govukSummaryList({
"rows": [
Expand Down
2 changes: 1 addition & 1 deletion quotas/jinja2/includes/quotas/tabs/measures.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<div class="quota__measures govuk-grid-row">
<div class="quota__measures__content govuk-grid-column-three-quarters">
<h2 class="govuk-heading-l">Details</h2>
<h2 class="govuk-heading-l">Measures</h2>
{% if measures %}
<p class="govuk-body">Showing currently active measures.</p>
{{ govukTable({
Expand Down
70 changes: 53 additions & 17 deletions quotas/jinja2/includes/quotas/tabs/sub_quotas.jinja
Original file line number Diff line number Diff line change
@@ -1,33 +1,69 @@
{% set table_rows = [] %}
{% for quota_association in quota_associations %}
{% for object in sub_quota_associations %}
{% set sub_quota_link %}
<a class="govuk-link govuk-!-font-weight-bold"
href="{{ url('quota-ui-detail', args=[quota_association.sub_quota.order_number.sid]) }}">
{{ quota_association.sub_quota.order_number }}
href="{{ url('quota-ui-detail', args=[object.sub_quota.order_number.sid]) }}">
{{ object.sub_quota.order_number }}
</a>
{% endset %}
{% set actions_html %}
<a class="govuk-link" href="{{ object.sub_quota.version_at(request.user.current_workbasket.transactions.last()).get_association_edit_url() }}">Edit</a>
<br/>
<a class="govuk-link" href="{{ url('quota_association-ui-delete', args=[object.pk]) }}">Delete</a>
{% endset %}
{{ table_rows.append([
{"html": sub_quota_link},
{"html": quota_association.sub_quota_relation_type},
{"text": quota_association.coefficient},
{"html": object.get_sub_quota_relation_type_display()},
{"text": object.coefficient},
{"text": actions_html }
]) or "" }}
{% endfor %}

{% for object in main_quota_associations %}
{% set main_quota_link %}
<a class="govuk-link govuk-!-font-weight-bold"
href="{{ url('quota-ui-detail', args=[object.main_quota.order_number.sid]) }}">
{{ object.main_quota.order_number }}
</a>
{% endset %}
{% set actions_html %}
<a class="govuk-link" href="{{ object.sub_quota.version_at(request.user.current_workbasket.transactions.last()).get_association_edit_url() }}">Edit</a>
<br/>
<a class="govuk-link" href="{{ url('quota_association-ui-delete', args=[object.pk]) }}">Delete</a>
{% endset %}

{{ table_rows.append([
{"html": main_quota_link},
{"html": object.get_sub_quota_relation_type_display()},
{"text": object.coefficient},
{"text": actions_html }
]) or "" }}
{% endfor %}

<div class="quota__sub-quotas govuk-grid-row">
<div class="quota__sub-quotas__content govuk-grid-column-three-quarters">
<h2 class="govuk-heading-l">Details</h2>
{% if quota_associations %}
{{ govukTable({
"head": [
{"text": "Sub-quota order number"},
{"text": "Relation type"},
<h2 class="govuk-heading-l">Quota associations</h2>
{% if sub_quota_associations or main_quota_associations %}
{% if main_quota_associations %}
<h3>Main quota</h3>
{% elif sub_quota_associations %}
<h3>Sub-quotas</h3>
{% endif %}
{{
govukTable({
"head": [
{"text": "Order number"},
{"text": "Relationship type"},
{"text": "Co-efficient"},
],
"rows": table_rows
}) }}
{% else %}
<p class="govuk-body">No active sub-quotas.</p>
{% endif %}
{"text": "Actions"}
],
"rows": table_rows
})
}}
{% else %}
<p class="govuk-body">No active main or sub-quotas.</p>
{% endif %}

</div>
{% include "includes/quotas/actions.jinja"%}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="quota__suspension-periods govuk-grid-row">
<div class="quota__suspension-periods__content govuk-grid-column-three-quarters">
<h2 class="govuk-heading-l">Details</h2>
<h2 class="govuk-heading-l">Suspension periods</h2>
{% if suspension_period %}
{{ govukSummaryList({
"rows": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

{% from "components/table/macro.njk" import govukTable %}

{% set page_title = "Update sub-quota definition and association" %}
{% set page_title = "Edit sub-quota definition and association" %}

{% block content %}
<h1 class="govuk-heading-xl">{{ page_title }}</h1>
<h2 class="govuk-heading">Main quota definition details</h2>
{% set main_definition = view.get_main_definition() %}
{% set table_rows = [] %}
Expand Down
23 changes: 18 additions & 5 deletions quotas/jinja2/quotas/definitions.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@
{% set page_title = "Quota ID: " ~ quota.order_number ~ " - Data" %}
{% set find_edit_url = url("quota-ui-list") %}

{% if sub_quotas %}
{% set page_subtitle = "Main quota" %}
{% elif main_quotas %}
{% set page_subtitle = "Sub-quota" %}
{% endif %}

{% set links = [
{
"text": "Quota definition periods",
"href": url('quota_definition-ui-list', kwargs={"sid": quota.sid}),
"selected": quota_type == None
},
{
"text": "Sub-quotas",
"href": url('quota_definition-ui-list-filter', kwargs={"sid": quota.sid, "quota_type": "sub_quotas"}),
"selected": quota_type == "sub_quotas",
"text": "Quota associations",
"href": url('quota_definition-ui-list-filter', kwargs={"sid": quota.sid, "quota_type": "quota_associations"}),
"selected": quota_type == "quota_associations",
},
{
"text": "Blocking periods",
Expand All @@ -43,9 +49,16 @@
{% endblock %}

{% block content %}

{% if page_subtitle %}
<span class="govuk-caption-xl">
{% block page_subtitle %}
{{ page_subtitle }}
{% endblock %}
</span>
{% endif %}
<h1 class="govuk-heading-xl">{{ page_title }}</h1>


{{ fake_tabs(links) }}
<div class="quota-definitions">
{% set base_url = url('quota_definition-ui-list', args=[quota.sid] ) %}
Expand All @@ -54,7 +67,7 @@
{% include "quotas/tables/blocking_periods.jinja" %}
{% elif quota_type == "suspension_periods" %}
{% include "quotas/tables/suspension_periods.jinja" %}
{% elif quota_type == "sub_quotas" %}
{% elif quota_type == "quota_associations" %}
{% include "quotas/tables/sub_quotas.jinja" %}
{% else %}
{% include "quotas/tables/definitions.jinja" %}
Expand Down
12 changes: 9 additions & 3 deletions quotas/jinja2/quotas/detail.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
{% from "components/summary-list/macro.njk" import govukSummaryList %}
{% from "components/table/macro.njk" import govukTable %}

{% set page_title = "Quota ID: " ~ object.order_number %}
{% set page_title = "Quota order number: " ~ object.order_number %}
{% set find_edit_url = url("quota-ui-list") %}

{% if sub_quota_associations %}
{% set title_caption = "Main quota" %}
{% elif main_quota_associations %}
{% set title_caption = "Sub-quota" %}
{% endif %}

{% set core_data_tab_html %}{% include "includes/quotas/tabs/core_data.jinja" %}{% endset %}
{% set definition_details_html %}{% include "includes/quotas/tabs/definition_details.jinja" %}{% endset %}
{% set sub_quotas_html %}{% include "includes/quotas/tabs/sub_quotas.jinja" %}{% endset %}
Expand All @@ -30,8 +36,8 @@
}
},
{
"label": "Sub-quotas",
"id": "sub-quotas",
"label": "Quota associations",
"id": "quotas-associations",
"panel": {
"html": sub_quotas_html
}
Expand Down
2 changes: 1 addition & 1 deletion quotas/jinja2/quotas/tables/definitions.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
{% endfor %}

{% set sid %}
{{ create_sortable_anchor(request, "sid", "Quota definition sid", base_url) }}
{{ create_sortable_anchor(request, "sid", "Quota definition SID", base_url) }}
{% endset %}

{% set start_date %}
Expand Down
48 changes: 42 additions & 6 deletions quotas/jinja2/quotas/tables/sub_quotas.jinja
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

<h2 class="govuk-heading-l">Sub-quotas</h2>

<h2 class="govuk-heading-l">Quota associations</h2>
{% set table_rows = [] %}
{% if sub_quotas %}
<h3 class="govuk-heading-m">Sub-quotas</h3>
{% for object in sub_quotas %}
{% set definition_link -%}
<a class="govuk-link" href="{{ url('quota-ui-detail', args=[object.sub_quota.order_number.sid]) }}#definition-details">{{ object.sub_quota.sid }}</a>
Expand All @@ -11,9 +11,9 @@
<a class="govuk-link" href="{{ url('quota-ui-detail', args=[object.sub_quota.order_number.sid]) }}">{{ object.sub_quota.order_number.order_number }}</a>
{% endset %}
{% set actions_html %}
<a class="govuk-link" href="{{ object.sub_quota.version_at(request.user.current_workbasket.transactions.last()).get_association_edit_url() }}">Edit association</a>
<a class="govuk-link" href="{{ object.sub_quota.version_at(request.user.current_workbasket.transactions.last()).get_association_edit_url() }}">Edit</a>
<br/>
<a class="govuk-link" href="{{ url('quota_association-ui-delete', args=[object.pk]) }}">Delete association</a>
<a class="govuk-link" href="{{ url('quota_association-ui-delete', args=[object.pk]) }}">Delete</a>
{% endset %}

{{ table_rows.append([
Expand All @@ -30,7 +30,43 @@
{{ govukTable({
"head": [
{"text": "Quota definition SID"},
{"text": "Sub-quota order number"},
{"text": "Order number"},
{"text": "Start date"},
{"text": "End date"},
{"text": "Relationship type"},
{"text": "Coefficient"},
{"text": "Actions"},
],
"rows": table_rows
}) }}
{% elif main_quotas %}
<h3 class="govuk-heading-m">Main quotas</h3>
{% for object in main_quotas %}
{% set definition_link -%}
<a class="govuk-link" href="{{ url('quota-ui-detail', args=[object.main_quota.order_number.sid]) }}#definition-details">{{ object.main_quota.sid }}</a>
{% endset %}
{% set main_quota_link -%}
<a class="govuk-link" href="{{ url('quota-ui-detail', args=[object.main_quota.order_number.sid]) }}">{{ object.main_quota.order_number.order_number }}</a>
{% endset %}
{% set actions_html %}
<a class="govuk-link" href="{{ object.sub_quota.version_at(request.user.current_workbasket.transactions.last()).get_association_edit_url() }}">Edit</a>
<br/>
<a class="govuk-link" href="{{ url('quota_association-ui-delete', args=[object.pk]) }}">Delete</a>
{% endset %}
{{ table_rows.append([
{"text": definition_link },
{"text": main_quota_link },
{"text": "{:%d %b %Y}".format(object.main_quota.version_at(request.user.current_workbasket.transactions.last()).valid_between.lower) },
{"text": "{:%d %b %Y}".format(object.main_quota.version_at(request.user.current_workbasket.transactions.last()).valid_between.upper) if object.main_quota.valid_between.upper else "-"},
{"text": object.get_sub_quota_relation_type_display() },
{"text": object.coefficient },
{"text": actions_html },
]) or "" }}
{% endfor %}
{{ govukTable({
"head": [
{"text": "Quota definition SID"},
{"text": "Order number"},
{"text": "Start date"},
{"text": "End date"},
{"text": "Relationship type"},
Expand All @@ -40,5 +76,5 @@
"rows": table_rows
}) }}
{% else %}
<p class="govuk-body">There are no sub-quotas for this quota order number.</p>
<p class="govuk-body">There are no main or sub-quotas for this quota order number.</p>
{% endif %}
3 changes: 2 additions & 1 deletion quotas/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ def test_quota_detail_sub_quota_tab(
valid_user_client,
date_ranges,
mock_quota_api_no_data,
session_request_with_workbasket,
):
quota_order_number = factories.QuotaOrderNumberFactory()
current_definition = factories.QuotaDefinitionFactory.create(
Expand Down Expand Up @@ -2010,7 +2011,7 @@ def test_quota_definition_view(client_with_current_workbasket):
response = client_with_current_workbasket.get(
reverse(
"quota_definition-ui-list-filter",
kwargs={"sid": main_quota.sid, "quota_type": "sub_quotas"},
kwargs={"sid": main_quota.sid, "quota_type": "quota_associations"},
),
)
assert response.status_code == 200
Expand Down
Loading

0 comments on commit 534d4da

Please sign in to comment.