Skip to content

Commit

Permalink
Refining progress bar (#1095)
Browse files Browse the repository at this point in the history
* updating dashboard presenter so quota usage has its own pending message

* calculating the quota usage percentage based on the raw bytes of used and allocated storage

* Update app/presenters/project_dashboard_presenter.rb

Co-authored-by: carolyncole <[email protected]>

---------

Co-authored-by: carolyncole <[email protected]>
  • Loading branch information
JaymeeH and carolyncole authored Dec 9, 2024
1 parent a85bddc commit 5297d89
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
11 changes: 8 additions & 3 deletions app/models/mediaflux/asset_metadata_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ def metadata
if metadata[:collection]
metadata[:total_file_count] = asset.xpath("./collection/accumulator/value/non-collections").text
metadata[:size] = asset.xpath("./collection/accumulator/value/total/@h").text
metadata[:quota_allocation] = asset.xpath("./collection/quota/allocation/@h").text
metadata[:accum_names] = asset.xpath("./collection/accumulator/@name")
metadata[:quota_used] = asset.xpath("./collection/quota/used/@h").text
metadata[:ctime] = asset.xpath("./ctime")

end

parse_image(asset.xpath("./meta/mf-image"), metadata) # this does not do anything because mf-image is not a part of the meta xpath

parse_note(asset.xpath("./meta/mf-note"), metadata) # this does not do anything because mf-note is not a part of the meta xpath

parse_quota(asset.xpath("./collection/quota"), metadata)
metadata
end

Expand All @@ -66,6 +64,13 @@ def parse_image(image, metadata)
end
end

def parse_quota(quota, metadata)
metadata[:quota_allocation] = quota.xpath("./allocation/@h").text
metadata[:quota_allocation_raw] = quota.xpath("./allocation").text.to_i
metadata[:quota_used] = quota.xpath("./used/@h").text
metadata[:quota_used_raw] = quota.xpath("./used").text.to_i
end

# Update this to match full 0.6.1 schema
def parse(asset)
{
Expand Down
16 changes: 12 additions & 4 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,7 @@ def self.default_storage_usage
end

def storage_usage(session_id:)
return unless in_mediaflux?

values = mediaflux_metadata(session_id:)
#value = values.fetch(:size, 0)
quota_value = values.fetch(:quota_used, '')

if quota_value.blank?
Expand All @@ -230,21 +227,32 @@ def storage_usage(session_id:)
end
end

def storage_usage_raw(session_id:)
values = mediaflux_metadata(session_id:)
quota_value = values.fetch(:quota_used_raw, 0)
quota_value
end

def self.default_storage_capacity
"0 GB"
end

def storage_capacity(session_id:)
values = mediaflux_metadata(session_id:)
quota_value = values.fetch(:quota_allocation, '') #if quota does not exist, set value to an empty string

if quota_value.blank?
return self.class.default_storage_capacity
else
return quota_value
end
end

def storage_capacity_raw(session_id:)
values = mediaflux_metadata(session_id:)
quota_value = values.fetch(:quota_allocation_raw, 0) #if quota does not exist, set value to 0
quota_value
end

# Fetches the first n files
def file_list(session_id:, size: 10)
return { files: [] } if mediaflux_id.nil?
Expand Down
12 changes: 9 additions & 3 deletions app/presenters/project_dashboard_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def last_activity

def updated_at
project.updated_at
end
end

def role(user)
if data_sponsor == user.uid
Expand All @@ -46,11 +46,17 @@ def role(user)
end

def quota_usage(session_id:)
quota_usage = "#{project.storage_usage(session_id:)} out of #{project.storage_capacity(session_id:)} used"
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:)
# figure out how to calculate percentage of storage used with different and unpredictable units
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
2 changes: 1 addition & 1 deletion app/views/welcome/_project_list_view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</table>
</a>
<div class="w3-light-grey w3-round-xlarge">
<div class="w3-orange w3-round-xlarge" style="height:6px;width:5%"></div>
<div class="w3-orange w3-round-xlarge" style="height:6px;width:<%= project.quota_percentage(session_id: current_user.mediaflux_session) %>%"></div>
</div>
</td>
<td class="status details <%= project.status.downcase %>"><%= project.status %></td>
Expand Down

0 comments on commit 5297d89

Please sign in to comment.