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

Profile page count #3156

Merged
merged 3 commits into from
Jul 27, 2018
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: 4 additions & 0 deletions app/models/drupal_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ def note_count
Node.where(status: 1, uid: uid, type: 'note').count
end

def revision_count
Revision.where(uid: uid).count
end

def node_count
Node.where(status: 1, uid: uid).count + Revision.where(uid: uid).count
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/notes/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<% elsif params[:action] == "author_topic" %>
<h3><%= raw t('notes.index.research_on', :tags => @tagnames.join(', '), :url1 => "/people/"+@user.name, :user_name => @user.name) %> <br /><small><%= raw t('notes.index.research_notes_and_wiki_edits_with_time', :count => @user.node_count, :time => time_ago_in_words(@user.created_at)) %></small></h3>
<% elsif params[:action] == "author" %>
<h3><%= raw t('notes.index.research_by', :url1 => "/people/"+@user.name, :user_name => @user.name) %> <small><%= raw t('notes.index.research_notes_and_wiki_edits', :count => @user.node_count) %> <% if @user.notes.length > 0 %><%= raw t('notes.index.starting_time', :time => time_ago_in_words(@user.created_at)) %><% end %></small></h3>
<h3><%= raw t('notes.index.research_by', :url1 => "/people/"+@user.name, :user_name => @user.name) %> <small><%= raw t('notes.index.research_notes_and_wiki_edits', :count1 => @user.note_count, :count2 => @user.revision_count) %> <% if @user.notes.length > 0 %><%= raw t('notes.index.starting_time', :time => time_ago_in_words(@user.created_at)) %><% end %></small></h3>
<% else %>
<h2><%= raw t('notes.index.research_notes_ideas_and_documentation') %></h2>
<% end %>
Expand Down
162 changes: 81 additions & 81 deletions app/views/users/profile.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<h3 style="margin-top:0;"><%= @user.name %> <%= @user.new_contributor %>
<small>
<%= @user.node_count %> <%= raw t('users.profile.notes_and_edits', :url1 => "/notes/author/"+@user.name) %>
<%= @user.note_count %><a href='/notes/author/<%= @user.name %>'> research notes</a> and <%= @user.revision_count %> wiki edits
<% if current_user && current_user.role == "admin" %> | <%= @user.email %><% end %>
<% if @user.role == "moderator" %> | <i class="fa fa-certificate"></i> <%= t('users.profile.moderator') %><% end %>
<% if @user.role == "admin" %> | <i class="fa fa-certificate"></i> <%= t('users.profile.admin') %><% end %>
Expand All @@ -18,10 +18,10 @@
<div class="row" id="highlight" style=" text-align: center;">
<h3 class="col-md-4 col-xs-12 col-sm-4"><a href = "/tag/question:*/author/<%= params[:id] %>"><%= Node.questions.where(status: 1, uid: @user.id).length %> questions asked </a><br><br> <%= Answer.where(uid: @profile_user.id).count %> answers posted</h3>
<h3 class="col-md-4 col-xs-12 col-sm-4"><a href = "/tag/activity:*/author/<%= params[:id] %>"><%= @count_activities_posted %> activities posted </a><br><br> <a href = "/tag/replication:*/author/<%= params[:id] %>"><%= @count_activities_attempted %> activities attempted</a></h3>
<% if !@map_lat.nil? && !@map_lon.nil? %>
<% if !@map_lat.nil? && !@map_lon.nil? %>
<%= render :partial => "map/userLeaflet" , locals: {haslocation: true} %>
<% elsif !current_user.nil? && current_user.id == @user.id %>
<%= render :partial => "map/userLeaflet" , locals: {haslocation: false} %>
<%= render :partial => "map/userLeaflet" , locals: {haslocation: false} %>
<% end %>
</div>
<hr />
Expand All @@ -39,7 +39,7 @@

<br />

<div class="tab-content">
<div class="tab-content">

<div class="tab-pane active" id="research">
<div class="btn-group text-center">
Expand All @@ -60,29 +60,29 @@
</div>

<% if current_user && current_user.uid == @profile_user.uid %>
<div class="tab-pane" id="draft">
<%= render :partial => "notes/draft_notes" %>
</div>
<div class="tab-pane" id="draft">
<%= render :partial => "notes/draft_notes" %>
</div>
<% end %>
</div>
</div>

<div class="tab-pane" id="questions">
<div class="btn-group text-center">
<a href="#asked" class="btn btn-default active" data-toggle="tab">Asked</a>
<a href="#answered" class="btn btn-default" data-toggle="tab">Answered</a>
</div>
<div class="tab-pane" id="questions">
<div class="btn-group text-center">
<a href="#asked" class="btn btn-default active" data-toggle="tab">Asked</a>
<a href="#answered" class="btn btn-default" data-toggle="tab">Answered</a>
</div>

