From 1bfd3f653cda3328ce49f71d0d66107b9deeb4f5 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sat, 1 Nov 2014 23:03:20 -0400 Subject: [PATCH 1/4] VRFS-2297 create help bubbles / tool tips for all instrument and friends/followers/recordings/sessions icons throughout app --- web/app/assets/javascripts/findBand.js | 23 +++++++++++++++---- web/app/assets/javascripts/findMusician.js | 14 +++++++---- web/app/assets/javascripts/hoverBand.js | 2 +- web/app/assets/javascripts/hoverMusician.js | 2 +- web/app/assets/javascripts/utils.js | 6 ++--- web/app/views/clients/_bandProfile.html.erb | 8 +++---- web/app/views/clients/_bands.html.erb | 8 +++---- web/app/views/clients/_help.html.erb | 16 ++++++------- web/app/views/clients/_hoverBand.html.erb | 8 +++---- web/app/views/clients/_hoverFan.html.erb | 6 ++--- web/app/views/clients/_hoverMusician.html.erb | 10 ++++---- web/app/views/clients/_musicians.html.erb | 2 +- web/app/views/clients/_profile.html.erb | 6 ++--- .../views/users/_feed_music_session.html.haml | 2 +- .../users/_feed_music_session_ajax.html.haml | 2 +- web/app/views/users/_feed_recording.html.haml | 2 +- .../users/_feed_recording_ajax.html.haml | 2 +- 17 files changed, 68 insertions(+), 51 deletions(-) diff --git a/web/app/assets/javascripts/findBand.js b/web/app/assets/javascripts/findBand.js index 644df8a9d..fd3f1358d 100644 --- a/web/app/assets/javascripts/findBand.js +++ b/web/app/assets/javascripts/findBand.js @@ -10,6 +10,9 @@ var instrument_logo_map = context.JK.getInstrumentIconMap24(); var did_show_band_page = false; var page_num=1, page_count=0; + var helpBubble = context.JK.HelpBubbleHelper; + var $screen = $('#bands-screen'); + var $results = $screen.find('#band-filter-results'); function loadBands(queryString) { // squelch nulls and undefines @@ -91,15 +94,18 @@ players = ''; playerVals = {}; for (var jj=0, ilen=bb['players'].length; jj'; + player_instrs += ''; } playerVals = { @@ -143,11 +149,18 @@ band_action_template: band_actions }; - var band_row = context.JK.fillTemplate(mTemplate, bVals); - renderings += band_row; - } + var $rendering = $(context.JK.fillTemplate(mTemplate, bVals)) - $('#band-filter-results').append(renderings); + var $offsetParent = $results.closest('.content'); + var data = {entity_type: 'band'}; + + var options = {positions: ['top', 'bottom', 'right', 'left'], offsetParent: $offsetParent}; + context.JK.helpBubble($('.follower-count', $rendering), 'follower-count', data, options); + context.JK.helpBubble($('.recording-count', $rendering), 'recording-count', data, options); + context.JK.helpBubble($('.session-count', $rendering), 'session-count', data, options); + + $results.append($rendering); + } $('.search-m-follow').on('click', followBand); context.JK.bindHoverEvents(); diff --git a/web/app/assets/javascripts/findMusician.js b/web/app/assets/javascripts/findMusician.js index 4b50a84f0..8b0596154 100644 --- a/web/app/assets/javascripts/findMusician.js +++ b/web/app/assets/javascripts/findMusician.js @@ -196,10 +196,12 @@ } instr_logos = ''; for (var jj = 0, ilen = musician['instruments'].length; jj < ilen; jj++) { + var toolTip = ''; if (musician['instruments'][jj].instrument_id in instrument_logo_map) { instr = instrument_logo_map[musician['instruments'][jj].instrument_id].asset; + toolTip = musician['instruments'][jj].instrument_id; } - instr_logos += ''; + instr_logos += ''; } var actionVals = { profile_url: "/client#/profile/" + musician.id, @@ -238,12 +240,14 @@ var $rendering = $(context.JK.fillTemplate(mTemplate, mVals)) var $offsetParent = $results.closest('.content'); + var data = {entity_type: 'musician'}; var options = {positions: ['top', 'bottom', 'right', 'left'], offsetParent: $offsetParent}; + var scoreOptions = {offsetParent: $offsetParent}; - context.JK.helpBubble($('.follower-count', $rendering), 'musician-follower-count', {}, options); - context.JK.helpBubble($('.friend-count', $rendering), 'musician-friend-count', {}, options); - context.JK.helpBubble($('.recording-count', $rendering), 'musician-recording-count', {}, options); - context.JK.helpBubble($('.session-count', $rendering), 'musician-session-count', {}, options); + context.JK.helpBubble($('.follower-count', $rendering), 'follower-count', data, options); + context.JK.helpBubble($('.friend-count', $rendering), 'friend-count', data, options); + context.JK.helpBubble($('.recording-count', $rendering), 'recording-count', data, options); + context.JK.helpBubble($('.session-count', $rendering), 'session-count', data, options); helpBubble.scoreBreakdown($('.latency', $rendering), false, musician['full_score'], myAudioLatency, musician['audio_latency'], musician['score'], scoreOptions); $results.append($rendering); diff --git a/web/app/assets/javascripts/hoverBand.js b/web/app/assets/javascripts/hoverBand.js index 6a94a8937..e635be516 100644 --- a/web/app/assets/javascripts/hoverBand.js +++ b/web/app/assets/javascripts/hoverBand.js @@ -38,7 +38,7 @@ instrumentHtml = '
'; if (val.instruments) { // @FIXME: edge case for Test user that has no instruments? $.each(val.instruments, function(index, instrument) { - instrumentHtml += ' '; + instrumentHtml += ' '; }); } diff --git a/web/app/assets/javascripts/hoverMusician.js b/web/app/assets/javascripts/hoverMusician.js index 815cd2f8b..756c16869 100644 --- a/web/app/assets/javascripts/hoverMusician.js +++ b/web/app/assets/javascripts/hoverMusician.js @@ -35,7 +35,7 @@ // instruments var instrumentHtml = ''; $.each(response.instruments, function(index, val) { - instrumentHtml += '
'; + instrumentHtml += '
'; }); // followings diff --git a/web/app/assets/javascripts/utils.js b/web/app/assets/javascripts/utils.js index 993d2139c..5b0019cfa 100644 --- a/web/app/assets/javascripts/utils.js +++ b/web/app/assets/javascripts/utils.js @@ -110,10 +110,10 @@ */ context.JK.helpBubble = function ($element, templateName, data, options) { if (!data) { - data = {} + data = {}; } if(!options) { - options = {} + options = {}; } $element.on('remove', function() { @@ -123,7 +123,7 @@ var holder = null; if (context._.isFunction(templateName)) { holder = function wrapper() { - return context.JK.helpBubbleFunctionHelper.apply(this, [templateName]) + return context.JK.helpBubbleFunctionHelper.apply(this, [templateName]); } } else { diff --git a/web/app/views/clients/_bandProfile.html.erb b/web/app/views/clients/_bandProfile.html.erb index 057af0a55..b98ee672f 100644 --- a/web/app/views/clients/_bandProfile.html.erb +++ b/web/app/views/clients/_bandProfile.html.erb @@ -104,10 +104,10 @@
- {friend_count} - {follower_count} - {recording_count} - {session_count} + {friend_count} + {follower_count} + {recording_count} + {session_count}
PROFILE diff --git a/web/app/views/clients/_bands.html.erb b/web/app/views/clients/_bands.html.erb index 84c9c8e36..001d3ff1c 100644 --- a/web/app/views/clients/_bands.html.erb +++ b/web/app/views/clients/_bands.html.erb @@ -1,5 +1,5 @@ -<%= content_tag(:div, :layout => 'screen', 'layout-id' => 'bands', :class => "screen secondary") do -%> +<%= content_tag(:div, :layout => 'screen', 'layout-id' => 'bands', :class => "screen secondary", :id => "bands-screen") do -%> <%= content_tag(:div, :class => :content) do -%> <%= content_tag(:div, :class => 'content-head') do -%> <%= content_tag(:div, image_tag("content/icon_bands.png", {:height => 19, :width => 19}), :class => 'content-icon') %> @@ -46,9 +46,9 @@
- {follow_count} - {recording_count} - {session_count} + {follow_count} + {recording_count} + {session_count}
{band_action_template} diff --git a/web/app/views/clients/_help.html.erb b/web/app/views/clients/_help.html.erb index 405384d99..f857c3f08 100644 --- a/web/app/views/clients/_help.html.erb +++ b/web/app/views/clients/_help.html.erb @@ -42,20 +42,20 @@ To be a valid output audio device, it must have at least 2 output ports. - - - - @@ -57,9 +57,9 @@

{name}

{location}
{genres}


- {follower_count}     - {recording_count}     - {session_count} + {follower_count} + {recording_count} + {session_count}



diff --git a/web/app/views/clients/_hoverFan.html.erb b/web/app/views/clients/_hoverFan.html.erb index 41029b7ee..3fbb36cc4 100644 --- a/web/app/views/clients/_hoverFan.html.erb +++ b/web/app/views/clients/_hoverFan.html.erb @@ -36,7 +36,7 @@ } function adjustFanFollowingCount(value) { - $("#spnFollowCount", "#fan-hover").text(parseInt($("#spnFollowCount", "#fan-hover").text()) + value); + // $("#spnFollowCount", "#fan-hover").text(parseInt($("#spnFollowCount", "#fan-hover").text()) + value); } function sendFanFriendRequest(userId) { @@ -65,8 +65,8 @@

{name}

{location}

- {friend_count}     - {follower_count} + {friend_count} + {follower_count}


{biography}

diff --git a/web/app/views/clients/_hoverMusician.html.erb b/web/app/views/clients/_hoverMusician.html.erb index dd1994d6d..72ce71b1c 100644 --- a/web/app/views/clients/_hoverMusician.html.erb +++ b/web/app/views/clients/_hoverMusician.html.erb @@ -70,7 +70,7 @@ } function adjustMusicianFollowingCount(value) { - $("#spnFollowCount", "#musician-hover").html(parseInt($("#spnFollowCount", "#musician-hover").html()) + value); + // $(".follower-count", "#musician-hover").html(parseInt($("#spnFollowCount", "#musician-hover").html()) + value); } function sendMusicianFriendRequest(userId) { @@ -102,10 +102,10 @@ {location}

{instruments}
- {friend_count}     - {follower_count}     - {recording_count}     - {session_count} + {friend_count} + {follower_count} + {recording_count} + {session_count}


diff --git a/web/app/views/clients/_musicians.html.erb b/web/app/views/clients/_musicians.html.erb index cd626c8f0..c31f8648e 100644 --- a/web/app/views/clients/_musicians.html.erb +++ b/web/app/views/clients/_musicians.html.erb @@ -43,7 +43,7 @@
{friend_count} friends - {follow_count} follows + {follow_count} followers {recording_count} recordings {session_count} sessions
diff --git a/web/app/views/clients/_profile.html.erb b/web/app/views/clients/_profile.html.erb index 408eed849..74070c8fd 100644 --- a/web/app/views/clients/_profile.html.erb +++ b/web/app/views/clients/_profile.html.erb @@ -200,9 +200,9 @@
- {follower_count} - {recording_count} - {session_count} + {follower_count} + {recording_count} + {session_count}
PROFILE diff --git a/web/app/views/users/_feed_music_session.html.haml b/web/app/views/users/_feed_music_session.html.haml index b1286de9e..4b9b8109b 100644 --- a/web/app/views/users/_feed_music_session.html.haml +++ b/web/app/views/users/_feed_music_session.html.haml @@ -71,7 +71,7 @@ .nowrap - if user.total_instruments - user.total_instruments.split('|').uniq.each do |instrument_id| - %img.instrument-icon{'instrument-id' =>instrument_id, height:24, width:24} + %img.instrument-icon{'instrument-id' =>instrument_id, 'title' => instrument_id, height:24, width:24} - else %img.instrument-icon{'instrument-id' =>'default', height:24, width:24} diff --git a/web/app/views/users/_feed_music_session_ajax.html.haml b/web/app/views/users/_feed_music_session_ajax.html.haml index 09ca8f7f7..9553b2ed8 100644 --- a/web/app/views/users/_feed_music_session_ajax.html.haml +++ b/web/app/views/users/_feed_music_session_ajax.html.haml @@ -76,7 +76,7 @@ .nowrap = '{% if(user.instruments) { %}' = '{% _.each(_.uniq(user.instruments), function(instrument_id) { %}' - %img.instrument-icon{'instrument-id' =>'{{instrument_id}}', height:24, width:24} + %img.instrument-icon{'instrument-id' =>'{{instrument_id}}', 'title' =>'{{instrument_id}}', height:24, width:24} = '{% }) %}' = '{% } else { %}' %img.instrument-icon{'instrument-id' =>'default', height:24, width:24} diff --git a/web/app/views/users/_feed_recording.html.haml b/web/app/views/users/_feed_recording.html.haml index 4753b7af2..dc73db1b7 100644 --- a/web/app/views/users/_feed_recording.html.haml +++ b/web/app/views/users/_feed_recording.html.haml @@ -88,7 +88,7 @@ %td .nowrap - track.instrument_ids.uniq.each do |instrument_id| - %img.instrument-icon{'instrument-id' => instrument_id, height:24, width:24} + %img.instrument-icon{'instrument-id' => instrument_id, 'title' => instrument_id, height:24, width:24} %br{:clear => "all"}/ %br/ diff --git a/web/app/views/users/_feed_recording_ajax.html.haml b/web/app/views/users/_feed_recording_ajax.html.haml index 11438e92f..351901f58 100644 --- a/web/app/views/users/_feed_recording_ajax.html.haml +++ b/web/app/views/users/_feed_recording_ajax.html.haml @@ -96,7 +96,7 @@ .nowrap = '{% if(track.instrument_ids) { %}' = '{% _.each(_.uniq(track.instrument_ids), function(instrument_id) { %}' - %img.instrument-icon{'instrument-id' =>'{{instrument_id}}', height:24, width:24} + %img.instrument-icon{'instrument-id' =>'{{instrument_id}}','title' =>'{{instrument_id}}', height:24, width:24} = '{% }) %}' = '{% } else { %}' %img.instrument-icon{'instrument-id' =>'default', height:24, width:24} From bdb57e6d54812975b4098c92e756fd4f307e889f Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sat, 1 Nov 2014 23:35:17 -0400 Subject: [PATCH 2/4] VRFS-2297 added tool tips to session and recording hover bubbles --- web/app/views/clients/_hoverBand.html.erb | 8 ++++---- web/app/views/clients/_hoverFan.html.erb | 6 +++--- web/app/views/clients/_hoverMusician.html.erb | 10 +++++----- web/app/views/clients/_hoverRecording.html.erb | 6 +++--- web/app/views/clients/_hoverSession.html.erb | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/web/app/views/clients/_hoverBand.html.erb b/web/app/views/clients/_hoverBand.html.erb index bced2bc54..6be6ddda9 100644 --- a/web/app/views/clients/_hoverBand.html.erb +++ b/web/app/views/clients/_hoverBand.html.erb @@ -46,7 +46,7 @@ } function adjustBandFollowingCount(value) { - // $("#spnFollowCount", "#band-hover").text(parseInt($("#spnFollowCount", "#band-hover").text()) + value); + $("#spnFollowCount", "#band-hover").text(parseInt($("#spnFollowCount", "#band-hover").text()) + value); } @@ -57,9 +57,9 @@

{name}

{location}
{genres}


- {follower_count} - {recording_count} - {session_count} + {follower_count} + {recording_count} + title="sessions">{session_count}



diff --git a/web/app/views/clients/_hoverFan.html.erb b/web/app/views/clients/_hoverFan.html.erb index 3fbb36cc4..6d4606675 100644 --- a/web/app/views/clients/_hoverFan.html.erb +++ b/web/app/views/clients/_hoverFan.html.erb @@ -36,7 +36,7 @@ } function adjustFanFollowingCount(value) { - // $("#spnFollowCount", "#fan-hover").text(parseInt($("#spnFollowCount", "#fan-hover").text()) + value); + $("#spnFollowCount", "#fan-hover").text(parseInt($("#spnFollowCount", "#fan-hover").text()) + value); } function sendFanFriendRequest(userId) { @@ -65,8 +65,8 @@

{name}

{location}

- {friend_count} - {follower_count} + {friend_count} + {follower_count}


{biography}

diff --git a/web/app/views/clients/_hoverMusician.html.erb b/web/app/views/clients/_hoverMusician.html.erb index 72ce71b1c..c92db5704 100644 --- a/web/app/views/clients/_hoverMusician.html.erb +++ b/web/app/views/clients/_hoverMusician.html.erb @@ -70,7 +70,7 @@ } function adjustMusicianFollowingCount(value) { - // $(".follower-count", "#musician-hover").html(parseInt($("#spnFollowCount", "#musician-hover").html()) + value); + $("#spnFollowCount", "#musician-hover").html(parseInt($("#spnFollowCount", "#musician-hover").html()) + value); } function sendMusicianFriendRequest(userId) { @@ -102,10 +102,10 @@ {location}

{instruments}
- {friend_count} - {follower_count} - {recording_count} - {session_count} + {friend_count} + {follower_count} + {recording_count} + {session_count}


diff --git a/web/app/views/clients/_hoverRecording.html.erb b/web/app/views/clients/_hoverRecording.html.erb index 214cf3df6..5e9dbed9a 100644 --- a/web/app/views/clients/_hoverRecording.html.erb +++ b/web/app/views/clients/_hoverRecording.html.erb @@ -22,9 +22,9 @@
{description}
- {play_count}      - {comment_count}      - {like_count} + {play_count} > + {comment_count} + {like_count}


diff --git a/web/app/views/clients/_hoverSession.html.erb b/web/app/views/clients/_hoverSession.html.erb index c9081737f..a1850dd58 100644 --- a/web/app/views/clients/_hoverSession.html.erb +++ b/web/app/views/clients/_hoverSession.html.erb @@ -23,8 +23,8 @@
{name}
{description}
- {comment_count}     - {like_count} + {comment_count} + {like_count}

MUSICIANS:

From ba80b257271b64a4d1ac21883e8caacfcef032a4 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sat, 1 Nov 2014 23:56:52 -0400 Subject: [PATCH 3/4] VRFS-2297 added tool tip to band tab of musician profile, couple of other bug fixes --- web/app/assets/javascripts/profile.js | 7 +++++-- web/app/views/clients/_hoverRecording.html.erb | 2 +- web/app/views/users/_feed_recording_ajax.html.haml | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/web/app/assets/javascripts/profile.js b/web/app/assets/javascripts/profile.js index 01816475c..a7b27526b 100644 --- a/web/app/assets/javascripts/profile.js +++ b/web/app/assets/javascripts/profile.js @@ -619,10 +619,12 @@ for (var j = 0; j < musician.instruments.length; j++) { var instrument = musician.instruments[j]; var inst = '/assets/content/icon_instrument_default24.png'; + var toolTip = ''; if (instrument.instrument_id in instrument_logo_map) { inst = instrument_logo_map[instrument.instrument_id].asset; + toolTip = instrument.instrument_id; } - instrumentLogoHtml += ' '; + instrumentLogoHtml += ' '; } } // this template is in _findSession.html.erb @@ -632,7 +634,8 @@ avatar_url: context.JK.resolveAvatarUrl(musician.photo_url), profile_url: "/client#/profile/" + musician.id, musician_name: musician.name, - instruments: instrumentLogoHtml + instruments: instrumentLogoHtml, + more_link: '' }); } } diff --git a/web/app/views/clients/_hoverRecording.html.erb b/web/app/views/clients/_hoverRecording.html.erb index 5e9dbed9a..fc8054056 100644 --- a/web/app/views/clients/_hoverRecording.html.erb +++ b/web/app/views/clients/_hoverRecording.html.erb @@ -22,7 +22,7 @@
{description}
- {play_count} > + {play_count} {comment_count} {like_count}
diff --git a/web/app/views/users/_feed_recording_ajax.html.haml b/web/app/views/users/_feed_recording_ajax.html.haml index 351901f58..4040bb9d8 100644 --- a/web/app/views/users/_feed_recording_ajax.html.haml +++ b/web/app/views/users/_feed_recording_ajax.html.haml @@ -96,7 +96,7 @@ .nowrap = '{% if(track.instrument_ids) { %}' = '{% _.each(_.uniq(track.instrument_ids), function(instrument_id) { %}' - %img.instrument-icon{'instrument-id' =>'{{instrument_id}}','title' =>'{{instrument_id}}', height:24, width:24} + %img.instrument-icon{'instrument-id' =>'{{instrument_id}}', 'title' =>'{{instrument_id}}', height:24, width:24} = '{% }) %}' = '{% } else { %}' %img.instrument-icon{'instrument-id' =>'default', height:24, width:24} From eb56be97dd3f78b66c6ce9d86fc941dd4a2dd8d5 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 2 Nov 2014 12:57:43 -0500 Subject: [PATCH 4/4] VRFS-2427 fix sorting / paging issue on Feeds screen --- ruby/lib/jam_ruby/models/feed.rb | 44 ++++--- ruby/spec/jam_ruby/models/feed_spec.rb | 124 ++++++++++---------- web/app/assets/javascripts/feedHelper.js | 15 ++- web/app/controllers/api_feeds_controller.rb | 4 +- web/app/views/api_feeds/index.rabl | 2 +- 5 files changed, 96 insertions(+), 93 deletions(-) diff --git a/ruby/lib/jam_ruby/models/feed.rb b/ruby/lib/jam_ruby/models/feed.rb index c2448e511..f61c949b6 100644 --- a/ruby/lib/jam_ruby/models/feed.rb +++ b/ruby/lib/jam_ruby/models/feed.rb @@ -10,6 +10,7 @@ module JamRuby TYPE_FILTERS = ['music_session', 'recording', 'all'] def self.index(user, params = {}) + limit = params[:limit] limit ||= 20 limit = limit.to_i @@ -19,13 +20,13 @@ module JamRuby sort ||= 'date' raise "not valid sort #{sort}" unless SORT_TYPES.include?(sort) - start = params[:start].presence - if sort == 'date' - start ||= FIXNUM_MAX - else - start ||= 0 - end - start = start.to_i + # start = params[:start].presence + # if sort == 'date' + # start ||= FIXNUM_MAX + # else + # start ||= 0 + # end + # start = start.to_i time_range = params[:time_range] time_range ||= 'all' @@ -46,13 +47,13 @@ module JamRuby # handle sort if sort == 'date' - query = query.where("feeds.id < #{start}") + # query = query.where("feeds.id < #{start}") query = query.order('feeds.active DESC, feeds.id DESC') elsif sort == 'plays' - query = query.offset(start) + # query = query.offset(start) query = query.order("feeds.active DESC, COALESCE(recordings.play_count, music_sessions.play_count) DESC") elsif sort == 'likes' - query = query.offset(start) + # query = query.offset(start) query = query.order("feeds.active DESC, COALESCE(recordings.like_count, music_sessions.like_count) DESC") else raise "sort not implemented: #{sort}" @@ -73,7 +74,6 @@ module JamRuby if target_user - query = query.joins("LEFT OUTER JOIN claimed_recordings ON recordings.id = claimed_recordings.recording_id AND claimed_recordings.discarded = FALSE AND (claimed_recordings.user_id = '#{target_user}' OR (recordings.band_id IN (SELECT band_id FROM bands_musicians where user_id='#{target_user}')))") query = query.joins("LEFT OUTER JOIN music_sessions_user_history ON music_sessions.id = music_sessions_user_history.music_session_id AND music_sessions_user_history.user_id = '#{target_user}'") query = query.group("feeds.id, feeds.recording_id, feeds.music_session_id, feeds.created_at, feeds.updated_at, recordings.id, music_sessions.id") @@ -110,17 +110,19 @@ module JamRuby query = query.where('music_sessions.id is NULL OR music_sessions_user_history.id IS NOT NULL') end + current_page = params[:next_page].nil? ? 1 : params[:next_page].to_i + next_page = current_page + 1 + + # will_paginate gem + query = query.paginate(:page => current_page, :per_page => limit) + if params[:hash] if query.length == 0 - { query:query, next: nil} + { query: query, next_page: nil} elsif query.length < limit - { query:query, next: nil} + { query: query, next_page: nil} else - if sort == 'date' - { query:query, next: query.last.id} - else - { query:query, next: start + limit} - end + { query: query, next_page: next_page } end else if query.length == 0 @@ -128,11 +130,7 @@ module JamRuby elsif query.length < limit [query, nil] else - if sort == 'date' - [query, query.last.id] - else - [query, start + limit] - end + [query, next_page] end end end diff --git a/ruby/spec/jam_ruby/models/feed_spec.rb b/ruby/spec/jam_ruby/models/feed_spec.rb index f63d03116..16ae1b73a 100644 --- a/ruby/spec/jam_ruby/models/feed_spec.rb +++ b/ruby/spec/jam_ruby/models/feed_spec.rb @@ -9,7 +9,7 @@ describe Feed do let (:band) { FactoryGirl.create(:band) } it "no result" do - feeds, start = Feed.index(user1) + feeds, next_page = Feed.index(user1) feeds.length.should == 0 end @@ -17,7 +17,7 @@ describe Feed do claimed_recording = FactoryGirl.create(:claimed_recording) MusicSessionUserHistory.delete_all # the factory makes a music_session while making the recording/claimed_recording MusicSession.delete_all # the factory makes a music_session while making the recording/claimed_recording - feeds, start = Feed.index(user1) + feeds, next_page = Feed.index(user1) feeds.length.should == 1 feeds[0].recording == claimed_recording.recording end @@ -33,13 +33,13 @@ describe Feed do # verify the mess above only made one recording Recording.count.should == 1 - feeds, start = Feed.index(user1) + feeds, next_page = Feed.index(user1) feeds.length.should == 1 end it "one music session" do music_session = FactoryGirl.create(:active_music_session) - feeds, start = Feed.index(user1) + feeds, next_page = Feed.index(user1) feeds.length.should == 1 feeds[0].music_session == music_session.music_session end @@ -49,7 +49,7 @@ describe Feed do MusicSessionUserHistory.delete_all # the factory makes a music_session while making the recording/claimed_recording MusicSession.delete_all - feeds, start = Feed.index(user1) + feeds, next_page = Feed.index(user1) feeds.length.should == 0 end @@ -57,7 +57,7 @@ describe Feed do it "sorts by active flag / index (date) DESC" do claimed_recording = FactoryGirl.create(:claimed_recording) - feeds, start = Feed.index(user1) + feeds, next_page = Feed.index(user1) feeds.length.should == 2 feeds[1].recording.should == claimed_recording.recording feeds[0].music_session.should == claimed_recording.recording.music_session.music_session @@ -69,13 +69,13 @@ describe Feed do FactoryGirl.create(:playable_play, playable: claimed_recording1.recording, claimed_recording: claimed_recording1, user:claimed_recording1.user) - feeds, start = Feed.index(user1, :sort => 'plays') + feeds, next_page = Feed.index(user1, :sort => 'plays') feeds.length.should == 4 FactoryGirl.create(:playable_play, playable: claimed_recording2.recording, claimed_recording: claimed_recording2, user:claimed_recording1.user) FactoryGirl.create(:playable_play, playable: claimed_recording2.recording, claimed_recording: claimed_recording2, user:claimed_recording2.user) - feeds, start = Feed.index(user1, :sort => 'plays') + feeds, next_page = Feed.index(user1, :sort => 'plays') feeds.length.should == 4 feeds[2].recording.should == claimed_recording2.recording feeds[3].recording.should == claimed_recording1.recording @@ -85,7 +85,7 @@ describe Feed do FactoryGirl.create(:playable_play, playable: claimed_recording1.recording.music_session.music_session, user: user3) - feeds, start = Feed.index(user1, :sort => 'plays') + feeds, next_page = Feed.index(user1, :sort => 'plays') feeds.length.should == 4 feeds[0].music_session.should == claimed_recording1.recording.music_session.music_session feeds[2].recording.should == claimed_recording2.recording @@ -98,13 +98,13 @@ describe Feed do FactoryGirl.create(:recording_like, recording: claimed_recording1.recording, claimed_recording: claimed_recording1, user:claimed_recording1.user) - feeds, start = Feed.index(user1, :sort => 'likes') + feeds, next_page = Feed.index(user1, :sort => 'likes') feeds.length.should == 4 FactoryGirl.create(:recording_like, recording: claimed_recording2.recording, claimed_recording: claimed_recording2, user:claimed_recording1.user) FactoryGirl.create(:recording_like, recording: claimed_recording2.recording, claimed_recording: claimed_recording2, user:claimed_recording2.user) - feeds, start = Feed.index(user1, :sort => 'likes') + feeds, next_page = Feed.index(user1, :sort => 'likes') feeds.length.should == 4 feeds = feeds.where("feeds.music_session_id is null") feeds[0].recording.should == claimed_recording2.recording @@ -114,7 +114,7 @@ describe Feed do FactoryGirl.create(:music_session_like, music_session: claimed_recording1.recording.music_session.music_session, user: user2) FactoryGirl.create(:music_session_like, music_session: claimed_recording1.recording.music_session.music_session, user: user3) - feeds, start = Feed.index(user1, :sort => 'likes') + feeds, next_page = Feed.index(user1, :sort => 'likes') feeds.length.should == 4 feeds[0].music_session.should == claimed_recording1.recording.music_session.music_session feeds[2].recording.should == claimed_recording2.recording @@ -127,7 +127,7 @@ describe Feed do # creates both recording and history record in feed claimed_recording1 = FactoryGirl.create(:claimed_recording) - feeds, start = Feed.index(user1, :type => 'music_session') + feeds, next_page = Feed.index(user1, :type => 'music_session') feeds.length.should == 1 feeds[0].music_session == claimed_recording1.recording.music_session.music_session end @@ -136,7 +136,7 @@ describe Feed do # creates both recording and history record in feed claimed_recording1 = FactoryGirl.create(:claimed_recording) - feeds, start = Feed.index(user1, :type => 'music_session') + feeds, next_page = Feed.index(user1, :type => 'music_session') feeds.length.should == 1 feeds[0].music_session == claimed_recording1.recording.music_session.music_session end @@ -151,7 +151,7 @@ describe Feed do claimed_recording1.recording.feed.created_at = 32.days.ago claimed_recording1.recording.feed.save! - feeds, start = Feed.index(user1, :type => 'recording', time_range: 'month') + feeds, next_page = Feed.index(user1, :type => 'recording', time_range: 'month') feeds.length.should == 0 end @@ -163,7 +163,7 @@ describe Feed do claimed_recording1.recording.feed.created_at = 48.hours.ago claimed_recording1.recording.feed.save! - feeds, start = Feed.index(user1, :type => 'recording', time_range: 'today') + feeds, next_page = Feed.index(user1, :type => 'recording', time_range: 'today') feeds.length.should == 0 end @@ -175,7 +175,7 @@ describe Feed do claimed_recording1.recording.feed.created_at = 8.days.ago claimed_recording1.recording.feed.save! - feeds, start = Feed.index(user1, :type => 'recording', time_range: 'week') + feeds, next_page = Feed.index(user1, :type => 'recording', time_range: 'week') feeds.length.should == 0 end @@ -187,7 +187,7 @@ describe Feed do claimed_recording1.recording.feed.created_at = 700.days.ago claimed_recording1.recording.feed.save! - feeds, start = Feed.index(user1, :type => 'recording', time_range: 'all') + feeds, next_page = Feed.index(user1, :type => 'recording', time_range: 'all') feeds.length.should == 1 end end @@ -200,19 +200,21 @@ describe Feed do ams.before_destroy options = {limit: 1} - feeds, start = Feed.index(user1, options) + feeds, next_page = Feed.index(user1, options) feeds.length.should == 1 feeds[0].recording.should == claimed_recording.recording + next_page.should == 2 - options[:start] = start - feeds, start = Feed.index(user1, options) + options[:next_page] = next_page + feeds, next_page = Feed.index(user1, options) feeds.length.should == 1 feeds[0].music_session.should == claimed_recording.recording.music_session.music_session + next_page.should == 3 - options[:start] = start - feeds, start = Feed.index(user1, options) + options[:next_page] = next_page + feeds, next_page = Feed.index(user1, options) feeds.length.should == 0 - start.should be_nil + next_page.should be_nil end it "supports likes pagination" do @@ -221,19 +223,21 @@ describe Feed do FactoryGirl.create(:music_session_like, music_session: claimed_recording1.recording.music_session.music_session, user: user1) options = {limit: 1, sort: 'likes'} - feeds, start = Feed.index(user1, options) + feeds, next_page = Feed.index(user1, options) feeds.length.should == 1 feeds[0].music_session.should == claimed_recording1.recording.music_session.music_session + next_page.should == 2 - options[:start] = start - feeds, start = Feed.index(user1, options) + options[:next_page] = next_page + feeds, next_page = Feed.index(user1, options) feeds.length.should == 1 feeds[0].recording.should == claimed_recording1.recording + next_page.should == 3 - options[:start] = start - feeds, start = Feed.index(user1, options) + options[:next_page] = next_page + feeds, next_page = Feed.index(user1, options) feeds.length.should == 0 - start.should be_nil + next_page.should be_nil end it "supports plays pagination" do @@ -242,19 +246,21 @@ describe Feed do FactoryGirl.create(:playable_play, playable: claimed_recording1.recording.music_session.music_session, user: user1) options = {limit: 1, sort: 'plays'} - feeds, start = Feed.index(user1, options) + feeds, next_page = Feed.index(user1, options) feeds.length.should == 1 feeds[0].music_session.should == claimed_recording1.recording.music_session.music_session + next_page.should == 2 - options[:start] = start - feeds, start = Feed.index(user1, options) + options[:next_page] = next_page + feeds, next_page = Feed.index(user1, options) feeds.length.should == 1 feeds[0].recording.should == claimed_recording1.recording + next_page.should == 3 - options[:start] = start - feeds, start = Feed.index(user1, options) + options[:next_page] = next_page + feeds, next_page = Feed.index(user1, options) feeds.length.should == 0 - start.should be_nil + next_page.should be_nil end end @@ -264,13 +270,13 @@ describe Feed do claimed_recording1.is_public = false claimed_recording1.save! - feeds, start = Feed.index(claimed_recording1.user) + feeds, next_page = Feed.index(claimed_recording1.user) feeds.length.should == 1 claimed_recording1.recording.music_session.music_session.fan_access = false claimed_recording1.recording.music_session.music_session.save! - feeds, start = Feed.index(claimed_recording1.user) + feeds, next_page = Feed.index(claimed_recording1.user) feeds.length.should == 1 end end @@ -287,7 +293,7 @@ describe Feed do claimed_recording1.recording.save! claimed_recording1.save! - feeds, start = Feed.index(user1, band: band.id) + feeds, next_page = Feed.index(user1, band: band.id) feeds.length.should == 0 end @@ -297,11 +303,11 @@ describe Feed do music_session = FactoryGirl.create(:active_music_session, band: band) music_session.music_session.fan_access.should be_true - feeds, start = Feed.index(user1, band: band.id) + feeds, next_page = Feed.index(user1, band: band.id) feeds.length.should == 1 feeds[0].music_session.should == music_session.music_session - feeds, start = Feed.index(user2, band: band.id) + feeds, next_page = Feed.index(user2, band: band.id) feeds.length.should == 1 feeds[0].music_session.should == music_session.music_session end @@ -312,13 +318,13 @@ describe Feed do music_session = FactoryGirl.create(:active_music_session, band: band, fan_access: false) music_session.music_session.fan_access.should be_false - feeds, start = Feed.index(user1, band: band.id) + feeds, next_page = Feed.index(user1, band: band.id) feeds.length.should == 1 feeds[0].music_session.should == music_session.music_session feeds[0].music_session.fan_access.should be_false - feeds, start = Feed.index(user2, band: band.id) + feeds, next_page = Feed.index(user2, band: band.id) feeds.length.should == 1 end @@ -329,11 +335,11 @@ describe Feed do claimed_recording1.recording.save! claimed_recording1.save! - feeds, start = Feed.index(claimed_recording1.user, band: band.id) + feeds, next_page = Feed.index(claimed_recording1.user, band: band.id) feeds.length.should == 1 feeds[0].recording.should == claimed_recording1.recording - feeds, start = Feed.index(user1, band: band.id) + feeds, next_page = Feed.index(user1, band: band.id) feeds.length.should == 1 feeds[0].recording.should == claimed_recording1.recording end @@ -348,11 +354,11 @@ describe Feed do claimed_recording1.user.bands << band claimed_recording1.user.save! - feeds, start = Feed.index(claimed_recording1.user, band: band.id) + feeds, next_page = Feed.index(claimed_recording1.user, band: band.id) feeds.length.should == 1 feeds[0].recording.should == claimed_recording1.recording - feeds, start = Feed.index(user1, band: band.id) + feeds, next_page = Feed.index(user1, band: band.id) feeds.length.should == 1 end end @@ -366,7 +372,7 @@ describe Feed do claimed_recording1.is_public = true claimed_recording1.save! - feeds, start = Feed.index(user1, user: user1.id) + feeds, next_page = Feed.index(user1, user: user1.id) feeds.length.should == 0 end @@ -374,11 +380,11 @@ describe Feed do music_session = FactoryGirl.create(:active_music_session) FactoryGirl.create(:music_session_user_history, :history => music_session.music_session, :user => user1) - feeds, start = Feed.index(user1, user: user1.id) + feeds, next_page = Feed.index(user1, user: user1.id) feeds.length.should == 1 feeds[0].music_session.should == music_session.music_session - feeds, start = Feed.index(user2, user: user1.id) + feeds, next_page = Feed.index(user2, user: user1.id) feeds.length.should == 1 feeds[0].music_session.should == music_session.music_session end @@ -389,13 +395,13 @@ describe Feed do music_session.music_session.fan_access.should be_false FactoryGirl.create(:music_session_user_history, :history => music_session.music_session, :user => user1) - feeds, start = Feed.index(user1, user: user1.id) + feeds, next_page = Feed.index(user1, user: user1.id) feeds.length.should == 1 feeds[0].music_session.should == music_session.music_session feeds[0].music_session.fan_access.should be_false - feeds, start = Feed.index(user2, user: user1.id) + feeds, next_page = Feed.index(user2, user: user1.id) feeds.length.should == 1 end @@ -404,11 +410,11 @@ describe Feed do claimed_recording1.is_public = true claimed_recording1.save! - feeds, start = Feed.index(claimed_recording1.user, user: claimed_recording1.user.id) + feeds, next_page = Feed.index(claimed_recording1.user, user: claimed_recording1.user.id) feeds.length.should == 1 feeds[0].recording.should == claimed_recording1.recording - feeds, start = Feed.index(user1, user: claimed_recording1.user.id) + feeds, next_page = Feed.index(user1, user: claimed_recording1.user.id) feeds.length.should == 1 feeds[0].recording.should == claimed_recording1.recording end @@ -418,11 +424,11 @@ describe Feed do claimed_recording1.is_public = false claimed_recording1.save! - feeds, start = Feed.index(claimed_recording1.user, user: claimed_recording1.user.id) + feeds, next_page = Feed.index(claimed_recording1.user, user: claimed_recording1.user.id) feeds.length.should == 1 feeds[0].recording.should == claimed_recording1.recording - feeds, start = Feed.index(user1, user: claimed_recording1.user.id) + feeds, next_page = Feed.index(user1, user: claimed_recording1.user.id) feeds.length.should == 1 end @@ -438,7 +444,7 @@ describe Feed do claimed_recording1.recording.save! claimed_recording1.save! - feeds, start = Feed.index(user1, user: user1.id) + feeds, next_page = Feed.index(user1, user: user1.id) feeds.length.should == 1 feeds[0].recording.should == claimed_recording1 .recording @@ -446,14 +452,14 @@ describe Feed do claimed_recording1.is_public = false claimed_recording1.save! - feeds, start = Feed.index(user1, user: user1.id) + feeds, next_page = Feed.index(user1, user: user1.id) feeds.length.should == 1 feeds[0].recording.should == claimed_recording1 .recording # take user1 out of the band; shouldn't be able to see it user1.bands.delete_all - feeds, start = Feed.index(user1, user: user1.id) + feeds, next_page = Feed.index(user1, user: user1.id) feeds.length.should == 0 end end diff --git a/web/app/assets/javascripts/feedHelper.js b/web/app/assets/javascripts/feedHelper.js index 01a4740e0..74dfae892 100644 --- a/web/app/assets/javascripts/feedHelper.js +++ b/web/app/assets/javascripts/feedHelper.js @@ -13,7 +13,6 @@ var userId = null; var currentFeedPage = 0; var feedBatchSize = 10; - var $next = null; var $screen = null; var $scroller = null; var $content = null; @@ -21,15 +20,15 @@ var $refresh = null; var $sortFeedBy = null; var $includeDate = null; - var next = null; + var nextPage = null; var $includeType = null; var didLoadAllFeeds = false, isLoading = false; function defaultQuery() { var query = { limit: feedBatchSize }; - if(next) { - query.since = next; + if(nextPage) { + query.next_page = nextPage; } if(userId) { query.user = userId; @@ -54,15 +53,15 @@ currentFeedPage = 0; $content.empty(); // TODO: do we need to delete audio elements? $noMoreFeeds.hide(); - next = null; + nextPage = null; } function handleFeedResponse(response) { - next = response.next; + nextPage = response.next_page; renderFeeds(response); - if(response.next == null) { - didLoadAllFeeds = true; + if(nextPage == null) { + didLoadAllFeeds = true; // if we less results than asked for, end searching logger.debug("end of feeds") diff --git a/web/app/controllers/api_feeds_controller.rb b/web/app/controllers/api_feeds_controller.rb index b2e2c08cd..bb5b140b5 100644 --- a/web/app/controllers/api_feeds_controller.rb +++ b/web/app/controllers/api_feeds_controller.rb @@ -4,7 +4,7 @@ class ApiFeedsController < ApiController def index data = Feed.index(current_user, - start: params[:since], + next_page: params[:next_page], limit: params[:limit], sort: params[:sort], time_range: params[:time_range], @@ -15,7 +15,7 @@ class ApiFeedsController < ApiController @feeds = data[:query] - @next = data[:next] + @next = data[:next_page] render "api_feeds/index", :layout => nil end end \ No newline at end of file diff --git a/web/app/views/api_feeds/index.rabl b/web/app/views/api_feeds/index.rabl index 5b7b8d9c3..3a486f387 100644 --- a/web/app/views/api_feeds/index.rabl +++ b/web/app/views/api_feeds/index.rabl @@ -1,4 +1,4 @@ -node :next do |page| +node :next_page do |page| @next end