From 91539720285cf725d6d111b36a34079ea5270517 Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson Date: Thu, 31 Oct 2024 20:13:42 +0100 Subject: [PATCH] Running total of score on review form (#4169) Live score label added to edit review form Fixes #3963 Co-authored-by: Ghulam Murtaza Co-authored-by: Saurabh Kumar --- eslint.config.mjs | 1 + hypha/apply/review/blocks.py | 1 + hypha/apply/review/fields.py | 2 +- .../templates/review/review_edit_form.html | 52 ++++++++++++++++--- .../review/templates/review/review_form.html | 40 +++++++++++--- hypha/apply/review/views.py | 4 +- .../javascript/behaviours/review-score.js | 49 +++++++++++++++++ hypha/templates/base.html | 3 ++ 8 files changed, 135 insertions(+), 17 deletions(-) create mode 100644 hypha/static_src/javascript/behaviours/review-score.js diff --git a/eslint.config.mjs b/eslint.config.mjs index a82dc9b7f7..c91087dccb 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -25,6 +25,7 @@ export default [ ...globals.browser, ...globals.commonjs, jQuery: true, + Alpine: true, }, }, diff --git a/hypha/apply/review/blocks.py b/hypha/apply/review/blocks.py index 2bc25ca696..b0cdc38f6c 100644 --- a/hypha/apply/review/blocks.py +++ b/hypha/apply/review/blocks.py @@ -74,6 +74,7 @@ class ScoreFieldWithoutTextBlock(OptionalFormFieldBlock): name = "score without text" field_class = forms.ChoiceField + widget = forms.Select(attrs={"data-score-field": "true"}) class Meta: icon = "order" diff --git a/hypha/apply/review/fields.py b/hypha/apply/review/fields.py index 079e01478d..e734f6f368 100644 --- a/hypha/apply/review/fields.py +++ b/hypha/apply/review/fields.py @@ -11,7 +11,7 @@ class ScoredAnswerWidget(forms.MultiWidget): def __init__(self, attrs=None): _widgets = ( TinyMCE(attrs=attrs, mce_attrs=MCE_ATTRIBUTES_SHORT), - widgets.Select(attrs=attrs, choices=RATE_CHOICES), + widgets.Select(attrs={"data-score-field": "true"}, choices=RATE_CHOICES), ) super().__init__(_widgets, attrs) diff --git a/hypha/apply/review/templates/review/review_edit_form.html b/hypha/apply/review/templates/review/review_edit_form.html index 7cd8446cfb..2657240123 100644 --- a/hypha/apply/review/templates/review/review_edit_form.html +++ b/hypha/apply/review/templates/review/review_edit_form.html @@ -1,6 +1,12 @@ {% extends "base-apply.html" %} -{% load i18n %} +{% load i18n static %} {% block title %}{{ title }}{% endblock %} + +{% block alpine_scripts %} + {{ block.super }} + +{% endblock %} + {% block content %} {% adminbar %} @@ -12,8 +18,19 @@ {% include "forms/includes/form_errors.html" with form=form %} -
-
+
+ + + + {{ form.media }} {% csrf_token %} @@ -22,7 +39,7 @@ {% endfor %} {% for field in form.visible_fields %} - {# to be replaced with better logic when we use stream form #} + {# to be replaced with better logic when we use stream form #} {% ifchanged field.field.group %} {% for key, value in form.titles.items %} {% if key == field.field.group %} @@ -37,10 +54,29 @@

{{ value }}

{{ field }} {% endif %} {% endfor %} - {% if not object.id or object.is_draft %} - - {% endif %} - +
+ + + + {% if not object.id or object.is_draft %} + + {% endif %} + +
+ {% trans "Total Score:" %} +
+
{% endblock %} diff --git a/hypha/apply/review/templates/review/review_form.html b/hypha/apply/review/templates/review/review_form.html index 2fca21495a..cf9c1f79ca 100644 --- a/hypha/apply/review/templates/review/review_form.html +++ b/hypha/apply/review/templates/review/review_form.html @@ -1,6 +1,12 @@ {% extends "base-apply.html" %} -{% load i18n %} +{% load i18n static %} {% block title %}{{ title }}{% endblock %} + +{% block alpine_scripts %} + {{ block.super }} + +{% endblock %} + {% block content %} {% adminbar %} @@ -23,9 +29,18 @@ {% include "forms/includes/form_errors.html" with form=form %} -
+
+ {% if not has_submitted_review %} -
+ {{ form.media }} {% csrf_token %} @@ -49,10 +64,21 @@

{{ value }}

{{ field.block }} {% endif %} {% endfor %} - {% if not object.id or object.is_draft %} - - {% endif %} - + +
+ {% if not object.id or object.is_draft %} + + {% endif %} + +
+ {% trans "Total Score:" %} +
+
+