Bugzilla – Attachment 132067 Details for
Bug 29749
Clean up OpacStarRatings
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29749: Clean up OpacStarRatings code
Bug-29749-Clean-up-OpacStarRatings-code.patch (text/plain), 21.21 KB, created by
Lucas Gass
on 2022-03-23 17:12:03 UTC
(
hide
)
Description:
Bug 29749: Clean up OpacStarRatings code
Filename:
MIME Type:
Creator:
Lucas Gass
Created:
2022-03-23 17:12:03 UTC
Size:
21.21 KB
patch
obsolete
>From fc079b6b5fa4ebabdd42fd32c52ce1c10b131927 Mon Sep 17 00:00:00 2001 >From: Lucas Gass <lucas@bywatersolutions.com> >Date: Tue, 21 Dec 2021 22:51:02 +0000 >Subject: [PATCH] Bug 29749: Clean up OpacStarRatings code > >To test: >1. Apply patch >2. Make sure OpacStarRatings is set to 'results, details, patrons' >3. Check out some items to a patron you can login to the OPAC as >4. Do a OPAC catalog search that will turn up some of those items you checked out >5. Go to the item's detail pages, logged in as the patron with those checkouts >6. From the detail page, rate some of those items. >7. Go to the user summary page, make sure you can see and change the ratings from there. >8. Go to the reading history page, make sure you can see and change those ratins from there. >9. Go back to the detail pages and make sure any changes you made on the user summary and reading history page are acuratly reflected >10. Look at those items from the results page. You should be able to view the ratings but not change them. >11. Again visit the OPAC, this time as a unauthenticated user. You should be able to view the ratings from the details page but not interact with them. >--- > .../en/includes/user-star-ratings.inc | 101 ++++++++++------- > .../bootstrap/en/modules/opac-detail.tt | 103 +++--------------- > .../en/modules/opac-readingrecord.tt | 2 +- > .../bootstrap/en/modules/opac-results.tt | 24 +--- > .../bootstrap/en/modules/opac-user.tt | 2 +- > opac/opac-detail.pl | 16 ++- > 6 files changed, 87 insertions(+), 161 deletions(-) > >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 >index c0ebd2c0c7..2073dd11cd 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/user-star-ratings.inc >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/user-star-ratings.inc >@@ -1,53 +1,74 @@ >-<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 %] >+[% IF interact %] >+ <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 %]"> > >- <div class="br-wrapper br-theme-fontawesome-stars js-hide"> >- <div class="br-widget br-readonly"> >+ [% IF ( rating_avg_int == 0 ) %] >+ <option value="" selected="selected"></option> >+ [% END %] > [% 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> >+ <option value="[% i | html %]" selected="selected">[% i | html %]</option> > [% ELSE %] >- <a href="#"></a> >+ <option value="[% i | html %]">[% i | html %]</option> > [% END %] > [% END %] >- </div> >- </div> >+ </select> >+ <img id="rating-loading" style="display:none" src="[% interface | html %]/[% theme | html %]/images/spinner-small.gif" alt="" /> > >- <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 %]"> >+ <!-- define some hidden vars for ratings --> > >- [% 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="" /> >+ <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 %]" /> > >- <!-- define some hidden vars for ratings --> >+ <input name="rate_button" type="submit" class="js-show" value="Rate me" /> > >- <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" aria-hidden="true"></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" aria-hidden="true"></i> Cancel rating</a>.</span> >+ [% END %] > >- [% 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" aria-hidden="true"></i> Cancel rating</a>.</span> >+ <div class="rating_text">Average rating: [% rating_avg | html %] ([% item.ratings.count | html %] votes)</div> >+ </div> >+[% ELSE %] >+ <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 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> >- [% 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" aria-hidden="true"></i> Cancel rating</a>.</span> >- [% END %] >- >- <div class="rating_text">Average rating: [% rating_avg | html %] ([% item.ratings.count | html %] votes)</div> >-</div> >+ [% IF item.ratings.count > 0 %] >+ <span id="rating_total_[% item.biblionumber | html %]"> ([% item.ratings.count | html %] votes)</span> >+ [% ELSE %] >+ <br /> >+ [% END %] >+ </div> >+[% END %] >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >index f6dc6014a2..ac98e74a8c 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >@@ -296,50 +296,10 @@ > [%# Following on one line due to translation issues %] > [% INCLUDE "openlibrary-readapi.inc" bib = { normalized_isbn => normalized_isbn,lccn => lccn, normalized_oclc => normalized_oclc } %] > >- [% IF ( OpacStarRatings != 'disable' ) %] >- <form method="post" action="/cgi-bin/koha/opac-ratings.pl"> >- <legend class="sr-only">Star ratings</legend> >- <div class="results_summary ratings"> >- >- [% SET rating_avg = ratings.get_avg_rating() %] >- [% rating_avg_int = BLOCK %][% rating_avg | format("%.0f") %][% END %] >- >- [% IF ( borrowernumber ) %] >- <select id="star_rating" name="rating" data-rating-enabled="1" autocomplete="off"> >- [% ELSE %] >- <select id="star_rating" name="rating" data-rating-enabled="0" disabled="disabled" autocomplete="off"> >- [% END %] >- [% 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="[% biblio.biblionumber | html %]" /> >- <input type="hidden" name='rating_value' id='rating_value' value="[% my_rating.rating_value | html %]" /> >- >- [% UNLESS ( rating_readonly ) %] <input name="rate_button" type="submit" value="Rate me" />[% END %] >- >- [% IF my_rating %] >- <span id="rating_value_text">Your rating: [% my_rating.rating_value | html %].</span> >- <span id="cancel_rating_text"><a href="#"><i class="fa fa-remove" aria-hidden="true"></i> Cancel rating</a>.</span> >- [% ELSE %] >- <span id="rating_value_text"></span> >- <span id="cancel_rating_text" style="display:none;"><a href="#"><i class="fa fa-remove" aria-hidden="true"></i> Cancel rating</a>.</span> >- [% END %] >- >- <span id="rating_text">Average rating: [% rating_avg | html %] ([% ratings.count | html %] votes)</span> >- </div> >- </form> >+ [% IF ( OpacStarRatings != 'disable' && loggedinusername) %] >+ [% INCLUDE 'user-star-ratings.inc' item=rating interact=1 %] >+ [% ELSIF ( OpacStarRatings != 'disable' )%] >+ [% INCLUDE 'user-star-ratings.inc' item=rating %] > [% END # / IF OpacStarRatings != 'disable' %] > > [% IF ( BakerTaylorContentURL ) %] >@@ -1379,8 +1339,16 @@ > [% INCLUDE 'datatables.inc' %] > [% INCLUDE 'columns_settings.inc' %] > [% INCLUDE greybox.inc %] >- [% IF ( OpacStarRatings != 'disable' ) %][% Asset.js("lib/jquery/plugins/jquery.barrating.min.js") | $raw %][% END %] > >+ [% IF ( OpacStarRatings != 'disable' ) %] >+ [% Asset.js("lib/jquery/plugins/jquery.barrating.min.js") | $raw %] >+ [% Asset.js("js/ratings.js") | $raw %] >+ <script> >+ var borrowernumber = [% borrowernumber | html %]; >+ var MSG_YOUR_RATING = _("Your rating: %s, "); >+ var MSG_AVERAGE_RATING = _("Average rating: %s (%s votes)"); >+ </script> >+ [% END %] > [% IF ( OpacHighlightedWords ) %][% Asset.js("lib/jquery/plugins/jquery.highlight-3.js") | $raw %][% END %] > [% IF ( Koha.Preference('OPACDetailQRCode') ) %] > [% Asset.js("lib/kjua/kjua.min.js") | $raw %] >@@ -1817,51 +1785,6 @@ > }); > }()); > [% END # /IF ( OPACShelfBrowser ) %] >- >- [% IF ( OpacStarRatings != 'disable' ) %] >- // ----------------------------------------------------- >- // star-ratings code >- // ----------------------------------------------------- >- // hide 'rate' button if javascript enabled >- >- $('input[name="rate_button"]').remove(); >- >- var rating_enabled = ( $("#star_rating").data("rating-enabled") == "1" ) ? false : true; >- $('#star_rating').barrating({ >- theme: 'fontawesome-stars', >- showSelectedRating: false, >- allowEmpty: true, >- deselectable: false, >- readonly: rating_enabled, >- onSelect: function(value, text) { >- $("#rating-loading").show(); >- $.post("/cgi-bin/koha/opac-ratings-ajax.pl", { >- rating_old_value: $("#rating_value").attr("value"), >- borrowernumber: "[% borrowernumber | html %]", >- biblionumber: "[% biblio.biblionumber | html %]", >- rating_value: value, >- auth_error: value >- }, function (data) { >- $("#rating_value").val(data.rating_value); >- if (data.rating_value) { >- $("#rating_value_text").text(_("Your rating: %s, ").format(data.rating_value)); >- $("#cancel_rating_text").show(); >- } else { >- $("#rating_value_text").text(''); >- $("#cancel_rating_text").hide(); >- } >- $("#rating_text").text(_("Average rating: %s (%s votes)").format(data.rating_avg, data.rating_total)); >- $("#rating-loading").hide(); >- }, "json"); >- } >- }); >- >- $("#cancel_rating_text a").on("click", function(e){ >- e.preventDefault(); >- $("#star_rating").barrating("set", ""); >- }); >- >- [% END # / IF ( OpacStarRatings != 'disable' )%] > }); > > $(document).ready(function() { >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 a3ad4f4e3d..fdc187f0e8 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt >@@ -149,7 +149,7 @@ > <p class="results-summary item-details">[% issue.author | html %]</p> > > [% IF ( Koha.Preference( 'OpacStarRatings' ) == 'all' ) %] >- [% INCLUDE 'user-star-ratings.inc' item=issue %] >+ [% INCLUDE 'user-star-ratings.inc' item=issue interact=1 %] > [% END %] > > </td> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >index 98106fdcd7..f9bc67bed6 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >@@ -502,29 +502,7 @@ > [% INCLUDE "openlibrary-readapi.inc" bib = SEARCH_RESULT %] > > [% IF ( OpacStarRatings == 'all' ) %] >- <div class="results_summary ratings"> >- [% SET rating_avg = SEARCH_RESULT.ratings.get_avg_rating() %] >- [% rating_avg_int = BLOCK %][% rating_avg | format("%.0f") %][% END %] >- <div class="br-wrapper br-theme-fontawesome-stars"> >- <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> >- >- [% IF SEARCH_RESULT.ratings.count > 0 %] >- <span id="rating_total_[% SEARCH_RESULT.biblionumber | html %]"> ([% SEARCH_RESULT.ratings.count | html %] votes)</span> >- [% ELSE %] >- <br /> >- [% END %] >- </div> <!-- / .results_summary --> >+ [% INCLUDE 'user-star-ratings.inc' item=SEARCH_RESULT %] > [% END # / IF OpacStarRatings %] > > [% INCLUDE 'title-actions-menu.inc' items=SEARCH_RESULT %] >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 481fecc1a1..c36b9baaf9 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt >@@ -318,7 +318,7 @@ > [% IF ( ISSUE.onsite_checkout ) %] <em class="onsite_checkout">(On-site checkout)</em>[% END %] > > [% IF ( Koha.Preference('OpacStarRatings') == 'all' ) %] >- [% INCLUDE 'user-star-ratings.inc' item=ISSUE %] >+ [% INCLUDE 'user-star-ratings.inc' item=ISSUE interact=1 %] > [% END %] > > [% IF ( ISSUE.recall ) %]<br><i>This item has been recalled. Please return by the new due date.</i>[% END %] >diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl >index 00c52eb5aa..246bc968d2 100755 >--- a/opac/opac-detail.pl >+++ b/opac/opac-detail.pl >@@ -1159,12 +1159,16 @@ if (C4::Context->preference("OPACURLOpenInNewWindow")) { > $template->param(borrowernumber => $borrowernumber); > > if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) { >- my $ratings = Koha::Ratings->search({ biblionumber => $biblionumber }); >- my $my_rating = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef; >- $template->param( >- ratings => $ratings, >- my_rating => $my_rating, >- ); >+ my $rating; >+ my $ratings = Koha::Ratings->search({ biblionumber => $biblionumber }); >+ my $my_rating = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef; >+ $rating->{ratings} = $ratings; >+ $rating->{my_rating} = $my_rating; >+ $rating->{borrowernumber} = $borrowernumber; >+ $rating->{biblionumber} = $biblionumber; >+ $template->param( >+ rating => $rating, >+ ); > } > > #Search for title in links >-- >2.20.1
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 29749
:
128850
| 132067