Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plugin detail rating #359

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions qgis-app/plugins/templates/plugins/plugin_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% block extrajs %}
{{ block.super }}
<script type="text/javascript" src="{% static "js/jquery.cookie.js" %}"></script>
<script type="text/javascript" src="{% static "jquery-ratings/jquery.ratings.js" %}"></script>
<script type="text/javascript" src="{% static "jquery-ratings/jquery.ratings.1.0.js" %}"></script>
<script type="text/javascript">

function csrfSafeMethod(method) {
Expand Down Expand Up @@ -87,7 +87,7 @@
</script>
{% endblock %}
{% block extracss %}
<link type="text/css" href="{% static "jquery-ratings/jquery.ratings.css" %}" rel="stylesheet" />
<link type="text/css" href="{% static "jquery-ratings/jquery.ratings.1.0.css" %}" rel="stylesheet" />
{{ block.super }}
<style>
.tooltip {
Expand Down
2 changes: 1 addition & 1 deletion qgis-app/plugins/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def get_context_data(self, **kwargs):
messages.error(self.request, msg, fail_silently=True)
context.update(
{
"rating": int(plugin.rating.get_rating()),
"rating": plugin.rating.get_rating(),
"votes": plugin.rating.votes,
}
)
Expand Down
5 changes: 5 additions & 0 deletions qgis-app/settings_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
from datetime import timedelta
from django.contrib.staticfiles.storage import ManifestStaticFilesStorage

DEBUG = ast.literal_eval(os.environ.get("DEBUG", "True"))
THUMBNAIL_DEBUG = DEBUG
Expand All @@ -31,6 +32,10 @@
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = "/static/"

# Manage static files storage ensuring that their
# filenames contain a hash of their content for cache busting
# STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'

INSTALLED_APPS = [
"django.contrib.auth",
"django.contrib.contenttypes",
Expand Down
4 changes: 2 additions & 2 deletions qgis-app/static/jquery-ratings/example.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<html>
<head>
<link type="text/css" rel="stylesheet" href="jquery.ratings.css" />
<link type="text/css" rel="stylesheet" href="jquery.ratings.1.0.css" />
<script src="jquery-1.3.2.min.js"></script>
<script src="jquery.ratings.js"></script>
<script src="jquery.ratings.1.0.js"></script>
<script src="example.js"></script>
</head>
<body>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added qgis-app/static/jquery-ratings/half-star-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added qgis-app/static/jquery-ratings/half-star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions qgis-app/static/jquery-ratings/jquery.ratings.1.0.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.jquery-ratings-star {
width: 16px;
height: 16px;
background-image: url('empty-star-16.png');
background-repeat: no-repeat;
position: relative;
float: left;
margin-right: 2px;
}

.jquery-ratings-full {
background-image: url('full-star-16.png');
}


.jquery-ratings-quarter {
background-image: url('quarter-star-16.png');
}

.jquery-ratings-half {
background-image: url('half-star-16.png');
}

.jquery-ratings-half-and-quarter {
background-image: url('half-and-quarter-star-16.png');
}

Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,21 @@ jQuery.fn.ratings = function(stars, initialRating) {
star.addClass('jquery-ratings-star');

//Add the full css class if the star is beneath the initial rating.
// The last star will depend on the decimal left
if(starIdx < initialRating) {
star.addClass('jquery-ratings-full');
let ratingDiff = initialRating - starIdx
if (ratingDiff > 0 && ratingDiff <= 0.3) {
star.addClass('jquery-ratings-quarter');
}
else if (ratingDiff > 0.3 && ratingDiff <= 0.6) {
star.addClass('jquery-ratings-half');
}
else if (ratingDiff > 0.6 && ratingDiff <= 0.9) {
star.addClass('jquery-ratings-half-and-quarter');
}
else {
star.addClass('jquery-ratings-full');
}
Comment on lines +45 to +59
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks 👍 On a first sight I was wondering about the uneven distribution >0.3 <= 0.6 for the "half star", but how you implemented it, every "partial star" is displayed for a range of 0.3 which is fine. With the stars it's hard to spot how many decimals are represented anyway :-)

}

//add the star to the container
Expand All @@ -60,21 +73,39 @@ jQuery.fn.ratings = function(stars, initialRating) {
star.mouseenter(function() {
//Highlight selected stars.
for(var index = 0; index < this.rating; index++) {
starsCollection[index].removeClass('jquery-ratings-half-and-quarter');
starsCollection[index].removeClass('jquery-ratings-half');
starsCollection[index].removeClass('jquery-ratings-quarter');
starsCollection[index].addClass('jquery-ratings-full');
}
//Unhighlight unselected stars.
for(var index = this.rating; index < stars; index++) {
starsCollection[index].removeClass('jquery-ratings-full');
starsCollection[index].removeClass('jquery-ratings-half-and-quarter');
starsCollection[index].removeClass('jquery-ratings-half');
starsCollection[index].removeClass('jquery-ratings-quarter');
}
});

container.mouseleave(function() {
//Highlight selected stars.
for(var index = 0; index < containerElement.rating; index++) {
starsCollection[index].addClass('jquery-ratings-full');
let ratingDiff = containerElement.rating - index
if (ratingDiff > 0 && ratingDiff <= 0.3) {
starsCollection[index].addClass('jquery-ratings-quarter');
}
else if (ratingDiff > 0.3 && ratingDiff <= 0.6) {
starsCollection[index].addClass('jquery-ratings-half');
}
else if (ratingDiff > 0.6 && ratingDiff <= 0.9) {
starsCollection[index].addClass('jquery-ratings-half-and-quarter');
}
else {
starsCollection[index].addClass('jquery-ratings-full');
}
}
//Unhighlight unselected stars.
for(var index = containerElement.rating; index < stars ; index++) {
for(var index = Math.floor(containerElement.rating); index < stars ; index++) {
starsCollection[index].removeClass('jquery-ratings-full');
}
});
Expand Down
13 changes: 0 additions & 13 deletions qgis-app/static/jquery-ratings/jquery.ratings.css

This file was deleted.

Binary file added qgis-app/static/jquery-ratings/quarter-star-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added qgis-app/static/jquery-ratings/quarter-star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading