Topic Ratings Plugin

(Daler) #124

Hey, Santa Angus! Got some room in your busy schedule? :slight_smile:

[feature request] Show the count of reviews along with the avg score 路 Issue #11 路 angusmcleod/discourse-ratings 路 GitHub

(Angus McLeod) #125

Added :santa: Setting is rating_show_count; default is false.

See further: The 400 blows - Truffaut - Ratings - Angus' Sandbox

(Daler) #126

Dear Santa, thank you very much! I always believed you were real :blush:

(Tumi) #127

Thanks for Your time. Ok i will learn how to do it all becouse im not a programmer鈥 Need some time. Pls tell me - should i learn a ruby laungage or not really ? Should i know somethink more ? How to learn it as fast as it possible (not for be a pro - just for myself needs)

(Angus McLeod) #128

@dalerka @hnaseri As discussed, I鈥檝e updated the average / count style. It now looks like this:

54 PM

Both the Amazon style and the use of an emoji has issues. I think it鈥檚 best we keep it simple.

Thanks for your suggestions :+1:

(Daler) #129

Thanks, Angus! I totally agree with you on KISS, but genuinely curious if you could expand on issues with Amazon鈥檚 approach. Is it about UX or Discourse-related?

(Angus McLeod) #130

There aren鈥檛 any inherent flaws with Amazon鈥檚 rating UI/UX or any inherent limitations in Discourse, it would just take considerably more work to achieve the same result in this plugin and there would be various UX tweaks to their approach and decisions that you鈥檇 need to make.

Effectively it would be a new feature-set rather than a UI tweak, which is all that is required for now.

Off the top of my head, some things you鈥檇 need to do would be:

  1. Fractional stars, which would entail a refactor of the CSS. Albeit, this has the minor caveat that the fractional star in Amazon typically does not represent the actual average. See the screenshot below for an example (4.5 according to the stars, 4.7 according to the text)

  2. Provide the rating breakdown from the server and set up the UI so that it鈥檚 consistent with the Discourse UI, e.g. the bar chart would be a new UI element you鈥檇 need to build specifically for this.

  3. Interactivity of the rating breakdown, i.e. in Amazon if you click on one of the ratings you see just those ratings. Once a rating breakdown is provided, the ability to filter the rating posts by rating is the natural next step.

Not to say that I wouldn鈥檛 want to do each of all of these things at some point, just not right now, particularly as these kind of features get more relevant when you鈥檙e dealing with consistently large volume of ratings, which (as far as I鈥檓 aware) we鈥檙e yet to see with this plugin.

(Matthew Boogaard) #131

This is awesome!

I鈥檝e been thinking how awesome a Discourse / ecommerce integration would be. There are heaps of third-party reviews systems, but they all to some extent take the SEO and community engagement away from your site.

IMO, this plugin + your Q&A plugin would work very nicely! Basically you could relate the post to a particular product (from say a CSV or XML product feed or ecommerce CMS鈥檚 API). I guess the ratings threads would need a way to restrict topic creation so that there is only one thread per product.

On the ecommerce CMS side you鈥檇 have some kind of widget that shows a snippet of the ratings and Q&A鈥檚 for that product, similar to the WP / Discourse integration.


(Angus McLeod) #132

Yes that鈥檚 all doable. I haven鈥檛 been doing a lot of work on the QnA plugin, so if you want to use that in a serious way you鈥檒l need to take a close look at it and test its functionality thoroughly.

Not entirely sure what you mean here, but this would seem to be something your moderators would handle, at least initially.

Sounds a bit like you may want to also use Topic List Previews.

(Daler) #133

:crazy_face: Today I updated the plugin to (fd25572) and the Rating-stars disappeared from items of topics list view and on suggested topics list (i.e. I can still see the stars on a topic page).

I cannot find any elements with .topic-rating class in the source code of the topic list view. Is it a bug or is there a new setting I should enable?

(Angus McLeod) #134

Yup, minor bug. It will work as normal now. Thanks for reporting.

(Daler) #135

Thanks! So, (just for the record) previously the plugin rendered the .topic-rating nested under .social-footer and now it renders nested under .topic-title (in a topic-list view).

Now, I also see that in the suggested topics list sometimes (randomly) the .topic-rating and .topic-excerpt elements don鈥檛 get rendered at all. Any ideas why?

UPDATE: Don鈥檛 know why, but the later issue with excerpt and rating not rendering randomly has suddenly disappeared. Magic :smile:

(Angus McLeod) #136

Hm yeah. This is all about plugin outlet placement in the topic list item template(s). The Ratings plugin is now using the topic-list-after-title outlet.

I鈥檝e handled the case you鈥檙e referring to. For social style, the plugin outlet will render content in the gutter now.

(Daler) #137

Haha, I鈥檓 sorry, didn鈥檛 mean to distract you.
The after-title position was actually preferable for me (even with Social style). My point was to help other people fix styling (target the right element). I made few CSS changes and removed hiding an extra middot.

So, if possible can you keep it the new way (i.e. rendering at after-title)?

UPDATE: Also with the recent update the .topic-ratings element doesn鈥檛 render on mobile (with social style topic list enabled). So, to keep it simple, maybe just render after title?

(Angus McLeod) #138

I鈥檝e fixed the mobile outlet, but I鈥檓 sorry, I think it makes more sense for the social style to have the outlet in the footer by default - it鈥檚 where all the other topic info is in that style.

If you want to move the element on your instance (i.e. more than just using CSS), you can use jQuery:'afterRender', () => {
  const $topicRating = $('.topic-rating');
  const $target = $(target);

This will make the topic-rating element the first child of whatever container you want to put it in.

(Daler) #139

No, problem at all! As long as things are kept consistent across updates :slight_smile:
Thank you for all your hard work!

(Anshul Kushwaha) #140

Hey @angus,

I want to extend this to allow for multiple ratings instead of just one.
e.g. in my case Train reviews can include punctuality, cleanliness, food.

I鈥檝e cloned the repo and exploring the code, a few pointers will be very helpful.

(Angus McLeod) #141

Do you mean multiple ratings on one topic? Yes that could be done I suppose. Basically, you鈥檒l need to add in additional custom fields, wherever the current rating custom fields are. And some conditional logic to handle the calculation of the average separately for each type.

For example, you may end up with something like this for saving the rating when a post is created:

  DiscourseEvent.on(:post_created) do |post, opts, user|
    if opts[:rating] || opts[:rating_type2]
      post.custom_fields['rating'] = opts[:rating] if opts[:rating]
      post.custom_fields['rating_type2'] = opts[:rating_type2] if opts[:rating_type2]
      post.custom_fields["rating_weight"] = 1
      RatingsHelper.handle_rating_update(post, opts)

Then add some conditional logic in handle_rating_update to calculate averages and push those averages to the topic, for each type of rating.

(Pari) #142

The newest version makes opening the rating topic too slow. for example if other topics would open in two seconds, rating topic opens in 5 seconds.

on the other hand is there an option to remove stars from below topic title and just let them be inside the topic?

(Angus McLeod) #143

Can you give me an example of this? In my own testing on localhost, and on, rating topics load at the same speed as any other topic.

I鈥檝e added settings for the average ratings in the topic and in the topic list: