Skip to content

Commit

Permalink
Change the show details to utilize the dashboard size presenter metho…
Browse files Browse the repository at this point in the history
…ds (#1250)

fixes #1249
  • Loading branch information
carolyncole authored Jan 27, 2025
1 parent a2c5ca0 commit fbdd755
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 55 deletions.
11 changes: 2 additions & 9 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,12 @@ def self.default_storage_usage

def storage_usage(session_id:)
values = mediaflux_metadata(session_id:)
quota_value = values.fetch(:quota_used, '')

if quota_value.blank?
return self.class.default_storage_usage
else
return quota_value
end
values.fetch(:quota_used, self.class.default_storage_usage) # if the storage is empty use the default
end

def storage_usage_raw(session_id:)
values = mediaflux_metadata(session_id:)
quota_value = values.fetch(:quota_used_raw, 0)
quota_value
values.fetch(:quota_used_raw, 0) # if the storage raw is empty use zero
end

def self.default_storage_capacity
Expand Down
21 changes: 1 addition & 20 deletions app/presenters/project_dashboard_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class ProjectDashboardPresenter < ProjectShowPresenter
include ActionView::Helpers::DateHelper

delegate :to_model, to: :project
delegate :to_model, :updated_at, to: :project

delegate :data_sponsor, :data_manager, to: :project_metadata

Expand Down Expand Up @@ -33,10 +33,6 @@ def last_activity
end
end

def updated_at
project.updated_at
end

def role(user)
if data_sponsor == user.uid
"Sponsor"
Expand All @@ -46,19 +42,4 @@ def role(user)
"Data User"
end
end

def quota_usage(session_id:)
if project.pending?
quota_usage = "0 KB out of 0 GB used"
else
quota_usage = "#{project.storage_usage(session_id:)} out of #{project.storage_capacity(session_id:)} used"
end
quota_usage
end

def quota_percentage(session_id:)
return 0 if project.pending? || project.storage_capacity_raw(session_id:).zero?

(project.storage_usage_raw(session_id:).to_f / project.storage_capacity_raw(session_id:).to_f) * 100
end
end
30 changes: 15 additions & 15 deletions app/presenters/project_show_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ def storage_usage(session_id:)
value*default_usage_divisor
end

def formatted_storage_usage(session_id:)
value = storage_usage(session_id: session_id)
format("%.3f", value)
end

def storage_capacity(session_id: nil)
return project_metadata.storage_capacity if session_id.nil?

Expand All @@ -58,21 +53,26 @@ def formatted_storage_capacity(session_id:)
format("%.3f", value)
end

def formatted_storage_remaining(session_id:)
value = storage_remaining(session_id:)
def formatted_quota_percentage(session_id:)
value = quota_percentage(session_id:)
format("%.3f", value)
end

def storage_usage_percent(session_id:)
capacity = storage_capacity(session_id: session_id)
return 0.0 if capacity.zero?

usage = storage_usage(session_id: session_id)

value = (usage/(capacity/default_capacity_divisor))*100.0
format("%.1f", value)
def quota_usage(session_id:)
if project.pending?
quota_usage = "0 KB out of 0 GB used"
else
quota_usage = "#{project.storage_usage(session_id:)} out of #{project.storage_capacity(session_id:)} used"
end
quota_usage
end

def quota_percentage(session_id:)
return 0 if project.pending? || project.storage_capacity_raw(session_id:).zero?

(project.storage_usage_raw(session_id:).to_f / project.storage_capacity_raw(session_id:).to_f) * 100
end

private

def default_usage_divisor
Expand Down
11 changes: 3 additions & 8 deletions app/views/projects/_project_details_heading.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,12 @@
</div>
</div>
<div class="row my-2">
<div class="progress" role="progressbar" aria-label="Storage quota usage" aria-valuenow="<%= @project.storage_usage_percent(session_id: current_user.mediaflux_session) %>" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar" style="width: <%= @project.storage_usage_percent(session_id: current_user.mediaflux_session) %>%"></div>
<div class="progress" role="progressbar" aria-label="Storage quota usage" aria-valuenow="<%= @project.formatted_quota_percentage(session_id: current_user.mediaflux_session) %>" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar" style="width: <%= @project.quota_percentage(session_id: current_user.mediaflux_session) %>%"></div>
</div>
</div>
<div class="row my-2">
<div class="col-6">
<%= @project.formatted_storage_usage(session_id: current_user.mediaflux_session) %> KB Used
</div>
<div class="col-6 text-secondary text-end">
<%= @project.formatted_storage_remaining(session_id: current_user.mediaflux_session) %> GB Free
</div>
<%= @project.quota_usage(session_id: current_user.mediaflux_session) %>
</div>
</div>
</div><!-- .row -->
Expand Down
5 changes: 2 additions & 3 deletions spec/system/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@
description: "hello world",
data_user_read_only: [read_only.uid],
data_user_read_write: [read_write.uid],
status: ::Project::PENDING_STATUS,
status: ::Project::APPROVED_STATUS,
created_on: Time.current.in_time_zone("America/New_York").iso8601,
created_by: FactoryBot.create(:user).uid,
project_id: "abc-123",
Expand All @@ -631,8 +631,7 @@
visit project_path(approved_project)

expect(page).to have_content "Storage (500.000 GB)"
expect(page).to have_content "0.400 KB Used"
expect(page).to have_content "500.000 GB Free"
expect(page).to have_content "400 bytes out of 500 GB used"
expect(page).to be_axe_clean
.according_to(:wcag2a, :wcag2aa, :wcag21a, :wcag21aa, :section508)
.skipping(:'color-contrast')
Expand Down

0 comments on commit fbdd755

Please sign in to comment.