Skip to content

Commit

Permalink
Add new stars images for plugins rating display
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpirix committed Feb 13, 2024
1 parent 998e0b5 commit 936701a
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 3 deletions.
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
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.
14 changes: 14 additions & 0 deletions qgis-app/static/jquery-ratings/jquery.ratings.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,17 @@
.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');
}

32 changes: 30 additions & 2 deletions qgis-app/static/jquery-ratings/jquery.ratings.js
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');
}
}

//add the star to the container
Expand All @@ -65,13 +78,28 @@ jQuery.fn.ratings = function(stars, initialRating) {
//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++) {
Expand Down
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.

0 comments on commit 936701a

Please sign in to comment.