From 9dbe1a51c780ce76b4c90e20ee27f8a7d97fff6b Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sat, 9 Feb 2013 11:45:11 -0500 Subject: [PATCH] find session fixes / set avatar and user name in header --- app/assets/javascripts/createSession.js | 4 +- app/assets/javascripts/findSession.js | 93 ++++++++++++------- app/assets/javascripts/header.js | 8 ++ .../stylesheets/client/createSession.css.scss | 4 + app/views/api_users/index.rabl | 2 +- app/views/api_users/show.rabl | 2 +- app/views/clients/_findSession.html.erb | 19 +++- app/views/clients/_header.html.erb | 4 +- 8 files changed, 93 insertions(+), 43 deletions(-) diff --git a/app/assets/javascripts/createSession.js b/app/assets/javascripts/createSession.js index 6e6aa19d5..2c186ac31 100644 --- a/app/assets/javascripts/createSession.js +++ b/app/assets/javascripts/createSession.js @@ -132,12 +132,10 @@ // top instrument in the user's profile. // 2. Otherwise, use the tracks from the last created session. data.tracks = [ - { instrument_id: "electric guitar", sound: "mono" }, - { instrument_id: "keyboard", sound: "mono" } + { instrument_id: "electric guitar", sound: "mono" } ]; var jsonData = JSON.stringify(data); - alert(jsonData); var url = "/api/sessions"; $.ajax({ diff --git a/app/assets/javascripts/findSession.js b/app/assets/javascripts/findSession.js index 9ae025c38..b50a555b9 100644 --- a/app/assets/javascripts/findSession.js +++ b/app/assets/javascripts/findSession.js @@ -73,6 +73,7 @@ $.ajax({ type: "GET", url: "/api/sessions?" + queryString, + async: false, success: startSessionLatencyChecks }); } @@ -89,7 +90,6 @@ var OTHER = 'div#sessions-other'; // INVITATION - //alert(sessionCounts[CATEGORY.INVITATION.index]); if (sessionCounts[CATEGORY.INVITATION.index] == 0) { priorVisible = false; $(INVITATION).hide(); @@ -104,7 +104,6 @@ $(FRIEND).removeClass('mt35'); } - //alert(sessionCounts[CATEGORY.FRIEND.index]); if (sessionCounts[CATEGORY.FRIEND.index] == 0) { priorVisible = false; $(FRIEND).hide(); @@ -119,7 +118,6 @@ $(OTHER).removeClass('mt35'); } - //alert(sessionCounts[CATEGORY.OTHER.index]); if (sessionCounts[CATEGORY.OTHER.index] == 0) { $(OTHER).hide(); } @@ -130,9 +128,14 @@ function getSelectedMusicians() { var selectedMusicians = []; - $('#musician-list-items :checked').each(function() { - selectedMusicians.push($(this).val()); - }); + // $('#musician-list-items :checked').each(function() { + // selectedMusicians.push($(this).val()); + // }); + + var selectedVal = $('#musician-list').val(); + if (selectedVal != '') { + selectedMusicians.push(selectedVal); + } return selectedMusicians; } @@ -205,53 +208,69 @@ */ function renderSession(sessionId) { var session = null; + // hack to prevent duplicate rows from being rendered when filtering + var sessionExists = false; var $tbGroup; if (invitationSessionGroup[sessionId] != null) { session = invitationSessionGroup[sessionId]; $tbGroup = $(CATEGORY.INVITATION.id); + + if ($("table#sessions-invitations tr[id='" + sessionId + "']").length > 0) { + sessionExists = true; + } } else if (friendSessionGroup[sessionId] != null) { session = friendSessionGroup[sessionId]; $tbGroup = $(CATEGORY.FRIEND.id); + + if ($("table#sessions-friends tr[id='" + sessionId + "']").length > 0) { + sessionExists = true; + } } else if (otherSessionGroup[sessionId] != null) { session = otherSessionGroup[sessionId]; $tbGroup = $(CATEGORY.OTHER.id); + + if ($("table#sessions-other tr[id='" + sessionId + "']").length > 0) { + sessionExists = true; + } } else { //alert('ERROR: No session with ID = ' + sessionId + ' found.'); return; } - var row = sessionList.renderSession(session, sessionLatency, $tbGroup, $('#template-session-row').html(), $('#template-musician-info').html(), - // populate the musician filter with musicians that haven't already been added - function(musicianArray) { - var template = $('#template-musician-filter').html(); - $.each(musicianArray, function(index, val) { - // check if this musician is already in the filter - if ( $('#musician-list-items input[value=' + val.id + ']').length == 0 ) { - var musicianOptionHtml = context.JK.fillTemplate(template, {value: val.id, label: val.name}); - $('#musician-list-items').append(musicianOptionHtml); - } + if (!sessionExists) { + var row = sessionList.renderSession(session, sessionLatency, $tbGroup, $('#template-session-row').html(), $('#template-musician-info').html(), + // populate the musician filter with musicians that haven't already been added + function(musicianArray) { + var template = $('#template-musician-option').html(); + $.each(musicianArray, function(index, val) { + // check if this musician is already in the filter + if ( $('#musician-list option[value=' + val.id + ']').length == 0 ) { + var musicianOptionHtml = context.JK.fillTemplate(template, {value: val.id, label: val.name}); + $('#musician-list').append(musicianOptionHtml); + } + }); }); - }); + } } // TODO: refactor this and GenreSelector into common code - function toggleMusicianBox() { - var boxHeight = $('#musician-list').css("height"); - // TODO: clean this up (check class name of arrow to determine current state) - if (boxHeight == "20px") { - $('#musician-list').css({height: "auto"}); - $('#musician-list-arrow').removeClass("arrow-down").addClass("arrow-up"); + // function toggleMusicianBox() { + // var boxHeight = $('#musician-list').css("height"); + // // TODO: clean this up (check class name of arrow to determine current state) + // if (boxHeight == "20px") { + // $('#musician-list').css({height: "auto"}); + // $('#musician-list-arrow').removeClass("arrow-down").addClass("arrow-up"); - } - else { - $('#musician-list').css({height: "20px"}); - $('#musician-list-arrow').removeClass("arrow-up").addClass("arrow-down"); - } - } + // } + // else { + // $('#musician-list').css({height: "20px"}); + // $('#musician-list-arrow').removeClass("arrow-up").addClass("arrow-down"); + // } + // } function afterShow(data) { clearResults(); @@ -264,6 +283,18 @@ $('table#sessions-friends').children(':not(:first-child)').remove(); $('table#sessions-other').children(':not(:first-child)').remove(); + // sessions = null; + // sessions = {}; + + // invitationSessionGroup = null; + // invitationSessionGroup = {}; + + // friendSessionGroup = null; + // friendSessionGroup = {}; + + // otherSessionGroup = null; + // otherSessionGroup = {}; + sessionCounts = [0, 0, 0]; } @@ -279,8 +310,8 @@ function events() { //$('#findSession-tableBody').on("click", '[action="delete"]', deleteSession); - $('#musician-list-header').on("click", toggleMusicianBox); - $('#musician-list-arrow').on("click", toggleMusicianBox); + // $('#musician-list-header').on("click", toggleMusicianBox); + // $('#musician-list-arrow').on("click", toggleMusicianBox); $('#session-keyword-srch').focus(function() { $(this).val(''); diff --git a/app/assets/javascripts/header.js b/app/assets/javascripts/header.js index 047cf2aed..e73902748 100644 --- a/app/assets/javascripts/header.js +++ b/app/assets/javascripts/header.js @@ -149,9 +149,16 @@ }).done(function(r) { userMe = r; updateAccountForms(); + updateHeader(); }).fail(app.ajaxError); } + function updateHeader() { + + $('#user').html(userMe.name); + $('#header-avatar').attr('src', userMe.photo_url); + } + function updateAccountForms() { var idTemplate = $('#template-identity-summary').html(); var idHtml = context.JK.fillTemplate(idTemplate, userMe); @@ -173,6 +180,7 @@ } this.initialize = function() { + events(); loadInstruments(); loadMe(); diff --git a/app/assets/stylesheets/client/createSession.css.scss b/app/assets/stylesheets/client/createSession.css.scss index 076b6fd91..33a850e27 100644 --- a/app/assets/stylesheets/client/createSession.css.scss +++ b/app/assets/stylesheets/client/createSession.css.scss @@ -9,6 +9,10 @@ width:145px; } +#find-session-genre select, #find-session-musician select { + width:145px; +} + .session-right { width:50%; float:right; diff --git a/app/views/api_users/index.rabl b/app/views/api_users/index.rabl index 3064a1366..8f9bbf9a7 100644 --- a/app/views/api_users/index.rabl +++ b/app/views/api_users/index.rabl @@ -1,4 +1,4 @@ collection @users # do not retrieve all child collections when showing a list of users -attributes :id, :first_name, :last_name, :city, :state, :country, :email, :online, :musician, :photo_url \ No newline at end of file +attributes :id, :first_name, :last_name, :name, :city, :state, :country, :email, :online, :musician, :photo_url \ No newline at end of file diff --git a/app/views/api_users/show.rabl b/app/views/api_users/show.rabl index 978bb6d8e..a4587db76 100644 --- a/app/views/api_users/show.rabl +++ b/app/views/api_users/show.rabl @@ -1,6 +1,6 @@ object @user -attributes :id, :first_name, :last_name, :city, :state, :country, :online, :photo_url, :musician, :gender, :birth_date, :internet_service_provider, :friend_count, :liker_count, :like_count, :band_like_count, :follower_count, :following_count, :band_following_count, :favorite_count, :recording_count, :session_count +attributes :id, :first_name, :last_name, :name, :city, :state, :country, :online, :photo_url, :musician, :gender, :birth_date, :internet_service_provider, :friend_count, :liker_count, :like_count, :band_like_count, :follower_count, :following_count, :band_following_count, :favorite_count, :recording_count, :session_count unless @user.friends.nil? || @user.friends.size == 0 child :friends => :friends do diff --git a/app/views/clients/_findSession.html.erb b/app/views/clients/_findSession.html.erb index 50c779de8..a44015f03 100644 --- a/app/views/clients/_findSession.html.erb +++ b/app/views/clients/_findSession.html.erb @@ -16,19 +16,23 @@
Filter Session List:
-
-
+
+ + +
-
+
<%= render "genreSelector" %>
@@ -104,7 +108,12 @@ - + + + + \ No newline at end of file diff --git a/app/views/clients/_header.html.erb b/app/views/clients/_header.html.erb index 8c27cc8f0..853657415 100644 --- a/app/views/clients/_header.html.erb +++ b/app/views/clients/_header.html.erb @@ -13,11 +13,11 @@
- <%= image_tag "header/avatar_jonathon.png", {:height => 246, :width => 246} %> +
-
Jonathon Wilson
+