From d6e8e15db543e1357fb154cd8ebfb3012dc5ce57 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Tue, 14 Apr 2020 16:31:28 +0000 Subject: [PATCH] Bug 25110: Allow patrons to add star ratings to titles on their summary/checkout page This patch adds the ability for logged-in patrons to add star ratings to titles in their list of current checkouts and on the reading history page. The reading history page previously only showed existing ratings. Now it will allow the entry of ratings as well. The JS and markup for the feature are in separate include files to facilitate re-use. It includes markup for non-js display of ratings and js-driven ratings controls. To test, apply the patch and set the OpacStarRatings to all, "results, details, and user" pages. - Log in to the OPAC as a user with checkouts. - On the "your summary" page, test the features of setting star ratings: - Any title with existing ratings should show the rating and the average rating number. - Set a rating. Confirm that it shows a message with your rating. - Click the "cancel rating" link, and confirm that your rating is removed. - Set a rating and reload the page. Confirm that the rating was saved. - Test the "cancel rating" link on the title you set before you reloaded the page. The rating should be cancelled. - Test the same functionality on the "your reading history" page. - Test these pages with the OpacStarRatings preference set to "only details" or "no." The pages should function correctly. --- .../prog/en/modules/admin/preferences/opac.pref | 2 +- .../bootstrap/en/includes/user-star-ratings.inc | 53 ++++++++++++++++++++++ .../bootstrap/en/modules/opac-readingrecord.tt | 28 ++++-------- .../opac-tmpl/bootstrap/en/modules/opac-user.tt | 13 +++++- koha-tmpl/opac-tmpl/bootstrap/js/script.js | 4 +- opac/opac-user.pl | 7 +++ 6 files changed, 85 insertions(+), 22 deletions(-) create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/includes/user-star-ratings.inc diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index 586695e9ad..39437c9f28 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -56,7 +56,7 @@ OPAC: - "Show star-ratings on" - pref: OpacStarRatings choices: - all: "results and details" + all: "results, details, and user" disable: "no" details: "only details" - "pages." diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/user-star-ratings.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/user-star-ratings.inc new file mode 100644 index 0000000000..63b4bb87df --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/user-star-ratings.inc @@ -0,0 +1,53 @@ +
+ + [% SET rating_avg = item.ratings.get_avg_rating() %] + [% rating_avg_int = BLOCK %][% rating_avg | format("%.0f") %][% END %] + +
+
+ [% FOREACH i IN [ 1 2 3 4 5 ] %] + [% IF rating_avg_int == i %] + + [% ELSIF rating_avg_int > i %] + + [% ELSE %] + + [% END %] + [% END %] +
+
+ + + + + + + + + + + + [% IF item.my_rating %] +
+ Your rating: [% item.my_rating.rating_value | html %]. + Cancel rating. +
+ [% ELSE %] + + + [% END %] + +
Average rating: [% rating_avg | html %] ([% item.ratings.count | html %] votes)
+
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt index 1f3dadcff5..3b95b586ed 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt @@ -145,24 +145,9 @@ [% END %]

[% issue.author | html %]

- [% IF ( Koha.Preference( 'OpacStarRatings' ) == 'all' && issue.my_rating ) %] -
-
-
- [% FOREACH i IN [ 1 2 3 4 5 ] %] - [% IF issue.my_rating.rating_value == i %] - - [% ELSIF issue.my_rating.rating_value > i %] - - [% ELSE %] - - [% END %] - [% END %] -
-
- Rated on [% issue.my_rating.timestamp | $KohaDates %] -
- [% END # / IF OpacStarRatings %] + [% IF ( Koha.Preference( 'OpacStarRatings' ) == 'all' ) %] + [% INCLUDE 'user-star-ratings.inc' item=issue %] + [% END %] @@ -235,5 +220,12 @@ } }); }); + var borrowernumber = "[% borrowernumber | html %]"; + var MSG_YOUR_RATING = _("Your rating: %s, "); + var MSG_AVERAGE_RATING = _("Average rating: %s (%s votes)"); + [% IF ( Koha.Preference('OpacStarRatings') == 'all' ) %] + [% Asset.js("lib/jquery/plugins/jquery.barrating.min.js") | $raw %] + [% Asset.js("js/ratings.js") | $raw %] + [% END %] [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt index 256262818d..4474c8eac6 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt @@ -294,6 +294,10 @@ [% INCLUDE 'biblio-title.inc' biblio=ISSUE %] [% IF ( ISSUE.enumchron ) %] [% ISSUE.enumchron | html %][% END %] + + [% IF ( Koha.Preference('OpacStarRatings') == 'all' ) %] + [% INCLUDE 'user-star-ratings.inc' item=ISSUE %] + [% END %] [% ISSUE.author | html %] @@ -778,8 +782,6 @@ $(document).ready(function(){ $('#opac-user-views').tabs(); - $(".js-show").show(); - $(".js-hide").hide(); $(".modal-nojs").addClass("modal").addClass("hide").removeClass("modal-nojs"); $(".suspend-until").prop("readonly",1); @@ -963,7 +965,14 @@ } }); //]]> + var borrowernumber = "[% borrowernumber | html %]"; + var MSG_YOUR_RATING = _("Your rating: %s, "); + var MSG_AVERAGE_RATING = _("Average rating: %s (%s votes)"); + [% IF ( Koha.Preference('OpacStarRatings') == 'all' ) %] + [% Asset.js("lib/jquery/plugins/jquery.barrating.min.js") | $raw %] + [% Asset.js("js/ratings.js") | $raw %] + [% END %] [% IF Koha.Preference('OverDriveCirculation') %] [% Asset.js("js/overdrive.js") | $raw %]