From a06ba7197e3916df8604e0c6367e269c45bc3b1d Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sat, 24 May 2014 03:58:47 -0400 Subject: [PATCH] VRFS-1670 session info page work --- ruby/lib/jam_ruby/models/music_session.rb | 43 +++++ .../javascripts/web/scheduled_session.js | 17 ++ web/app/assets/javascripts/web/web.js | 1 + .../stylesheets/client/content.css.scss | 12 ++ .../controllers/music_sessions_controller.rb | 33 +++- .../api_music_sessions/history_show.rabl | 11 +- web/app/views/api_music_sessions/show.rabl | 2 +- .../api_music_sessions/show_history.rabl | 153 ++++++++++++++++++ .../music_sessions/session_info.html.erb | 0 .../music_sessions/session_info.html.haml | 78 +++++++++ web/app/views/users/_feed_recording.html.haml | 2 +- 11 files changed, 346 insertions(+), 6 deletions(-) create mode 100644 web/app/assets/javascripts/web/scheduled_session.js create mode 100644 web/app/views/api_music_sessions/show_history.rabl delete mode 100644 web/app/views/music_sessions/session_info.html.erb create mode 100644 web/app/views/music_sessions/session_info.html.haml diff --git a/ruby/lib/jam_ruby/models/music_session.rb b/ruby/lib/jam_ruby/models/music_session.rb index b9d6ea35c..89a54131a 100644 --- a/ruby/lib/jam_ruby/models/music_session.rb +++ b/ruby/lib/jam_ruby/models/music_session.rb @@ -20,6 +20,7 @@ module JamRuby has_many :music_session_user_histories, :class_name => "JamRuby::MusicSessionUserHistory", :foreign_key => "music_session_id", :dependent => :delete_all has_many :comments, :class_name => "JamRuby::MusicSessionComment", :foreign_key => "music_session_id" + has_many :session_info_comments, :class_name => "JamRuby::SessionInfoComment", :foreign_key => "music_session_id" has_many :likes, :class_name => "JamRuby::MusicSessionLiker", :foreign_key => "session_id" has_many :plays, :class_name => "JamRuby::PlayablePlay", :as => :playable, :dependent => :destroy has_one :share_token, :class_name => "JamRuby::ShareToken", :inverse_of => :shareable, :foreign_key => 'shareable_id' @@ -80,6 +81,29 @@ module JamRuby tracks end + def can_join? user, as_musician + if as_musician + unless user.musician + return false # "a fan can not join a music session as a musician" + end + + if self.musician_access + if self.approval_required + return self.invited_musicians.exists?(user) + else + return true + end + + else + # the creator can always join, and the invited users can join + return self.creator == user || self.invited_musicians.exists?(user) + end + else + # it's a fan, and the only way a fan can join is if fan_access is true + self.fan_access + end + end + def self.index(current_user, user_id, band_id = nil, genre = nil) hide_private = false if current_user.id != user_id @@ -226,6 +250,25 @@ module JamRuby active_music_session && active_music_session.mount end + def can_delete? user + self.creator == user && self.started_at.nil? + end + + def legal_policy_url + # TODO: move to DB or config file + case legal_policy + when "standard" + return "http://www.jamkazam.com/session-legal-policies/standard" + when "creative" + return "http://www.jamkazam.com/session-legal-policies/creativecommons" + when "offline" + return "http://www.jamkazam.com/session-legal-policies/offline" + when "jamtracks" + return "http://www.jamkazam.com/session-legal-policies/jamtracks" + else + return "" + end + def recordings Recording.where(music_session_id: self.id) end diff --git a/web/app/assets/javascripts/web/scheduled_session.js b/web/app/assets/javascripts/web/scheduled_session.js new file mode 100644 index 000000000..ca4cdc005 --- /dev/null +++ b/web/app/assets/javascripts/web/scheduled_session.js @@ -0,0 +1,17 @@ +(function(context, $) { + + "use strict"; + + context.JK = context.JK || {}; + + context.JK.ShowSessionInfo = function(app) { + var logger = context.JK.logger; + var rest = JK.Rest(); + + function initialize(musicSessionId) { + } + + this.initialize = initialize; + } + +})(window, jQuery); \ No newline at end of file diff --git a/web/app/assets/javascripts/web/web.js b/web/app/assets/javascripts/web/web.js index f79dba4a7..edf1ca888 100644 --- a/web/app/assets/javascripts/web/web.js +++ b/web/app/assets/javascripts/web/web.js @@ -53,6 +53,7 @@ //= require web/downloads //= require web/congratulations //= require web/sessions +//= require web/scheduled_session //= require web/recordings //= require web/welcome //= require banner diff --git a/web/app/assets/stylesheets/client/content.css.scss b/web/app/assets/stylesheets/client/content.css.scss index 6685d883d..ecfef5fe6 100644 --- a/web/app/assets/stylesheets/client/content.css.scss +++ b/web/app/assets/stylesheets/client/content.css.scss @@ -307,6 +307,10 @@ width:110px; } +a.gold { + color: #cc9900 !important; +} + a.arrow-up { float:right; margin-right:5px; @@ -465,6 +469,10 @@ ul.shortcuts { } } +.clearall { + clear: both; +} + .tagline { font-size:30px; margin-top:35px; @@ -495,6 +503,10 @@ a.arrow-down-orange { white-space:normal; } +.ib { + display: inline-block; +} + .w0 {width:0% !important} .w5 {width:5% !important} .w10 {width:10% !important} diff --git a/web/app/controllers/music_sessions_controller.rb b/web/app/controllers/music_sessions_controller.rb index 9419204d5..66886feaa 100644 --- a/web/app/controllers/music_sessions_controller.rb +++ b/web/app/controllers/music_sessions_controller.rb @@ -8,8 +8,37 @@ class MusicSessionsController < ApplicationController end def session_info - @music_session = MusicSession.find(params[:id]) - render :layout => "web" + @can_view = true + @can_comment = false + + # check whether user is logged in + if current_user.nil? + @music_session = MusicSession.new + @can_view = false + render :layout => "web", :status => 404 + + else + + @music_session = MusicSession.find(params[:id]) + current_user_invitation = Invitation.where("music_session_id = ? AND receiver_id = ?", music_session.id, current_user.id) + + # get all invitations for users that do not have an RSVP request + @pending_invitations = + + if @music_session.scheduled_start > Time.now.utc + if @music_session.musician_access && @music_session.approval_required && invitations.blank? + @can_view = false + end + # only allow comments for invitees before the session has started + unless current_user_invitation.blank? + @can_comment = true + end + else + + end + + render :layout => "web" + end end end diff --git a/web/app/views/api_music_sessions/history_show.rabl b/web/app/views/api_music_sessions/history_show.rabl index 40a5bbc52..e21bc7558 100644 --- a/web/app/views/api_music_sessions/history_show.rabl +++ b/web/app/views/api_music_sessions/history_show.rabl @@ -16,8 +16,8 @@ if !current_user } else - attributes :id, :music_session_id, :description, :musician_access, :approval_required, :fan_access, :fan_chat, - :band_id, :user_id, :genre_id, :created_at, :like_count, :comment_count + attributes :id, :music_session_id, :name, :description, :musician_access, :approval_required, :fan_access, :fan_chat, + :band_id, :user_id, :genre_id, :created_at, :like_count, :comment_count, :scheduled_start, :scheduled_duration, :language node :share_url do |history| unless history.share_token.nil? @@ -49,6 +49,13 @@ else } } + child(:music_notations => :music_notations) { + node do |music_notation| + attributes :id + note(:filename) { |music_notation| music_notation.filename } + end + } + child(:active_music_session => :active_music_session) { attributes :claimed_recording_initiator_id, :track_changes_counter diff --git a/web/app/views/api_music_sessions/show.rabl b/web/app/views/api_music_sessions/show.rabl index 87fcfc683..f2498edaf 100644 --- a/web/app/views/api_music_sessions/show.rabl +++ b/web/app/views/api_music_sessions/show.rabl @@ -13,7 +13,7 @@ if !current_user } else - attributes :id, :description, :musician_access, :approval_required, :fan_access, :fan_chat, :band_id, :user_id, :claimed_recording_initiator_id, :track_changes_counter, :max_score + attributes :id, :name, :description, :musician_access, :approval_required, :fan_access, :fan_chat, :band_id, :user_id, :claimed_recording_initiator_id, :track_changes_counter, :max_score node :genres do |item| [item.genre.description] # XXX: need to return single genre; not array diff --git a/web/app/views/api_music_sessions/show_history.rabl b/web/app/views/api_music_sessions/show_history.rabl new file mode 100644 index 000000000..e21bc7558 --- /dev/null +++ b/web/app/views/api_music_sessions/show_history.rabl @@ -0,0 +1,153 @@ +object @history + +if !current_user + # there should be more data returned, but we need to think very carefully about what data is public for a music session + attributes :id + + child(:active_music_session => :active_music_session) { + node do |music_session| + child({:mount => :mount}, :if => lambda { |music_session| music_session.fan_access}) { + attributes :id, :name, :sourced, :listeners, :bitrate, :subtype, :url + node(:mime_type) { |mount| mount.resolve_string(:mime_type) } + node(:bitrate) { |mount| mount.resolve_string(:bitrate) } + node(:subtype) { |mount| mount.resolve_string(:subtype) } + } + end + } +else + + attributes :id, :music_session_id, :name, :description, :musician_access, :approval_required, :fan_access, :fan_chat, + :band_id, :user_id, :genre_id, :created_at, :like_count, :comment_count, :scheduled_start, :scheduled_duration, :language + + node :share_url do |history| + unless history.share_token.nil? + share_token_url(history.share_token.token) + end + end + + child(:creator => :creator) { + attributes :name, :photo_url + } + + child(:band => :band) { + attributes :name, :photo_url + } + + child(:music_session_user_histories => :users) { + attributes :instruments + + child(:user => :user) { + attributes :name, :photo_url + } + } + + child(:comments => :comments) { + attributes :comment, :created_at + + child(:user => :creator) { + attributes :id, :first_name, :last_name, :name, :photo_url, :musician + } + } + + child(:music_notations => :music_notations) { + node do |music_notation| + attributes :id + note(:filename) { |music_notation| music_notation.filename } + end + } + + child(:active_music_session => :active_music_session) { + attributes :claimed_recording_initiator_id, :track_changes_counter + + node :genres do |item| + [item.genre.description] # XXX: need to return single genre; not array + end + + if :is_recording? + node do |music_session| + { :recording => partial("api_recordings/show", :object => music_session.recording) } + end + end + + node :share_url do |music_session| + unless music_session.music_session.share_token.nil? + share_token_url(music_session.music_session.share_token.token) + end + end + + child(:connections => :participants) { + collection @music_sessions, :object_root => false + attributes :ip_address, :client_id, :joined_session_at + + node :user do |connection| + { :id => connection.user.id, :photo_url => connection.user.photo_url, :name => connection.user.name, :is_friend => connection.user.friends?(current_user), :connection_state => connection.aasm_state } + end + + child(:tracks => :tracks) { + attributes :id, :connection_id, :instrument_id, :sound, :client_track_id, :updated_at + } + } + + + child({:invitations => :invitations}) { + attributes :id, :sender_id, :receiver_id + } + + # only show join_requests if the current_user is in the session + node(:join_requests, :if => lambda { |music_session| music_session.users.exists?(current_user) } ) do |music_session| + child(:join_requests => :join_requests) { + attributes :id, :text + child(:user => :user) { + attributes :id, :name + } + } + end + + # only show currently playing recording data if the current_user is in the session + node(:claimed_recording, :if => lambda { |music_session| music_session.users.exists?(current_user) } ) do |music_session| + + child(:claimed_recording => :claimed_recording) { + attributes :id, :name, :description, :is_public + + child(:recording => :recording) { + attributes :id, :created_at, :duration + child(:band => :band) { + attributes :id, :name + } + + child(:mixes => :mixes) { + attributes :id, :is_completed + + node :mp3_url do |mix| + mix[:mp3_url] + end + + node :ogg_url do |mix| + mix[:ogg_url] + end + } + + child(:recorded_tracks => :recorded_tracks) { + attributes :id, :fully_uploaded, :client_track_id, :client_id, :instrument_id + + node :url do |recorded_track| + recorded_track[:url] + end + + child(:user => :user) { + attributes :id, :first_name, :last_name, :city, :state, :country, :photo_url + } + } + } + } + end + + # only show mount info if fan_access is public. Eventually we'll also need to show this in other scenarios, like if invited + child({:mount => :mount}, :if => lambda { |music_session| music_session.fan_access}) { + attributes :id, :name, :sourced, :listeners, :bitrate, :subtype, :url + node(:mime_type) { |mount| mount.resolve_string(:mime_type) } + node(:bitrate) { |mount| mount.resolve_string(:bitrate) } + node(:subtype) { |mount| mount.resolve_string(:subtype) } + } + } +end \ No newline at end of file diff --git a/web/app/views/music_sessions/session_info.html.erb b/web/app/views/music_sessions/session_info.html.erb deleted file mode 100644 index e69de29bb..000000000 diff --git a/web/app/views/music_sessions/session_info.html.haml b/web/app/views/music_sessions/session_info.html.haml new file mode 100644 index 000000000..886934321 --- /dev/null +++ b/web/app/views/music_sessions/session_info.html.haml @@ -0,0 +1,78 @@ +- unless @music_session.nil? + - provide(:title, @music_session.name) + +.sessions-page + - if @can_view + .landing-band + .landing-avatar + - unless @music_session.creator.photo_url.blank? + = image_tag "#{@music_session.creator.photo_url}", alt: "" + - else + = image_tag "shared/avatar_generic.png", alt: "" + - end + = @music_session.creator.name + %br/ + %span.f12 Session Creator + %br/ + %br/ + .f12 Tell the session creator you'd like to play in this session + %br/ + %br/ + %a.button-orange{:id => "btn-rsvp"} + RSVP NOW! + .landing-details + .left.f20.teal + %strong SESSION + %br/ + %strong Date/Time: + .right.w75.ib.mb10 + = @music_session.scheduled_start + .clearall.left.w20.ib.mb10 + %strong Genre: + .right.w75.ib.mb10 + = @music_session.scheduled_start + .clearall.left.w20.ib.mb10 + %strong Name: + .right.w75.ib.mb10 + = @music_session.name + .clearall.left.w20.ib.mb10 + %strong Description: + .right.w75.ib.mb10 + = @music_session.description + .clearall.left.w20.ib.mb10 + %strong Notation Files: + .right.w75.ib.mb10 + - @music_session.music_notations.each do |n| + %a.gold{:href => n.file_url}  + .clearall.left.w20.ib.mb10 + %strong Language: + .right.w75.ib.mb10 + = @music_session.language + .clearall.left.w20.ib.mb10 + %strong Access: + .right.w75.ib.mb10 + = @music_session.access + .clearall.left.w20.ib.mb10 + %strong Legal: + .right.w75.ib.mb10 + = @music_session.legal_policy.capitalize agreement( + %a.{:href => @music_session.legal_policy_url, :target => "_blank"} View full legal details) + + %br{clear:'all'} + + .landing-sidebar + %br/ + %h2 SESSION MUSICIANS + %br/ + .left.w65.ib + %strong RSVPs + .right.w30.ib.f11.center Your latency + + - else + .left.f20.teal + %strong SESSION NOT FOUND + %br/ + .clearall.left.w20.ib.mb10 + + + diff --git a/web/app/views/users/_feed_recording.html.haml b/web/app/views/users/_feed_recording.html.haml index d487821c2..389175298 100644 --- a/web/app/views/users/_feed_recording.html.haml +++ b/web/app/views/users/_feed_recording.html.haml @@ -88,7 +88,7 @@ %td .nowrap - track.instrument_ids.uniq.each do |instrument_id| - %img.instrument-icon{'instrument-id' =>instrument_id, height:24, width:24} + %img.instrument-icon{'instrument-id' => instrument_id, height:24, width:24} %br{:clear => "all"}/ %br/