Skip to content

Commit

Permalink
Adding project quota to the datatable (#1077)
Browse files Browse the repository at this point in the history
* adding project quota to the datatable
adding storage capacity and usage to the dashboard presenter
passing the session id through the welcome controller

* creating a single return value for quota usage through the presenter
passing that value to the dashboard datatable
returning default values for non-approved projects

* re-naming variables for readability

* updating quota usage text

* first pass at creating css for quota progress bar

* second pass at creating css for progress bar

* adding progress bar to the datatable with a fixed height & width

* placing progress bar inline with the quota and defaulting it to a fixed 5 percent for un-approved projects

* refining table headings

* passing dash session variables in the index

* cleaning up unused code
  • Loading branch information
JaymeeH authored Dec 5, 2024
1 parent e976c51 commit d75921b
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,6 @@ project_create_8.txt

# Ignore rspec report
/spec/fixtures/failed_tests.txt

# Ignore prettier config
.prettierrc
11 changes: 11 additions & 0 deletions app/assets/stylesheets/_settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@
margin-left: 22em;
}

.w3-light-grey{
width: 10em;
margin-left: auto;
margin-right: 2em;
}

.quota-usage {
margin-left: auto;
padding-right: 2em;
}

#dashboard-nav{
@include tab-nav;
margin-top: 3em;
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ def index
@dashboard_projects = Project.users_projects(@current_user).map { |project| ProjectDashboardPresenter.new(project) }

@my_inventory_requests = current_user.user_requests.where(type: "FileInventoryRequest")
@dashtab = "project"
session[:dashtab] ||= @dashtab
@dashtab = session[:dashtab]
@dash_session = "project"
session[:dashtab] ||= @dash_session
@dash_session = session[:dashtab]
@session_id = current_user.mediaflux_session
end

def emulate
Expand Down
16 changes: 5 additions & 11 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,21 +234,15 @@ def self.default_storage_capacity
"0 GB"
end

def storage_capacity_xml

mediaflux_document.at_xpath("/request/service/args/meta/tigerdata:project/StorageCapacity/text()", tigerdata: "http://tigerdata.princeton.edu")
end

def storage_capacity(session_id:)
requested_capacity = storage_capacity_xml

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

backup_value = requested_capacity || self.class.default_storage_capacity #return the default storage capacity, if the requested capacity is nil

return backup_value if quota_value.blank?
quota_value #return the requested storage capacity if a quota has not been set for a project, if storage has not been requested return "0 GB"
if quota_value.blank?
return self.class.default_storage_capacity
else
return quota_value
end
end

# Fetches the first n files
Expand Down
9 changes: 9 additions & 0 deletions app/presenters/project_dashboard_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,13 @@ def role(user)
"Data User"
end
end

def quota_usage(session_id:)
quota_usage = "#{project.storage_usage(session_id:)} out of #{project.storage_capacity(session_id:)} used"
quota_usage
end

def quota_percentage(session_id:)
# figure out how to calculate percentage of storage used with different and unpredictable units
end
end
4 changes: 4 additions & 0 deletions app/views/welcome/_project_list_view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
</tr>
</table>
</a>
<div class="w3-light-grey w3-round-xlarge">
<div class="w3-orange w3-round-xlarge" style="height:6px;width:5%"></div>
</div>
</td>
<td class="status details <%= project.status.downcase %>"><%= project.status %></td>
<td class="project-type details"><%= project.type %></td>
<td class="user-role details"><%= project.role(current_user) %></td>
<td class="last-download details"><%= project.latest_file_list_time %></td>
<td class="last-activity details"><%= project.last_activity %></td>
<td class="quota-usage"><%= project.quota_usage(session_id: current_user.mediaflux_session) %></td>
</tr>
1 change: 1 addition & 0 deletions app/views/welcome/_projects_listing.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<th>role</th>
<th>download</th>
<th>activity</th>
<th>quota_usage</th>
</tr>
</thead>
<tbody>
Expand Down
11 changes: 6 additions & 5 deletions app/views/welcome/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<h1>Welcome to TigerData</h1>
Please log in.
<% else %>

<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">

<div class="welcome-pane">
<h1>Welcome, <%= current_user.given_name %>!</h1>
<div class="project-button">
Expand All @@ -17,11 +18,11 @@
<button id="dash-activity" class="tab-nav"> Activity </button>
<button id="dash-admin" class="tab-nav"> Administration </button>
</div>
<% if @dashtab == "project"%>
<% if @dash_session == "project"%>
<%= render partial: "projects_listing", locals: { projects: @dashboard_projects, table_id: "projects-listing" } %>
<% elsif @dashtab == "activity" %>
<% elsif @dash_session == "activity" %>
<%= render partial: "recent_activity" %>
<% elsif @dashtab == "admin" %>
<% elsif @dash_session == "admin" %>
<%= render partial: "admin_listing" %>
<% end %>
<% end %>
Expand All @@ -31,7 +32,7 @@
// Make the AJAX call for version information explicitly on this page
// (and for now only on this page) so that we don't make extra calls
// to Mediaflux for every page loaded.
dashStyle('<%= @dashtab %>');
dashStyle('<%= @dash_session %>');
dashTab();
displayMediafluxVersion('<%= mediaflux_info_index_path(format: "json") %>', <%= !current_user.nil? %>);

Expand Down

0 comments on commit d75921b

Please sign in to comment.