diff --git a/db/manifest b/db/manifest index 8b4c6e74c..bceb5bfa8 100755 --- a/db/manifest +++ b/db/manifest @@ -178,3 +178,5 @@ update_ams_index_2.sql sms_index.sql music_sessions_description_search.sql rsvp_slots_prof_level.sql +add_file_name_music_notation.sql +change_scheduled_start_music_session.sql \ No newline at end of file diff --git a/db/up/add_file_name_music_notation.sql b/db/up/add_file_name_music_notation.sql new file mode 100644 index 000000000..2f5c658df --- /dev/null +++ b/db/up/add_file_name_music_notation.sql @@ -0,0 +1 @@ +ALTER TABLE music_notations ADD COLUMN file_name VARCHAR(255); \ No newline at end of file diff --git a/db/up/change_scheduled_start_music_session.sql b/db/up/change_scheduled_start_music_session.sql new file mode 100644 index 000000000..df4979919 --- /dev/null +++ b/db/up/change_scheduled_start_music_session.sql @@ -0,0 +1 @@ +ALTER TABLE music_sessions ALTER COLUMN scheduled_start TYPE timestamp without time zone; \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/music_notation.rb b/ruby/lib/jam_ruby/models/music_notation.rb index 8e926520e..2c205de30 100644 --- a/ruby/lib/jam_ruby/models/music_notation.rb +++ b/ruby/lib/jam_ruby/models/music_notation.rb @@ -4,7 +4,7 @@ module JamRuby self.primary_key = 'id' - attr_accessible :file_url, :size + attr_accessible :file_url, :size, :file_name belongs_to :user, :class_name => "JamRuby::User", foreign_key: :user_id belongs_to :music_session, :class_name => "JamRuby::MusicSession", foreign_key: :music_session_id @@ -30,10 +30,6 @@ module JamRuby s3_manager.sign_url(self[:file_url], {:expires => expiration_time, :secure => false}) end - def filename - File.basename(self.file_url) - end - private def delete_s3_files diff --git a/ruby/lib/jam_ruby/models/music_session.rb b/ruby/lib/jam_ruby/models/music_session.rb index 553486183..f7b293c83 100644 --- a/ruby/lib/jam_ruby/models/music_session.rb +++ b/ruby/lib/jam_ruby/models/music_session.rb @@ -13,6 +13,7 @@ module JamRuby attr_accessor :legal_terms, :language_description, :scheduled_start_time, :access_description attr_accessor :approved_rsvps, :open_slots, :pending_invitations + attr_accessor :approved_rsvps_detail, :open_slots_detail self.table_name = "music_sessions" @@ -252,6 +253,7 @@ module JamRuby ms.scheduled_start = options[:start] ms.scheduled_duration = options[:duration].to_i * 1.minutes if options[:duration] ms.recurring_mode = options[:recurring_mode] if options[:recurring_mode] + ms.timezone = options[:timezone] if options[:timezone] ms.legal_terms = true ms.creator = user @@ -271,13 +273,13 @@ module JamRuby ms.rsvp_slots << rsvp - if !rs[:approve].nil? && rs[:approve] == true + if rs[:approve] == true self_rsvp_slot_ids.push rsvp.id else rsvp_slot_ids.push rsvp.id end end if options[:rsvp_slots] - RsvpRequest.create({session_id: ms.id, rsvp_slots: self_rsvp_slot_ids, :autoapprove => true}, user).map(&:id) + RsvpRequest.create({session_id: ms.id, rsvp_slots: self_rsvp_slot_ids, :autoapprove => true}, user) options[:invitations].each do |invite_id| invitation = Invitation.new @@ -491,6 +493,38 @@ module JamRuby users_collapsed_instruments end + def approved_rsvps_detail + users = User.find_by_sql(%Q{select u.id, u.photo_url, u.first_name, u.last_name, rs.instrument_id, ii.description, rs.proficiency_level + from rsvp_slots rs + inner join rsvp_requests_rsvp_slots rrrs on rrrs.rsvp_slot_id = rs.id + inner join rsvp_requests rr on rrrs.rsvp_request_id = rr.id + inner join instruments ii on ii.id = rs.instrument_id + inner join users u on u.id = rr.user_id + where rrrs.chosen = true and rs.music_session_id = '#{self.id}' + order by u.id} + ) + + users_collapsed_instruments = [] + user = User.new + + # build User array with instruments collapsed + users.each_with_index do |u, index| + if index == 0 || users[index].id != users[index-1].id + user = User.new + user.id = u.id + user.photo_url = u.photo_url + user.first_name = u.first_name + user.last_name = u.last_name + user.instrument_list = [{id: u.instrument_id, desc: u.description, level: u.proficiency_level}] + users_collapsed_instruments << user + else + user.instrument_list << {id: u.instrument_id, desc: u.description, level: u.proficiency_level} + end + end + + users_collapsed_instruments + end + # get all slots for this session and perform a set difference with all chosen slots; # this will return those that are not filled yet def open_slots @@ -507,6 +541,22 @@ module JamRuby ) end + def open_slots_detail + RsvpSlot.find_by_sql(%Q{select rs.*, ii.description + from rsvp_slots rs + inner join instruments ii on ii.id = rs.instrument_id + where rs.music_session_id = '#{self.id}' + except + select distinct rs.*, iii.description + from rsvp_slots rs + inner join instruments iii on iii.id = rs.instrument_id + inner join rsvp_requests_rsvp_slots rrrs on rrrs.rsvp_slot_id = rs.id + where rs.music_session_id = '#{self.id}' + and rrrs.chosen = true + } + ) + end + # retrieve users that have invitations but have not submitted an RSVP request for this session def pending_invitations User.find_by_sql(%Q{select u.id, u.email, u.photo_url, u.first_name, u.last_name diff --git a/web/app/assets/javascripts/scheduled_session.js b/web/app/assets/javascripts/scheduled_session.js index 2d0249e4c..4fdec4dd8 100644 --- a/web/app/assets/javascripts/scheduled_session.js +++ b/web/app/assets/javascripts/scheduled_session.js @@ -50,6 +50,7 @@ var ONE_HOUR = 3600 * 1000; var ONE_MINUTE = 60 * 1000; + var ONE_DAY = ONE_HOUR * 24; var defaultTimeArray = ["12:00 AM", "12:30 AM", "01:00 AM", "01:30 AM", "02:00 AM", "02:30 AM", "03:00 AM", "03:30 AM", "04:00 AM", "04:30 AM", "05:00 AM", "05:30 AM", "06:00 AM", "06:30 AM", @@ -60,9 +61,12 @@ "11:00 PM", "11:30 PM"]; var proficiencyDescriptionMap = { - "1": "Beginner", - "2": "Intermediate", - "3": "Expert" + "0": "Any", + "1": "Beg", + "2": "Beg/Int", + "3": "Int", + "4": "Int/Adv", + "5": "Adv" }; function afterLoadScheduledSessions(sessionList) { @@ -126,7 +130,7 @@ function afterLoadUserDetail(userDetail) { var userInstruments = []; $.each(userDetail.instruments, function(index, userInstrument) { - userInstrument.level = proficiencyDescriptionMap[userInstrument.proficiency_level]; + userInstrument.level = userInstrument.proficiency_level; userInstruments.push(userInstrument); }) @@ -229,7 +233,37 @@ $('#session-invited-disp').html(sessionInvitedString); if (createSessionSettings.createType == 'start-scheduled') { + var session = scheduledSessions[createSessionSettings.selectedSessionId]; + if (session.approved_rsvps_detail.length > 0) { + var instruments_me = []; + $.each(session.approved_rsvps_detail, function(index, user) { + if (user.id == context.JK.currentUserId) { + $.each(user.instrument_list, function(index, instrument) { + instruments_me.push(instrument.desc); + }); + } + }); + $('#session-instruments-me-disp').html(instruments_me.join(', ')); + } + if (session.open_slots_detail.length > 0) { + var instruments_rsvp = {}; + $.each(session.open_slots_detail, function(index, slot) { + if (instruments_rsvp[slot.description]) { + instruments_rsvp[slot.description]["count"] = instruments_rsvp[slot.description]["count"] + 1; + } + else { + instrumens_rsvp[slot.description] = {"count": 1, "level": slot.proficiency_desc}; + } + }); + + var instruments_rsvp_arr = $.makeArray(instruments_rsvp); + var instruments_str_arr = []; + $.map(instruments_rsvp_arr, function(val, i) { + instruments_str_arr.push(i + ' (' + val.count + ') (' + val.level + ')'); + }) + $('#session-instruments-rsvp-disp').html(instruments_str_arr.join(', ')); + } } else { var instruments_me = []; @@ -240,7 +274,7 @@ var instruments_rsvp = []; $.each(instrumentRSVP.getSelectedInstruments(), function(index, instrument) { - instruments_rsvp.push(instrument.name + ' (' + instrument.count + ') (' + instrument.level + ')'); + instruments_rsvp.push(instrument.name + ' (' + instrument.count + ') (' + proficiencyDescriptionMap[instrument.level] + ')'); }); $('#session-instruments-rsvp-disp').html(instruments_rsvp.join(', ')); } @@ -481,6 +515,9 @@ data.start = createSessionSettings.startDate + ' ' + createSessionSettings.startTime; var endDate = new Date(createSessionSettings.startDate + ' ' + createSessionSettings.endTime); data.duration = (endDate - new Date(data.start)) / ONE_MINUTE; + if (createSessionSettings.endTime == defaultTimeArray[0]) { + data.duration += ONE_DAY / ONE_MINUTE; + } } data.invitations = inviteMusiciansUtil.getInvitedFriends(); data.recurring_mode = createSessionSettings.recurring_mode.value; @@ -501,7 +538,7 @@ var slot = {}; slot.instrument_id = instrument.id; slot.proficiency_level = instrument.level; - slot.approve = true; + slot.approve = false; data.rsvp_slots.push(slot); } }); diff --git a/web/app/controllers/api_music_notations_controller.rb b/web/app/controllers/api_music_notations_controller.rb index b90085c64..f92216547 100644 --- a/web/app/controllers/api_music_notations_controller.rb +++ b/web/app/controllers/api_music_notations_controller.rb @@ -17,6 +17,7 @@ class ApiMusicNotationsController < ApiController params[:files].each do |file| music_notation = MusicNotation.new music_notation.file_url = file + music_notation.file_name = file.original_filename music_notation.user = current_user music_notation.save diff --git a/web/app/views/api_music_sessions/show_history.rabl b/web/app/views/api_music_sessions/show_history.rabl index 9358fcf5d..92d443c43 100644 --- a/web/app/views/api_music_sessions/show_history.rabl +++ b/web/app/views/api_music_sessions/show_history.rabl @@ -86,6 +86,14 @@ else end } + child({:approved_rsvps_detail => :approved_rsvps_detail}) { + attributes :id, :photo_url, :first_name, :last_name, :instrument_list + } + + child({:open_slots_detail => :open_slots_detail}) { + attributes :id, :instrument_id, :proficiency_level, :proficiency_desc, :description + } + child({:open_slots => :open_slots}) { attributes :id, :instrument_id, :proficiency_level, :proficiency_desc } diff --git a/web/app/views/clients/_scheduledSession.html.erb b/web/app/views/clients/_scheduledSession.html.erb index b40e3aaa9..f8efcc61f 100644 --- a/web/app/views/clients/_scheduledSession.html.erb +++ b/web/app/views/clients/_scheduledSession.html.erb @@ -465,9 +465,9 @@