VRFS-3036 band web search args
This commit is contained in:
parent
8480f582ad
commit
1bd1794318
|
|
@ -7,6 +7,7 @@ module JamRuby
|
|||
serialize :data_blob, JSON
|
||||
|
||||
KEY_BAND_SEARCH_TYPE = 'band_search_type'
|
||||
KEY_BAND_TYPE = 'band_type'
|
||||
KEY_BAND_STATUS = 'band_status'
|
||||
KEY_PLAY_COMMIT = 'play_commitment'
|
||||
KEY_TOUR_OPTION = 'touring_option'
|
||||
|
|
@ -23,7 +24,8 @@ module JamRuby
|
|||
TO_HIRE => 'search bands to hire',
|
||||
}
|
||||
|
||||
SKILL_VAL_STRS = [ANY_VAL_STR, 'amateur', 'professional']
|
||||
BAND_TYPE_VAL_STRS = [ANY_VAL_STR, 'amateur', 'professional']
|
||||
BAND_TYPES = BAND_TYPE_VAL_STRS.map(&:camelcase)
|
||||
|
||||
SORT_VALS = %W{ distance latency }
|
||||
SORT_ORDERS = {
|
||||
|
|
@ -42,7 +44,7 @@ module JamRuby
|
|||
GenrePlayer::VIRTUAL_BAND,
|
||||
GenrePlayer::TRADITIONAL_BAND,
|
||||
]
|
||||
BAND_STATUSS = {
|
||||
BAND_STATUS = {
|
||||
BAND_STATUS_VALS[0] => 'Any',
|
||||
BAND_STATUS_VALS[1] => 'Virtual Band',
|
||||
BAND_STATUS_VALS[2] => 'Traditional Band',
|
||||
|
|
@ -79,7 +81,7 @@ module JamRuby
|
|||
return @@jschema if @@jschema
|
||||
@@jschema = {
|
||||
TO_JOIN => BaseSearch.json_schema.merge({
|
||||
KEY_SKILL => self::SKILL_VAL_STRS[0].to_s,
|
||||
KEY_BAND_TYPE => self::BAND_TYPE_VAL_STRS[0].to_s,
|
||||
KEY_BAND_STATUS => BAND_STATUS_VALS[0],
|
||||
KEY_PLAY_COMMIT => PLAY_COMMIT_VALS[0],
|
||||
KEY_TOUR_OPTION => TOUR_OPTION_VALS[0],
|
||||
|
|
@ -87,8 +89,8 @@ module JamRuby
|
|||
TO_HIRE => {
|
||||
KEY_SORT_ORDER => self::HIRE_SORT_VALS[0],
|
||||
KEY_GENRES => [],
|
||||
KEY_SKILL => self::SKILL_VAL_STRS[0].to_s,
|
||||
KEY_GIGS => self::GIG_COUNTS[0].to_s,
|
||||
KEY_BAND_STATUS => BAND_STATUS_VALS[0],
|
||||
KEY_PERF_SAMPLES => self::PERF_SAMPLES[0].to_s,
|
||||
KEY_HIRE_MAX_COST => 0,
|
||||
KEY_HIRE_FREE => 1,
|
||||
|
|
@ -100,7 +102,8 @@ module JamRuby
|
|||
return @@search_meta if @@search_meta
|
||||
toJoinMeta = super(self.json_schema[TO_JOIN])
|
||||
toJoinMeta.merge!({
|
||||
KEY_BAND_STATUS => { keys: BAND_STATUS_VALS, map: BAND_STATUSS },
|
||||
KEY_BAND_TYPE => { keys: BAND_TYPE_VAL_STRS, map: BAND_TYPES },
|
||||
KEY_BAND_STATUS => { keys: BAND_STATUS_VALS, map: BAND_STATUS },
|
||||
KEY_PLAY_COMMIT => { keys: PLAY_COMMIT_VALS, map: PLAY_COMMITS },
|
||||
KEY_TOUR_OPTION => { keys: TOUR_OPTION_VALS, map: TOUR_OPTIONS }
|
||||
})
|
||||
|
|
@ -119,10 +122,6 @@ module JamRuby
|
|||
Band
|
||||
end
|
||||
|
||||
def _sort_order(rel, filter)
|
||||
rel
|
||||
end
|
||||
|
||||
def _genres(rel, filter)
|
||||
super(rel, filter)
|
||||
end
|
||||
|
|
@ -192,17 +191,41 @@ module JamRuby
|
|||
end
|
||||
end
|
||||
|
||||
def _skill_level(rel, filter)
|
||||
case filter[KEY_SKILL]
|
||||
when SKILL_VAL_STRS[1]
|
||||
rel.where(band_type: SKILL_VAL_STRS[1])
|
||||
when SKILL_VAL_STRS[2]
|
||||
def _band_type(rel, filter)
|
||||
case filter[KEY_BAND_TYPE]
|
||||
when BAND_TYPE_VAL_STRS[1]
|
||||
rel.where(band_type: BAND_TYPE_VAL_STRS[1])
|
||||
when BAND_TYPE_VAL_STRS[2]
|
||||
rel.where(band_type: SKILL_VAL_STRS[2])
|
||||
else
|
||||
rel
|
||||
end
|
||||
end
|
||||
|
||||
def _sort_order(rel, filter)
|
||||
val = filter[KEY_SORT_ORDER]
|
||||
if 'distance' == val
|
||||
# locidispid = self.user.last_jam_locidispid || 0
|
||||
# my_locid = locidispid / 1000000
|
||||
# rel = rel.joins("LEFT JOIN geoiplocations AS my_geo ON my_geo.locid = #{my_locid}")
|
||||
# rel = rel.joins("LEFT JOIN geoiplocations AS other_geo ON users.last_jam_locidispid/1000000 = other_geo.locid")
|
||||
# rel = rel.group("users.id, my_geo.geog, other_geo.geog")
|
||||
# rel = rel.order('st_distance(my_geo.geog, other_geo.geog)')
|
||||
|
||||
elsif 'latency' == val
|
||||
# rel = rel.joins("LEFT JOIN current_scores ON current_scores.a_userid = users.id AND current_scores.b_userid = '#{self.user.id}'")
|
||||
# rel = rel.order('current_scores.full_score ASC')
|
||||
|
||||
elsif 'price_asc' == val
|
||||
rel = rel.order('gig_minimum ASC')
|
||||
|
||||
elsif 'price_desc' == val
|
||||
rel = rel.order('gig_minimum DESC')
|
||||
end
|
||||
|
||||
rel
|
||||
end
|
||||
|
||||
def do_search(filter)
|
||||
rel = Band.unscoped
|
||||
filter.keys.each do |fkey|
|
||||
|
|
@ -332,5 +355,67 @@ module JamRuby
|
|||
process_results_page(rel.all)
|
||||
end
|
||||
|
||||
def description(filter)
|
||||
return '' if self.is_blank?
|
||||
|
||||
str = 'Current Search: '
|
||||
|
||||
str += 'Sort = '
|
||||
case sort = filter[KEY_SORT_ORDER]
|
||||
when 'distance'
|
||||
str += SORT_ORDERS[sort]
|
||||
when 'latency'
|
||||
str += SORT_ORDERS[sort]
|
||||
when 'price_asc'
|
||||
str += HIRE_SORT_ORDERS[sort]
|
||||
when 'price_desc'
|
||||
str += HIRE_SORT_ORDERS[sort]
|
||||
end
|
||||
|
||||
if (val = filter[KEY_BAND_TYPE].to_i) != ANY_VAL_INT
|
||||
str += "; Band type = #{SKILL_LEVELS[val]}"
|
||||
end
|
||||
if (val = filter[KEY_BAND_STATUS]) != ANY_VAL_STR
|
||||
str += "; Band status = #{BAND_STATUS[val]}"
|
||||
end
|
||||
if (val = filter[KEY_PLAY_COMMIT]) != ANY_VAL_STR
|
||||
str += "; Play Commitment = #{PLAY_COMMITS[val]}"
|
||||
end
|
||||
if (val = filter[KEY_TOUR_OPTION]) != ANY_VAL_STR
|
||||
str += "; Touring Options = #{TOUR_OPTIONS[val]}"
|
||||
end
|
||||
if (val = filter[KEY_PERF_SAMPLES]) != ANY_VAL_STR
|
||||
str += "; Performance Samples = #{PERF_SAMPLES[val]}"
|
||||
end
|
||||
if (val = filter[KEY_HIRE_MAX_COST].to_i) > 0
|
||||
str += "; Maximum gig cost = $#{val}"
|
||||
end
|
||||
if filter[KEY_HIRE_FREE]
|
||||
str += "; Bands playing free gigs"
|
||||
end
|
||||
if (val = filter[KEY_GIGS].to_i) != GIG_COUNTS[0]
|
||||
str += "; Concert Gigs = #{GIG_LABELS[val]}"
|
||||
end
|
||||
if 0 < (val = filter[KEY_GENRES]).length
|
||||
str += "; Genres = "
|
||||
genres = Genre.where(["id IN (?)", val]).order('description').pluck(:description)
|
||||
genres.each_with_index do |gg, idx|
|
||||
str += "#{gg}"
|
||||
str += ', ' unless idx==(genres.length-1)
|
||||
end
|
||||
end
|
||||
if 0 < (val = filter[KEY_INSTRUMENTS]).length
|
||||
str += "; Instruments = "
|
||||
instr_ids = val.collect { |vv| vv['instrument_id'] }
|
||||
instrs = Instrument.where(["id IN (?)", instr_ids]).order(:description)
|
||||
instrs.each_with_index do |ii, idx|
|
||||
proficiency = val.detect { |vv| vv['instrument_id'] == ii.id }['proficiency_level']
|
||||
str += "#{ii.description} (#{INSTRUMENT_PROFICIENCY[proficiency.to_i]})"
|
||||
str += ', ' unless idx==(instrs.length-1)
|
||||
end
|
||||
end
|
||||
str
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ module JamRuby
|
|||
KEY_SORT_ORDER => self::SORT_VALS[0],
|
||||
KEY_INSTRUMENTS => [],
|
||||
KEY_GENRES => [],
|
||||
KEY_SKILL => self::SKILL_VALS[0].to_s,
|
||||
KEY_GIGS => self::GIG_COUNTS[0].to_s,
|
||||
}
|
||||
end
|
||||
|
|
@ -139,19 +138,6 @@ module JamRuby
|
|||
end
|
||||
|
||||
def _sort_order(rel)
|
||||
val = json[self.class::KEY_SORT_ORDER]
|
||||
if self.class::SORT_VALS[1] == val
|
||||
locidispid = self.user.last_jam_locidispid || 0
|
||||
my_locid = locidispid / 1000000
|
||||
rel = rel.joins("LEFT JOIN geoiplocations AS my_geo ON my_geo.locid = #{my_locid}")
|
||||
rel = rel.joins("LEFT JOIN geoiplocations AS other_geo ON users.last_jam_locidispid/1000000 = other_geo.locid")
|
||||
rel = rel.group("users.id, my_geo.geog, other_geo.geog")
|
||||
rel = rel.order('st_distance(my_geo.geog, other_geo.geog)')
|
||||
else
|
||||
rel = rel.joins("LEFT JOIN current_scores ON current_scores.a_userid = users.id AND current_scores.b_userid = '#{self.user.id}'")
|
||||
rel = rel.order('current_scores.full_score ASC')
|
||||
end
|
||||
rel
|
||||
end
|
||||
|
||||
def do_search(params={})
|
||||
|
|
|
|||
|
|
@ -53,7 +53,8 @@ module JamRuby
|
|||
@@jschema = BaseSearch.json_schema.merge({
|
||||
KEY_INTERESTS => INTEREST_VALS[0],
|
||||
KEY_STUDIOS => STUDIO_COUNTS[0].to_s,
|
||||
KEY_AGES => []
|
||||
KEY_AGES => [],
|
||||
KEY_SKILL => self::SKILL_VALS[0].to_s,
|
||||
})
|
||||
end
|
||||
|
||||
|
|
@ -126,6 +127,22 @@ module JamRuby
|
|||
rel
|
||||
end
|
||||
|
||||
def _sort_order(rel)
|
||||
val = json[self.class::KEY_SORT_ORDER]
|
||||
if self.class::SORT_VALS[1] == val
|
||||
locidispid = self.user.last_jam_locidispid || 0
|
||||
my_locid = locidispid / 1000000
|
||||
rel = rel.joins("LEFT JOIN geoiplocations AS my_geo ON my_geo.locid = #{my_locid}")
|
||||
rel = rel.joins("LEFT JOIN geoiplocations AS other_geo ON users.last_jam_locidispid/1000000 = other_geo.locid")
|
||||
rel = rel.group("users.id, my_geo.geog, other_geo.geog")
|
||||
rel = rel.order('st_distance(my_geo.geog, other_geo.geog)')
|
||||
else
|
||||
rel = rel.joins("LEFT JOIN current_scores ON current_scores.a_userid = users.id AND current_scores.b_userid = '#{self.user.id}'")
|
||||
rel = rel.order('current_scores.full_score ASC')
|
||||
end
|
||||
rel
|
||||
end
|
||||
|
||||
def do_search(params={})
|
||||
rel = User.musicians.where('users.id <> ?', self.user.id)
|
||||
rel = self._genres(rel)
|
||||
|
|
|
|||
|
|
@ -72,9 +72,9 @@ describe 'Band Search Model' do
|
|||
expect(search.results.count).to eq(Band.all.map(&:genres).flatten.select { |bb| bb.id == band_id }.count)
|
||||
end
|
||||
|
||||
it "filters by skill level" do
|
||||
it "filters by band_type" do
|
||||
band.update_attribute(:band_type, BandSearch::SKILL_VAL_STRS[1])
|
||||
filter[BandSearch::KEY_SKILL] = BandSearch::SKILL_VAL_STRS[1]
|
||||
filter[BandSearch::KEY_BAND_TYPE] = BandSearch::SKILL_VAL_STRS[1]
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(1)
|
||||
expect(search.results[0].id).to eq(band.id)
|
||||
|
|
@ -90,6 +90,12 @@ describe 'Band Search Model' do
|
|||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(1)
|
||||
expect(search.results[0].id).to eq(band.id)
|
||||
|
||||
filter[BandSearch::KEY_INSTRUMENTS] = [{'instrument_id' => minst.instrument_id,
|
||||
'proficiency_level' => minst.proficiency_level + 1
|
||||
}]
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(0)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -616,16 +616,16 @@ context.JK.BandSearchFilter = class BandSearchFilter extends BaseSearchFilter
|
|||
this._populateSelectIdentifier('band_type')
|
||||
|
||||
_populatePlayCommit: () =>
|
||||
this._populateSelectIdentifier('play_commit')
|
||||
this._populateSelectIdentifier('play_commitment')
|
||||
|
||||
_populateTourOption: () =>
|
||||
this._populateSelectIdentifier('tour_option')
|
||||
this._populateSelectIdentifier('touring_option')
|
||||
|
||||
_populateSortOrder: () =>
|
||||
this._populateSelectIdentifier('sort_order')
|
||||
|
||||
_populatePerformSamples: () =>
|
||||
this._populateSelectIdentifier('perform_samples')
|
||||
this._populateSelectIdentifier('performance_samples')
|
||||
|
||||
_populateGenres: () =>
|
||||
super()
|
||||
|
|
|
|||
Loading…
Reference in New Issue