Skip to content

Commit

Permalink
Merge branch 'master' into TP2000-1194--js-linter
Browse files Browse the repository at this point in the history
  • Loading branch information
a-gleeson committed Mar 25, 2024
2 parents 35a1528 + 7ca6977 commit b87ff5b
Show file tree
Hide file tree
Showing 21 changed files with 880 additions and 323 deletions.
5 changes: 5 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# @tamato will be requested for
# review when someone opens a pull request.
* @uktrade/tamato
18 changes: 18 additions & 0 deletions checks/migrations/0008_alter_trackedmodelcheck_processing_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.10 on 2024-03-21 18:05

from django.db import migrations
from django.db import models


class Migration(migrations.Migration):
dependencies = [
("checks", "0007_transactioncheck_timestamps"),
]

operations = [
migrations.AlterField(
model_name="trackedmodelcheck",
name="processing_time",
field=models.FloatField(null=True),
),
]
2 changes: 1 addition & 1 deletion checks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class TrackedModelCheck(TimestampedMixin):
message = fields.TextField(null=True)
"""The text content returned by the check, if any."""

processing_time = fields.DecimalField(null=True, decimal_places=4, max_digits=6)
processing_time = fields.FloatField(null=True)
"""Added processing_time used to record the time taken to process a rule in
seconds."""

Expand Down
113 changes: 31 additions & 82 deletions common/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@

from crispy_forms_gds.fields import DateInputField
from crispy_forms_gds.helper import FormHelper
from crispy_forms_gds.layout import HTML
from crispy_forms_gds.layout import Div
from crispy_forms_gds.layout import Field
from crispy_forms_gds.layout import Fieldset
from crispy_forms_gds.layout import Layout
from crispy_forms_gds.layout import Size
from crispy_forms_gds.layout import Submit
from django import forms
from django.contrib.postgres.forms.ranges import DateRangeField
from django.core.exceptions import ValidationError
from django.db.models import TextChoices
from django.forms.renderers import get_default_renderer
from django.forms.utils import ErrorList

from common.util import TaricDateRange
from common.util import get_model_indefinite_article
from common.validators import AlphanumericValidator
from common.widgets import FormSetFieldWidget
from common.widgets import MultipleFileInput
from common.widgets import RadioNestedWidget
Expand Down Expand Up @@ -235,85 +233,6 @@ def get_bound_field(self, form, field_name):
return super().get_bound_field(form, field_name)


class WorkbasketActions(TextChoices):
CREATE = "CREATE", "Create a new workbasket"
EDIT = "EDIT", "Edit workbaskets"


class DITTariffManagerActions(TextChoices):
PACKAGE_WORKBASKETS = "PACKAGE_WORKBASKETS", "Package workbaskets"


class HMRCCDSManagerActions(TextChoices):
PROCESS_ENVELOPES = "PROCESS_ENVELOPES", "Process envelopes"


class CommonUserActions(TextChoices):
SEARCH = "SEARCH", "Search the tariff"
# Change this to be dependent on permissions later


class ImportUserActions(TextChoices):
IMPORT = "IMPORT", "Import EU TARIC files"


class WorkbasketManagerActions(TextChoices):
WORKBASKET_LIST_ALL = "WORKBASKET_LIST_ALL", "Search for workbaskets"


class HomeForm(forms.Form):
def __init__(self, *args, **kwargs):
self.user = kwargs.pop("user")
super().__init__(*args, **kwargs)

choices = []

if self.user.has_perm("workbaskets.add_workbasket"):
choices += WorkbasketActions.choices

if self.user.has_perm("publishing.manage_packaging_queue"):
choices += DITTariffManagerActions.choices

if self.user.has_perm("publishing.consume_from_packaging_queue"):
choices += HMRCCDSManagerActions.choices

choices += CommonUserActions.choices

if self.user.has_perm("common.add_trackedmodel") or self.user.has_perm(
"common.change_trackedmodel",
):
choices += ImportUserActions.choices

if self.user.has_perm("workbaskets.view_workbasket"):
choices += WorkbasketManagerActions.choices

self.fields["workbasket_action"] = forms.ChoiceField(
label="",
choices=choices,
widget=forms.RadioSelect,
required=True,
)

