Skip to content

Commit 50fb1b5

Browse files
committed
Add Placement Types management functionality
- Introduced PlacementTypesController with actions for new, create, edit, and update. - Added routes for placement types. - Implemented views for managing placement types. - Created policies to manage access to placement types. - Added tests for placement types functionality in both request and policy specs. fixes #5778
1 parent d9b0c92 commit 50fb1b5

File tree

15 files changed

+320
-1
lines changed

15 files changed

+320
-1
lines changed

app/controllers/casa_org_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class CasaOrgController < ApplicationController
88
before_action :set_sent_emails, only: %i[edit update]
99
before_action :set_contact_topics, only: %i[edit update]
1010
before_action :set_custom_org_links, only: %i[edit update]
11+
before_action :set_placement_types, only: %i[edit update]
1112
before_action :require_organization!
1213
after_action :verify_authorized
1314
before_action :set_active_storage_url_options, only: %i[edit update]
@@ -95,6 +96,10 @@ def set_custom_org_links
9596
@custom_org_links = @casa_org.custom_org_links
9697
end
9798

99+
def set_placement_types
100+
@placement_types = @casa_org.placement_types
101+
end
102+
98103
def set_active_storage_url_options
99104
ActiveStorage::Current.url_options = {host: request.base_url}
100105
end
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
class PlacementTypesController < ApplicationController
2+
before_action :set_placement_type, only: %i[edit update]
3+
after_action :verify_authorized
4+
after_action :verify_policy_scoped
5+
6+
def new
7+
@placement_type = policy_scope(PlacementType).new(casa_org: current_organization)
8+
authorize @placement_type
9+
end
10+
11+
def create
12+
@placement_type = policy_scope(PlacementType).new(placement_type_params)
13+
authorize @placement_type
14+
15+
if @placement_type.save
16+
redirect_to edit_casa_org_path(current_organization), notice: "Placement Type was successfully created."
17+
else
18+
render :new, status: :unprocessable_entity
19+
end
20+
end
21+
22+
def edit
23+
authorize @placement_type
24+
end
25+
26+
def update
27+
authorize @placement_type
28+
29+
if @placement_type.update(placement_type_params)
30+
redirect_to edit_casa_org_path(current_organization), notice: "Placement Type was successfully updated."
31+
else
32+
render :edit, status: :unprocessable_entity
33+
end
34+
end
35+
36+
private
37+
38+
def set_placement_type
39+
@placement_type = policy_scope(PlacementType).find(params[:id])
40+
rescue ActiveRecord::RecordNotFound
41+
redirect_to edit_casa_org_path
42+
end
43+
44+
def placement_type_params
45+
params.require(:placement_type).permit(:name).merge(casa_org: current_organization)
46+
end
47+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class PlacementTypePolicy < ApplicationPolicy
2+
class Scope < ApplicationPolicy::Scope
3+
def resolve
4+
case user
5+
when CasaAdmin
6+
scope.where(casa_org: @user.casa_org)
7+
when Volunteer, Supervisor
8+
scope.none
9+
else
10+
scope.none
11+
end
12+
end
13+
end
14+
15+
def edit?
16+
is_admin_same_org?
17+
end
18+
19+
alias_method :new?, :edit?
20+
alias_method :create?, :edit?
21+
alias_method :update?, :edit?
22+
end
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<div class="row">
2+
<div class="col-lg-12">
3+
<div class="card-style mb-30">
4+
<div class="row align-items-center">
5+
<div class="col-md-6">
6+
<h3>Placement Types</h3>
7+
</div>
8+
<div class="col-md-6">
9+
<div class="breadcrumb-wrapper">
10+
<span class="ml-5">
11+
<%= link_to new_placement_type_path, class: "btn-sm main-btn primary-btn btn-hover" do %>
12+
<i class="lni lni-plus mr-10"></i>
13+
New Placement Type
14+
<% end %>
15+
</span>
16+
</div>
17+
</div>
18+
</div>
19+
<div class="table-wrapper table-responsive">
20+
<table class="table striped-table" id="contact-types">
21+
<thead>
22+
<tr>
23+
<th>Name</th>
24+
<th>Actions</th>
25+
</tr>
26+
</thead>
27+
<tbody>
28+
<% placement_types.each do |placement_type| %>
29+
<tr id="placement_type-<%= placement_type.id %>">
30+
<td scope="row" class="min-width">
31+
<%= placement_type.name %>
32+
</td>
33+
<td>
34+
<%= link_to edit_placement_type_path(placement_type) do %>
35+
<div class="action">
36+
<button class="text-danger">
37+
<i class="lni lni-pencil-alt"></i> Edit
38+
</button>
39+
</div>
40+
<% end %>
41+
</td>
42+
</tr>
43+
<% end %>
44+
</tbody>
45+
</table>
46+
</div>
47+
</div>
48+
</div>
49+
</div>

