diff --git a/ruby/lib/jam_ruby/models/music_session_comment.rb b/ruby/lib/jam_ruby/models/music_session_comment.rb index 71fa8ae9a..b23383b33 100644 --- a/ruby/lib/jam_ruby/models/music_session_comment.rb +++ b/ruby/lib/jam_ruby/models/music_session_comment.rb @@ -7,8 +7,13 @@ module JamRuby default_scope order('created_at DESC') - belongs_to :music_session, :class_name => "JamRuby::MusicSessionHistory", :foreign_key => "music_session_id" - belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "creator_id" + belongs_to(:music_session_history, + :class_name => "JamRuby::MusicSessionHistory", + :foreign_key => "music_session_id") + + belongs_to(:user, + :class_name => "JamRuby::User", + :foreign_key => "creator_id") 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 045515d38..d1b41016a 100644 --- a/ruby/lib/jam_ruby/models/music_session_history.rb +++ b/ruby/lib/jam_ruby/models/music_session_history.rb @@ -130,5 +130,16 @@ module JamRuby .order('created_at DESC') end + def comments + @comments ||= JamRuby::MusicSessionComment + .where(:music_session_id => self.music_session_id) + .order('created_at DESC') + end + + def likes + @likes ||= JamRuby::MusicSessionLiker + .where(:music_session_id => self.music_session_id) + end + end end diff --git a/ruby/lib/jam_ruby/models/music_session_liker.rb b/ruby/lib/jam_ruby/models/music_session_liker.rb index a7d89fc72..538822c6e 100644 --- a/ruby/lib/jam_ruby/models/music_session_liker.rb +++ b/ruby/lib/jam_ruby/models/music_session_liker.rb @@ -5,8 +5,13 @@ module JamRuby self.primary_key = 'id' - belongs_to :music_session, :class_name => "JamRuby::MusicSessionHistory", :foreign_key => "music_session_id" - belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "liker_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/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js index 556512a40..c8206317c 100644 --- a/web/app/assets/javascripts/jam_rest.js +++ b/web/app/assets/javascripts/jam_rest.js @@ -35,7 +35,6 @@ } function updateSession(id, newSession, onSuccess) { - logger.debug('Rest.updateSession'); return $.ajax('/api/sessions/' + id, { type: "PUT", data : newSession, @@ -44,6 +43,56 @@ }); } + function addSessionComment(sessionId, userId, comment) { + return $.ajax({ + url: '/api/sessions/' + sessionId + "/comments", + type: "POST", + data : JSON.stringify({"comment": comment, "user_id": userId}), + dataType : 'json', + contentType: 'application/json' + }); + } + + function addSessionLike(sessionId, userId) { + return $.ajax({ + url: '/api/sessions/' + sessionId + "/likes", + type: "POST", + data : JSON.stringify({"user_id": userId}), + dataType : 'json', + contentType: 'application/json' + }); + } + + function addRecordingComment(recordingId, userId, comment) { + return $.ajax({ + url: '/api/recordings/' + recordingId + "/comments", + type: "POST", + data : JSON.stringify({"comment": comment, "user_id": userId}), + dataType : 'json', + contentType: 'application/json' + }); + } + + function addRecordingLike(recordingId, userId) { + return $.ajax({ + url: '/api/recordings/' + recordingId + "/likes", + type: "POST", + data : JSON.stringify({"user_id": userId}), + dataType : 'json', + contentType: 'application/json' + }); + } + + function addRecordingPlay(recordingId, userId) { + return $.ajax({ + url: '/api/recordings/' + recordingId + "/plays", + type: "POST", + data : JSON.stringify({"user_id": userId}), + dataType : 'json', + contentType: 'application/json' + }); + } + function getBand(bandId) { return $.ajax({ type: "GET", @@ -705,6 +754,11 @@ this.getBandFollowing = getBandFollowing; this.getBands = getBands; this.updateSession = updateSession; + this.addSessionComment = addSessionComment; + this.addSessionLike = addSessionLike; + this.addRecordingComment = addRecordingComment; + this.addRecordingLike = addRecordingLike; + this.addRecordingPlay = addRecordingPlay; this.getSession = getSession; this.getClientDownloads = getClientDownloads; this.createInvitation = createInvitation; diff --git a/web/app/controllers/api_music_sessions_controller.rb b/web/app/controllers/api_music_sessions_controller.rb index ecfd62359..cf0aad771 100644 --- a/web/app/controllers/api_music_sessions_controller.rb +++ b/web/app/controllers/api_music_sessions_controller.rb @@ -89,7 +89,6 @@ class ApiMusicSessionsController < ApiController end def participant_create - @connection = MusicSessionManager.new.participant_create( current_user, params[:id], @@ -243,14 +242,17 @@ class ApiMusicSessionsController < ApiController def add_comment if params[:id].blank? render :json => { :message => "Session ID is required" }, :status => 400 + return end if params[:user_id].blank? render :json => { :message => "User ID is required" }, :status => 400 + return end if params[:comment].blank? render :json => { :message => "Comment is required" }, :status => 400 + return end comment = MusicSessionComment.new @@ -262,18 +264,17 @@ class ApiMusicSessionsController < ApiController if comment.errors.any? render :json => { :message => "Unexpected error occurred" }, :status => 500 + return else render :json => {}, :status => 201 + return end end def add_like if params[:id].blank? render :json => { :message => "Session ID is required" }, :status => 400 - end - - if params[:user_id].blank? - render :json => { :message => "User ID is required" }, :status => 400 + return end liker = MusicSessionLiker.new @@ -284,8 +285,10 @@ class ApiMusicSessionsController < ApiController if liker.errors.any? render :json => { :message => "Unexpected error occurred" }, :status => 500 + return else render :json => {}, :status => 201 + return end end diff --git a/web/app/controllers/api_recordings_controller.rb b/web/app/controllers/api_recordings_controller.rb index ce06547c6..1947b7baa 100644 --- a/web/app/controllers/api_recordings_controller.rb +++ b/web/app/controllers/api_recordings_controller.rb @@ -83,14 +83,17 @@ class ApiRecordingsController < ApiController def add_comment if params[:id].blank? render :json => { :message => "Recording ID is required" }, :status => 400 + return end if params[:user_id].blank? render :json => { :message => "User ID is required" }, :status => 400 + return end if params[:comment].blank? render :json => { :message => "Comment is required" }, :status => 400 + return end comment = RecordingComment.new @@ -102,18 +105,17 @@ class ApiRecordingsController < ApiController if comment.errors.any? render :json => { :message => "Unexpected error occurred" }, :status => 500 + return else render :json => {}, :status => 201 + return end end def add_like if params[:id].blank? render :json => { :message => "Recording ID is required" }, :status => 400 - end - - if params[:user_id].blank? - render :json => { :message => "User ID is required" }, :status => 400 + return end liker = RecordingLiker.new @@ -124,18 +126,17 @@ class ApiRecordingsController < ApiController if liker.errors.any? render :json => { :message => "Unexpected error occurred" }, :status => 500 + return else render :json => {}, :status => 201 + return end end def add_play if params[:id].blank? render :json => { :message => "Recording ID is required" }, :status => 400 - end - - if params[:user_id].blank? - render :json => { :message => "User ID is required" }, :status => 400 + return end play = RecordingPlay.new @@ -146,8 +147,10 @@ class ApiRecordingsController < ApiController if play.errors.any? render :json => { :message => "Unexpected error occurred" }, :status => 500 + return else render :json => {}, :status => 201 + return end end diff --git a/web/app/views/music_sessions/show.html.erb b/web/app/views/music_sessions/show.html.erb index 1ba28d42f..2bad9aa50 100644 --- a/web/app/views/music_sessions/show.html.erb +++ b/web/app/views/music_sessions/show.html.erb @@ -27,14 +27,16 @@
<%= @music_session.created_at.strftime("%b %e %Y, %l:%M %p") %>


