VRFS-575: moved association to perf data from music_session to music_session_user_history; updated admin links for perf data
This commit is contained in:
parent
f7ea752ea4
commit
eb079464ab
|
|
@ -25,7 +25,6 @@ ActiveAdmin.register JamRuby::MusicSessionHistory, :as => 'Music Session History
|
|||
row :creator do |msh| auto_link(msh.user, msh.user.try(:email)) end
|
||||
row :band do |msh| auto_link(msh.band, msh.band.try(:name)) end
|
||||
row :genres
|
||||
row :perf_data do |msg| link_to('Data Link', "http://#{msh.perf_uri}") end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -36,6 +35,9 @@ ActiveAdmin.register JamRuby::MusicSessionHistory, :as => 'Music Session History
|
|||
column :joined do |msuh| msuh.created_at.strftime('%b %d %Y, %H:%M') end
|
||||
column :duration do |msuh| "#{msuh.duration_minutes} minutes" end
|
||||
column :active do |msuh| msuh.session_removed_at.nil? end
|
||||
column :perf_data do |msuh|
|
||||
link_to('Data Link', uu) unless (uu = msuh.perf_uri).blank?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,22 +5,17 @@ module JamRuby
|
|||
|
||||
self.primary_key = 'id'
|
||||
|
||||
# for some reason the association is not working, i suspect has to do with the foreign key
|
||||
def music_session_user_histories
|
||||
# NOTE: for some reason the association is not working, i suspect has to do with the foreign key (jkolyer)
|
||||
# has_many(:music_session_user_histories,
|
||||
# :class_name => "JamRuby::MusicSessionUserHistory",
|
||||
# :foreign_key => :music_session_id,
|
||||
# :order => 'created_at DESC',
|
||||
# :inverse_of => :music_session_history)
|
||||
@msuh ||= JamRuby::MusicSessionUserHistory
|
||||
.where(:music_session_id => self.music_session_id)
|
||||
.order('created_at DESC')
|
||||
end
|
||||
# has_many(:music_session_user_histories,
|
||||
# :class_name => "JamRuby::MusicSessionUserHistory",
|
||||
# :foreign_key => :music_session_id,
|
||||
# :order => 'created_at DESC',
|
||||
# :inverse_of => :music_session_history)
|
||||
|
||||
has_one(:perf_data,
|
||||
:class_name => "JamRuby::MusicSessionPerfData",
|
||||
:foreign_key => "music_session_id",
|
||||
:inverse_of => :music_session)
|
||||
|
||||
belongs_to(:user,
|
||||
:class_name => 'JamRuby::User',
|
||||
|
|
@ -98,10 +93,5 @@ module JamRuby
|
|||
end_time = self.session_removed_at || Time.now
|
||||
(end_time - self.created_at) / 60.0
|
||||
end
|
||||
|
||||
def perf_uri
|
||||
self.perf_data.try(:uri)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ module JamRuby
|
|||
|
||||
attr_accessible :uri
|
||||
|
||||
belongs_to(:music_session,
|
||||
belongs_to(:music_session_user_history,
|
||||
:class_name => "JamRuby::MusicSessionHistory",
|
||||
:foreign_key => :music_session_id,
|
||||
:foreign_key => :client_id,
|
||||
:inverse_of => :perf_data)
|
||||
|
||||
# mount_uploader :uri, PerfDataUploader
|
||||
|
|
|
|||
|
|
@ -10,17 +10,22 @@ module JamRuby
|
|||
:foreign_key => "user_id",
|
||||
:inverse_of => :music_session_user_histories)
|
||||
|
||||
# for some reason the association is not working, i suspect has to do with the foreign key
|
||||
has_one(:perf_data,
|
||||
:class_name => "JamRuby::MusicSessionPerfData",
|
||||
:foreign_key => "client_id",
|
||||
:inverse_of => :music_session_user_history)
|
||||
|
||||
def music_session_history
|
||||
# NOTE: for some reason the association is not working, i suspect has to do with the foreign key (jkolyer)
|
||||
# belongs_to(:music_session_history,
|
||||
# :class_name => "JamRuby::MusicSessionHistory",
|
||||
# :foreign_key => :music_session_id,
|
||||
# :inverse_of => :music_session_user_histories)
|
||||
@msh ||= JamRuby::MusicSessionHistory
|
||||
.where(:music_session_id => self.music_session_id)
|
||||
.limit(1)
|
||||
.first
|
||||
end
|
||||
# belongs_to(:music_session_history,
|
||||
# :class_name => "JamRuby::MusicSessionHistory",
|
||||
# :foreign_key => :music_session_id,
|
||||
# :inverse_of => :music_session_user_histories)
|
||||
|
||||
def self.save(music_session_id, user_id, client_id)
|
||||
session_user_history = MusicSessionUserHistory.new()
|
||||
|
|
@ -48,5 +53,9 @@ module JamRuby
|
|||
hist.update_attribute(:session_removed_at, Time.now) if hist
|
||||
end
|
||||
|
||||
def perf_uri
|
||||
self.perf_data.try(:uri)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue