diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index cff3b1b28..4eb8d5288 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -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! @@ -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 diff --git a/app/views/organizations/populations_served.html.erb b/app/views/organizations/populations_served.html.erb new file mode 100644 index 000000000..7c1a42300 --- /dev/null +++ b/app/views/organizations/populations_served.html.erb @@ -0,0 +1,25 @@ +
+

+ Sector Distribution for <%= @organization.name %> +

+ + <% if @sectors_by_people.any? %> + + <% else %> +

No sectors found for this organization.

+ <% end %> + +
+ <%= link_to "← Back to Organization", organization_path(@organization), + class: "btn btn-secondary-outline" %> +
+
diff --git a/app/views/organizations/show.html.erb b/app/views/organizations/show.html.erb index 088d2a5e1..b98d10982 100644 --- a/app/views/organizations/show.html.erb +++ b/app/views/organizations/show.html.erb @@ -148,6 +148,11 @@ <% else %>

None selected.

<% end %> +
+ <%= 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" %> +
<% end %> diff --git a/config/routes.rb b/config/routes.rb index 88e7690b9..a72c4b5e5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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