<%= @music_session.description %>

-
- <%= image_tag "content/icon_like.png", {:width => 12, :height => 12} %> LIKE    - <%= image_tag "content/icon_share.png", {:width => 13, :height => 15} %> SHARE -
+ <% if @music_session.session_removed_at.blank? %> +
+ <%= image_tag "content/icon_like.png", {:width => 12, :height => 12, :alt => ""} %> LIKE    + <%= image_tag "content/icon_share.png", {:width => 13, :height => 15, :alt => ""} %> SHARE +
+ <% end %>
- <%= image_tag "content/icon_playbutton.png", {:width => 20, :height => 20} %> + <%= image_tag "content/icon_playbutton.png", {:width => 20, :height => 20, :alt => ""} %> <% if @music_session.session_removed_at.blank? %>
SESSION IN PROGRESS
1:23
@@ -45,10 +47,13 @@
<%= @music_session.genres.split('|').first.capitalize %>
- <%= @music_session.comment_count %> - <%= image_tag "content/icon_comment.png", {:width => 13, :height => 12, :align => "absmiddle", :style => "vertical-align:middle"} %>     - <%= @music_session.like_count %> - <%= image_tag "content/icon_like.png", {:width => 12, :height => 12, :align => "absmiddle", :style => "vertical-align:middle"} %> + + <%= @music_session.comment_count %> + <%= image_tag "content/icon_comment.png", {:width => 13, :height => 12, :align => "absmiddle", :style => "vertical-align:middle", :alt => ""} %>     + + <%= @music_session.like_count %> + <%= image_tag "content/icon_like.png", {:width => 12, :height => 12, :align => "absmiddle", :style => "vertical-align:middle", :alt => ""} %> +


