VRFS-3036 band results display
This commit is contained in:
parent
e50dc6e20d
commit
4f5a39db18
|
|
@ -69,6 +69,7 @@ module JamRuby
|
|||
end
|
||||
|
||||
def follower_count
|
||||
# FIXME: this could be a lot of followers; calling size loads all the data into memory
|
||||
self.followers.size
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -77,6 +77,10 @@ module JamRuby
|
|||
PERF_SAMPLES_VALS = TOUR_OPTION_VALS.clone
|
||||
PERF_SAMPLES = TOUR_OPTIONS.clone
|
||||
|
||||
COUNT_FOLLOW = :count_follow
|
||||
COUNT_RECORD = :count_record
|
||||
COUNT_SESSION = :count_session
|
||||
|
||||
def self.json_schema
|
||||
return @@jschema if @@jschema
|
||||
@@jschema = {
|
||||
|
|
@ -241,16 +245,19 @@ module JamRuby
|
|||
rel.includes([:instruments])
|
||||
end
|
||||
|
||||
def process_results_page(_results)
|
||||
def _process_results_page(_results)
|
||||
@results = _results
|
||||
if user
|
||||
@user_counters = @results.inject({}) { |hh,val| hh[val.id] = []; hh }
|
||||
mids = "'#{@results.map(&:id).join("','")}'"
|
||||
@user_counters = @results.inject({}) { |hh,val| hh[val.id] = {}; hh }
|
||||
|
||||
# this gets counts for each search result
|
||||
@results.each do |bb|
|
||||
counters = { }
|
||||
@user_counters[bb.id] << counters
|
||||
counters = {
|
||||
COUNT_FOLLOW => Follow.where(:followable_id => bb.id).count,
|
||||
COUNT_RECORD => Recording.where(:band_id => bb.id).count,
|
||||
COUNT_SESSION => MusicSession.where(:band_id => bb.id).count
|
||||
}
|
||||
@user_counters[bb.id] = counters
|
||||
end
|
||||
else
|
||||
@user_counters = {}
|
||||
|
|
@ -262,7 +269,7 @@ module JamRuby
|
|||
|
||||
def _count(musician, key)
|
||||
if mm = @user_counters[musician.id]
|
||||
return mm.detect { |ii| ii.is_a?(Hash) }[key]
|
||||
return mm[key]
|
||||
end if @user_counters
|
||||
0
|
||||
end
|
||||
|
|
@ -273,10 +280,6 @@ module JamRuby
|
|||
_count(musician, COUNT_FOLLOW)
|
||||
end
|
||||
|
||||
def friend_count(musician)
|
||||
_count(musician, COUNT_FRIEND)
|
||||
end
|
||||
|
||||
def record_count(musician)
|
||||
_count(musician, COUNT_RECORD)
|
||||
end
|
||||
|
|
@ -285,13 +288,6 @@ module JamRuby
|
|||
_count(musician, COUNT_SESSION)
|
||||
end
|
||||
|
||||
def is_friend?(musician)
|
||||
if mm = @user_counters[musician.id]
|
||||
return mm.include?(RESULT_FRIEND)
|
||||
end if @user_counters
|
||||
false
|
||||
end
|
||||
|
||||
def is_follower?(musician)
|
||||
if mm = @user_counters[musician.id]
|
||||
return mm.include?(RESULT_FOLLOW)
|
||||
|
|
@ -352,7 +348,7 @@ module JamRuby
|
|||
rel = self.search_includes(rel)
|
||||
@page_count = rel.total_pages
|
||||
|
||||
process_results_page(rel.all)
|
||||
_process_results_page(rel.all)
|
||||
end
|
||||
|
||||
def description(filter)
|
||||
|
|
|
|||
|
|
@ -53,6 +53,12 @@ describe 'Band Search Model' do
|
|||
expect(search.results.count).to eq(Band.count)
|
||||
end
|
||||
|
||||
it "has follower counts" do
|
||||
Follow.create(user_id: searcher.id, followable: Band.first)
|
||||
search.search_results_page
|
||||
expect(search.user_counters[Band.first.id][BandSearch::COUNT_FOLLOW]).to eq(1)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "filtering by keys" do
|
||||
|
|
|
|||
|
|
@ -790,12 +790,30 @@ context.JK.BandSearchFilter = class BandSearchFilter extends BaseSearchFilter
|
|||
context.JK.bindHoverEvents()
|
||||
return
|
||||
|
||||
_bindMessageBand: () =>
|
||||
|
||||
_bindFriendBand: () =>
|
||||
|
||||
_bindFollowBand: () =>
|
||||
|
||||
objThis = this
|
||||
if 0 == $(this).closest('.button-orange').size()
|
||||
return false
|
||||
$(this).click (ee) ->
|
||||
ee.preventDefault()
|
||||
return
|
||||
evt.stopPropagation()
|
||||
newFollowing = {}
|
||||
newFollowing.band_id = $(this).parent().data('band-id')
|
||||
url = '/api/users/' + context.JK.currentUserId + '/followings'
|
||||
$.ajax
|
||||
type: 'POST'
|
||||
dataType: 'json'
|
||||
contentType: 'application/json'
|
||||
url: url
|
||||
data: JSON.stringify(newFollowing)
|
||||
processData: false
|
||||
success: (response) ->
|
||||
$('div[data-band-id=' + newFollowing.band_id + '] .search-m-follow').removeClass('button-orange').addClass 'button-grey'
|
||||
return
|
||||
error: app.ajaxError(arguments)
|
||||
return
|
||||
|
||||
_formatLocation: (band) ->
|
||||
|
||||
friendRequestCallback: (user_id)=>
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ if @search.is_a?(BaseSearch)
|
|||
end
|
||||
|
||||
node :follow_count do |musician| @search.follow_count(musician) end
|
||||
node :friend_count do |musician| @search.friend_count(musician) end
|
||||
node :recording_count do |musician| @search.record_count(musician) end
|
||||
node :session_count do |musician| @search.session_count(musician) end
|
||||
|
||||
|
|
|
|||
|
|
@ -183,18 +183,13 @@ script#template-find-band-row type="text/template"
|
|||
.clearall
|
||||
|
||||
script#template-band-action-btns type="text/template"
|
||||
a.button-orange.smallbutton href="{profile_url}"
|
||||
PROFILE
|
||||
a.smallbutton.search-m-follow href="#" class="{button_follow}"
|
||||
FOLLOW
|
||||
a.button-orange.smallbutton href="{profile_url}" PROFILE
|
||||
a.smallbutton.search-m-follow href="#" class="{button_follow}" FOLLOW
|
||||
|
||||
script#template-band-edit-btns type="text/template"
|
||||
a.button-orange.smallbutton href="{profile_url}"
|
||||
PROFILE
|
||||
a.button-orange.smallbutton href="{band_edit_url}"
|
||||
EDIT BAND
|
||||
a.button-orange.smallbutton href="{band_member_url}"
|
||||
INVITE
|
||||
a.button-orange.smallbutton href="{profile_url}" PROFILE
|
||||
a.button-orange.smallbutton href="{band_edit_url}" EDIT BAND
|
||||
a.button-orange.smallbutton href="{band_member_url}" INVITE
|
||||
|
||||
script#template-band-player-info type="text/template"
|
||||
tr
|
||||
|
|
|
|||
Loading…
Reference in New Issue