Skip to content

Commit

Permalink
Update grants Reviews Recap view to use Aid Categories / approved all…
Browse files Browse the repository at this point in the history
…ocations
  • Loading branch information
estyxx committed Sep 15, 2024
1 parent 3d051f9 commit 0d69c50
Show file tree
Hide file tree
Showing 3 changed files with 2,756 additions and 66 deletions.
8 changes: 6 additions & 2 deletions backend/reviews/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.postgres.expressions import ArraySubquery
from django.contrib.postgres.aggregates import ArrayAgg
from django.db.models.expressions import ExpressionWrapper
from django.db.models import FloatField
from django.db.models.functions import Cast
Expand Down Expand Up @@ -340,6 +341,9 @@ def _review_grants_recap_view(self, request, review_session):
)
.values("id")
),
approved_aid_categories=ArrayAgg(
"allocations__category_id",
),
)
.order_by(F("score").desc(nulls_last=True))
.prefetch_related(
Expand Down Expand Up @@ -378,8 +382,8 @@ def _review_grants_recap_view(self, request, review_session):
],
all_approved_category=[
category
for category in AidCategory.objects.filter(
conference_id=review_session.conference_id
for category in AidCategory.objects.for_conference(
conference=review_session.conference
)
],
all_statuses=Grant.Status.choices,
Expand Down
72 changes: 47 additions & 25 deletions backend/reviews/templates/grants-recap.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,24 @@
width: 150px;
}

.approved-type-choices {
.approved-aid-categories-choices {
width: 200px;
}

.status-choices,
.approved-type-choices {
.approved-aid-categories-choices {
list-style: none;
}

.status-choices li,
.approved-type-choices li {
.approved-aid-categories-choices li {
list-style: none;
}

label:has(input.approved-aid-category:disabled) {
opacity: 0.6;
}

.needs-list {
display: inline-block;
margin-top: 0;
Expand Down Expand Up @@ -289,32 +293,44 @@
const grantRow = document.querySelector(`#grant-${grantId}`);

const originalStatus = grantRow.dataset.originalStatus;
const originalApprovedType = grantRow.dataset.originalApprovedType;

const originalApprovedAidCategories = grantRow.dataset.originalApprovedAidCategories;
grantRow.querySelector(`.status-decision-radio[value="${originalStatus}"]`).checked = true;

if (originalApprovedType !== 'None') {
grantRow.querySelector(`.approved-type-choices input[value="${originalApprovedType}"]`).checked = true;
}
const checkboxes = grantRow.querySelectorAll(`.approved-aid-categories-choices input[type="checkbox"]`);
checkboxes.forEach(checkbox => {
checkbox.checked = false;

if (originalApprovedAidCategories.includes(checkbox.value)) {
checkbox.checked = true;
}
});

if (originalStatus === "approved") {
grantRow.querySelector(`.approved-type-choices`).classList.remove('hidden');
checkboxes.forEach(checkbox => {
checkbox.disabled = false;
});
} else {
grantRow.querySelector(`.approved-type-choices`).classList.add('hidden');
checkboxes.forEach(checkbox => {
checkbox.disabled = true;
});
}
});
});

document.querySelectorAll('.status-decision-radio').forEach(radio => {
radio.addEventListener('click', () => {
const grantId = radio.name.split('-')[1];

const approvedTypeSection = document.querySelector(`.approved-type-choices[data-item-id="${grantId}"]`)
const approvedAidCategorySection = document.querySelector(`.approved-aid-categories-choices[data-item-id="${grantId}"]`);
const checkboxes = approvedAidCategorySection.querySelectorAll('input[type="checkbox"]');

if (radio.value === "approved") {
approvedTypeSection.classList.remove('hidden');
checkboxes.forEach(checkbox => {
checkbox.disabled = false;
});
} else {
approvedTypeSection.classList.add('hidden');
checkboxes.forEach(checkbox => {
checkbox.disabled = true;
});
}
});
});
Expand Down Expand Up @@ -452,7 +468,7 @@ <h3>
</th>
<th scope="col">
<div class="text">
<span>Approved type</span>
<span>Approved Aids</span>
</div>
<div class="clear"></div>
</th>
Expand All @@ -470,7 +486,7 @@ <h3>
</script>
<tr
data-original-status="{{ item.status }}"
data-original-approved-type="{{ item.approved_type }}"
data-original-approved-aid-categories="{{ item.approved_aid_categories }}"
class="grant-item"
id="grant-{{ item.id }}"
data-type="{{ item.type }}"
Expand Down Expand Up @@ -624,23 +640,29 @@ <h3>
{% if perms.reviews.decision_reviewsession %}
<ul
data-item-id="{{ item.id }}"
class="approved-type-choices {% if item.status != 'approved' %}hidden{% endif %}"
class="approved-aid-categories-choices"
>
{% for category in all_approved_category %}
<li>
<label>
<input {% if item.approved_type == category.id %}checked{% endif %}
type="radio" name="approvedaidcategory-{{item.id}}" value="{{category.id}}" />

<input
type="checkbox"
name="approvedaidcategory-{{item.id}}"
class="approved-aid-category"
value="{{category.id}}"
{% if item.status != 'approved' %}disabled{% endif %}
{% if category.id in item.approved_aid_categories %}
checked
{% elif not item.approved_aid_categories and item.status == 'approved' and category.included_by_default %}
{% comment %} TODO FIX THIS IF {% endcomment %}
checked
{% endif %}
/>
{{category.name}}
</label>
</li>
{% endfor %}
<li>
<label>
<input class="unset-radio" type="radio" name="approvedtype-{{item.id}}" value="unset" />
Unset
</label>
</li>
</ul>
{% else %} No permission to change. {% endif %}
</td>
Expand Down
Loading

0 comments on commit 0d69c50

Please sign in to comment.