Skip to content

Commit

Permalink
Chore: Refactor participants datagrid to handle clubs
Browse files Browse the repository at this point in the history
Summary of updates:

- create a new ambassador/participants_controller
  - for the show, edit, and update actions
  - ChAs and CAs will share this controller

- create a new data_grids/participants_controller
  - ChAs and CAs will share this controller

- consolidate the views so ChAs and CAs will use the same views
- for the datagrid view it will be shared for admins, ChAs, and CAs

Refs: #5319
  • Loading branch information
shaun-technovation committed Jan 23, 2025
1 parent b1de69f commit 410ff36
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 90 deletions.
18 changes: 18 additions & 0 deletions app/controllers/ambassador/participants_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Ambassador
class ParticipantsController < AmbassadorController
def show
@account = Account
.joins(:chapterable_assignments)
.where(
chapterable_assignments: {
chapterable_type: current_ambassador.chapterable_type.capitalize,
chapterable_id: current_ambassador.current_chapterable.id
}
)
.find(params[:id])

@teams = Team.current.in_region(current_ambassador)
@season_flag = SeasonFlag.new(@account)
end
end
end
3 changes: 2 additions & 1 deletion app/controllers/concerns/datagrid_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def index
}
)

if controller_name == "unaffiliated_participants"
if controller_name == "participants" ||
controller_name == "unaffiliated_participants"
render "data_grids/#{controller_name}/index"
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
module ChapterAmbassador
class ParticipantsController < ChapterAmbassadorController
module DataGrids::Ambassador
class ParticipantsController < AmbassadorController
include DatagridController

layout "ambassador"

use_datagrid with: AccountsGrid,

html_scope: ->(scope, user, params) {
scope
.joins(:chapterable_assignments)
.where(chapterable_assignments: {chapterable_type: "Chapter", chapterable_id: user.current_chapter.id})
.where(
chapterable_assignments: {
chapterable_type: user.chapterable_type.capitalize,
chapterable_id: user.current_chapterable.id
}
)
.page(params[:page])
},

csv_scope: "->(scope, user, _params) {
scope
.joins(:chapterable_assignments)
.where(chapterable_assignments: {chapterable_type: 'Chapter', chapterable_id: user.current_chapter.id})
.where(chapterable_assignments: {chapterable_type: user.chapterable_type.capitalize, chapterable_id: user.current_chapterable.id})
}"

def show
@account = Account
.joins(:chapterable_assignments)
.where(chapterable_assignments: {chapterable_type: "Chapter", chapterable_id: current_ambassador.current_chapter.id})
.where(
chapterable_assignments: {
chapterable_type: current_ambassador.chapterable_type.capitalize,
chapterable_id: current_ambassador.current_chapterable.id
}
)
.find(params[:id])

@teams = Team.current.in_region(current_ambassador)
Expand Down
8 changes: 8 additions & 0 deletions app/models/club_ambassador_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,12 @@ def chapterable_type
def scope_name
"club_ambassador"
end

def secondary_regions
[]
end

def other_regions
secondary_regions
end
end
28 changes: 15 additions & 13 deletions app/views/admin/participants/_student_debugging.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,30 @@
</dl>
</div>

<% if not profile.team.present? %>
<h4 class="reset">Help them with their team matching</h4>
<% if current_scope != "club_ambassador" %>
<% if !profile.team.present? %>
<h4 class="reset">Help them with their team matching</h4>

<div class="panel">
<%= form_tag(send("#{current_scope}_team_memberships_path")) do %>
<%= hidden_field_tag :account_id, profile.account_id %>
<div class="panel">
<%= form_tag(send("#{current_scope}_team_memberships_path")) do %>
<%= hidden_field_tag :account_id, profile.account_id %>

<h6>Add <%= profile.full_name %> to a team</h6>
<h6>Add <%= profile.full_name %> to a team</h6>

<p>
<p>
<%= select_tag "team_id",
options_from_collection_for_select(@teams, "id", "name"),
prompt: "Select a team",
required: true,
class: "chosen" %>
options_from_collection_for_select(@teams, "id", "name"),
prompt: "Select a team",
required: true,
class: "chosen" %>
</p>

<p>
<%= submit_tag 'Add', class: "button" %>
<%= submit_tag 'Add', class: "button" %>
</p>
<% end %>
</div>
</div>
<% end %>
<% end %>

<% if (current_account.is_admin? && profile.age >= 14) ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<% provide :title, "Viewing #{@account.scope_name.titleize}" %>

<% provide :subnav, render('chapter_ambassador/participants/sub_menu') %>

<div class="panel">
<%= render "participant_flags/season", flag: @season_flag %>

Expand Down
37 changes: 0 additions & 37 deletions app/views/chapter_ambassador/participants/_sub_menu.en.html.erb

This file was deleted.

16 changes: 0 additions & 16 deletions app/views/chapter_ambassador/participants/index.en.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/club_ambassador/_navigation.en.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<nav>
<%= link_to "Dashboard", club_ambassador_dashboard_path %>

<%# link_to "Participants",
<%= link_to "Participants",
club_ambassador_participants_path,
data: { turbolinks: false },
class: al(club_ambassador_participants_path) %>
Expand Down
17 changes: 17 additions & 0 deletions app/views/data_grids/participants/index.en.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% provide :title, "Participants" %>

<%= render "datagrid/datagrid",
grid: @accounts_grid,
form_url: send("#{current_scope}_participants_path"),
model_name: "account",
scope: current_scope.to_sym do %>

<% if current_account.chapter_ambassador? %>
<p class="float-right">
<%= link_to "Find a missing participant",
new_chapter_ambassador_missing_participant_search_path,
data: { turbolinks: false },
class: "button small subnav--help-link" %>
</p>
<% end %>
<% end %>
5 changes: 4 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@
resources :accounts, only: :show, controller: :participants do
resource :chapter_account_assignments, only: [:create]
end
resources :participants, only: [:index, :show, :edit, :update]
resources :participants, only: [:show, :edit, :update], controller: "/ambassador/participants"
resources :participants, only: [:index], controller: "/data_grids/ambassador/participants"
resources :unaffiliated_participants, only: [:index], controller: "/data_grids/ambassador/unaffiliated_participants"
resources :participant_sessions, only: [:show, :destroy]

Expand Down Expand Up @@ -227,6 +228,8 @@
resource :public_information, only: [:show, :edit, :update], controller: "club_public_information"

resource :club_admin, only: :show, controller: "club_admin"
resources :participants, only: [:show, :edit, :update], controller: "/ambassador/participants"
resources :participants, only: [:index], controller: "/data_grids/ambassador/participants"
resources :unaffiliated_participants, only: [:index], controller: "/data_grids/ambassador/unaffiliated_participants"
resources :saved_searches, only: [:show, :create, :update, :destroy]
end
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require "rails_helper"

RSpec.describe DataGrids::Ambassador::ParticipantsController do
describe "GET #index" do
context "as a chapter ambassador" do
before do
sign_in(:chapter_ambassador)
end

it "returns an OK 200 status code" do
get :index

expect(response.status).to eq(200)
end
end

context "as a club ambassador" do
before do
sign_in(:club_ambassador)
end

it "returns an OK 200 status code" do
get :index

expect(response.status).to eq(200)
end
end
end
end

0 comments on commit 410ff36

Please sign in to comment.