@@ -68,9 +73,65 @@ <% content_for :after_black_bar do %>
- <%= render :partial => "shared/comments", :locals => {:comments => @music_session.comments} %> + <%= render :partial => "shared/comments", :locals => {:comments => @music_session.comments, :id => "txtSessionComment"} %> <% end %> <%= javascript_include_tag "web/sessions" %> <%= render "clients/shareDialog" %> + + diff --git a/web/app/views/recordings/show.html.erb b/web/app/views/recordings/show.html.erb index 60b11a6d7..0bdb1e444 100644 --- a/web/app/views/recordings/show.html.erb +++ b/web/app/views/recordings/show.html.erb @@ -28,17 +28,17 @@

<%= @claimed_recording.name %>

- <%= image_tag "content/icon_like.png", {:width => 12, :height => 12} %> LIKE    - <%= image_tag "content/icon_share.png", {:width => 13, :height => 15} %> SHARE + <%= image_tag "content/icon_like.png", {:width => 12, :height => 12, :alt => ""} %> LIKE    + <%= image_tag "content/icon_share.png", {:width => 13, :height => 15, :alt => ""} %> SHARE

<%= @claimed_recording.description %>

- <%= image_tag "content/icon_playbutton.png", {:width => 20, :height => 20} %> + <%= image_tag "content/icon_playbutton.png", {:width => 20, :height => 20, :alt => ""} %>
0:00
-
<%= image_tag "content/slider_playcontrols.png", {:width => 5, :height => 16} %>
+
<%= image_tag "content/slider_playcontrols.png", {:width => 5, :height => 16, :alt => ""} %>
4:59
@@ -47,12 +47,12 @@
<%= @claimed_recording.genre_id.capitalize %>
- <%= @claimed_recording.recording.play_count %> - <%= image_tag "content/icon_arrow.png", {:width => 7, :height => 12, :align => "absmiddle"} %>     - <%= @claimed_recording.recording.comment_count %> - <%= image_tag "content/icon_comment.png", {:width => 13, :height => 12, :align => "absmiddle"} %>     - <%= @claimed_recording.recording.like_count %> - <%= image_tag "content/icon_like.png", {:width => 12, :height => 12, :align => "absmiddle"} %> + <%= @claimed_recording.recording.play_count %> + <%= image_tag "content/icon_arrow.png", {:width => 7, :height => 12, :align => "absmiddle", :alt => ""} %>     + <%= @claimed_recording.recording.comment_count %> + <%= image_tag "content/icon_comment.png", {:width => 13, :height => 12, :align => "absmiddle", :alt => ""} %>     + <%= @claimed_recording.recording.like_count %> + <%= image_tag "content/icon_like.png", {:width => 12, :height => 12, :align => "absmiddle", :alt => ""} %>


@@ -72,9 +72,73 @@ <% content_for :after_black_bar do %>
- <%= render :partial => "shared/comments", :locals => {:comments => @claimed_recording.recording.comments} %> + <%= render :partial => "shared/comments", :locals => {:comments => @claimed_recording.recording.comments, :id => "txtRecordingComment"} %> <% end %> <%= javascript_include_tag "web/recordings" %> -<%= render "clients/shareDialog" %> \ No newline at end of file +<%= render "clients/shareDialog" %> + + diff --git a/web/app/views/shared/_comments.html.erb b/web/app/views/shared/_comments.html.erb index 955d8baae..1094e747e 100644 --- a/web/app/views/shared/_comments.html.erb +++ b/web/app/views/shared/_comments.html.erb @@ -4,7 +4,7 @@ <%= image_tag "shared/avatar_generic.png", {:alt => ""} %>
- +