From d37a3576f21a5eb1ad09efb1080e66fec452c1f6 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. Signed-off-by: David Nind Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize --- .../en/modules/admin/preferences/opac.pref | 2 +- .../en/includes/user-star-ratings.inc | 53 +++++++++++++++++++ .../en/modules/opac-readingrecord.tt | 28 ++++------ .../bootstrap/en/modules/opac-user.tt | 14 ++++- koha-tmpl/opac-tmpl/bootstrap/js/ratings.js | 46 ++++++++++++++++ koha-tmpl/opac-tmpl/bootstrap/js/script.js | 4 +- opac/opac-user.pl | 7 +++ 7 files changed, 132 insertions(+), 22 deletions(-) create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/includes/user-star-ratings.inc create mode 100644 koha-tmpl/opac-tmpl/bootstrap/js/ratings.js 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 bdb940820d..550c0bafc1 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 @@ -57,7 +57,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 865ff87f65..ca47aca576 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt @@ -294,7 +294,12 @@ [% INCLUDE 'biblio-title.inc' biblio=ISSUE %] [% IF ( ISSUE.enumchron ) %] [% ISSUE.enumchron | html %][% END %] + [% IF ( ISSUE.onsite_checkout ) %] (On-site checkout)[% END %] + + [% IF ( Koha.Preference('OpacStarRatings') == 'all' ) %] + [% INCLUDE 'user-star-ratings.inc' item=ISSUE %] + [% END %] [% ISSUE.author | html %] @@ -779,8 +784,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); @@ -964,7 +967,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 %]