From edddaab122948c4af6a27ba690bdfe1267ff6b07 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 12 Aug 2024 22:38:05 +0100 Subject: [PATCH] Use turbo for pagination --- app/controllers/diary_comments_controller.rb | 2 + app/controllers/diary_entries_controller.rb | 2 + app/controllers/traces_controller.rb | 2 + app/controllers/user_blocks_controller.rb | 15 ++++++ app/controllers/users_controller.rb | 2 + app/views/diary_comments/_page.html.erb | 26 ++++++++++ app/views/diary_comments/index.html.erb | 26 +--------- app/views/diary_entries/_page.html.erb | 11 ++++ app/views/diary_entries/index.html.erb | 12 +---- app/views/shared/_pagination.html.erb | 4 +- app/views/traces/_page.html.erb | 19 +++++++ app/views/traces/index.html.erb | 18 +------ app/views/user_blocks/_block.html.erb | 6 +-- app/views/user_blocks/_blocks.html.erb | 54 ++++++++++---------- app/views/user_blocks/blocks_by.html.erb | 2 +- app/views/user_blocks/blocks_on.html.erb | 2 +- app/views/user_blocks/index.html.erb | 2 +- app/views/users/_page.html.erb | 50 ++++++++++++++++++ app/views/users/index.html.erb | 49 +----------------- config/locales/en.yml | 15 +++--- 20 files changed, 179 insertions(+), 140 deletions(-) create mode 100644 app/views/diary_comments/_page.html.erb create mode 100644 app/views/diary_entries/_page.html.erb create mode 100644 app/views/traces/_page.html.erb create mode 100644 app/views/users/_page.html.erb diff --git a/app/controllers/diary_comments_controller.rb b/app/controllers/diary_comments_controller.rb index 35dbbb559..f6597cf4c 100644 --- a/app/controllers/diary_comments_controller.rb +++ b/app/controllers/diary_comments_controller.rb @@ -24,6 +24,8 @@ class DiaryCommentsController < ApplicationController @params = params.permit(:display_name, :before, :after) @comments, @newer_comments_id, @older_comments_id = get_page_items(comments, :includes => [:user]) + + render :partial => "page" if turbo_frame_request_id == "pagination" end def create diff --git a/app/controllers/diary_entries_controller.rb b/app/controllers/diary_entries_controller.rb index dd7efc7ca..ff6dfc826 100644 --- a/app/controllers/diary_entries_controller.rb +++ b/app/controllers/diary_entries_controller.rb @@ -60,6 +60,8 @@ class DiaryEntriesController < ApplicationController @params = params.permit(:display_name, :friends, :nearby, :language) @entries, @newer_entries_id, @older_entries_id = get_page_items(entries, :includes => [:user, :language]) + + render :partial => "page" if turbo_frame_request_id == "pagination" end def show diff --git a/app/controllers/traces_controller.rb b/app/controllers/traces_controller.rb index 5bee44886..02b553d0a 100644 --- a/app/controllers/traces_controller.rb +++ b/app/controllers/traces_controller.rb @@ -65,6 +65,8 @@ class TracesController < ApplicationController # final helper vars for view @target_user = target_user + + render :partial => "page" if turbo_frame_request_id == "pagination" end def show diff --git a/app/controllers/user_blocks_controller.rb b/app/controllers/user_blocks_controller.rb index ae6e3c1cd..167223d91 100644 --- a/app/controllers/user_blocks_controller.rb +++ b/app/controllers/user_blocks_controller.rb @@ -21,6 +21,11 @@ class UserBlocksController < ApplicationController user_blocks = UserBlock.all @user_blocks, @newer_user_blocks_id, @older_user_blocks_id = get_page_items(user_blocks, :includes => [:user, :creator, :revoker]) + + @show_user_name = true + @show_creator_name = true + + render :partial => "blocks" if turbo_frame_request_id == "pagination" end def show @@ -118,6 +123,11 @@ class UserBlocksController < ApplicationController user_blocks = UserBlock.where(:user => @user) @user_blocks, @newer_user_blocks_id, @older_user_blocks_id = get_page_items(user_blocks, :includes => [:user, :creator, :revoker]) + + @show_user_name = false + @show_creator_name = true + + render :partial => "blocks" if turbo_frame_request_id == "pagination" end ## @@ -128,6 +138,11 @@ class UserBlocksController < ApplicationController user_blocks = UserBlock.where(:creator => @user) @user_blocks, @newer_user_blocks_id, @older_user_blocks_id = get_page_items(user_blocks, :includes => [:user, :creator, :revoker]) + + @show_user_name = true + @show_creator_name = false + + render :partial => "blocks" if turbo_frame_request_id == "pagination" end private diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0830e51d4..4ebeb1ec3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -40,6 +40,8 @@ class UsersController < ApplicationController @users_count = users.count @users, @newer_users_id, @older_users_id = get_page_items(users, :limit => 50) + + render :partial => "page" if turbo_frame_request_id == "pagination" end end diff --git a/app/views/diary_comments/_page.html.erb b/app/views/diary_comments/_page.html.erb new file mode 100644 index 000000000..53472e3ea --- /dev/null +++ b/app/views/diary_comments/_page.html.erb @@ -0,0 +1,26 @@ + + + + + + + + + + <% @comments.each do |comment| -%> + + + + + + <% end -%> +
<%= t ".post" %><%= t ".when" %><%= t ".comment" %>
"><%= link_to comment.diary_entry.title, diary_entry_path(comment.diary_entry.user, comment.diary_entry) %>"> + <%= friendly_date_ago(comment.created_at) %> + "><%= comment.body.to_html %>
+ + <%= render "shared/pagination", + :newer_key => "diary_comments.page.newer_comments", + :older_key => "diary_comments.page.older_comments", + :newer_id => @newer_comments_id, + :older_id => @older_comments_id %> +
diff --git a/app/views/diary_comments/index.html.erb b/app/views/diary_comments/index.html.erb index 0dd03d9d0..e68b3fb6b 100644 --- a/app/views/diary_comments/index.html.erb +++ b/app/views/diary_comments/index.html.erb @@ -5,30 +5,6 @@ <% if @comments.empty? %>

