Bugzilla – Attachment 103365 Details for
Bug 25110
Allow patrons to add star ratings to titles on their summary/checkout page
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25110: Allow patrons to add star ratings to titles on their summary/checkout page
Bug-25110-Allow-patrons-to-add-star-ratings-to-tit.patch (text/plain), 14.63 KB, created by
Owen Leonard
on 2020-04-21 12:00:50 UTC
(
hide
)
Description:
Bug 25110: Allow patrons to add star ratings to titles on their summary/checkout page
Filename:
MIME Type:
Creator:
Owen Leonard
Created:
2020-04-21 12:00:50 UTC
Size:
14.63 KB
patch
obsolete
>From 1f99d33d03e182032cdb63ccc4f91c2dc17c4ce4 Mon Sep 17 00:00:00 2001 >From: Owen Leonard <oleonard@myacpl.org> >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. > >Edit: Add JS file which was missing from the commit! >--- > .../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 | 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 44be2236d2..112c4c1a27 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 @@ >+<div class="results_summary ratings" id="rating-[% item.itemnumber | html %]"> >+ >+ [% SET rating_avg = item.ratings.get_avg_rating() %] >+ [% rating_avg_int = BLOCK %][% rating_avg | format("%.0f") %][% END %] >+ >+ <div class="br-wrapper br-theme-fontawesome-stars js-hide"> >+ <div class="br-widget br-readonly"> >+ [% FOREACH i IN [ 1 2 3 4 5 ] %] >+ [% IF rating_avg_int == i %] >+ <a href="#" class="br-selected br-current"></a> >+ [% ELSIF rating_avg_int > i %] >+ <a href="#" class="br-selected"></a> >+ [% ELSE %] >+ <a href="#"></a> >+ [% END %] >+ [% END %] >+ </div> >+ </div> >+ >+ <select class="star_rating" id="star_rating-[% item.itemnumber | html %]" name="rating" autocomplete="off" data-biblionumber="[% item.biblionumber | html %]" data-context="rating-[% item.itemnumber | html %]"> >+ >+ [% IF ( rating_avg_int == 0 ) %] >+ <option value="" selected="selected"></option> >+ [% END %] >+ [% FOREACH i IN [ 1 2 3 4 5 ] %] >+ [% IF rating_avg_int == i %] >+ <option value="[% i | html %]" selected="selected">[% i | html %]</option> >+ [% ELSE %] >+ <option value="[% i | html %]">[% i | html %]</option> >+ [% END %] >+ [% END %] >+ </select> >+ <img id="rating-loading" style="display:none" src="[% interface | html %]/[% theme | html %]/images/spinner-small.gif" alt="" /> >+ >+ <!-- define some hidden vars for ratings --> >+ >+ <input type="hidden" name="biblionumber" value="[% item.biblionumber | html %]" /> >+ <input type="hidden" name="rating_value" class="rating_value" value="[% item.my_rating.rating_value | html %]" /> >+ >+ <input name="rate_button" type="submit" class="js-show" value="Rate me" /> >+ >+ [% IF item.my_rating %] >+ <div> >+ <span class="rating_value_text">Your rating: [% item.my_rating.rating_value | html %].</span> >+ <span class="cancel_rating_text js-show"><a href="#" data-context="star_rating-[% item.itemnumber | html %]"><i class="fa fa-remove"></i> Cancel rating</a>.</span> >+ </div> >+ [% ELSE %] >+ <span class="rating_value_text"></span> >+ <span class="cancel_rating_text" style="display:none;"><a href="#" data-context="star_rating-[% item.itemnumber | html %]"><i class="fa fa-remove"></i> Cancel rating</a>.</span> >+ [% END %] >+ >+ <div class="rating_text">Average rating: [% rating_avg | html %] ([% item.ratings.count | html %] votes)</div> >+</div> >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 %] > <p class="results-summary item-details">[% issue.author | html %]</p> > >- [% IF ( Koha.Preference( 'OpacStarRatings' ) == 'all' && issue.my_rating ) %] >- <div class="results_summary ratings"> >- <div class="br-wrapper br-theme-fontawesome-stars"> >- <div class="br-widget br-readonly"> >- [% FOREACH i IN [ 1 2 3 4 5 ] %] >- [% IF issue.my_rating.rating_value == i %] >- <a href="#" class="br-selected br-current"></a> >- [% ELSIF issue.my_rating.rating_value > i %] >- <a href="#" class="br-selected"></a> >- [% ELSE %] >- <a href="#"></a> >- [% END %] >- [% END %] >- </div> >- </div> >- Rated on [% issue.my_rating.timestamp | $KohaDates %] >- </div> <!-- / .results_summary --> >- [% END # / IF OpacStarRatings %] >+ [% IF ( Koha.Preference( 'OpacStarRatings' ) == 'all' ) %] >+ [% INCLUDE 'user-star-ratings.inc' item=issue %] >+ [% END %] > > </td> > <td> >@@ -235,5 +220,12 @@ > } > }); > }); >+ var borrowernumber = "[% borrowernumber | html %]"; >+ var MSG_YOUR_RATING = _("Your rating: %s, "); >+ var MSG_AVERAGE_RATING = _("Average rating: %s (%s votes)"); > </script> >+ [% 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 @@ > <td class="title"> > <a class="title" href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% ISSUE.biblionumber | html %]">[% INCLUDE 'biblio-title.inc' biblio=ISSUE %]</a> > [% IF ( ISSUE.enumchron ) %] [% ISSUE.enumchron | html %][% END %] >+ > [% IF ( ISSUE.onsite_checkout ) %] <i class="onsite_checkout">(On-site checkout)</i>[% END %] >+ >+ [% IF ( Koha.Preference('OpacStarRatings') == 'all' ) %] >+ [% INCLUDE 'user-star-ratings.inc' item=ISSUE %] >+ [% END %] > </td> > > <td class="author">[% ISSUE.author | html %]</td> >@@ -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)"); > </script> >+ [% 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 %] > <script> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/ratings.js b/koha-tmpl/opac-tmpl/bootstrap/js/ratings.js >new file mode 100644 >index 0000000000..971e604f2f >--- /dev/null >+++ b/koha-tmpl/opac-tmpl/bootstrap/js/ratings.js >@@ -0,0 +1,46 @@ >+/* global borrowernumber MSG_YOUR_RATING MSG_AVERAGE_RATING */ >+// ----------------------------------------------------- >+// star-ratings code >+// ----------------------------------------------------- >+// hide 'rate' button if javascript enabled >+ >+$(document).ready(function(){ >+ $("input[name='rate_button']").remove(); >+ >+ var star_ratings = $(".star_rating"); >+ >+ star_ratings.barrating({ >+ theme: 'fontawesome-stars', >+ showSelectedRating: false, >+ allowEmpty: true, >+ deselectable: false, >+ onSelect: function( value ) { >+ var context = $("#" + this.$elem.data("context") ); >+ $(".rating-loading", context ).show(); >+ $.post("/cgi-bin/koha/opac-ratings-ajax.pl", { >+ rating_old_value: $(".rating_value", context ).attr("value"), >+ borrowernumber: borrowernumber, >+ biblionumber: this.$elem.data('biblionumber'), >+ rating_value: value, >+ auth_error: value >+ }, function (data) { >+ $(".rating_value", context ).val(data.rating_value); >+ if (data.rating_value) { >+ $(".rating_value_text", context ).text( MSG_YOUR_RATING.format(data.rating_value) ); >+ $(".cancel_rating_text", context ).show(); >+ } else { >+ $(".rating_value_text", context ).text(""); >+ $(".cancel_rating_text", context ).hide(); >+ } >+ $(".rating_text", context ).text( MSG_AVERAGE_RATING.format(data.rating_avg, data.rating_total) ); >+ $(".rating-loading", context ).hide(); >+ }, "json"); >+ } >+ }); >+ >+ $("body").on("click", ".cancel_rating_text a", function(e){ >+ e.preventDefault(); >+ var context = "#" + $(this).data("context"); >+ $(context).barrating("set", ""); >+ }); >+}); >diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/script.js b/koha-tmpl/opac-tmpl/bootstrap/js/script.js >index 30d792f448..6bd94be58d 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/js/script.js >+++ b/koha-tmpl/opac-tmpl/bootstrap/js/script.js >@@ -42,6 +42,8 @@ $(document).ready(function(){ > window.close(); > }); > $(".focus").focus(); >+ $(".js-show").show(); >+ $(".js-hide").hide(); > > if( $(window).width() < 768 ){ > facetMenu("hide"); >@@ -70,4 +72,4 @@ $(document).ready(function(){ > e.preventDefault(); > $("#loginModal").modal("show"); > }); >-}); >\ No newline at end of file >+}); >diff --git a/opac/opac-user.pl b/opac/opac-user.pl >index d94d3d0e2b..6d967c8803 100755 >--- a/opac/opac-user.pl >+++ b/opac/opac-user.pl >@@ -43,6 +43,7 @@ use Koha::Patrons; > use Koha::Patron::Messages; > use Koha::Patron::Discharge; > use Koha::Patrons; >+use Koha::Ratings; > use Koha::Token; > > use constant ATTRIBUTE_SHOW_BARCODE => 'SHOW_BCODE'; >@@ -267,6 +268,12 @@ if ( $pending_checkouts->count ) { # Useless test > $issue->{'description'} = $itemtypes->{$itemtype}->{'description'}; > } > >+ if ( C4::Context->preference('OpacStarRatings') eq 'all' ) { >+ my $ratings = Koha::Ratings->search({ biblionumber => $issue->{biblionumber} }); >+ $issue->{ratings} = $ratings; >+ $issue->{my_rating} = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef; >+ } >+ > $issue->{biblio_object} = Koha::Biblios->find($issue->{biblionumber}); > push @issuedat, $issue; > $count++; >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 25110
:
102938
|
103017
|
103080
|
103081
|
103365
|
103405
|
103718
|
103719