Add contributors count to tag pages
This has been marked as a good candidate for becoming a first-timers-only issue like these, meaning that it's simple, self-contained, and with some extra formatting, could be a great entry point for a new contributor. If you're familiar enough with this code, please consider reformatting or reposting it as a first-timers-only issue, and then ping @jywarren to get it labelled. Or, if this is not your first time, try to solve it yourself!
The new tag pages have a great "intro" section sourced from the first paragraph of the corresponding wiki page, as of #985:
https://publiclab.org/tag/dustduino
But if no corresponding page exists, they do not.
You can see the contributor count for that topic here:
https://publiclab.org/contributors/dustduino

We should show how many people contributed to that topic on the tag page itself, just below the title, in smaller grey text just below this line: https://github.com/publiclab/plots2/blob/master/app/views/tag/show.html.erb#L12
See how we calculate that in the contributors action in the tag_controller: https://github.com/publiclab/plots2/blob/master/app/controllers/tag_controller.rb#L217
@users = @notes.collect(&:author).uniq
However, that @notes is all notes, not just those on this page (since /tag/dustuino is paginated). So see the tag_controller to see how that's calculated. We'll likely have to add that code as well to be able to display this on the main tag page under def show in the same controller.
Update: We may just want to display the number in the tab for Contributors, just before the word, like: 14 Contributors. That would go on this line:
https://github.com/publiclab/plots2/blob/master/app/views/tag/show.html.erb#L61 And could look like this:
<li<% if @node_type == "contributors" %> class="active"<% end %>><a href="/contributors/<%= params[:id] %>"><i class="fa fa-user"></i> <%= @notes.collect(&:author).uniq.length %> <%= raw t('tag.show.contributors') %></a></li>
However, we still want to be sure we're counting all contributors, and not just the ones for content shown on this page. We may want to add a followup issue to convert this count to a generalized tag-based method for counting contributors. OK -- did that in #1419
@jywarren I am interested to take this up. I need some context here though.
- We need to show the contributors count for the tag or the wiki page?
- If there is no wiki page for that tag, where will the count be shown?
- Is contributor count dependent on the notes displayed? If so, then how?
https://github.com/publiclab/plots2/blob/master/app/controllers/tag_controller.rb#L217 shows all contributors for that tag, and we can use a phrase like:
#people have contributed to this topic.
For now, let's just keep this inside the wiki block, and only show it if there's a corresponding wiki page.
Contributor count will probably need to be calculated separately from how @notes is already generated, since @notes will be paginated, so you'd only see results from currently shown notes.
You could do this, even though it's going to be a lot of processing:
all_notes = DrupalNode.where(:status => 1, :type => 'note')
.includes(:drupal_node_revision,:drupal_tag)
.where('term_data.name = ?', params[:id])
.order("node_revisions.timestamp DESC")
@contributors = all_notes.collect(&:author).uniq
If we'd like to be more efficient, we could use .select() to narrow and not return any database columns we don't explicitly need: http://guides.rubyonrails.org/active_record_querying.html#selecting-specific-fields
But you have to be careful -- every single field you need to make the relationships is required... so it's a little delicate to do properly.
Thanks!
@jywarren Is this issue still open? I'd like to help out.
@arkokoley It is, I suppose. Feel free to come back here or on our Gitter should you need any help. Thanks.
Hi, @arkokoley, just checking if you've gotten stuck on this at all, or if I could help in any way? Thanks!
Hey, @arkokoley! What's the status on this? If you require any assistance from our side, feel free to ask for help or hop on to one of the chatrooms.
Just a note to folks - as we haven't heard back from people, this is up for grabs!
@jywarren I can take a stab at this if still open
Super, please do, esp. as I don't think there's been activity on it recently. We're happy to help!
On Thu, Jun 1, 2017 at 2:30 PM, Austin Denny [email protected] wrote:
@jywarren https://github.com/jywarren I can take a stab at this if still open
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/publiclab/plots2/issues/1028#issuecomment-305580068, or mute the thread https://github.com/notifications/unsubscribe-auth/AABfJ5ff3fN_kcUbCd2VKIKQuvi7oGMAks5r_wM_gaJpZM4K-ONt .
@jywarren I like to contribute on this issue!! Can I?
Yes please!
On Mon, Sep 4, 2017 at 12:36 PM, Amit Chambial [email protected] wrote:
@jywarren https://github.com/jywarren I like to contribute on this issue!! Can I?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/publiclab/plots2/issues/1028#issuecomment-326999447, or mute the thread https://github.com/notifications/unsubscribe-auth/AABfJ6ucqkxu3pk0L1If_Cq2E6mL3sujks5sfCcegaJpZM4K-ONt .
I am using
notes = Node.where(status: 1, type: 'note')
.includes(:revision, :tag)
.where('term_data.name = ?', params[:id])
users = notes.collect(&:author).uniq
if !users.nil?
@length=users.length
end
to count users. And Badge to show number contributor.If contributors are zero then show no badge
Hmm, do you think you could open a pull request so we can look at your changes in context? Thanks!
On Wed, Sep 6, 2017 at 3:52 AM, Amit Chambial [email protected] wrote:
I am using
notes = Node.where(status: 1, type: 'note') .includes(:revision, :tag) .where('term_data.name = ?', params[:id]) users = notes.collect(&:author).uniq if !users.nil? @length=users.length end
to count users. And Badge to show number contributor.If contributors are zero then show no badge
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/publiclab/plots2/issues/1028#issuecomment-327404690, or mute the thread https://github.com/notifications/unsubscribe-auth/AABfJ6E351M6M_kXRVP3W8AdTjHvi4qYks5sfk8jgaJpZM4K-ONt .
My rake test queries are giving errors and I am not able to remove the errors.I have tried googling it and many more things but it still giving error..My output to bundle exec rake test:all --trace is :
https://gist.github.com/devaman/ad0585e5d8ea49d61533dc256c2f7be4
@jywarren I have submitted a pull request on this issue.Can you review it...
Thanks to @devaman for this fix!!!