<%= t ".no_comments" %>

- <% else %> - - - - - - - - - <% @comments.each do |comment| -%> - - - - - - <% end -%> -
<%= t ".post" %><%= t ".when" %><%= t ".comment" %>
"><%= link_to comment.diary_entry.title, diary_entry_path(comment.diary_entry.user, comment.diary_entry) %>"> - <%= friendly_date_ago(comment.created_at) %> - "><%= comment.body.to_html %>
- - <%= render "shared/pagination", - :newer_key => "diary_comments.index.newer_comments", - :older_key => "diary_comments.index.older_comments", - :newer_id => @newer_comments_id, - :older_id => @older_comments_id %> + <%= render :partial => "page" %> <% end -%> diff --git a/app/views/diary_entries/_page.html.erb b/app/views/diary_entries/_page.html.erb new file mode 100644 index 000000000..34f364ac4 --- /dev/null +++ b/app/views/diary_entries/_page.html.erb @@ -0,0 +1,11 @@ + +

<%= t ".recent_entries" %>

+ + <%= render @entries %> + + <%= render "shared/pagination", + :newer_key => "diary_entries.page.newer_entries", + :older_key => "diary_entries.page.older_entries", + :newer_id => @newer_entries_id, + :older_id => @older_entries_id %> +
diff --git a/app/views/diary_entries/index.html.erb b/app/views/diary_entries/index.html.erb index 15be9e964..0457cc4a2 100644 --- a/app/views/diary_entries/index.html.erb +++ b/app/views/diary_entries/index.html.erb @@ -43,16 +43,8 @@ <% if @entries.empty? %>

<%= t ".no_entries" %>

<% else %> -

<%= t ".recent_entries" %>

