Skip to content

Commit

Permalink
profile page instance variable fixes (publiclab#5186)
Browse files Browse the repository at this point in the history
* profile page instance variable fixes

* fixes

* Update _tagging.html.erb

* Update _tagging.html.erb

* Update _follow.html.erb

* Update _unfollow.html.erb

* Update profile.html.erb

* Update profile.html.erb
  • Loading branch information
jywarren authored and icarito committed Apr 9, 2019
1 parent 0074183 commit ce1a1da
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 97 deletions.
50 changes: 25 additions & 25 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,71 +135,71 @@ def profile
elsif !current_user && params[:id].nil?
redirect_to "/"
else
@user = User.find_by(username: params[:id])
if !@user
@profile_user = User.find_by(username: params[:id])
if !@profile_user
flash[:error] = I18n.t('users_controller.no_user_found_name', username: params[:id])
redirect_to "/"
else
@title = @user.name
@title = @profile_user.name
@notes = Node.research_notes
.paginate(page: params[:page], per_page: 24)
.order("nid DESC")
.where(status: 1, uid: @user.uid)
.where(status: 1, uid: @profile_user.uid)

if current_user && current_user.uid == @user.uid
if current_user && current_user.uid == @profile_user.uid
coauthor_nids = Node.joins(:node_tag)
.joins('LEFT OUTER JOIN term_data ON term_data.tid = community_tags.tid')
.select('node.*, term_data.*, community_tags.*')
.where(type: 'note', status: 3)
.where('term_data.name = (?)', "with:#{@user.username}")
.where('term_data.name = (?)', "with:#{@profile_user.username}")
.collect(&:nid)
@drafts = Node.where('(nid IN (?) OR (status = 3 AND uid = ?))', coauthor_nids, @user.uid)
@drafts = Node.where('(nid IN (?) OR (status = 3 AND uid = ?))', coauthor_nids, @profile_user.uid)
.paginate(page: params[:page], per_page: 24)
end
@coauthored = @user.coauthored_notes
@coauthored = @profile_user.coauthored_notes
.paginate(page: params[:page], per_page: 24)
.order('node_revisions.timestamp DESC')
@questions = @user.questions
@questions = @profile_user.questions
.order('node.nid DESC')
.paginate(page: params[:page], per_page: 24)
@likes = (@user.liked_notes.includes(%i(tag comments)) + @user.liked_pages)
@likes = (@profile_user.liked_notes.includes(%i(tag comments)) + @profile_user.liked_pages)
.paginate(page: params[:page], per_page: 24)
questions = Node.questions
.where(status: 1)
.order('node.nid DESC')
ans_ques = questions.select { |q| q.answers.collect(&:author).include?(@user) }
ans_ques = questions.select { |q| q.answers.collect(&:author).include?(@profile_user) }
@answered_questions = ans_ques.paginate(page: params[:page], per_page: 24)
wikis = Revision.order("nid DESC")
.where('node.type' => 'page', 'node.status' => 1, uid: @user.uid)
.where('node.type' => 'page', 'node.status' => 1, uid: @profile_user.uid)
.joins(:node)
.limit(20)
@wikis = wikis.collect(&:parent).uniq

@comment_count = Comment.where(status: 1, uid: @user.uid).count
@comment_count = Comment.where(status: 1, uid: @profile_user.uid).count

# User's social links
@github = @user.social_link("github")
@twitter = @user.social_link("twitter")
@facebook = @user.social_link("facebook")
@instagram = @user.social_link("instagram")
@count_activities_posted = Tag.tagged_nodes_by_author("activity:*", @user).count
@count_activities_attempted = Tag.tagged_nodes_by_author("replication:*", @user).count
@github = @profile_user.social_link("github")
@twitter = @profile_user.social_link("twitter")
@facebook = @profile_user.social_link("facebook")
@instagram = @profile_user.social_link("instagram")
@count_activities_posted = Tag.tagged_nodes_by_author("activity:*", @profile_user).count
@count_activities_attempted = Tag.tagged_nodes_by_author("replication:*", @profile_user).count
@map_lat = nil
@map_lon = nil
if @user.has_power_tag("lat") && @user.has_power_tag("lon")
@map_lat = @user.get_value_of_power_tag("lat").to_f
@map_lon = @user.get_value_of_power_tag("lon").to_f
@map_blurred = @user.has_tag('blurred:true')
if @profile_user.has_power_tag("lat") && @profile_user.has_power_tag("lon")
@map_lat = @profile_user.get_value_of_power_tag("lat").to_f
@map_lon = @profile_user.get_value_of_power_tag("lon").to_f
@map_blurred = @profile_user.has_tag('blurred:true')
end

if @user.status == 0
if @profile_user.status == 0
if current_user&.can_moderate?
flash.now[:error] = I18n.t('users_controller.user_has_been_banned')
else
flash[:error] = I18n.t('users_controller.user_has_been_banned')
redirect_to "/"
end
elsif @user.status == 5
elsif @profile_user.status == 5
flash.now[:warning] = I18n.t('users_controller.user_has_been_moderated')
end
end
Expand Down
3 changes: 2 additions & 1 deletion app/views/map/_userLeaflet.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<%= render :partial => "map/mapDependencies" %>
<% user = user || @user # allow overriding w/ local variable %>
<% if haslocation == true %>
<style>
Expand All @@ -20,7 +21,7 @@
// var hash = new L.Hash(map);
<% if !(@map_blurred == true) %>
var default_Icon =new PLmarker_default() ;
L.marker([<%= @map_lat %>, <%= @map_lon %>] , {icon: default_Icon}).addTo(map).bindPopup("<a href='https://publiclab.org/profile/<%= @user.username %>'><%= @user.username %> </a>");
L.marker([<%= @map_lat %>, <%= @map_lon %>] , {icon: default_Icon}).addTo(map).bindPopup("<a href='https://publiclab.org/profile/<%= user.username %>'><%= user.username %> </a>");
<% end %>
</script>
<% else %>
Expand Down
8 changes: 5 additions & 3 deletions app/views/tag/_tagging.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<% user = user || @user # allow overriding w/ local variable %>

<!-- This is the sidebar tagging display, also renders Subscribe button for multiple subscription -->
<div>
<h1 style="display: inline-block; margin-right: 20px;">Tags</h1>
Expand All @@ -17,7 +19,7 @@
</span>
<% else %>
<span id="tags">
<%= render partial: 'tag/tags', locals: { power_tag: false, label_name: 'label-primary', tags: @user.user_tags } %>
<%= render partial: 'tag/tags', locals: { power_tag: false, label_name: 'label-primary', tags: user.user_tags, user: user } %>
</span>
<% end %>
Expand Down Expand Up @@ -47,7 +49,7 @@ $(".label").on("click", function(e){
<% parent ||= nil %>
<% if current_user && (parent != :profile || (current_user.id == @user.id || current_user.role == "admin")) %>
<% if current_user && (parent != :profile || (current_user.id == user.id || current_user.role == "admin")) %>
<% url = url || "/tag/create/" + @node.id.to_s %>
<form id="tagform" class="form" data-remote="true" action="<%= url %>">
Expand All @@ -70,7 +72,7 @@ $(".label").on("click", function(e){
initTagForm("/tag/delete/<%= @node.id %>", '#tagform');
<% else %>
// user tags:
initTagForm("/profile/tags/delete/<%= @user.id %>", '#tagform');
initTagForm("/profile/tags/delete/<%= user.id %>", '#tagform');
<% end %>
});
</script>
Expand Down
3 changes: 2 additions & 1 deletion app/views/tag/_tags.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% user = user || @user # allow overriding w/ local variable %>
<ul class= "list-inline">
<% tags.each do |tag| %>
<% if tag.class == NodeTag %>
Expand All @@ -23,7 +24,7 @@
<%= tag.name[0..5] + tag.name.split(':')[1] %>
<% end %>
<% if current_user && ( current_user.uid == tag.uid || current_user.role == "admin" || current_user.role == "moderator") %>
<a data-confirm="Are you sure you want to delete it?" class="tag-delete" data-remote="true" href="/profile/tags/delete/<%= @user.id %>?name=<%= tag.name %>" data-method="delete">x</a>
<a data-confirm="Are you sure you want to delete it?" class="tag-delete" data-remote="true" href="/profile/tags/delete/<%= user.id %>?name=<%= tag.name %>" data-method="delete">x</a>
<% end %>
</span></li>
Expand Down
7 changes: 5 additions & 2 deletions app/views/users/_answered.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<div id="answered-question">
<div class="row">

<% user = user || @user # allow overriding w/ local variable %>
<% @answered_questions.each_with_index do |question,i| %>
<% answers = if @user then question&.answers.where(uid: @user.uid) else question.answers end %>
<% answers = if user then question&.answers.where(uid: user.uid) else question.answers end %>
<div class="col-md-4" style="margin-top:30px;">
<div class="note note-pane note-answer">
<div class="header-icon"><i class="fa fa-question-circle"></i></div>
Expand All @@ -13,7 +16,7 @@
<a href="/profile/<%= question.author.name %>"><%= question.author.name %></a>
asked about <span style="color:#888;"><%= time_ago_in_words(question.created_at) %> ago</span>
</p>
<div class="text-center"><span id="question-<%= question.nid %>-toggle" class="btn btn-default btn-xs">Answers <%= if @user then "by #{@user.name}" end %><i class="fa fa-caret-down"></i></span></div>
<div class="text-center"><span id="question-<%= question.nid %>-toggle" class="btn btn-default btn-xs">Answers <%= if user then "by #{user.name}" end %><i class="fa fa-caret-down"></i></span></div>
<div id="question-<%= question.nid %>" class="user-answer">
<% answers.each do |answer| %>
<p>answered on <a href="<%= question.path(:question) %>#a<%= answer.id %>" style="color:#888;"><%= answer.created_at.strftime("%b %d, %Y") %></a><span class="pull-right"><% if answer.accepted %><i class="fa fa-check-square" style="color: #1fa67a;"></i> <% end %><i class="fa fa-star" style="color: #FFEB3B;"></i> <%= answer.likers.length %></span></p>
Expand Down
3 changes: 2 additions & 1 deletion app/views/users/_follow.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<% user = user || @user # allow overriding w/ local variable %>
<%= form_for(current_user.active_relationships.build) do |f| %>
<div><%= hidden_field_tag :followed_id, @user.id %></div>
<div><%= hidden_field_tag :followed_id, user.id %></div>
<%= f.submit "Follow", class: "btn btn-primary" %>
<% end %>
3 changes: 2 additions & 1 deletion app/views/users/_unfollow.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%= form_for(current_user.active_relationships.where(followed_id: @user.id).first,
<% user = user || @user # allow overriding w/ local variable %>
<%= form_for(current_user.active_relationships.where(followed_id: user.id).first,
html: { method: :delete }) do |f| %>
<%= f.submit "Unfollow", class: "btn" %>
<% end %>
6 changes: 4 additions & 2 deletions app/views/users/likes.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<div class="col-md-3">

<% user = user || @user # allow overriding w/ local variable %>
<% if @wikis && @wikis.length > 0 %>
<h3 style="margin-top:0;"><%= t('users.likes.wiki_liked_by') %> <a href="/profile/<%= @user.name %>"><%= @user.name %></a></h3>
<h3 style="margin-top:0;"><%= t('users.likes.wiki_liked_by') %> <a href="/profile/<%= user.name %>"><%= user.name %></a></h3>
<ul class="nav bullet">
<% @wikis.each do |wiki| %>
Expand All @@ -18,7 +20,7 @@
</div>
<div class="col-md-9">
<h3 style="margin-top:0;"><i class="fa fa-star-o"></i> <%= t('users.likes.liked_by') %> <a href="/profile/<%= @user.name %>"><%= @user.name %></a></h3>
<h3 style="margin-top:0;"><i class="fa fa-star-o"></i> <%= t('users.likes.liked_by') %> <a href="/profile/<%= user.name %>"><%= user.name %></a></h3>
<hr />
Expand Down
Loading

0 comments on commit ce1a1da

Please sign in to comment.