Skip to content

Commit

Permalink
Added sort order for project dashboards (#1091)
Browse files Browse the repository at this point in the history
  • Loading branch information
kelynch authored Dec 5, 2024
1 parent d75921b commit 6680269
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
4 changes: 4 additions & 0 deletions app/presenters/project_dashboard_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def last_activity
end
end

def updated_at
project.updated_at
end

def role(user)
if data_sponsor == user.uid
"Sponsor"
Expand Down
4 changes: 2 additions & 2 deletions app/views/welcome/_admin_listing.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<div class="section">
<h2>Pending Projects</h2>
<% if !@pending_projects.empty? %>
<%= render partial: "projects_listing", locals: { projects: @pending_projects, table_id: "projects-listing-pending" } %>
<%= render partial: "projects_listing", locals: { projects: @pending_projects.sort_by(&:updated_at), table_id: "projects-listing-pending" } %>
<% else %>
<p> (none) </p>
<% end %>
</div>
<div class="section">
<h2>Recently Approved Projects</h2>
<% if !@approved_projects.empty? %>
<%= render partial: "projects_listing", locals: { projects: @approved_projects, table_id: "projects-listing-approved"} %>
<%= render partial: "projects_listing", locals: { projects: @approved_projects.sort_by(&:updated_at).reverse, table_id: "projects-listing-approved"} %>
<% else %>
<p> (none) </p>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/welcome/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<button id="dash-admin" class="tab-nav"> Administration </button>
</div>
<% if @dash_session == "project"%>
<%= render partial: "projects_listing", locals: { projects: @dashboard_projects, table_id: "projects-listing" } %>
<%= render partial: "projects_listing", locals: { projects: @dashboard_projects.sort_by(&:updated_at).reverse, table_id: "projects-listing" } %>
<% elsif @dash_session == "activity" %>
<%= render partial: "recent_activity" %>
<% elsif @dash_session == "admin" %>
Expand Down
12 changes: 6 additions & 6 deletions spec/system/welcome_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,18 @@
end

it "paginates the projects; 8 per page" do
projects = (1..16).map { FactoryBot.create(:project, data_sponsor: other_user.uid, data_manager: other_user.uid, data_user_read_only: [current_user.uid]) }
projects = (1..17).map { FactoryBot.create(:project, data_sponsor: other_user.uid, data_manager: other_user.uid, data_user_read_only: [current_user.uid]) }
sign_in current_user
visit "/"
expect(page).to have_content("8 out of 17 shown")
expect(page).to have_content("8 out of 18 shown")
find("a.paginate_button", text: 2).click
expect(page).to have_content(projects[8].title)
expect(page).to have_content(projects.sort_by(&:updated_at).reverse[8].title)
find("a.paginate_button", text: 3).click
expect(page).to have_content(projects.last.title)
expect(page).to have_content(projects.sort_by(&:updated_at).reverse.last.title)
find("a.paginate_button", text: "<").click
expect(page).to have_content(projects[14].title)
expect(page).to have_content(projects.sort_by(&:updated_at).reverse[14].title)
find("a.paginate_button", text: "<").click
expect(page).to have_content(projects.first.title)
expect(page).to have_content(projects.sort_by(&:updated_at).reverse.first.title)
end
end

Expand Down

0 comments on commit 6680269

Please sign in to comment.