self.helper = FormHelper(self)
self.helper.layout = Layout(
Fieldset(
HTML.h3("What would you like to do?"),
HTML.details(
"What is a workbasket?",
"A workbasket is used to collect all the changes you make to the UK's import and export tariff data. "
"Workbaskets group these changes so they can be checked by the Customs Declaration Service (CDS) before going live.",
),
"workbasket_action",
),
Submit(
"submit",
"Continue",
data_module="govuk-button",
data_prevent_double_click="true",
),
)


class DescriptionHelpBox(Div):
template = "components/description_help.jinja"

Expand Down Expand Up @@ -814,3 +733,33 @@ def clean(self, data, initial=None):
else:
files = cleaned_data(data, initial)
return files


class HomeSearchForm(forms.Form):
search_term = forms.CharField(
required=False,
widget=forms.TextInput(
attrs={"placeholder": "Search by tariff element name or ID"},
),
validators=[AlphanumericValidator],
max_length=18,
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.helper = FormHelper(self)
self.helper.label_size = Size.SMALL
self.helper.legend_size = Size.SMALL
self.helper.layout = Layout(
Div(
Field.text("search_term"),
Submit(
"submit",
"Search",
data_module="govuk-button",
data_prevent_double_click="true",
),
css_id="homepage-search-form",
),
)
169 changes: 169 additions & 0 deletions common/jinja2/common/homepage.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
{% extends "layouts/form.jinja" %}

{% set page_title = "Home" %}

{% block content %}
<h1 class="govuk-heading-xl govuk-!-margin-bottom-3">Search the Tariff Application Platform</h1>
<span class="govuk-caption-l govuk-!-margin-bottom-4">This service lets you manage the UK's import and export tariff data</span>

{% block form %}
<div class="govuk-grid-row">
<div id="homepage-search" class="govuk-grid-column-full">
{% call django_form() %}
{{ crispy(form) }}
{% endcall %}
</div>
</div>
{% endblock %}

<div id="homepage-articles" class="govuk-grid-row">
{% if can_view_workbasket %}
<article class="homepage-card">
<h3 class="govuk-heading-m">What would you like to do?</h3>
<p class="govuk-body">
Create a new workbasket, edit an existing workbasket, package or search for workbaskets.
</p>

<div class="govuk-grid-row">
{% if can_add_workbasket %}
<div class="govuk-grid-column-one-half">
<a
href="{{ url('workbaskets:workbasket-ui-create') }}"
class="govuk-button homepage-workbasket-action"
>Create a <br> workbasket</a>
</div>
{% endif %}

{% if can_edit_workbasket %}
<div class="govuk-grid-column-one-half">
<a
href="{{ url('workbaskets:workbasket-ui-list') }}"
class="govuk-button homepage-workbasket-action"
>Edit a <br> workbasket</a>
</div>
{% endif %}

{% if can_manage_packaging %}
<div class="govuk-grid-column-one-half">
<a
href="{{ url('publishing:packaged-workbasket-queue-ui-list') }}"
class="govuk-button homepage-workbasket-action"
>Package <br> workbaskets</a>
</div>
{% endif %}

<div class="govuk-grid-column-one-half">
<a
href="{{ url('workbaskets:workbasket-ui-list-all') }}"
class="govuk-button homepage-workbasket-action"
>Search for <br> workbaskets</a>
</div>
</div>
</article>
{% endif %}

{% if can_edit_workbasket %}
<article class="homepage-card">
<h3 class="govuk-heading-m">Currently working on</h3>
{% if not assigned_workbaskets %}
<p class="govuk-body">You are not currently assigned to a workbasket.</p>
{% else %}
<ul class="govuk-list">
{% for workbasket in assigned_workbaskets %}
<li>
<p class="homepage-workbasket-details govuk-body">
<a
href="{{ url("workbaskets:workbasket-ui-detail", kwargs={"pk": workbasket["id"]}) }}"
class="govuk-link"
>Workbasket ID {{ workbasket["id"] }}</a>
<span>
{% if workbasket["rule_violations_count"] %}
- {{ workbasket["assignment_type"] }}, rule violation{{ workbasket["rule_violations_count"]|pluralize }}
<span class="rule-violation-badge">{{ workbasket["rule_violations_count"] }}</span>
{% else %}
- {{ workbasket["assignment_type"] }}
{% endif %}
</span>
</p>
</li>
{% endfor %}
</ul>
{% endif %}
</article>
{% endif %}

{% if can_import_taric %}
<article class="homepage-card">
<h3 class="govuk-heading-m">EU TARIC files</h3>
<p class="govuk-body">
<a href="{{ url('commodity_importer-ui-list') }}"
class="govuk-link"
>View EU import list and import new TARIC files</a>
</p>
</article>
{% endif %}

{% if can_consume_packaging %}
<article class="homepage-card">
<h3 class="govuk-heading-m">Envelopes</h3>
<p class="govuk-body">
<a href="{{ url('publishing:envelope-queue-ui-list') }}"
class="govuk-link"
>Process envelopes</a>
</p>
</article>
{% endif %}

<article class="homepage-card">
<h3 class="govuk-heading-m">Resources</h3>
<p class="govuk-body">
We have a range of resources you can use with the Tariff Application Platform.
</p>
<ul id="homepage-tap-resources" class="govuk-list govuk-list--spaced">
<li>
<a href="{{ url('app-info') }}" class="govuk-link">Application information</a>
</li>
{% if request.user.is_superuser %}
<li>
<a href="{{ url('import_batch-ui-list') }}" class="govuk-link">Importer V1</a>
</li>
<li>
<a href="{{ url('taric_parser_import_ui_list') }}" class="govuk-link">Importer V2</a>
</li>
{% endif %}
{% if can_view_reports %}
<li>
<a href="{{ url('reports:index') }}" class="govuk-link"><abbr title="Tariff Application Platform">TAP</abbr> reports</a>
</li>
{% endif %}
<li>
<a href="https://uktrade.github.io/tariff-data-manual/#home" class="govuk-link" rel="noreferrer noopener" target="_blank">Tariff data manual</a>
</li>
</ul>
</article>
</div>

<hr class="govuk-section-break govuk-section-break--l govuk-section-break--visible">

<div class="govuk-grid-row">
<h2 class="govuk-heading-l govuk-grid-column-full govuk-!-margin-bottom-3">How can we support you?</h2>

<article class="homepage-card">
<h3 class="govuk-heading-m">Get help</h3>
<p class="govuk-body">
Find documentation, guidance, training and updates in the
<a
href="https://data-services-help.trade.gov.uk/tariff-application-platform/"
class="govuk-link"
>
<abbr title="Tariff Application Platform">TAP</abbr> help centre.
</a>
</p>
</article>

<article class="homepage-card govuk-!-padding-bottom-5">
<h3 class="govuk-heading-m">Get in touch</h3>
<p class="govuk-body"><a class="govuk-link" href="mailto:[email protected]">Contact us</a> if you have a question or suggestion.</p>
</article>
</div>
{% endblock %}
21 changes: 16 additions & 5 deletions common/jinja2/common/maintenance.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@
{% set page_title = "Sorry, the service is unavailable" %}

{% set workbasket_html %}{% endset %}
{% set logout_login_link %}{% endset %}
{% set can_view_workbasket %}{% endset %}
{% set can_import_taric %}{% endset %}
{% set can_manage_packaging %}{% endset %}
{% set can_consume_packaging %}{% endset %}

{% block header %}
{{ govukHeader({
"homepageUrl": "https://gov.uk/",
"serviceName": service_name,
"serviceUrl": "/",
}) }}
<header class="govuk-header" role="banner" data-module="govuk-header">
<div class="govuk-header__container govuk-width-container">
<div class="govuk-header__logotype">
<a
href="/"
class="govuk-header__link govuk-header__link--service-name govuk-!-margin-right-1"
>{{ service_name }}</a>
<strong class="govuk-tag govuk-phase-banner__content__tag ">{{ phase_banner_tag }}</strong>
</div>
</div>
</header>
{% endblock %}

{% block breadcrumb %}{% endblock %}
Expand Down
Loading

0 comments on commit b87ff5b

Please sign in to comment.