VRFS-1326 fixed integration of latest/buzz

This commit is contained in:
Jonathan Kolyer 2014-03-04 05:38:58 +00:00
parent e2cae90fa3
commit 17088d49b5
4 changed files with 12 additions and 32 deletions

View File

@ -31,7 +31,6 @@ ActiveAdmin.register JamRuby::PromoLatest, :as => 'Latest' do
def new
@promo = JamRuby::PromoLatest.new
@promo.aasm_state = 'active'
@latests = PromoLatest.latest_candidates
super
end
@ -42,7 +41,6 @@ ActiveAdmin.register JamRuby::PromoLatest, :as => 'Latest' do
def edit
@promo = resource
@latests = PromoLatest.latest_candidates
super
end

View File

@ -34,9 +34,11 @@ class JamRuby::Promotional < ActiveRecord::Base
aasm_state
end
def self.active(max_count=100)
def self.active(max_count=10)
rel = self.where(:aasm_state => ACTIVE_STATE)
rel = rel.limit(mc) if 0 < (mc = max_count.to_i)
if 0 < (mc = max_count.to_i)
rel = rel.limit(mc)
end
rel
end
@ -82,31 +84,11 @@ class JamRuby::PromoLatest < JamRuby::Promotional
attr_accessible :latest
def music_session_history
@music_session_history ||= MusicSessionHistory.find_by_id(latest_id)
self.latest if self.latest.is_a? MusicSessionHistory
end
def recording
@recording ||= Recording.find_by_id(latest_id)
end
def self.latest_candidates
recordings = Recording
.where('music_session_id IS NOT NULL')
.order('created_at DESC')
.limit(10)
sessions = MusicSession
.where("music_sessions.id NOT IN ('#{recordings.map(&:music_session_id).join("','")}')")
.order('created_at DESC')
.limit(10)
latests = (recordings + sessions).sort { |o1,o2| o2.created_at <=> o1.created_at }
latests.collect do |ll|
nm = if ll.is_a?(Recording)
"#{ll.class.name.demodulize}: #{ll.band.present? ? ll.band.name : ll.owner.name}"
else
"#{ll.class.name.demodulize}: #{ll.band.present? ? ll.band.name : ll.creator.name}"
end
{ :name => nm, :id => ll.id, :record => ll }
end
self.latest if self.latest.is_a? Recording
end
def self.create_with_params(params)
@ -118,8 +100,8 @@ class JamRuby::PromoLatest < JamRuby::Promotional
def update_with_params(params)
if (latest_id = params[:latest_id]).present?
self.latest = Recording.where(:id => latest_id).limit(1).all[0] ||
MusicSession.where(:id => latest_id).limit(1).all[0]
self.latest = Recording.where(:id => latest_id).limit(1).first ||
MusicSessionHistory.where(:id => latest_id).limit(1).first
end
self.position = params[:position]
self.aasm_state = params[:aasm_state]
@ -131,7 +113,7 @@ class JamRuby::PromoLatest < JamRuby::Promotional
nm = if ll.is_a?(Recording)
ll.band.present? ? ll.band.name : ll.owner.name
else
ll.band.present? ? ll.band.name : ll.creator.name
ll.band.present? ? ll.band.name : ll.user.name
end
"#{ll.class.name.demodulize}: #{nm} (#{ll.created_at})"
end

View File

@ -206,10 +206,10 @@ class UsersController < ApplicationController
Slide.new("bands", "web/carousel_bands.jpg", "http://www.youtube.com/embed/eaYNM7p6Z5s")
]
@promo_buzz = Promotional.where(:type => 'JamRuby::PromoBuzz', :aasm_state => :active).where('latest_id IS NOT NULL').order(:position)
@promo_buzz = PromoBuzz.active
if Rails.application.config.use_promos_on_homepage
@promo_latest = Promotional.where(:type => 'JamRuby::PromoLatest', :aasm_state => :active).where('latest_id IS NOT NULL').order(:position).limit(10)
@promo_latest = PromoLatest.active
else
@promo_latest, start = Feed.index(nil, limit: 10)
end

View File

@ -213,6 +213,6 @@ if defined?(Bundler)
config.send_join_session_email_notifications = true
config.use_promos_on_homepage = false
config.use_promos_on_homepage = true
end
end