Skip to content

Commit

Permalink
Select Cost Centre and Financial Year for Edit Payroll page (#537)
Browse files Browse the repository at this point in the history
Co-authored-by: Sam Dudley <[email protected]>
  • Loading branch information
CaitBarnard and SamDudley authored Oct 31, 2024
1 parent f39151e commit d248d77
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion forecast/templates/forecast/edit/choose_cost_centre.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
{% breadcrumb "Choose cost centre" "choose_cost_centre" %}
{% endblock %}

{% block title %}Edit Forecast - Choose Cost Centre{% endblock %}
{% block title %}Edit {{ view.get_page_header }} - Choose Cost Centre{% endblock %}

{% block content %}
<h3 class="govuk-heading-l">My cost centres</h3>
<div id="cost-centre-list-app"></div>
{% endblock %}
{% block scripts %}
<script>
window.nextPage = "{{ view.next_page }}";
window.costCentres = {{ view.get_user_cost_centres|safe }};
window.currentFinancialYear = {{ view.get_financial_year|safe }};
window.currentFinancialYearDisplay = "{{ view.get_financial_year_display|safe }}";
Expand Down
4 changes: 4 additions & 0 deletions forecast/views/edit_select_cost_centre.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ChooseCostCentreView(
template_name = "forecast/edit/choose_cost_centre.html"
form_class = MyCostCentresForm
cost_centre = None
next_page = "forecast"

def test_func(self):
can_edit = can_edit_at_least_one_cost_centre(self.request.user)
Expand Down Expand Up @@ -80,6 +81,9 @@ def get_user_cost_centres(self):

return json.dumps(cost_centres)

def get_page_header(self):
return self.next_page.capitalize()

def get_form_kwargs(self):
kwargs = super(ChooseCostCentreView, self).get_form_kwargs()
kwargs["user"] = self.request.user
Expand Down
4 changes: 3 additions & 1 deletion front_end/src/Components/CostCentreList/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const CostCentreList = ({rowIndex, cellKey, format}) => {
const [financialYears, setFinancialYears] = useState([])
const [forecastFinYearDisplay, setForecastFinYearDisplay] = useState(null)
const [forecastFinYear, setForecastFinYear] = useState(null)
const [nextPage, setNextPage] = useState(null)

useEffect(() => {
const timer = () => {
Expand All @@ -18,6 +19,7 @@ const CostCentreList = ({rowIndex, cellKey, format}) => {
if (window.financialYears){
setFinancialYears(window.financialYears)
}
setNextPage(window.nextPage)
} else {
timer()
}
Expand Down Expand Up @@ -68,7 +70,7 @@ const CostCentreList = ({rowIndex, cellKey, format}) => {
<ul className="cost-centre-list">
{displayedCentres.map((costCentre, index) => {
return <li key={index}>
<a href={ `/forecast/edit/${costCentre.code}/${forecastFinYear}` } className="govuk-link">{costCentre.code} - {costCentre.name}</a>
<a href={ `/${nextPage}/edit/${costCentre.code}/${forecastFinYear}` } className="govuk-link">{costCentre.code} - {costCentre.name}</a>

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
</li>
})}
</ul>
Expand Down
3 changes: 2 additions & 1 deletion payroll/templates/payroll/page/edit_payroll.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

{% block breadcrumbs %}
{{ block.super }}
{% breadcrumb "Choose cost centre" "payroll:choose_cost_centre" %}
{% breadcrumb "Edit payroll" "edit_payroll" %}
{% endblock breadcrumbs %}

Expand All @@ -14,7 +15,7 @@ <h1 class="govuk-heading-l">Edit payroll</h1>

<h1 class="govuk-heading-l">Forecast</h1>
<p class="govuk-body-s">
This is a temporary table to demostrate the forecast figures. Eventually these
This is a temporary table to demonstrate the forecast figures. Eventually these
figures would end up in the "Edit forecast" table.
</p>
<table class="govuk-table">
Expand Down
8 changes: 7 additions & 1 deletion payroll/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from django.urls import path

from forecast.views.edit_select_cost_centre import ChooseCostCentreView

from . import views


app_name = "payroll"

urlpatterns = [
# TODO: Add choose financial year and cost centre url.
path(
"edit/<str:cost_centre_code>/<int:financial_year>/",
views.edit_payroll_page,
Expand All @@ -17,4 +18,9 @@
views.PayrollView.as_view(),
name="api",
),
path(
"edit/choose-cost-centre/",
ChooseCostCentreView.as_view(next_page="payroll"),
name="choose_cost_centre",
),
]

0 comments on commit d248d77

Please sign in to comment.