app/views/casa_org/edit.html.erb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,18 @@
166166
<div class="tables-wrapper">
167167
<%= render "contact_topics" %>
168168
</div>
169+
170+
<div class="title-wrapper pt-30">
171+
<div class="row align-items-center">
172+
<div class="col-md-6">
173+
<div class="title mb-30">
174+
<h2 id="placement-types">
175+
Manage Placement Types
176+
</h2>
177+
</div>
178+
</div>
179+
</div>
180+
</div>
181+
<div class="tables-wrapper">
182+
<%= render "placement_types", placement_types: @placement_types %>
183+
</div>

app/views/layouts/_sidebar.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
{ title: "Contact Types", icon: "user", path: edit_casa_org_path(current_organization, anchor: 'contact-types'), render_check: policy(:application).modify_organization? },
5858
{ title: "Court Details", icon: "library", path: edit_casa_org_path(current_organization, anchor: 'court-details'), render_check: policy(:application).modify_organization? },
5959
{ title: "Learning Hours", icon: "timer", path: edit_casa_org_path(current_organization, anchor: 'learning-hours'), render_check: policy(:application).modify_organization? },
60-
{ title: "Case Contact Topics", icon: "comments", path: edit_casa_org_path(current_organization, anchor: 'case-contact-topics'), render_check: policy(:application).modify_organization? }
60+
{ title: "Case Contact Topics", icon: "comments", path: edit_casa_org_path(current_organization, anchor: 'case-contact-topics'), render_check: policy(:application).modify_organization? },
61+
{ title: "Placement Types", icon: "comments", path: edit_casa_org_path(current_organization, anchor: 'placement-types'), render_check: policy(:application).modify_organization? }
6162
]) %>
6263
<% end %>
6364
<% if current_organization.custom_org_links.any?(&:active) %>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<div class="input-style-1">
2+
<%= form.label :placement_started_at, "Placement Started At" %>
3+
<%= form.date_field :placement_started_at,
4+
value: placement.placement_started_at&.to_date || Time.zone.now,
5+
class: "form-control" %>
6+
</div>
7+
<div class="select-style-1">
8+
<%= form.label :placement_type_id, "Placement Type" %>
9+
<div class="select-position">
10+
<%= form.collection_select(
11+
:placement_type_id,
12+
PlacementType.for_organization(current_organization).order_alphabetically,
13+
:id, :name,
14+
{include_hidden: false, include_blank: "-Select Placement Type-"},
15+
{class: "form-control"}
16+
) %>
17+
</div>
18+
</div>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<div class="title-wrapper pt-30">
2+
<div class="row align-items-center">
3+
<div class="col-md-6">
4+
<div class="title mb-30">
5+
<h1>
6+
<%= title %>
7+
</h1>
8+
</div>
9+
</div>
10+
</div>
11+
</div><!-- ==== end title ==== -->
12+
13+
<!-- ========== card start ========== -->
14+
<div class="card-style mb-30">
15+
<%= form_with(model: placement_type, local: true) do |form| %>
16+
<div class="alert-box danger-alert">
17+
<%= render "/shared/error_messages", resource: placement_type %>
18+
</div>
19+
<div class="input-style-1">
20+
<%= form.label :name, "Name" %>
21+
<%= form.text_field :name, class: "form-control", required: true %>
22+
</div>
23+
24+
<div class="actions mb-10">
25+
<%= button_tag(type: "submit", class: "btn-sm main-btn primary-btn btn-hover") do %>
26+
<i class="lni lni-checkmark-circle mr-5"></i> Submit
27+
<% end %>
28+
</div>
29+
<% end %>
30+
</div>
31+
<!-- card end -->
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= render partial: "form", locals: {title: "Edit Placement Type", placement_type: @placement_type} %>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= render partial: "form", locals: {title: "New Placement Type", placement_type: @placement_type} %>

0 commit comments

Comments
 (0)