<div class="tab-content">
<div class="tab-pane active" id="asked">
<%= render :partial => "questions/questions" %>
</div>
<div class="tab-content">
<div class="tab-pane active" id="asked">
<%= render :partial => "questions/questions" %>
</div>

<div class="tab-pane" id="answered">
<%= render :partial => "users/answered" %>
</div>
</div>
</div>
<div class="tab-pane" id="answered">
<%= render :partial => "users/answered" %>
</div>
</div>
</div>

<div class="tab-pane" id="maps">
<p><i><%= raw t('users.profile.view_these_maps', :url1 => "//mapknitter.org/profile/"+@user.name) %></i></p>
Expand All @@ -105,10 +105,10 @@

<div class="tab-pane" id="barnstars">
<% if @user.user %>
<% @user.user.barnstars.each do |tag| %>
<p style="color:#aaa;"><i style="color:#db4;" class="fa fa-large fa fa-star-o"></i> <i><%= raw t('users.profile.barnstar_awarded_to_by', :url1 => "/profile/"+tag.node.author.name, :author => tag.node.author.name, :url2 => "/wiki/barnstars#"+tag.name.split(':').last.split('-').each{|w| w.capitalize!}.join('+'), :barnstar => tag.name.split(':').last.split('-').each{|w| w.capitalize!}.join(' '), :url3 => "/profile/"+tag.author.username, :awarder => tag.author.username, :url4 => tag.node.path, :work => tag.node.title) %></i></p>
<hr />
<% end %>
<% @user.user.barnstars.each do |tag| %>
<p style="color:#aaa;"><i style="color:#db4;" class="fa fa-large fa fa-star-o"></i> <i><%= raw t('users.profile.barnstar_awarded_to_by', :url1 => "/profile/"+tag.node.author.name, :author => tag.node.author.name, :url2 => "/wiki/barnstars#"+tag.name.split(':').last.split('-').each{|w| w.capitalize!}.join('+'), :barnstar => tag.name.split(':').last.split('-').each{|w| w.capitalize!}.join(' '), :url3 => "/profile/"+tag.author.username, :awarder => tag.author.username, :url4 => tag.node.path, :work => tag.node.title) %></i></p>
<hr />
<% end %>
<% end %>
</div>
</div>
Expand All @@ -127,37 +127,37 @@
<%= render :partial => "tag/tagging", locals: { url: "/profile/tags/create/#{ @user.id }", parent: :profile } %>

<div class="profile_icons" style="text-align: center;">
<% if @twitter.nil? == false %>
<% if @twitter.nil? == false %>
<a href="<%= @twitter %>" >
<i class="fa fa-twitter fa-3x" aria-hidden="true"></i>
<i class="fa fa-twitter fa-3x" aria-hidden="true"></i>
</a>
<% end %>
<% if @facebook.nil? == false %>
<a href="<%= @facebook %>" >
<i class="fa fa-facebook fa-3x" aria-hidden="true"></i>
</a>
<a href="<%= @facebook %>" >
<i class="fa fa-facebook fa-3x" aria-hidden="true"></i>
</a>
<% end %>
<% if @github.nil? == false %>
<a href="<%= @github %>" >
<i class="fa fa-github fa-3x" aria-hidden="true"></i>
</a>
<a href="<%= @github %>" >
<i class="fa fa-github fa-3x" aria-hidden="true"></i>
</a>
<% end %>
<% if @instagram.nil? == false %>
<a href="<%= @instagram %>" >
<i class="fa fa-instagram fa-3x" aria-hidden="true"></i>
</a>
<a href="<%= @instagram %>" >
<i class="fa fa-instagram fa-3x" aria-hidden="true"></i>
</a>
<% end %>
</div>
<br>
<% if current_user && @profile_user %>
<% unless current_user == @profile_user %>
<hr />
<div id="follow_form" class="col-md-offset-4">
<% if current_user.following?(@profile_user) %>
<%= render 'unfollow' %>
<% else %>
<%= render 'follow' %>
<% end %>
<% if current_user.following?(@profile_user) %>
<%= render 'unfollow' %>
<% else %>
<%= render 'follow' %>
<% end %>
</div>
<br />
<% end %>
Expand Down Expand Up @@ -225,7 +225,7 @@
<hr />

<% if params[:preview] %>
<hr />
<hr />

