diff --git a/db/up/like_follower_poly_assoc.sql b/db/up/like_follower_poly_assoc.sql index bfae7b284..ade837a30 100644 --- a/db/up/like_follower_poly_assoc.sql +++ b/db/up/like_follower_poly_assoc.sql @@ -2,8 +2,6 @@ drop table users_followers; drop table users_likers; drop table bands_followers; drop table bands_likers; -drop table music_sessions_likers; -drop table recordings_likers; alter table music_sessions_history add constraint music_sessions_history_pkey PRIMARY KEY (id); diff --git a/db/up/music_session_constraints.sql b/db/up/music_session_constraints.sql index f070bc571..c3cc58a19 100644 --- a/db/up/music_session_constraints.sql +++ b/db/up/music_session_constraints.sql @@ -1,6 +1,6 @@ alter table music_sessions_comments drop constraint music_sessions_comments_music_session_id_fkey; alter table music_sessions_comments add constraint ms_comments_ms_history_fkey foreign key (music_session_id) -references music_sessions_history(music_session_id) match simple +references music_sessions_history(id) match simple ON UPDATE NO ACTION ON DELETE CASCADE; alter table music_sessions_likers drop constraint music_sessions_likers_music_session_id_fkey; diff --git a/ruby/lib/jam_ruby.rb b/ruby/lib/jam_ruby.rb index d051ee683..db1b6a3d7 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -73,6 +73,7 @@ require "jam_ruby/models/friendship" require "jam_ruby/models/music_session" require "jam_ruby/models/music_session_comment" require "jam_ruby/models/music_session_history" +require "jam_ruby/models/music_session_liker" require "jam_ruby/models/music_session_user_history" require "jam_ruby/models/music_session_perf_data" require "jam_ruby/models/invitation" @@ -87,6 +88,7 @@ require "jam_ruby/models/track" require "jam_ruby/models/search" require "jam_ruby/models/recording" require "jam_ruby/models/recording_comment" +require "jam_ruby/models/recording_liker" require "jam_ruby/models/recording_play" require "jam_ruby/models/recorded_track" require "jam_ruby/models/recorded_track_observer" diff --git a/ruby/lib/jam_ruby/models/follow.rb b/ruby/lib/jam_ruby/models/follow.rb index 768b7589d..0a8437597 100644 --- a/ruby/lib/jam_ruby/models/follow.rb +++ b/ruby/lib/jam_ruby/models/follow.rb @@ -2,7 +2,12 @@ module JamRuby class Follow < ActiveRecord::Base belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "user_id" - belongs_to :likable, :polymorphic => true + belongs_to :followable, :polymorphic => true + + def type + type = self.followable_type.gsub("JamRuby::", "").downcase + type + end end end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/music_session_history.rb b/ruby/lib/jam_ruby/models/music_session_history.rb index 1fae0c97b..9c40b9add 100644 --- a/ruby/lib/jam_ruby/models/music_session_history.rb +++ b/ruby/lib/jam_ruby/models/music_session_history.rb @@ -21,7 +21,7 @@ module JamRuby has_many :music_session_user_histories, :class_name => "JamRuby::MusicSessionUserHistory", :foreign_key => "music_session_id" has_many :comments, :class_name => "JamRuby::MusicSessionComment", :foreign_key => "music_session_id" - has_many :likes, :as => :likable, :class_name => "JamRuby::Like", :dependent => :destroy + has_many :likes, :class_name => "JamRuby::MusicSessionLiker", :foreign_key => "session_id" has_one :share_token, :class_name => "JamRuby::ShareToken", :inverse_of => :shareable, :foreign_key => 'shareable_id' before_create :generate_share_token diff --git a/ruby/lib/jam_ruby/models/music_session_liker.rb b/ruby/lib/jam_ruby/models/music_session_liker.rb new file mode 100644 index 000000000..538822c6e --- /dev/null +++ b/ruby/lib/jam_ruby/models/music_session_liker.rb @@ -0,0 +1,17 @@ +module JamRuby + class MusicSessionLiker < ActiveRecord::Base + + self.table_name = "music_sessions_likers" + + self.primary_key = 'id' + + belongs_to(:music_session_history, + :class_name => "JamRuby::MusicSessionHistory", + :foreign_key => "music_session_id") + + belongs_to(:user, + :class_name => "JamRuby::User", + :foreign_key => "liker_id") + + end +end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/notification.rb b/ruby/lib/jam_ruby/models/notification.rb index 5ed469eca..48c363a1b 100644 --- a/ruby/lib/jam_ruby/models/notification.rb +++ b/ruby/lib/jam_ruby/models/notification.rb @@ -64,7 +64,7 @@ module JamRuby def retrieve_user_followers(connection, user_id) follower_ids = [] - connection.exec("SELECT uf.follower_id as friend_id FROM users_followers uf WHERE uf.user_id = $1", [user_id]) do |follower_results| + connection.exec("SELECT u.user_id as follower_id FROM follows f WHERE f.followable_id = $1", [user_id]) do |follower_results| follower_results.each do |follower_result| follower_ids.push(follower_result['follower_id']) end @@ -460,11 +460,11 @@ module JamRuby if music_session.musician_access || music_session.fan_access friends = Friendship.where(:friend_id => user.id) - user_followers = UserFollower.where(:user_id => user.id) + user_followers = user.followers # construct an array of User objects representing friends and followers friend_users = friends.map { |fu| fu.user } - follower_users = user_followers.map { |uf| uf.follower } + follower_users = user_followers.map { |uf| uf.user } friends_and_followers = friend_users.concat(follower_users).uniq # remove anyone in the session @@ -509,22 +509,21 @@ module JamRuby # if the session is private, don't send any notifications if music_session.musician_access || music_session.fan_access - band_followers = BandFollower.where(:band_id => band.id) - notifications, online_followers, offline_followers = [], [], [] notification_msg = format_msg(NotificationTypes::BAND_SESSION_JOIN, nil, band) - band_followers.each do |bf| - if (bf.follower.musician && music_session.musician_access) || (!bf.follower.musician && music_session.fan_access) + band.followers.each do |bf| + follower = bf.user + if (follower.musician && music_session.musician_access) || (!follower.musician && music_session.fan_access) notification = Notification.new notification.band_id = band.id notification.description = NotificationTypes::BAND_SESSION_JOIN - notification.target_user_id = bf.follower.id + notification.target_user_id = follower.id notification.save - if bf.follower.online + if follower.online msg = @@message_factory.band_session_join( - bf.follower.id, + follower.id, music_session.id, band.photo_url, notification_msg, @@ -532,9 +531,9 @@ module JamRuby notification.created_at.to_s ) - @@mq_router.publish_to_user(bf.follower.id, msg) + @@mq_router.publish_to_user(follower.id, msg) else - offline_followers << bf.follower + offline_followers << follower end end end @@ -551,11 +550,11 @@ module JamRuby user = recording.owner friends = Friendship.where(:friend_id => user.id) - user_followers = UserFollower.where(:user_id => user.id) + user_followers = user.followers # construct an array of User objects representing friends and followers friend_users = friends.map { |fu| fu.friend } - follower_users = user_followers.map { |uf| uf.follower } + follower_users = user_followers.map { |uf| uf.user } friends_and_followers = friend_users.concat(follower_users).uniq notifications, online_ff, offline_ff = [], [], [] @@ -592,20 +591,20 @@ module JamRuby def send_band_recording_saved(recording) - band_followers = BandFollower.where(:band_id => band.id) notification_msg = format_msg(NotificationTypes::BAND_RECORDING_SAVED, nil, recording.band) - band_followers.each do |bf| + band.followers.each do |bf| + follower = bf.user notification = Notification.new notification.description = NotificationTypes::BAND_RECORDING_SAVED notification.band_id = band.id - notification.target_user_id = bf.follower.id + notification.target_user_id = follower.id notification.recording_id = recording.id notification.save - if bf.follower.online + if follower.online msg = @@message_factory.band_recording_saved( - bf.follower.id, + follower.id, recording.id, band.photo_url, notification_msg, @@ -615,7 +614,7 @@ module JamRuby @@mq_router.publish_to_user(of.id, notification_msg) else - offline_followers << bf.follower + offline_followers << follower end end diff --git a/ruby/lib/jam_ruby/models/recording.rb b/ruby/lib/jam_ruby/models/recording.rb index 37a4f17ef..631431928 100644 --- a/ruby/lib/jam_ruby/models/recording.rb +++ b/ruby/lib/jam_ruby/models/recording.rb @@ -10,8 +10,7 @@ module JamRuby has_many :mixes, :class_name => "JamRuby::Mix", :inverse_of => :recording, :foreign_key => 'recording_id', :dependent => :destroy has_many :recorded_tracks, :class_name => "JamRuby::RecordedTrack", :foreign_key => :recording_id, :dependent => :destroy has_many :comments, :class_name => "JamRuby::RecordingComment", :foreign_key => "recording_id" - # has_many :likes, :class_name => "JamRuby::RecordingLiker", :foreign_key => "recording_id" - has_many :likes, :as => :likable, :class_name => "JamRuby::Like", :dependent => :destroy + has_many :likes, :class_name => "JamRuby::RecordingLiker", :foreign_key => "recording_id" has_many :plays, :class_name => "JamRuby::RecordingPlay", :foreign_key => "recording_id" belongs_to :owner, :class_name => "JamRuby::User", :inverse_of => :owned_recordings, :foreign_key => 'owner_id' diff --git a/ruby/lib/jam_ruby/models/recording_liker.rb b/ruby/lib/jam_ruby/models/recording_liker.rb new file mode 100644 index 000000000..041465d2b --- /dev/null +++ b/ruby/lib/jam_ruby/models/recording_liker.rb @@ -0,0 +1,12 @@ +module JamRuby + class RecordingLiker < ActiveRecord::Base + + self.table_name = "recordings_likers" + + self.primary_key = 'id' + + belongs_to :recording, :class_name => "JamRuby::Recording", :foreign_key => "recording_id" + belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "liker_id" + + end +end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/search.rb b/ruby/lib/jam_ruby/models/search.rb index db86dfc82..324b1a9f0 100644 --- a/ruby/lib/jam_ruby/models/search.rb +++ b/ruby/lib/jam_ruby/models/search.rb @@ -124,7 +124,7 @@ module JamRuby .order("play_count DESC, users.created_at DESC") when :followed sel_str = "COUNT(follows) AS search_follow_count, #{sel_str}" - rel = rel.joins("LEFT JOIN users_followers AS follows ON follows.user_id = users.id") + rel = rel.joins("LEFT JOIN follows ON follows.followable_id = users.id") .group("users.id") .order("COUNT(follows) DESC, users.created_at DESC") when :playing @@ -170,7 +170,7 @@ module JamRuby @results.each do |uu| counters = { } counters[COUNT_FRIEND] = Friendship.where(:user_id => uu.id).count - counters[COUNT_FOLLOW] = UserFollowing.where(:user_id => uu.id).count + counters[COUNT_FOLLOW] = Follow.where(:followable_id => uu.id).count counters[COUNT_RECORD] = ClaimedRecording.where(:user_id => uu.id).count counters[COUNT_SESSION] = MusicSession.where(:user_id => uu.id).count @user_counters[uu.id] << counters @@ -179,8 +179,8 @@ module JamRuby # this section determines follow/like/friend status for each search result # so that action links can be activated or not rel = User.select("users.id AS uid") - rel = rel.joins("LEFT JOIN users_followers AS follows ON follows.follower_id = '#{user.id}'") - rel = rel.where(["users.id IN (#{mids}) AND follows.user_id = users.id"]) + rel = rel.joins("LEFT JOIN follows ON follows.user_id = '#{user.id}'") + rel = rel.where(["users.id IN (#{mids}) AND follows.followable_id = users.id"]) rel.all.each { |val| @user_counters[val.uid] << RESULT_FOLLOW } rel = User.select("users.id AS uid") @@ -288,7 +288,7 @@ module JamRuby .order("play_count DESC, bands.created_at DESC") when :followed sel_str = "COUNT(follows) AS search_follow_count, #{sel_str}" - rel = rel.joins("LEFT JOIN bands_followers AS follows ON follows.band_id = bands.id") + rel = rel.joins("LEFT JOIN follows ON follows.followable_id = bands.id") .group("bands.id") .order("COUNT(follows) DESC, bands.created_at DESC") when :playing @@ -317,7 +317,7 @@ module JamRuby # this gets counts for each search result @results.each do |bb| counters = { } - counters[COUNT_FOLLOW] = BandFollowing.where(:band_id => bb.id).count + counters[COUNT_FOLLOW] = Follow.where(:followable_id => bb.id).count counters[COUNT_RECORD] = Recording.where(:band_id => bb.id).count counters[COUNT_SESSION] = MusicSession.where(:band_id => bb.id).count @user_counters[bb.id] << counters @@ -327,8 +327,8 @@ module JamRuby # so that action links can be activated or not rel = Band.select("bands.id AS bid") - rel = rel.joins("LEFT JOIN bands_followers AS follows ON follows.follower_id = '#{user.id}'") - rel = rel.where(["bands.id IN (#{mids}) AND follows.band_id = bands.id"]) + rel = rel.joins("LEFT JOIN follows ON follows.user_id = '#{user.id}'") + rel = rel.where(["bands.id IN (#{mids}) AND follows.followable_id = bands.id"]) rel.all.each { |val| @user_counters[val.bid] << RESULT_FOLLOW } else diff --git a/ruby/lib/jam_ruby/models/user.rb b/ruby/lib/jam_ruby/models/user.rb index 83bb2e8fb..24d273571 100644 --- a/ruby/lib/jam_ruby/models/user.rb +++ b/ruby/lib/jam_ruby/models/user.rb @@ -238,7 +238,7 @@ module JamRuby # check if "this user" likes entity def likes?(entity) - self.likings.where(:user_id => self.id).where(:likable_id => entity.id).size > 0 + self.likings.where(:likable_id => entity.id).size > 0 end def liking_count @@ -251,7 +251,7 @@ module JamRuby # check if "this user" follows entity def following?(entity) - self.followings.where(:user_id => self.id).where(:likable_id => entity.id).size > 0 + self.followings.where(:followable_id => entity.id).size > 0 end def following_count @@ -547,8 +547,7 @@ module JamRuby end def create_user_following(targetUserId) - targetUser = User.new - targetUser.id = targetUserId + targetUser = User.find(targetUserId) follow = Follow.new follow.followable = targetUser @@ -556,14 +555,12 @@ module JamRuby follow.save # TODO: make this async - user = User.find(targetUserId) - Notification.send_new_user_follower(self, user) + Notification.send_new_user_follower(self, targetUser) end def create_band_following(targetBandId) - targetBand= Band.new - targetBand.id = targetBandId + targetBand= Band.find(targetBandId) follow = Follow.new follow.followable = targetBand @@ -571,17 +568,15 @@ module JamRuby follow.save # TODO: make this async - band = Band.find(targetBandId) - Notification.send_new_band_follower(self, band) + Notification.send_new_band_follower(self, targetBand) end - def self.delete_following(likerId, targetEntityId) - Follow.delete_all "(user_id = '#{liker_id}' AND followable_id = '#{targetEntityId}')" + def self.delete_following(followerId, targetEntityId) + Follow.delete_all "(user_id = '#{followerId}' AND followable_id = '#{targetEntityId}')" end def create_user_like(targetUserId) - targetUser = User.new - targetUser.id = targetUserId + targetUser = User.find(targetUserId) like = Like.new like.likable = targetUser @@ -590,8 +585,7 @@ module JamRuby end def create_band_like(targetBandId) - targetBand = Band.new - targetBand.id = targetBandId + targetBand = Band.find(targetBandId) like = Like.new like.likable = targetBand @@ -599,6 +593,24 @@ module JamRuby like.save end + def create_session_like(targetSessionId) + targetSession = MusicSessionHistory.find(targetSessionId) + + like = Like.new + like.likable = targetSession + like.user = self + like.save + end + + def create_recording_like(targetRecordingId) + targetRecording = Recording.find(targetRecordingId) + + like = Like.new + like.likable = targetRecording + like.user = self + like.save + end + def self.delete_like(likerId, targetEntityId) Like.delete_all "(user_id = '#{liker_id}' AND likable_id = '#{targetEntityId}')" end @@ -1075,8 +1087,8 @@ module JamRuby end def top_followings - @topf ||= User.joins("INNER JOIN users_followers AS follows ON follows.user_id = users.id") - .where(['follows.follower_id = ?',self.id]) + @topf ||= User.joins("INNER JOIN follows ON follows.followable_id = users.id") + .where(['follows.user_id = ?',self.id]) .order('follows.created_at DESC') .limit(3) end diff --git a/ruby/spec/jam_ruby/models/band_filter_search_spec.rb b/ruby/spec/jam_ruby/models/band_filter_search_spec.rb index 1f5ec1eba..d1fca2b11 100644 --- a/ruby/spec/jam_ruby/models/band_filter_search_spec.rb +++ b/ruby/spec/jam_ruby/models/band_filter_search_spec.rb @@ -31,7 +31,7 @@ describe 'Band search' do it "finds bands with proper ordering" do # the ordering should be create_at since no followers exist - expect(BandFollower.count).to eq(0) + expect(Follow.count).to eq(0) results = Search.band_filter({ :per_page => Band.count }) results.results.each_with_index do |uu, idx| expect(uu.id).to eq(@bands.reverse[idx].id) @@ -42,17 +42,47 @@ describe 'Band search' do users = [] 4.downto(1) { |nn| users << FactoryGirl.create(:user) } + users.each_with_index do |u, index| + if index != 0 + f1 = Follow.new + f1.user = u + f1.followable = @band4 + f1.save + end + end + + users.each_with_index do |u, index| + if index != 0 + f1 = Follow.new + f1.user = u + f1.followable = @band3 + f1.save + end + end + + f1 = Follow.new + f1.user = users.first + f1.followable = @band2 + f1.save + # establish sorting order - @band4.followers.concat(users[1..-1]) - @band3.followers.concat(users[1..3]) - @band2.followers.concat(users[0]) + # @band4.followers.concat(users[1..-1]) + # @band3.followers.concat(users[1..3]) + # @band2.followers.concat(users[0]) @bands.map(&:reload) expect(@band4.followers.count).to be 3 - expect(BandFollower.count).to be 7 + expect(Follow.count).to be 7 # refresh the order to ensure it works right - @band2.followers.concat(users[1..-1]) + users.each_with_index do |u, index| + f1 = Follow.new + f1.user = u + f1.followable = @band2 + f1.save + end + + # @band2.followers.concat(users[1..-1]) results = Search.band_filter({ :per_page => @bands.size }, users[0]) expect(results.results[0].id).to eq(@band2.id) @@ -85,8 +115,15 @@ describe 'Band search' do users = [] 2.downto(1) { |nn| users << FactoryGirl.create(:user) } + users.each do |u| + f1 = Follow.new + f1.user = u + f1.followable = @band1 + f1.save + end + # establish sorting order - @band1.followers.concat(users) + # @band1.followers.concat(users) results = Search.band_filter({},@band1) uu = results.results.detect { |mm| mm.id == @band1.id } expect(uu).to_not be_nil diff --git a/ruby/spec/jam_ruby/models/musician_search_spec.rb b/ruby/spec/jam_ruby/models/musician_search_spec.rb index b9043be98..5f0b0dc62 100644 --- a/ruby/spec/jam_ruby/models/musician_search_spec.rb +++ b/ruby/spec/jam_ruby/models/musician_search_spec.rb @@ -24,7 +24,7 @@ describe 'Musician search' do it "finds musicians with proper ordering" do # the ordering should be create_at since no followers exist - expect(UserFollower.count).to eq(0) + expect(Follow.count).to eq(0) results = Search.musician_filter({ :per_page => User.musicians.count }) results.results.each_with_index do |uu, idx| expect(uu.id).to eq(@users.reverse[idx].id) @@ -33,14 +33,63 @@ describe 'Musician search' do it "sorts musicians by followers" do # establish sorting order - @user4.followers.concat([@user2, @user3, @user4]) - @user3.followers.concat([@user3, @user4]) - @user2.followers.concat([@user1]) + + # @user4 + f1 = Follow.new + f1.user = @user2 + f1.followable = @user4 + f1.save + + f2 = Follow.new + f2.user = @user3 + f2.followable = @user4 + f2.save + + f3 = Follow.new + f3.user = @user4 + f3.followable = @user4 + f3.save + + # @user3 + f4 = Follow.new + f4.user = @user3 + f4.followable = @user3 + f4.save + + f5 = Follow.new + f5.user = @user4 + f5.followable = @user3 + f5.save + + # @user2 + f6 = Follow.new + f6.user = @user1 + f6.followable = @user2 + f6.save + + # @user4.followers.concat([@user2, @user3, @user4]) + # @user3.followers.concat([@user3, @user4]) + # @user2.followers.concat([@user1]) expect(@user4.followers.count).to be 3 - expect(UserFollower.count).to be 6 + expect(Follow.count).to be 6 # refresh the order to ensure it works right - @user2.followers.concat([@user3, @user4, @user2]) + f1 = Follow.new + f1.user = @user3 + f1.followable = @user2 + f1.save + + f2 = Follow.new + f2.user = @user4 + f2.followable = @user2 + f2.save + + f3 = Follow.new + f3.user = @user2 + f3.followable = @user2 + f3.save + + # @user2.followers.concat([@user3, @user4, @user2]) results = Search.musician_filter({ :per_page => @users.size }, @user3) expect(results.results[0].id).to eq(@user2.id) @@ -85,9 +134,24 @@ describe 'Musician search' do context 'musician stat counters' do it "displays musicians top followings" do - @user4.followers.concat([@user4]) - @user3.followers.concat([@user4]) - @user2.followers.concat([@user4]) + f1 = Follow.new + f1.user = @user4 + f1.followable = @user4 + f1.save + + f2 = Follow.new + f2.user = @user4 + f2.followable = @user3 + f2.save + + f3 = Follow.new + f3.user = @user4 + f3.followable = @user2 + f3.save + + # @user4.followers.concat([@user4]) + # @user3.followers.concat([@user4]) + # @user2.followers.concat([@user4]) expect(@user4.top_followings.count).to be 3 expect(@user4.top_followings.map(&:id)).to match_array((@users - [@user1]).map(&:id)) end diff --git a/web/app/assets/javascripts/bandProfile.js b/web/app/assets/javascripts/bandProfile.js index 723220128..6b2285604 100644 --- a/web/app/assets/javascripts/bandProfile.js +++ b/web/app/assets/javascripts/bandProfile.js @@ -13,7 +13,6 @@ function beforeShow(data) { bandId = data.id; - setIsMember(); } function afterShow(data) { @@ -49,12 +48,14 @@ rest.addFollowing(newFollowing) .done(function() { if (isBand) { + var newCount = parseInt($("#band-profile-follower-stats").text()) + 1; + var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower"; + $('#band-profile-follower-stats').html(newCount + text); configureBandFollowingButton(true); } else { configureMemberFollowingButton(true, id); } - configureFollowingButton(); }) .fail(app.ajaxError); } @@ -67,6 +68,9 @@ .done(function() { renderActive(); // refresh stats if (isBand) { + var newCount = parseInt($("#band-profile-follower-stats").text()) - 1; + var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower"; + $('#band-profile-follower-stats').html(newCount + text); configureBandFollowingButton(false); } else { @@ -100,30 +104,6 @@ return alreadyFollowing; } - function isFollowing() { - var alreadyFollowing = false; - - var url = "/api/users/" + context.JK.currentUserId + "/band_followings/" + bandId; - $.ajax({ - type: "GET", - dataType: "json", - url: url, - async: false, - processData: false, - success: function(response) { - if (response.id !== undefined) { - alreadyFollowing = true; - } - else { - alreadyFollowing = false; - } - }, - error: app.ajaxError - }); - - return alreadyFollowing; - } - function configureBandFollowingButton(following) { $('#btn-follow-band').unbind("click"); @@ -201,45 +181,51 @@ } function bindAbout() { - var url = "/api/bands/" + bandId; - $.ajax({ - type: "GET", - dataType: "json", - url: url, - async: false, - processData:false, - success: function(response) { - band = response; - }, - error: app.ajaxError - }); - if (band) { + rest.getBand(bandId) + .done(function(response) { + band = response; + setIsMember(); + if (band) { + // name + $('#band-profile-name').html(band.name); - // name - $('#band-profile-name').html(band.name); + // avatar + $('#band-profile-avatar').attr('src', context.JK.resolveAvatarUrl(band.photo_url)); - // avatar - $('#band-profile-avatar').attr('src', context.JK.resolveAvatarUrl(band.photo_url)); + // location + $('#band-profile-location').html(band.location); - // location - $('#band-profile-location').html(band.location); + // stats + var text = band.follower_count > 1 || band.follower_count == 0 ? " Followers" : " Follower"; + $('#band-profile-follower-stats').html(band.follower_count + text); - // stats - var text = band.follower_count > 1 || band.follower_count == 0 ? " Followers" : " Follower"; - $('#band-profile-follower-stats').html(band.follower_count + text); + text = band.session_count > 1 || band.session_count == 0 ? " Sessions" : " Session"; + $('#band-profile-session-stats').html(band.session_count + text); - text = band.session_count > 1 || band.session_count == 0 ? " Sessions" : " Session"; - $('#band-profile-session-stats').html(band.session_count + text); + text = band.recording_count > 1 || band.recording_count == 0 ? " Recordings" : " Recording"; + $('#band-profile-recording-stats').html(band.recording_count + text); - text = band.recording_count > 1 || band.recording_count == 0 ? " Recordings" : " Recording"; - $('#band-profile-recording-stats').html(band.recording_count + text); - - $('#band-profile-biography').html(band.biography); - } - else { - logger.debug("No band found with bandId = " + bandId); - } + $('#band-profile-biography').html(band.biography); + + // wire up Follow click + configureBandFollowingButton(band.is_following); + } + else { + logger.debug("No band found with bandId = " + bandId); + } + }) + .fail(function(xhr) { + if(xhr.status >= 500) { + context.JK.fetchUserNetworkOrServerFailure(); + } + else if(xhr.status == 404) { + context.JK.entityNotFound("Band"); + } + else { + context.JK.app.ajaxError(arguments); + } + }); } /****************** SOCIAL TAB *****************/ @@ -270,6 +256,8 @@ $.each(response, function(index, val) { var template = $('#template-band-profile-social').html(); var followerHtml = context.JK.fillTemplate(template, { + userId: val.user_id, + hoverAction: val.musician ? "musician" : "fan", avatar_url: context.JK.resolveAvatarUrl(val.photo_url), userName: val.name, location: val.location @@ -280,6 +268,7 @@ }, error: app.ajaxError }); + context.JK.bindHoverEvents(); } /****************** HISTORY TAB *****************/ @@ -445,10 +434,6 @@ $('#band-profile-members-link').click(renderMembers); $('#band-profile-social-link').click(renderSocial); - // wire up Follow click - var following = isFollowing(); - configureBandFollowingButton(following); - if (isMember) { $("#btn-follow-band").hide(); $("#btn-edit-band-profile").show(); diff --git a/web/app/assets/javascripts/findMusician.js b/web/app/assets/javascripts/findMusician.js index 10afec2f3..5ddc3bae5 100644 --- a/web/app/assets/javascripts/findMusician.js +++ b/web/app/assets/javascripts/findMusician.js @@ -5,6 +5,7 @@ context.JK.FindMusicianScreen = function(app) { var logger = context.JK.logger; + var rest = context.JK.Rest(); var musicians = {}; var musicianList; var instrument_logo_map = context.JK.getInstrumentIconMap24(); @@ -176,7 +177,7 @@ evt.stopPropagation(); var uid = $(this).parent().data('musician-id'); - context.JK.sendFriendRequest(app, uid, friendRequestCallback); + rest.sendFriendRequest(app, uid, friendRequestCallback); } function friendRequestCallback(user_id) { diff --git a/web/app/assets/javascripts/hoverMusician.js b/web/app/assets/javascripts/hoverMusician.js index 2789981b0..63280f2ff 100644 --- a/web/app/assets/javascripts/hoverMusician.js +++ b/web/app/assets/javascripts/hoverMusician.js @@ -31,8 +31,19 @@ followingHtml += '