From c99d8545c1791dbe31d6511fab05851047697bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Wed, 28 May 2025 12:34:52 +0400 Subject: [PATCH 1/2] Add username filter to admin invitations index --- .../admin/invitations_controller.rb | 26 +++++++++++++++---- .../admin/_username_search_form.html.erb | 11 ++++++++ app/views/admin/donations/index.html.erb | 13 ++-------- app/views/admin/invitations/index.html.erb | 6 +++++ 4 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 app/views/admin/_username_search_form.html.erb diff --git a/app/controllers/admin/invitations_controller.rb b/app/controllers/admin/invitations_controller.rb index 97a33b3..c5c0290 100644 --- a/app/controllers/admin/invitations_controller.rb +++ b/app/controllers/admin/invitations_controller.rb @@ -1,12 +1,28 @@ class Admin::InvitationsController < Admin::BaseController + before_action :set_current_section + def index - @current_section = :invitations - @pagy, @invitations_used = pagy(Invitation.used.order('used_at desc')) + @username = params[:username].presence + accepted_scope = Invitation.used.order('used_at desc') + unused_scope = Invitation.unused + + if @username + accepted_scope = accepted_scope.joins(:user).where(users: { cn: @username }) + unused_scope = unused_scope.joins(:user).where(users: { cn: @username }) + end + + @pagy, @invitations_used = pagy(accepted_scope) @stats = { - available: Invitation.unused.count, - accepted: @invitations_used.length, - users_with_referrals: Invitation.used.distinct.count(:user_id) + available: unused_scope.count, + accepted: accepted_scope.count, + users_with_referrals: accepted_scope.distinct.count(:user_id) } end + + private + + def set_current_section + @current_section = :invitations + end end diff --git a/app/views/admin/_username_search_form.html.erb b/app/views/admin/_username_search_form.html.erb new file mode 100644 index 0000000..b318c86 --- /dev/null +++ b/app/views/admin/_username_search_form.html.erb @@ -0,0 +1,11 @@ +<%= form_with url: path, method: :get, local: true, class: "flex gap-1" do %> + <%= text_field_tag :username, @username, placeholder: 'Filter by username' %> + <%= button_tag type: 'submit', name: nil, title: "Filter", class: 'btn-md btn-icon btn-outline' do %> + <%= render partial: "icons/filter", locals: { custom_class: "text-blue-600 h-4 w-4 inline" } %> + <% end %> + <% if @username %> + <%= link_to path, title: "Remove filter", class: 'btn-md btn-icon btn-outline' do %> + <%= render partial: "icons/x", locals: { custom_class: "text-red-600 h-4 w-4 inline" } %> + <% end %> + <% end %> +<% end %> diff --git a/app/views/admin/donations/index.html.erb b/app/views/admin/donations/index.html.erb index ca1acc1..2e80ba2 100644 --- a/app/views/admin/donations/index.html.erb +++ b/app/views/admin/donations/index.html.erb @@ -19,17 +19,8 @@
- <%= form_with url: admin_donations_path, method: :get, local: true, class: "flex gap-1" do %> - <%= text_field_tag :username, @username, placeholder: 'Filter by username' %> - <%= button_tag type: 'submit', name: nil, title: "Filter", class: 'btn-md btn-icon btn-outline' do %> - <%= render partial: "icons/filter", locals: { custom_class: "text-blue-600 h-4 w-4 inline" } %> - <% end %> - <% if @username %> - <%= link_to admin_donations_path, title: "Remove filter", class: 'btn-md btn-icon btn-outline' do %> - <%= render partial: "icons/x", locals: { custom_class: "text-red-600 h-4 w-4 inline" } %> - <% end %> - <% end %> - <% end %> + <%= render partial: "admin/username_search_form", + locals: { path: admin_donations_path } %>
<% if @pending_donations.present? %> diff --git a/app/views/admin/invitations/index.html.erb b/app/views/admin/invitations/index.html.erb index f18555f..acc5606 100644 --- a/app/views/admin/invitations/index.html.erb +++ b/app/views/admin/invitations/index.html.erb @@ -21,6 +21,12 @@ ) %> <% end %> + +
+ <%= render partial: "admin/username_search_form", + locals: { path: admin_invitations_path } %> +
+ <% if @invitations_used.any? %>

Accepted

From c6a187b25a09445fe74290fe532fd89257395dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Wed, 28 May 2025 12:50:10 +0400 Subject: [PATCH 2/2] Limit invitees on admin user page, link to invitations for more --- app/controllers/admin/users_controller.rb | 4 ++++ app/views/admin/users/show.html.erb | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 0baeed7..e6504e4 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -24,6 +24,10 @@ class Admin::UsersController < Admin::BaseController # GET /admin/users/:username def show + @invitees = @user.invitees + @recent_invitees = @user.invitees.order(created_at: :desc).limit(5) + @more_invitees = (@invitees - @recent_invitees).count + if Setting.lndhub_admin_enabled? @lndhub_user = @user.lndhub_user end diff --git a/app/views/admin/users/show.html.erb b/app/views/admin/users/show.html.erb index 6147850..367b5a7 100644 --- a/app/views/admin/users/show.html.erb +++ b/app/views/admin/users/show.html.erb @@ -99,10 +99,13 @@ Invited users - <% if @user.invitees.length > 0 %> + <% if @invitees.any? %>
    - <% @user.invitees.order(cn: :asc).each do |invitee| %> -
  • <%= link_to invitee.cn, admin_user_path(invitee.cn), class: 'ks-text-link' %>
  • + <% @recent_invitees.each do |invitee| %> +
  • <%= link_to invitee.cn, admin_user_path(invitee.cn), class: "ks-text-link" %>
  • + <% end %> + <% if @more_invitees > 0 %> +
  • and <%= link_to "#{@more_invitees} more", admin_invitations_path(username: @user.cn), class: "ks-text-link" %>
  • <% end %>
<% else %>—<% end %>