- - <%= render @entries %> - - <%= render "shared/pagination", - :newer_key => "diary_entries.index.newer_entries", - :older_key => "diary_entries.index.older_entries", - :newer_id => @newer_entries_id, - :older_id => @older_entries_id %> -<% end %> + <%= render :partial => "page" %> +<% end -%> <% unless params[:friends] or params[:nearby] -%> <% content_for :auto_discovery_link_tag do -%> diff --git a/app/views/shared/_pagination.html.erb b/app/views/shared/_pagination.html.erb index 3dbce6f98..67b69e864 100644 --- a/app/views/shared/_pagination.html.erb +++ b/app/views/shared/_pagination.html.erb @@ -7,7 +7,7 @@ <% end %> <% if newer_id -%>
  • - <%= link_to newer_link_content, @params.merge(:before => nil, :after => newer_id), :class => link_class %> + <%= link_to newer_link_content, @params.merge(:before => nil, :after => newer_id), :class => link_class, :data => { "turbo-frame" => "pagination", "turbo-action" => "advance" } %>
  • <% else -%>
  • @@ -21,7 +21,7 @@ <% end %> <% if older_id -%>
  • - <%= link_to older_link_content, @params.merge(:before => older_id, :after => nil), :class => link_class %> + <%= link_to older_link_content, @params.merge(:before => older_id, :after => nil), :class => link_class, :data => { "turbo-frame" => "pagination", "turbo-action" => "advance" } %>
  • <% else -%>
  • diff --git a/app/views/traces/_page.html.erb b/app/views/traces/_page.html.erb new file mode 100644 index 000000000..38cdc7341 --- /dev/null +++ b/app/views/traces/_page.html.erb @@ -0,0 +1,19 @@ + + <%= render "shared/pagination", + :newer_key => "traces.page.newer", + :older_key => "traces.page.older", + :newer_id => @newer_traces_id, + :older_id => @older_traces_id %> + + + + <%= render @traces %> + +
    + + <%= render "shared/pagination", + :newer_key => "traces.page.newer", + :older_key => "traces.page.older", + :newer_id => @newer_traces_id, + :older_id => @older_traces_id %> +
    diff --git a/app/views/traces/index.html.erb b/app/views/traces/index.html.erb index 6e27ac7e4..998dd248d 100644 --- a/app/views/traces/index.html.erb +++ b/app/views/traces/index.html.erb @@ -69,23 +69,7 @@ <% end %> <% if @traces.size > 0 %> - <%= render "shared/pagination", - :newer_key => "traces.trace_paging_nav.newer", - :older_key => "traces.trace_paging_nav.older", - :newer_id => @newer_traces_id, - :older_id => @older_traces_id %> - - - - <%= render @traces %> - -
    - - <%= render "shared/pagination", - :newer_key => "traces.trace_paging_nav.newer", - :older_key => "traces.trace_paging_nav.older", - :newer_id => @newer_traces_id, - :older_id => @older_traces_id %> + <%= render :partial => "page" %> <% else %>

    <%= t ".empty_title" %>

    <%= t ".empty_upload_html", :upload_link => link_to(t(".upload_new"), new_trace_path), diff --git a/app/views/user_blocks/_block.html.erb b/app/views/user_blocks/_block.html.erb index 5444bdd5b..68850c28d 100644 --- a/app/views/user_blocks/_block.html.erb +++ b/app/views/user_blocks/_block.html.erb @@ -1,8 +1,8 @@ - <% if show_user_name %> + <% if @show_user_name %> <%= link_to block.user.display_name, block.user, :class => "username d-inline-block text-truncate text-wrap" %> <% end %> - <% if show_creator_name %> + <% if @show_creator_name %> <%= link_to block.creator.display_name, block.creator, :class => "username d-inline-block text-truncate text-wrap" %> <% end %> <%= h truncate(block.reason) %> @@ -17,7 +17,7 @@ <%= link_to t(".show"), block %> <% if current_user && (current_user.id == block.creator_id || current_user.id == block.revoker_id) %><%= link_to t(".edit"), edit_user_block_path(block) %><% end %> - <% if show_revoke_link %> + <% if can?(:revoke, UserBlock) %> <% if block.active? %><%= link_to t(".revoke"), revoke_user_block_path(block) %><% end %> <% end %> diff --git a/app/views/user_blocks/_blocks.html.erb b/app/views/user_blocks/_blocks.html.erb index c508dcd47..8816acb15 100644 --- a/app/views/user_blocks/_blocks.html.erb +++ b/app/views/user_blocks/_blocks.html.erb @@ -1,27 +1,29 @@ - - - - <% if show_user_name %> - - <% end %> - <% if show_creator_name %> - - <% end %> - - - - - - <% if show_revoke_link %> - - <% end %> - - - <%= render :partial => "block", :locals => { :show_revoke_link => show_revoke_link, :show_user_name => show_user_name, :show_creator_name => show_creator_name }, :collection => @user_blocks %> -
    <%= t ".display_name" %><%= t ".creator_name" %><%= t ".reason" %><%= t ".status" %><%= t ".revoker_name" %>
    + + + + + <% if @show_user_name %> + + <% end %> + <% if @show_creator_name %> + + <% end %> + + + + + + <% if can?(:revoke, UserBlock) %> + + <% end %> + + + <%= render :partial => "block", :collection => @user_blocks %> +
    <%= t ".display_name" %><%= t ".creator_name" %><%= t ".reason" %><%= t ".status" %><%= t ".revoker_name" %>
    -<%= render "shared/pagination", - :newer_key => "user_blocks.blocks.newer", - :older_key => "user_blocks.blocks.older", - :newer_id => @newer_user_blocks_id, - :older_id => @older_user_blocks_id %> + <%= render "shared/pagination", + :newer_key => "user_blocks.blocks.newer", + :older_key => "user_blocks.blocks.older", + :newer_id => @newer_user_blocks_id, + :older_id => @older_user_blocks_id %> +
    diff --git a/app/views/user_blocks/blocks_by.html.erb b/app/views/user_blocks/blocks_by.html.erb index 7fa0a4fbb..38254a5a3 100644 --- a/app/views/user_blocks/blocks_by.html.erb +++ b/app/views/user_blocks/blocks_by.html.erb @@ -7,7 +7,7 @@ <% end %> <% unless @user_blocks.empty? %> -<%= render :partial => "blocks", :locals => { :show_revoke_link => can?(:revoke, UserBlock), :show_user_name => true, :show_creator_name => false } %> +<%= render :partial => "blocks" %> <% else %>

    <%= t ".empty", :name => @user.display_name %>

    <% end %> diff --git a/app/views/user_blocks/blocks_on.html.erb b/app/views/user_blocks/blocks_on.html.erb index 0c15b8866..38254a5a3 100644 --- a/app/views/user_blocks/blocks_on.html.erb +++ b/app/views/user_blocks/blocks_on.html.erb @@ -7,7 +7,7 @@ <% end %> <% unless @user_blocks.empty? %> -<%= render :partial => "blocks", :locals => { :show_revoke_link => can?(:revoke, UserBlock), :show_user_name => false, :show_creator_name => true } %> +<%= render :partial => "blocks" %> <% else %>

    <%= t ".empty", :name => @user.display_name %>

    <% end %> diff --git a/app/views/user_blocks/index.html.erb b/app/views/user_blocks/index.html.erb index 4d200b516..854d62037 100644 --- a/app/views/user_blocks/index.html.erb +++ b/app/views/user_blocks/index.html.erb @@ -7,7 +7,7 @@ <% end %> <% unless @user_blocks.empty? %> -<%= render :partial => "blocks", :locals => { :show_revoke_link => can?(:revoke, UserBlock), :show_user_name => true, :show_creator_name => true } %> +<%= render :partial => "blocks" %> <% else %>

    <%= t ".empty" %>

    <% end %> diff --git a/app/views/users/_page.html.erb b/app/views/users/_page.html.erb new file mode 100644 index 000000000..3307c7b11 --- /dev/null +++ b/app/views/users/_page.html.erb @@ -0,0 +1,50 @@ + + <%= form_tag do %> +
    +
    + <%= render "shared/pagination", + :newer_key => "users.page.newer", + :older_key => "users.page.older", + :newer_id => @newer_users_id, + :older_id => @older_users_id %> +
    +
    + <%= t ".found_users", :count => @users_count %> +
    +
    + + <%= hidden_field_tag :status, params[:status] if params[:status] %> + <%= hidden_field_tag :ip, params[:ip] if params[:ip] %> + <%= hidden_field_tag :page, params[:page] if params[:page] %> + + + + + + + + <%= render @users %> +
    + + <%= check_box_tag "user_all", "1", false %> +
    + +
    +
    + <%= render "shared/pagination", + :newer_key => "users.page.newer", + :older_key => "users.page.older", + :newer_id => @newer_users_id, + :older_id => @older_users_id %> +
    +
    + <%= t ".found_users", :count => @users_count %> +
    +
    + +
    + <%= submit_tag t(".confirm"), :name => "confirm", :class => "btn btn-primary" %> + <%= submit_tag t(".hide"), :name => "hide", :class => "btn btn-primary" %> +
    + <% end %> + diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index e8031900f..abf0092ce 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -9,54 +9,7 @@ <% end %> <% unless @users.empty? %> - <%= form_tag do %> -
    -
    - <%= render "shared/pagination", - :newer_key => "users.index.newer", - :older_key => "users.index.older", - :newer_id => @newer_users_id, - :older_id => @older_users_id %> -
    -
    - <%= t ".found_users", :count => @users_count %> -
    -
    - - <%= hidden_field_tag :status, params[:status] if params[:status] %> - <%= hidden_field_tag :ip, params[:ip] if params[:ip] %> - <%= hidden_field_tag :page, params[:page] if params[:page] %> - - - - - - - - <%= render @users %> -
    - - <%= check_box_tag "user_all", "1", false %> -
    - -
    -
    - <%= render "shared/pagination", - :newer_key => "users.index.newer", - :older_key => "users.index.older", - :newer_id => @newer_users_id, - :older_id => @older_users_id %> -
    -
    - <%= t ".found_users", :count => @users_count %> -
    -
    - -
    - <%= submit_tag t(".confirm"), :name => "confirm", :class => "btn btn-primary" %> - <%= submit_tag t(".hide"), :name => "hide", :class => "btn btn-primary" %> -
    - <% end %> + <%= render :partial => "page" %> <% else %>

    <%= t ".empty" %>

    <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 30721562a..4d5ce7f58 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -538,6 +538,7 @@ en: new_title: Compose a new entry in my user diary my_diary: My Diary no_entries: No diary entries + page: recent_entries: "Recent diary entries" older_entries: Older Entries newer_entries: Newer Entries @@ -604,6 +605,7 @@ en: heading: "%{user}'s Diary Comments" subheading_html: "Diary Comments added by %{user}" no_comments: "No diary comments" + page: post: Post when: When comment: Comment @@ -2522,9 +2524,6 @@ en: trace_not_found: "Trace not found!" visibility: "Visibility:" confirm_delete: "Delete this trace?" - trace_paging_nav: - older: "Older Traces" - newer: "Newer Traces" trace: pending: "PENDING" count_points: @@ -2556,6 +2555,9 @@ en: my_traces: "My Traces" traces_from: "Public Traces from %{user}" remove_tag_filter: "Remove Tag Filter" + page: + older: "Older Traces" + newer: "Newer Traces" destroy: scheduled_for_deletion: "Trace scheduled for deletion" make_public: @@ -2875,16 +2877,17 @@ en: index: title: Users heading: Users + summary_html: "%{name} created from %{ip_address} on %{date}" + summary_no_ip_html: "%{name} created on %{date}" + empty: No matching users found + page: older: "Older Users" newer: "Newer Users" found_users: one: "%{count} user found" other: "%{count} users found" - summary_html: "%{name} created from %{ip_address} on %{date}" - summary_no_ip_html: "%{name} created on %{date}" confirm: Confirm Selected Users hide: Hide Selected Users - empty: No matching users found suspended: title: Account Suspended heading: Account Suspended -- 2.39.5