Skip to content

Commit

Permalink
GYR1-494 (#4645)
Browse files Browse the repository at this point in the history
* WIP

* WIP

* WIP

* Spec fix

* Async load and more specs

* WIP

* Replaced pixels with rem

* Changed method name for clarity

* WIP

* Fix for issues found by Erica
  • Loading branch information
tofarr authored Jul 16, 2024
1 parent 61838b6 commit e91e952
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 8 deletions.
3 changes: 3 additions & 0 deletions app/assets/images/icons/warning.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 65 additions & 4 deletions app/assets/stylesheets/pages/dashboard.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,74 @@

.dashboard-show-page-body{
.card{
border: 1px solid #757575;
border: 0.1rem solid #757575;
}
select.select__element{
border: 1px solid #CFC5BF;
border-radius: 5px;
border: 0.1rem solid #CFC5BF;
border-radius: 0.5rem;
background-image: image-url('dropdown.svg');
background-repeat: no-repeat;
background-position: right 10px center;
background-position: right 1rem center;
}

.capacity {
table {
border-collapse: collapse;
border-spacing: 0;
width: 100%;

tr th {
font-weight: normal;
color: #757575;
text-align: left;
padding: 1.2rem 0;
}

tr {
border-bottom: 0.1rem solid #BEBEBE;
td {
padding: 1.2rem 0;
}
td:last-child {
font-weight: bold;
}
}

tr:last-child {
border-bottom: none;
}

.organization-link {
color: #000;
text-decoration: none;
}

.controls>div {
display: flex;
align-items: center;
gap: 0.5rem;
img {
width: 1.8rem;
height: 1.8rem;
}
}

.under-capacity {
color: #07866C;
}

.at-capacity {
}

.over-capacity {
color: #D73D02;
}
}
}

.paging {
display: flex;
justify-content: flex-end;
gap: 2rem;
}
}
36 changes: 36 additions & 0 deletions app/controllers/hub/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class DashboardController < Hub::BaseController
layout "hub"
before_action :require_dashboard_user
before_action :load_filter_options, only: [:index, :show]
helper_method :capacity_css_class
helper_method :capacity_count

def index
model = @filter_options.first.model
Expand All @@ -13,6 +15,7 @@ def show
@selected_value = "#{params[:type]}/#{params[:id]}"
selected_option = @filter_options.find{ |option| option.value == @selected_value }
@selected = selected_option.model
load_capacity
end

private
Expand Down Expand Up @@ -92,5 +95,38 @@ def self.flatten_filter_options(filter_options, result)

DashboardFilterOption = Struct.new(:value, :model, :children, :has_parent)

def load_capacity
return if @selected.instance_of? Site
if @selected.instance_of? Coalition
@capacity = @selected.organizations.filter(&:capacity_limit)
@capacity.sort! do |a, b|
sort_a = (a.active_client_count.to_f / a.capacity_limit)
sort_b = (b.active_client_count.to_f / b.capacity_limit)
sort_b <=> sort_a
end
elsif @selected.instance_of?(Organization) && @selected.capacity_limit
@capacity = [@selected]
end
end

def capacity_css_class(organization)
if organization.active_client_count > (organization.capacity_limit || 0)
"over-capacity"
elsif organization.active_client_count < (organization.capacity_limit || 0)
"under-capacity"
else
"at-capacity"
end
end

def capacity_count
if @selected.instance_of? Coalition
@selected.organizations.count(&:capacity_limit)
elsif @selected.instance_of?(Organization) && @selected.capacity_limit
1
else
0
end
end
end
end
39 changes: 36 additions & 3 deletions app/views/hub/dashboard/_capacity.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
<div class="card">
<h2>Capacity</h2>
<p>TODO: Implement</p>
<div class="card capacity">
<h2><%= I18n.t("hub.dashboard.show.capacity") %></h2>
<table>
<thead>
<tr>
<th><%= I18n.t("hub.dashboard.show.org_name") %></th>
<th><%= I18n.t("hub.dashboard.show.current_capacity") %></th>
</tr>
</thead>
<tbody>
<% @capacity[..3].each do |organization| %>
<tr>
<td>
<%= link_to "#{organization.name}",
can?(:edit, organization) ? edit_hub_organization_path(id: organization) : hub_organization_path(id: organization),
class: "organization-link"
%>
</td>
<td class="controls">
<div class="<%= capacity_css_class(organization) %>">
<div><%= organization.active_client_count %>/<%= organization.capacity_limit %></div>
<% if organization.active_client_count.to_f / organization.capacity_limit > 1 %>
<%= image_tag('icons/warning.svg', alt: "") %>
<% end %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
<% if @selected.instance_of? Coalition %>
<div class="paging">
<div><%= @capacity.length %> of <%= capacity_count %></div>
<%= link_to I18n.t("hub.dashboard.show.view_all"), hub_organizations_path %>
</div>
<% end %>
</div>
2 changes: 1 addition & 1 deletion app/views/hub/dashboard/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</select>
</div>
<%= render "hub/dashboard/service_level_agreements_notifications" %>
<% if [Coalition, Organization].include?(@selected.class) %>
<% if @capacity.present? %>
<%= render "hub/dashboard/capacity" %>
<% end %>
<%= render "hub/dashboard/returns_by_status" %>
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,11 @@ en:
title: Add a new CTC client
dashboard:
show:
capacity: Capacity
current_capacity: Current Capacity
org_name: Organization Name
title: Dashboard
view_all: View All
documents:
confirm:
text: Is this a %{document_type} for %{client_name}'s %{filing_year} tax return?
Expand Down
4 changes: 4 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,11 @@ es:
title: Agregar un nuevo cliente
dashboard:
show:
capacity: Capacidad
current_capacity: Capacidad actual
org_name: Nombre de la Organización
title: Panel
view_all: Ver todo
documents:
confirm:
text: "¿Es esta una %{document_type} para la declaración de impuestos %{filing_year} de %{client_name}?"
Expand Down
36 changes: 36 additions & 0 deletions spec/controllers/hub/dashboard_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@
model = VitaPartner.first
expect(response).to redirect_to "/en/hub/dashboard/#{model.class.name.downcase}/#{model.id}"
end

context "with a nested set of Coalitions and Organizations" do
let(:coalition) { create :coalition }
let(:user) { create(:user, role: create(:coalition_lead_role, coalition: coalition)) }
let(:orgs) do
[
create(:organization, coalition: coalition),
create(:organization, coalition: coalition),
create(:organization, coalition: coalition)
]
end

it "sets filter options correctly" do
expected_filter_options = [
"coalition/#{coalition.id}",
"organization/#{orgs[0].id}",
"organization/#{orgs[1].id}",
"organization/#{orgs[2].id}"
]
get :index
expect(assigns(:filter_options).length).to eq 4
expect(assigns(:filter_options).map{|option| option.value }).to eq expected_filter_options
end
end
end
end

Expand All @@ -33,6 +57,18 @@
expect(assigns(:filter_options).length).to eq 1
expect(assigns(:filter_options)[0].model).to eq model
end

it "shows the capacity panel" do
model = VitaPartner.first
get :show, params: { id: model.id, type: model.class.name.downcase }
expect(response.body).to have_text I18n.t('hub.dashboard.show.capacity')
expect(response.body).to have_text I18n.t('hub.dashboard.show.org_name')
expect(response.body).to have_text Organization.first.name
# Count instances of substring - note: string.count doesn't do this!
expect(response.body.scan(/organization-link/).length).to eq(1)
end
end
end
end


0 comments on commit e91e952

Please sign in to comment.