From 23ccc855d502b5b45a19f871fbcc6401ba57c0c8 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Sun, 8 Mar 2015 06:07:30 +0000 Subject: [PATCH] VRFS-2795 instrument selection; json posting --- web/app/assets/javascripts/jam_rest.js | 3 ++- .../musician_search_filter.js.coffee | 26 ++++++++++++------- web/app/controllers/api_search_controller.rb | 4 ++- .../clients/_musician_search_filter.html.slim | 4 +-- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js index 390aba7ac..341878d2a 100644 --- a/web/app/assets/javascripts/jam_rest.js +++ b/web/app/assets/javascripts/jam_rest.js @@ -1584,7 +1584,8 @@ function postMusicianSearchFilter(query) { return $.ajax({ type: "POST", - url: "/api/search/musicians.json?" + $.param(query) + url: "/api/search/musicians.json", + data: query }); } diff --git a/web/app/assets/javascripts/musician_search_filter.js.coffee b/web/app/assets/javascripts/musician_search_filter.js.coffee index 3a444ea12..92594fa28 100644 --- a/web/app/assets/javascripts/musician_search_filter.js.coffee +++ b/web/app/assets/javascripts/musician_search_filter.js.coffee @@ -97,9 +97,9 @@ context.JK.MusicianSearchFilter = class MusicianSearchFilter selected = '' ageLabel = ages_map[key] if 0 < @searchFilter.ages.length - + key_val = key.toString() ageMatch = $.grep(@searchFilter.ages, (n, i) -> - n.id == key + n == key_val ) if ageMatch.length > 0 selected = 'checked' @@ -117,7 +117,7 @@ context.JK.MusicianSearchFilter = class MusicianSearchFilter selected = '' if 0 < @searchFilter.genres.length genreMatch = $.grep(@searchFilter.genres, (n, i) -> - n.id == genre.id + n == genre.id ) if genreMatch.length > 0 selected = 'checked' @@ -133,17 +133,24 @@ context.JK.MusicianSearchFilter = class MusicianSearchFilter $.each instruments, (index, instrument) => instrumentTemplate = $('#template-search-filter-setup-instrument').html() selected = '' + proficiency = '1' if 0 < @searchFilter.instruments.length - instrumentMatch = $.grep(@searchFilter.instruments, (n, i) -> - n.id == instrument.id + instMatch = $.grep(@searchFilter.instruments, (inst, i) -> + yn = inst.instrument_id == instrument.id + proficiency = inst.proficiency_level if yn + yn ) - if instrumentMatch.length > 0 - selected = 'checked' + if instMatch.length > 0 + selected = 'checked' instrumentHtml = context.JK.fillTemplate(instrumentTemplate, id: instrument.id description: instrument.description - checked: selected) + checked: selected + ) $('#search-filter-instruments').append instrumentHtml + instsel = '#search-filter-instruments tr[data-instrument-id="'+instrument.id+'"] select' + $(instsel).val(proficiency) + return true _selectedValue: (identifier) => elem = $ '#musician-search-filter-builder select[name='+identifier+']' @@ -171,6 +178,5 @@ context.JK.MusicianSearchFilter = class MusicianSearchFilter $.each gon.musician_search_filter.filter_keys.multi, (index, key) => @searchFilter[key] = this._selectedMultiValue(key) - @logger.debug("performSearch: "+JSON.stringify(@searchFilter)) - @rest.postMusicianSearchFilter { filter: @searchFilter } + @rest.postMusicianSearchFilter { filter: JSON.stringify(@searchFilter), page: 1 } \ No newline at end of file diff --git a/web/app/controllers/api_search_controller.rb b/web/app/controllers/api_search_controller.rb index 459ef5374..69fe64db6 100644 --- a/web/app/controllers/api_search_controller.rb +++ b/web/app/controllers/api_search_controller.rb @@ -27,8 +27,10 @@ class ApiSearchController < ApiController render :json => MusicianSearch.search_filter_json(current_user), :status => 200 elsif request.post? + logger.debug("*** params = #{params.inspect}") ms = MusicianSearch.user_search_filter(current_user) - results = ms.search_results_page(params[:filter]) + json = JSON.parse(params[:filter], :create_additions => false) + results = ms.search_results_page(json, [params[:page].to_i, 1].max) render :json => results, :status => 200 end end diff --git a/web/app/views/clients/_musician_search_filter.html.slim b/web/app/views/clients/_musician_search_filter.html.slim index 0e5ba7e5b..52f31775b 100644 --- a/web/app/views/clients/_musician_search_filter.html.slim +++ b/web/app/views/clients/_musician_search_filter.html.slim @@ -45,8 +45,8 @@ script#template-musician-search-filter type="text/template" script#template-search-filter-setup-instrument type="text/template" tr data-instrument-id="{id}" - td {description} - td align="right" width="50%" + td {description} + td align="right" width="50%" id="{proficiency_id}" select.proficiency_selector name="proficiency" option value="1" Beginner option value="2" Intermediate