diff --git a/db/manifest b/db/manifest index 497c11631..e933ef5e8 100755 --- a/db/manifest +++ b/db/manifest @@ -229,4 +229,5 @@ deletable_recordings.sql jam_tracks.sql shopping_carts.sql recurly.sql -add_track_resource_id.sql \ No newline at end of file +add_track_resource_id.sql +user_genres.sql diff --git a/ruby/lib/jam_ruby.rb b/ruby/lib/jam_ruby.rb index 07234042f..ac0ad6c52 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -85,7 +85,7 @@ require "jam_ruby/models/feedback_observer" #require "jam_ruby/models/max_mind_geo" #require "jam_ruby/models/max_mind_isp" require "jam_ruby/models/max_mind_release" -require "jam_ruby/models/band_genre" +require "jam_ruby/models/genre_player" require "jam_ruby/models/genre" require "jam_ruby/models/user" require "jam_ruby/models/rsvp_request" diff --git a/ruby/lib/jam_ruby/models/band.rb b/ruby/lib/jam_ruby/models/band.rb index 58ea30e1b..de3a47d54 100644 --- a/ruby/lib/jam_ruby/models/band.rb +++ b/ruby/lib/jam_ruby/models/band.rb @@ -30,8 +30,8 @@ module JamRuby has_many :users, :through => :band_musicians, :class_name => "JamRuby::User" # genres - has_many :band_genres, class_name: "JamRuby::BandGenre", dependent: :destroy - has_many :genres, class_name: "JamRuby::Genre", :through => :band_genres + has_many :genre_players, as: :player, class_name: "JamRuby::GenrePlayer", dependent: :destroy + has_many :genres, through: :genre_players, class_name: "JamRuby::Genre" # recordings has_many :recordings, :class_name => "JamRuby::Recording", :foreign_key => "band_id", dependent: :destroy diff --git a/ruby/lib/jam_ruby/models/band_genre.rb b/ruby/lib/jam_ruby/models/band_genre.rb deleted file mode 100644 index 9bd4051d4..000000000 --- a/ruby/lib/jam_ruby/models/band_genre.rb +++ /dev/null @@ -1,11 +0,0 @@ -module JamRuby - class BandGenre < ActiveRecord::Base - - self.table_name = "bands_genres" - - self.primary_key = 'id' - - belongs_to :user, class_name: "JamRuby::User" - belongs_to :genre, class_name: "JamRuby::Genre" - end -end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/genre.rb b/ruby/lib/jam_ruby/models/genre.rb index e2e0faa1d..1b0cd9ada 100644 --- a/ruby/lib/jam_ruby/models/genre.rb +++ b/ruby/lib/jam_ruby/models/genre.rb @@ -4,8 +4,9 @@ module JamRuby self.primary_key = 'id' # bands - has_many :band_genres, class_name: "JamRuby::BandGenre" - has_many :bands, class_name: "JamRuby::Band", :through => :band_genres + # has_many :genre_players, class_name: "JamRuby::GenrePlayer" + # has_many :bands, class_name: "JamRuby::Band", through: :genre_players, condition: ['player_type = ?', 'JamRuby::Band'] + # has_many :users, class_name: "JamRuby::User", through: :genre_players, condition: ['player_type = ?', 'JamRuby::User'] # music sessions @@ -21,4 +22,4 @@ module JamRuby description end end -end \ No newline at end of file +end diff --git a/ruby/lib/jam_ruby/models/genre_player.rb b/ruby/lib/jam_ruby/models/genre_player.rb new file mode 100644 index 000000000..76bdb4ccf --- /dev/null +++ b/ruby/lib/jam_ruby/models/genre_player.rb @@ -0,0 +1,10 @@ +module JamRuby + class GenrePlayer < ActiveRecord::Base + + self.table_name = "genre_players" + + belongs_to :player, polymorphic: true + belongs_to :genre, class_name: "JamRuby::Genre" + + end +end diff --git a/ruby/lib/jam_ruby/models/search.rb b/ruby/lib/jam_ruby/models/search.rb index 9bc0d7bb1..ae0ba396e 100644 --- a/ruby/lib/jam_ruby/models/search.rb +++ b/ruby/lib/jam_ruby/models/search.rb @@ -432,7 +432,7 @@ module JamRuby rel = Band.scoped unless (genre = params[:genre]).blank? - rel = Band.joins("RIGHT JOIN bands_genres AS bgenres ON bgenres.band_id = bands.id") + rel = Band.joins("RIGHT JOIN genre_players AS bgenres ON bgenres.player_id = bands.id AND bgenres.player_type = 'JamRuby::Band'") .where(['bgenres.genre_id = ? AND bands.id IS NOT NULL', genre]) end diff --git a/ruby/lib/jam_ruby/models/user.rb b/ruby/lib/jam_ruby/models/user.rb index 831b9235a..ba874eb73 100644 --- a/ruby/lib/jam_ruby/models/user.rb +++ b/ruby/lib/jam_ruby/models/user.rb @@ -56,6 +56,10 @@ module JamRuby has_many :band_musicians, :class_name => "JamRuby::BandMusician" has_many :bands, :through => :band_musicians, :class_name => "JamRuby::Band" + # genres + has_many :genre_players, as: :player, class_name: "JamRuby::GenrePlayer", dependent: :destroy + has_many :genres, through: :genre_players, class_name: "JamRuby::Genre" + # recordings has_many :owned_recordings, :class_name => "JamRuby::Recording", :foreign_key => "owner_id" has_many :recordings, :through => :claimed_recordings, :class_name => "JamRuby::Recording" @@ -601,6 +605,16 @@ module JamRuby return recordings end + def update_genres(gids) + unless self.new_record? + GenrePlayer.delete_all(["player_id = ? AND player_type = ?", + self.id, self.class.name]) + end + gids.each do |gid| + self.genres << Genre.find_by_id(gid) + end + end + # given an array of instruments, update a user's instruments def update_instruments(instruments) # delete all instruments for this user first diff --git a/web/app/assets/javascripts/accounts_profile.js b/web/app/assets/javascripts/accounts_profile.js index 91e7f2665..79b8389fe 100644 --- a/web/app/assets/javascripts/accounts_profile.js +++ b/web/app/assets/javascripts/accounts_profile.js @@ -33,7 +33,7 @@ $('#account-profile-content-scroller form .error').removeClass("error") } - function populateAccountProfile(userDetail, instruments) { + function populateAccountProfile(userDetail, instruments) { var template = context.JK.fillTemplate($('#template-account-profile').html(), { country: userDetail.country, region: userDetail.state, @@ -48,11 +48,9 @@ }); var content_root = $('#account-profile-content-scroller') - content_root.html(template); // now use javascript to fix up values too hard to do with templating - // set gender $('select[name=gender]', content_root).val(userDetail.gender) @@ -66,22 +64,18 @@ $('select#user_birth_date_1i', content_root).val(parseInt(birthDateYear)); $('select#user_birth_date_2i', content_root).val(parseInt(birthDateMonth)); $('select#user_birth_date_3i', content_root).val(parseInt(birthDateDay)); - } + loadGenres(userDetail.genres); + // update instruments $.each(instruments, function(index, instrument) { - var template = context.JK.fillTemplate($('#account-profile-instrument').html(), { checked : isUserInstrument(instrument, userDetail.instruments) ? "checked=\"checked\"" :"", description : instrument.description, id : instrument.id }) - - $('.instrument_selector', content_root).append(template) - - }) // and fill in the proficiency for the instruments that the user can play if(userDetail.instruments) { @@ -91,7 +85,6 @@ } context.JK.dropdown($('select', content_root)); - } function isUserInstrument(instrument, userInstruments) { @@ -107,6 +100,47 @@ return isUserInstrument; } + function loadGenres(selectedGenres) { + $("#user-genres").empty(); + + rest.getGenres().done(function (genres) { + $.each(genres, function (index, genre) { + var genreTemplate = $('#template-user-setup-genres').html(); + var selected = ''; + if (selectedGenres) { + var genreMatch = $.grep(selectedGenres, function (n, i) { + return n.id === genre.id; + }); + if (genreMatch.length > 0) { + selected = "checked"; + } + } + var genreHtml = context.JK.fillTemplate(genreTemplate, { + id: genre.id, + description: genre.description, + checked: selected + }); + + $('#user-genres').append(genreHtml); + }); + }); + } + function resetGenres() { + $('input[type=checkbox]:checked', '#user-genres').each(function (i) { + $(this).removeAttr("checked"); + }); + var $tdGenres = $("#tdBandGenres"); + } + + function getSelectedGenres() { + var genres = []; + $('input[type=checkbox]:checked', '#user-genres').each(function (i) { + var genre = $(this).val(); + genres.push(genre); + }); + return genres; + } + function populateAccountProfileLocation(userDetail, regions, cities) { populateRegions(regions, userDetail.state); populateCities(cities, userDetail.city); @@ -259,12 +293,12 @@ $.when( api.getUserDetail(), api.getInstruments()) - .done(function(userDetailResponse, instrumentsResponse) { + .done(function(userDetailResponse, instrumentsResponse) { var userDetail = userDetailResponse[0]; recentUserDetail = userDetail // store userDetail for later - var instruments = instrumentsResponse[0]; // show page; which can be done quickly at this point - populateAccountProfile(userDetail, instruments); + populateAccountProfile(userDetail, + instrumentsResponse[0]); selectLocation = new context.JK.SelectLocation(getCountryElement(), getRegionElement(), getCityElement(), app); selectLocation.load(userDetail.country, userDetail.state, userDetail.city) @@ -295,6 +329,7 @@ var subscribeEmail = getSubscribeEmail().is(':checked'); var birthDate = getBirthDate(); var instruments = getInstrumentsValue(); + var genres = getSelectedGenres(); api.updateUser({ country: country, @@ -305,6 +340,7 @@ gender: gender, birth_date: birthDate, instruments: instruments, + genres: genres, subscribe_email: subscribeEmail }) .done(postUpdateProfileSuccess) diff --git a/web/app/assets/stylesheets/client/account.css.scss b/web/app/assets/stylesheets/client/account.css.scss index c34722147..965ed4036 100644 --- a/web/app/assets/stylesheets/client/account.css.scss +++ b/web/app/assets/stylesheets/client/account.css.scss @@ -117,7 +117,7 @@ box-shadow: 2px 2px 3px 0 #888888 inset; color: #000; font-size: 14px; - height: 178px; + height: 100px; overflow: auto; width: 100%; diff --git a/web/app/assets/stylesheets/client/profile.css.scss b/web/app/assets/stylesheets/client/profile.css.scss index e28a376cc..752dea419 100644 --- a/web/app/assets/stylesheets/client/profile.css.scss +++ b/web/app/assets/stylesheets/client/profile.css.scss @@ -205,6 +205,18 @@ padding-right:5px; } +.user-setup-genres { + width:40%; + height:90px; + background-color:#c5c5c5; + border:none; + -webkit-box-shadow: inset 2px 2px 3px 0px #888; + box-shadow: inset 2px 2px 3px 0px #888; + color:#000; + overflow:auto; + font-size:14px; +} + .profile-band-list-result { width:100%; min-height:85px; diff --git a/web/app/controllers/api_users_controller.rb b/web/app/controllers/api_users_controller.rb index e475a4a70..7d8d40f94 100644 --- a/web/app/controllers/api_users_controller.rb +++ b/web/app/controllers/api_users_controller.rb @@ -23,9 +23,10 @@ class ApiUsersController < ApiController end def show - @user = User.includes([{:musician_instruments => :instrument}, - {:band_musicians => :user}, - :bands, :instruments]) + @user = User.includes([{musician_instruments: :instrument}, + {band_musicians: :user}, + {genre_players: :genre}, + :bands, :instruments, :genres]) .find(params[:id]) respond_with @user, responder: ApiResponder, :status => 200 @@ -43,6 +44,7 @@ class ApiUsersController < ApiController @user.country = params[:country] if params.has_key?(:country) @user.musician = params[:musician] if params.has_key?(:musician) @user.update_instruments(params[:instruments].nil? ? [] : params[:instruments]) if params.has_key?(:instruments) + @user.update_genres(params[:genres].nil? ? [] : params[:genres]) if params.has_key?(:genres) @user.show_whats_next = params[:show_whats_next] if params.has_key?(:show_whats_next) @user.subscribe_email = params[:subscribe_email] if params.has_key?(:subscribe_email) @user.biography = params[:biography] if params.has_key?(:biography) diff --git a/web/app/views/api_users/show.rabl b/web/app/views/api_users/show.rabl index aa1030f48..b005b0fa8 100644 --- a/web/app/views/api_users/show.rabl +++ b/web/app/views/api_users/show.rabl @@ -83,6 +83,10 @@ child :musician_instruments => :instruments do attributes :description, :proficiency_level, :priority, :instrument_id end +child :genres do + attributes :description, :id +end + child :music_sessions => :sessions do attributes :id, :description, :musician_access, :approval_required, :fan_access end diff --git a/web/app/views/clients/_account_profile.html.erb b/web/app/views/clients/_account_profile.html.erb index c297b0f7b..af76ee2e7 100644 --- a/web/app/views/clients/_account_profile.html.erb +++ b/web/app/views/clients/_account_profile.html.erb @@ -94,6 +94,13 @@ +