Reputation Plugin Version 0.2

REPUTATION PLUGIN
this plugin shows a reputation for each user in user’s card:

For now this is showing just the received like but I will improve the rules for giving reputation and make some more complex algorithm than counting just received likes for reputation
This is my first plugin for discourse and this is the 0.1 version of this pluing and I hope I can develope this plugin with your helps.
I’m trying to develope this plugin to get the reputation calculation rules from admin in admin pannel
v0.2:

  • Outlet text conflict SOLVED
  • Showing s start image with “Your reputation” tooltip

special thanks from cakeday’s author. I learned many things from his plugin.

10 Likes

I have some translation problem for showing the word “Your reputation” in diffrent language.You every body now any answer for this?
[SOLVED]

https://meta.discourse.org/t/contribute-a-translation-to-discourse/14882/30?u=pad_pors

1 Like

For something so deceptively simple looking, yml files sure can be enough of a bother at times.

In this case you have a spelling error. It’s “label” not “lable” that you’re after.

4 Likes

Is there any problem with this code for reading likes(this is helper):

import { registerUnbound } from 'discourse-common/lib/helpers';
registerUnbound('show', function(params) {
	var target = -1;
	$.ajax({
  url: "/users/" + params + "/summary.json",
  dataType: 'json',
  async: false,
  success: function(data) {
  	target = data.user_summary.likes_received;
  }
});
	return new Handlebars.SafeString(target);
});

and the handlebar is:
{{show username}}
It works well in local but doesn’t work well in website

I would look into getting the Likes Given count from one of the tables instead of an AJAX request. If for only your own site, it might not be a problem. But it is possible for a site to set the Summary page to logged in only, which could cause a problem.

AFAICT there are 3 tables that have Likes Given counts.

One is directory_items.likes_received (the Users page) but that can also be logged in only, and it has various period_type’s

Another is user_stats.likes_received (the Summary page)

The other is user_actions.action_type where user_actions.action_type = 2
and it would need to do a COUNT query.

1 Like

how can I use these in my plugin?
Should I use helper or using just handlebars are enough

I used the helper file to read the DOM. I guess it could do AJAX as well, but if a site required being logged in you would need to pass that along somehow.

Offhand I know of three plugins that work with he database. Each has SQL stuff in its the top level plugin.rb file in heredoc syntax.

https://github.com/discourse/discourse-tagging
(Tagging has since been moved into the Core)

https://github.com/discourse/discourse-moderator-attention

2 Likes

how can I handle the conflict in showing results?
the texts are unreadable

Sorry, I’ve had too much nog or not enough I guess, but you’ve lost me.

What conflict of what results? What text is unreadable? The links to the GitHub repos aren’t working for you?

2 Likes

I was hoping it might be a simple CSS fix like adding style="clear: both" or something.

But after looking closely there seems to be an issue with the Core HTML eg.

<div class="names">
  <span>
    <h1 class="  username">
      <a href="/users/adminguy1" data-ember-action="" data-ember-action-1163="1163">
      AdminGuy1 
        <i class="fa fa-shield" aria-hidden="true"></i>
        <span class="sr-only">[en. is a moderator]</span>
      </a>
    </h1>
    <!---->
    <h2>good guy</h2>
    <span id="ember1164" class="ember-view">
      <div id="ember1166" class="user-card-post-names-outlet mitt-show-user-card-post-names ember-view">
      <!---->
      </div>
      <div id="ember1168" class="user-card-post-names-outlet Score ember-view">
      Your reputation: -1
      </div>
    </span>
  </span>
</div>

https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/templates/components/user-card-contents.hbs#L15-L35

Having h tags inside of span tags is not valid HTML so it seems senseless to try and apply CSS fixes to it. Though perhaps changing the plugin template divs to spans might improve the display as div tags inside of span tags is not valid HTML either.

I know work is being done with how plugin-outlets will work so probably best to wait until that settles down and concentrate on other areas of your plugin for the time being.

1 Like

At times senseless is my middle name. :blush:

If you have your template output an element with a class value, you can use CSS in your assets/stylesheets folder to get it to the far right side of the card.

Not the best solution and it will likely break at some time in the future, but you should be able to see at least some of it without it being obscured or needing to look in view-source.

.your-class {
  text-align: right;
}
4 Likes

CSS problem solved and some changes took effect in version 0.2

Hello , Is there a demo?

I think this plugin has stopped working/been deprecated in Disco’s recent/current version (2.4.0 Beta11)