Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class OrganizationsController < ApplicationController
include AhoyTracking
before_action :set_organization, only: [ :show, :edit, :update, :destroy ]
before_action :set_organization, only: [ :show, :edit, :update, :destroy, :populations_served ]

def index
authorize!
Expand Down Expand Up @@ -118,6 +118,19 @@ def set_index_variables
@organization_statuses = OrganizationStatus.all
end

def populations_served
authorize! @organization

people = @organization.users.includes(:person).map(&:person).compact

sector_counts = Hash.new(0)
people.each do |person|
primary_sector = person.sectors.first
sector_counts[primary_sector] += 1 if primary_sector
end
@sectors_by_people = sector_counts.sort_by { |_sector, count| -count }
end

private

def set_organization
Expand Down
25 changes: 25 additions & 0 deletions app/views/organizations/populations_served.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<div class="rounded-lg border border-gray-200 bg-gray-50 p-6 shadow-sm">
<h2 class="text-lg font-semibold text-gray-800 mb-4">
Sector Distribution for <%= @organization.name %>
</h2>

<% if @sectors_by_people.any? %>
<ul class="space-y-2">
<% @sectors_by_people.each do |sector, count| %>
<li class="flex items-center justify-between p-2 bg-white rounded border border-gray-100 shadow-sm">
<span><%= sector.name %></span>
<span class="text-gray-600 font-medium">
<%= count %> <%= count == 1 ? "person" : "people" %>
</span>
</li>
<% end %>
</ul>
<% else %>
<p class="text-gray-500 italic">No sectors found for this organization.</p>
<% end %>

<div class="mt-6">
<%= link_to "← Back to Organization", organization_path(@organization),
class: "btn btn-secondary-outline" %>
</div>
</div>
5 changes: 5 additions & 0 deletions app/views/organizations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@
<% else %>
<p class="text-gray-500 italic">None selected.</p>
<% end %>
<div class="mt-4">
<%= link_to "Sector Distribution",
populations_served_organization_path(@organization),
class: "inline-block px-4 py-2 bg-gray-100 border border-gray-300 rounded shadow-sm text-gray-800 hover:bg-gray-200 transition" %>
</div>
</div>
<% end %>
</div>
Expand Down
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@
post :resend
end
end
resources :organizations
resources :organizations do
member do
get :populations_served
end
end
resources :organization_statuses
resources :organization_people
resources :quotes
Expand Down