Skip to content

Commit

Permalink
Social Media Feature on profile page (Part of #1802) (#1816)
Browse files Browse the repository at this point in the history
* Updated users_controller.rb

For facebook , twitter , github .

* Social Media feature added

* Social Media Feature added .

Using fontawesome library .

* Updated user.rb

* Updated users_controller.rb

* Updated users_controller.rb

* Updated user.rb

* Tests added for power tags

* tests added for power tags

* round icons
  • Loading branch information
sagarpreet-chadha authored and jywarren committed Dec 4, 2017
1 parent 9c06d7a commit cbf6e37
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
16 changes: 16 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ def profile
.joins(:node)
.limit(20)
@wikis = wikis.collect(&:parent).uniq
@twitter = nil
@facebook = nil
@github = nil
if @profile_user.has_power_tag("twitter") == true
twitter_user_name = @profile_user.get_value_of_power_tag("twitter")
@twitter = "https://twitter.com/" + twitter_user_name.to_s
end
if @profile_user.has_power_tag("facebook") == true
facebook_user_name = @profile_user.get_value_of_power_tag("facebook")
@facebook = "https://facebook.com/" + facebook_user_name.to_s
end
if @profile_user.has_power_tag("github") == true
github_user_name = @profile_user.get_value_of_power_tag("github")
@github = "https://github.com/" + github_user_name.to_s
end

if @user.status == 0
if current_user && (current_user.role == "admin" || current_user.role == "moderator")
flash.now[:error] = I18n.t('users_controller.user_has_been_banned')
Expand Down
16 changes: 16 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,22 @@ def has_tag(tagname)
user_tags.collect(&:value).include?(tagname)
end

# power tags have "key:value" format, and should be searched with a "key:*" wildcard
def has_power_tag(key)
all_key_tags_ids = Tag.where('name LIKE ?' , key + ':%').collect(&:tid)
tids = TagSelection.where('user_id = ? AND tid IN (?)', self.id , all_key_tags_ids)
!tids.blank?
end

def get_value_of_power_tag(key)
all_key_tags = Tag.where('name LIKE ?' , key + ':%')
all_key_tags_ids = all_key_tags.collect(&:tid)
tids = TagSelection.where('user_id = ? AND tid IN (?)', self.id , all_key_tags_ids).collect(&:tid)
tname = Tag.find(tids.first)
tvalue = tname.name.partition(':').last
tvalue
end

def subscriptions(type = :tag)
if type == :tag
TagSelection.find_all_by_user_id uid, conditions: { following: true }
Expand Down
20 changes: 19 additions & 1 deletion app/views/users/profile.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,25 @@
<img class="img-circle" id="profile-photo" style="width:50%;margin-bottom:20px;" src="<%= @user.user.profile_image %>" />
</div>
<% end %>


<div style="text-align: -webkit-center;">
<% if @twitter.nil? == false %>
<a href="<%= @twitter %>" >
<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>
<% end %>
<% if @github.nil? == false %>
<a href="<%= @github %>" >
<i class="fa fa-github fa-3x" aria-hidden="true"></i>
</a>
<% end %>
</div>
<br>
<% if current_user && @profile_user %>
<% unless current_user == @profile_user %>
<hr />
Expand Down
10 changes: 10 additions & 0 deletions test/unit/node_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ class NodeTest < ActiveSupport::TestCase
assert_equal node.normal_tags, [node_tags(:test2)]
end

test 'returns power tag' do
node = node(:blog)
assert_equal node.power_tag_objects("lat") , [node_tags(:map_lat)]
end

test 'has power tag' do
node = node(:blog)
assert node.has_power_tag("lat")
end

test 'should show question icon for question node' do
node = node(:question)
assert_equal 'question-circle', node.icon
Expand Down
11 changes: 11 additions & 0 deletions test/unit/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,15 @@ class UserTest < ActiveSupport::TestCase
node2 = rusers(:lurker).node.find_by_nid(20)
assert_equal [node2], lurker.content_followed_in_past_period(2.hours.ago)
end

test 'returns value of power tag' do
bob = rusers(:bob)
assert_equal bob.get_value_of_power_tag("question") , "spectrometer"
end

test 'has power tag' do
bob = rusers(:bob)
assert bob.has_power_tag("question")
end

end

0 comments on commit cbf6e37

Please sign in to comment.