Fix pagination for ajax views

This commit is contained in:
Georg Gadinger 2020-05-09 04:39:09 +02:00
parent adf5968ad0
commit 9b4c8027b8
10 changed files with 30 additions and 16 deletions

View File

@ -9,7 +9,7 @@ class GroupController < ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.js format.js { render layout: false }
end end
end end
end end

View File

@ -49,7 +49,7 @@ class InboxController < ApplicationController
@disabled = true if @inbox.empty? @disabled = true if @inbox.empty?
respond_to do |format| respond_to do |format|
format.html format.html
format.js format.js { render layout: false }
end end
end end
end end

View File

@ -9,7 +9,7 @@ class NotificationsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.js format.js { render layout: false }
end end
end end

View File

@ -8,7 +8,7 @@ class PublicController < ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.js format.js { render layout: false }
end end
end end
end end

View File

@ -7,7 +7,7 @@ class QuestionController < ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.js format.js { render layout: false }
end end
end end
end end

View File

@ -9,7 +9,7 @@ class StaticController < ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.js format.js { render layout: false }
end end
else else
return render 'static/front' return render 'static/front'

View File

@ -19,7 +19,7 @@ class UserController < ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.js format.js { render layout: false }
end end
end end
@ -78,7 +78,11 @@ class UserController < ApplicationController
@users_last_id = @users.map(&:id).min @users_last_id = @users.map(&:id).min
@more_data_available = !@user.cursored_followers(last_id: @users_last_id, size: 1).count.zero? @more_data_available = !@user.cursored_followers(last_id: @users_last_id, size: 1).count.zero?
@type = :friend @type = :friend
render 'show_follow'
respond_to do |format|
format.html { render "show_follow" }
format.js { render "show_follow", layout: false }
end
end end
def friends def friends
@ -88,7 +92,11 @@ class UserController < ApplicationController
@users_last_id = @users.map(&:id).min @users_last_id = @users.map(&:id).min
@more_data_available = !@user.cursored_friends(last_id: @users_last_id, size: 1).count.zero? @more_data_available = !@user.cursored_friends(last_id: @users_last_id, size: 1).count.zero?
@type = :friend @type = :friend
render 'show_follow'
respond_to do |format|
format.html { render "show_follow" }
format.js { render "show_follow", layout: false }
end
end end
def questions def questions
@ -97,6 +105,11 @@ class UserController < ApplicationController
@questions = @user.cursored_questions(author_is_anonymous: false, last_id: params[:last_id]) @questions = @user.cursored_questions(author_is_anonymous: false, last_id: params[:last_id])
@questions_last_id = @questions.map(&:id).min @questions_last_id = @questions.map(&:id).min
@more_data_available = !@user.cursored_questions(author_is_anonymous: false, last_id: @questions_last_id, size: 1).count.zero? @more_data_available = !@user.cursored_questions(author_is_anonymous: false, last_id: @questions_last_id, size: 1).count.zero?
respond_to do |format|
format.html
format.js { render layout: false }
end
end end
def data def data

View File

@ -15,6 +15,7 @@
.media .media
= render "notifications/type/#{notification.target_type.downcase}", notification: notification = render "notifications/type/#{notification.target_type.downcase}", notification: notification
- unless @notifications.count.zero?
= render 'shared/cursored_pagination_dummy', more_data_available: @more_data_available, last_id: @notifications_last_id, permitted_params: %i[type] = render 'shared/cursored_pagination_dummy', more_data_available: @more_data_available, last_id: @notifications_last_id, permitted_params: %i[type]
- if @more_data_available - if @more_data_available

View File

@ -1,6 +1,6 @@
$('#notifications').append('<% @notifications.each do |notification| $('#notifications').append('<% @notifications.each do |notification|
%><%= j render 'notifications/notification', notification: notification %><li class="list-group-item"><div class="media"><%= j render "notifications/type/#{notification.target_type.downcase}", notification: notification
%><% end %>'); %></div></li><% end %>');
<% if @more_data_available %> <% if @more_data_available %>
$('#pagination').html('<%= j render 'shared/cursored_pagination_dummy', more_data_available: @more_data_available, last_id: @notifications_last_id, permitted_params: %i[type] %>'); $('#pagination').html('<%= j render 'shared/cursored_pagination_dummy', more_data_available: @more_data_available, last_id: @notifications_last_id, permitted_params: %i[type] %>');
<% else %> <% else %>