Skip to content

Commit

Permalink
[Scorecards] toggle off section page previous year elements if no pre…
Browse files Browse the repository at this point in the history
…vious year
  • Loading branch information
struan committed Mar 3, 2025
1 parent aca7850 commit 097b9c0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
36 changes: 19 additions & 17 deletions scoring/templates/scoring/section.html
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,14 @@ <h3 class="fs-5 mb-0 lh-base text-center">{{ council_type.name|title }}</h3>
</div>
{% endif %}

{% if comparison_councils %}
{% if comparison_councils and previous_year %}
{% comment %} On mobile previous year score will be display by default {% endcomment %}
<div class="col-lg-6 display-only-large-up">
<div class="card">
<div class="card-body">
<div class="form-check-flex d-none d-md-flex">
<input class="form-check-input" type="checkbox" id="js-toggle-previous-year-score" aria-checked="false" role="switch">
<label class="form-check-label" for="js-toggle-previous-year-score">Display 2023 scores<span class="badge bg-primary-100 text-primary ms-1">NEW</span></label>
<label class="form-check-label" for="js-toggle-previous-year-score">Display {{ previous_year.year }} scores<span class="badge bg-primary-100 text-primary ms-1">NEW</span></label>
</div>
<div class="d-none d-md-flex flex-row gap-3 mt-3">
<h4 class="visually-hidden">Legends for difference column</h4>
Expand Down Expand Up @@ -343,20 +343,20 @@ <h4 class="visually-hidden">Legends for difference column</h4>
<span class="mb-1 d-block">Councils with full marks per question</span>
</th>
</tr>
{% if previous_year %}
<tr class="bg-primary-100 display-only-large-up fs-7 text-primary">
<th scope="col" class="py-2 border-start"></th>

{% for comparison in comparison_councils %}
<th scope="col" class="py-2 border-start border-light">2025</th>
{% comment %} TODO: Add previous year dynamically or we can just hardcode it. {% endcomment %}
<th scope="col" class="py-2 js-previous-year-score">2023</th>
{% comment %} TODO: Add previous year dynamically or we can just hardcode it. {% endcomment %}
<th scope="col" class="js-current-year-score py-2 border-end border-light text-center">Versus 2023</th>
<th scope="col" class="py-2 border-start border-light">{{ plan_year }}</th>
<th scope="col" class="py-2 js-previous-year-score">{{ previous_year.year }}</th>
<th scope="col" class="js-current-year-score py-2 border-end border-light text-center">Versus {{ previous_year.year }}</th>
<th scope="col" class="js-previous-year-score py-2 border-end border-light text-center">Difference</th>
{% endfor %}

<th class="py-2 border-end">2025 results</th>
<th class="py-2 border-end">{{ plan_year }} results</th>
</tr>
{% endif %}

{% comment %} Mobile version {% endcomment %}
<tr class="text-bg-primary d-lg-none">
Expand All @@ -378,16 +378,18 @@ <h4 class="visually-hidden">Legends for difference column</h4>
<span class="me-2">{{ comparison.score|format_mark }}/{{ question.details.max_score }}</span>
<span class="badge bg-secondary d-md-none">{{ comparison.council_name }}</span>
</td>
{% comment %} TODO: Include previous scorecards score(2023) {% endcomment %}
{% comment %} TODO: IF NA(Question didn't exist previous version): display "NA" {% endcomment %}
<td data-column="score" class="js-previous-year-score display-only-large-up text-start flex-row score">
<span class="me-2">{{ comparison.previous_score|format_mark }}/{{ question.details.max_score }}</span>
<span class="badge bg-secondary d-md-none">{{ comparison.council_name }}</span>
</td>
{% if previous_year %}
<td data-column="score" class="js-previous-year-score display-only-large-up text-start flex-row score">
<span class="me-2">{{ comparison.previous_score|format_mark }}/{{ question.details.max_score }}</span>
<span class="badge bg-secondary d-md-none">{{ comparison.council_name }}</span>
</td>

<td class="border-end border-bottom border-opacity-25 text-center display-only-large-up">
{% include "scoring/includes/integer_score_change.html" with change=comparison.change %}
</td>
<td class="border-end border-bottom border-opacity-25 text-center display-only-large-up">
{% include "scoring/includes/integer_score_change.html" with change=comparison.change %}
</td>
{% else %}
<td class="border-end border-bottom border-opacity-25 text-center display-only-large-up"></td>
{% endif %}
{% endfor %}

<td data-column="score" class="score ps-5 ps-lg-2">
Expand Down
5 changes: 4 additions & 1 deletion scoring/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,17 +691,19 @@ def get_object(self):
def add_comparisons(self, context, comparison_slugs, comparison_questions):
section = context["section"]
comparisons = None
previous_year = None
if comparison_slugs:
comparisons = (
PlanScore.objects.select_related("council")
.filter(year=self.request.year, council__slug__in=comparison_slugs)
.order_by("council__name")
)
previous_year = comparisons.first().previous_year
comparison_sections = PlanSectionScore.sections_for_plans(
plans=comparisons,
plan_year=self.request.year,
plan_sections=PlanSection.objects.filter(code=section.code),
previous_year=comparisons.first().previous_year,
previous_year=previous_year,
)

first_comparison = comparison_slugs[0]
Expand Down Expand Up @@ -740,6 +742,7 @@ def add_comparisons(self, context, comparison_slugs, comparison_questions):
* -1
)

context["previous_year"] = previous_year
context["comparison_councils"] = comparisons
context["comparison_scores"] = comparison_scores

Expand Down

0 comments on commit 097b9c0

Please sign in to comment.