<div class="row">
<div class="col-md-3 col-md-offset-1">
Expand All @@ -243,23 +243,23 @@
<h5><b><%= link_to @profile_user.following_users.count, following_path(id: @profile_user.username) %></b></h5>
</div>
</div>
<hr />
<hr />

<% end %>

<div class="hidden-xs">
<% if @wikis && @wikis.length > 0 %>
<h4><%= t('users.profile.wiki_contributed_to') %></h4>
<ul class="nav bullet">
<% @wikis.each do |wiki| %>
<% unless (!@node.nil? && wiki.nid == @node.nid) %>
<h4><%= t('users.profile.wiki_contributed_to') %></h4>
<ul class="nav bullet">
<% @wikis.each do |wiki| %>
<% unless (!@node.nil? && wiki.nid == @node.nid) %>
<li><a href="<%= wiki.path %>"><i class="fa fa-<%= wiki.icon %>"></i> <%= wiki.latest.title %></a> <small style="color:#888;"><%= t('users.profile.updated') %> <%= distance_of_time_in_words(wiki.updated_at, Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %> <%= t('users.profile.by') %> <a href="/profile/<%= wiki.latest.author.name %>"><%= wiki.latest.author.name %></a></small></li>
<% end %>
<% end %>
<% end %>
<% if params[:controller] == "search" %>
<li><a href="/tag/<%= params[:id] %>"><%= t('users.profile.more') %>...</a></li>
<% end %>
</ul>
<% if params[:controller] == "search" %>
<li><a href="/tag/<%= params[:id] %>"><%= t('users.profile.more') %>...</a></li>
<% end %>
</ul>
<% end %>
</div>

Expand All @@ -269,39 +269,39 @@
<script src = "https://cdn.jsdelivr.net/npm/frappe-charts@0.0.8/dist/frappe-charts.min.iife.js"></script>

<script type = "text/javascript">
$('#btn-token').click(function() {
alert("Your access token is: <%= @user.user.token %>");
});

$('#link_social_media').click(function(){
var sign = prompt("Enter Your Social Media User name like twitter:publiclab or instagram:publiclab");
$.post('/profile/tags/create/<%=@user.uid %> ',{"name": sign,"id":<%=@user.uid %>}, function(data) {
window.location='/profile/<%=@user.name %> ';
});
});

(function () {
var profile = Object.create(Profile);
profile.value.user_id = "<%= @user.uid %>"
profile.display_comments();

<% if @user && @user.user %>
var notes = <%= @user.user.daily_note_tally.to_a.sort %>
var comments = <%= @user.user.weekly_comment_tally.to_a.sort.to_json %>
var notesObject = {};
notes.forEach(function(element){
notesObject[element[0]] = element[1];
$('#btn-token').click(function() {
alert("Your access token is: <%= @user.user.token %>");
});
<% end %>

profile.value.notes = notesObject;
profile.value.comments = comments;
profile.plot_graph();
$('#link_social_media').click(function(){
var sign = prompt("Enter Your Social Media User name like twitter:publiclab or instagram:publiclab");
$.post('/profile/tags/create/<%=@user.uid %> ',{"name": sign,"id":<%=@user.uid %>}, function(data) {
window.location='/profile/<%=@user.name %> ';
});
});

(function () {
var profile = Object.create(Profile);
profile.value.user_id = "<%= @user.uid %>"
profile.display_comments();

<% if @user && @user.user %>
var notes = <%= @user.user.daily_note_tally.to_a.sort %>
var comments = <%= @user.user.weekly_comment_tally.to_a.sort.to_json %>
var notesObject = {};
notes.forEach(function(element){
notesObject[element[0]] = element[1];
});
<% end %>

profile.value.notes = notesObject;
profile.value.comments = comments;
profile.plot_graph();

profile.value.name = "<%= @user.name %>"
profile.fetch_maps();
profile.value.name = "<%= @user.name %>"
profile.fetch_maps();

})();
})();
</script>

<style type="text/css">
Expand Down
2 changes: 1 addition & 1 deletion config/locales/views/notes/index/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ en:
research_on: "Research on \"%{tags}\" by <a href='%{url1}'>%{user_name}</a>"
research_notes_and_wiki_edits_with_time: "%{count} research notes and wiki edits starting %{time} ago"
research_by: "Research by <a href='%{url1}'>%{user_name}</a>"
research_notes_and_wiki_edits: "%{count} research notes and wiki edits"
research_notes_and_wiki_edits: "%{count1} research notes and %{count2} wiki edits"
starting_time: "starting %{time} ago"
research_notes_ideas_and_documentation: "Research notes <small class=\"hidden-sm\">ideas & documentation from contributors like you</small>"
recent: "Recent"
Expand Down