From 76eeabcf9043f94cfdf3d16c8b97c616f493c3c9 Mon Sep 17 00:00:00 2001 From: Claudia De Fazio Date: Tue, 8 Feb 2022 09:56:52 -0500 Subject: [PATCH] Fixing sorting urency and teams hierarchy --- app/controllers/static_pages_controller.rb | 1 - app/models/team.rb | 19 ++++++++++++++++++- app/views/static_pages/home.html.erb | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 048e9e3..7602001 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -33,7 +33,6 @@ def get_teams current_week = week_range(now.cwyear, now.cweek) @teams = Team.all.sort_by{|team| team.find_priority_weighted(current_week[:start_date], current_week[:end_date])|| "other" } @unsubmitted = {current_week: {}, previous_week: {}} - @priority = {current_week: {}, previous_week: {}} @teams.each do |team| @unsubmitted[:current_week][team.id] = team.users_not_submitted(team.current_feedback).map{|user| user.name} @unsubmitted[:previous_week][team.id] = team.users_not_submitted(team.current_feedback(now - 7.days)).map{|user| user.name} diff --git a/app/models/team.rb b/app/models/team.rb index e50dd56..dc128a3 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -132,6 +132,17 @@ def self.generate_team_code(length = 6) @@reverse_order_avg_rating = false + def week_range(cyear, cweek) + start_date = Date.commercial(cyear, cweek) + end_date = start_date.next_day(6) + + start_date = Time.zone.local(start_date.year, start_date.month, start_date.day) + end_date = Time.zone.local(end_date.year, end_date.month, end_date.day) + + {start_date: start_date.to_datetime.beginning_of_day, + end_date: end_date.to_datetime.end_of_day} + end + def self.order_by(field) if field == 'team_name' if @@reverse_order_avg_rating == false @@ -142,7 +153,13 @@ def self.order_by(field) return Team.order('team_name').reverse_order end else - return Team.order('team_name') + now = Time.zone.now.to_datetime + start_date = Date.commercial(now.cwyear, now.cweek) + end_date = start_date.next_day(6) + start_date = start_date.to_datetime.beginning_of_day + end_date = end_date.to_datetime.end_of_day + return Team.all.sort_by{|team| team.find_priority_weighted(start_date, end_date)|| "other" } end end + end diff --git a/app/views/static_pages/home.html.erb b/app/views/static_pages/home.html.erb index 5f3327b..5e86334 100644 --- a/app/views/static_pages/home.html.erb +++ b/app/views/static_pages/home.html.erb @@ -16,7 +16,7 @@ - Urgency/Intervention Level + <%= link_to 'Urgency/Intervention Level', root_path %> Average Rating (Out of 10) <%= link_to 'Team Name', root_path(order_by: 'team_name') %> Team Members