diff --git a/app/assets/images/icons/warning.svg b/app/assets/images/icons/warning.svg new file mode 100644 index 0000000000..9dc44a252e --- /dev/null +++ b/app/assets/images/icons/warning.svg @@ -0,0 +1,3 @@ + diff --git a/app/assets/stylesheets/pages/dashboard.scss b/app/assets/stylesheets/pages/dashboard.scss index 2e8983d863..852d883db5 100644 --- a/app/assets/stylesheets/pages/dashboard.scss +++ b/app/assets/stylesheets/pages/dashboard.scss @@ -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; } } diff --git a/app/controllers/hub/dashboard_controller.rb b/app/controllers/hub/dashboard_controller.rb index 37f67348c2..3d8ace7f8c 100644 --- a/app/controllers/hub/dashboard_controller.rb +++ b/app/controllers/hub/dashboard_controller.rb @@ -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 @@ -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 @@ -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 \ No newline at end of file diff --git a/app/views/hub/dashboard/_capacity.html.erb b/app/views/hub/dashboard/_capacity.html.erb index 4ec7e85407..ef9194749f 100644 --- a/app/views/hub/dashboard/_capacity.html.erb +++ b/app/views/hub/dashboard/_capacity.html.erb @@ -1,4 +1,37 @@ -
TODO: Implement
+<%= I18n.t("hub.dashboard.show.org_name") %> | +<%= I18n.t("hub.dashboard.show.current_capacity") %> | +
---|---|
+ <%= link_to "#{organization.name}", + can?(:edit, organization) ? edit_hub_organization_path(id: organization) : hub_organization_path(id: organization), + class: "organization-link" + %> + | +
+
+
+ <%= organization.active_client_count %>/<%= organization.capacity_limit %>
+ <% if organization.active_client_count.to_f / organization.capacity_limit > 1 %>
+ <%= image_tag('icons/warning.svg', alt: "") %>
+ <% end %>
+ |
+