diff --git a/app/controllers/proposals_dashboard_controller.rb b/app/controllers/proposals_dashboard_controller.rb index 2fb86587d..04e79b9f4 100644 --- a/app/controllers/proposals_dashboard_controller.rb +++ b/app/controllers/proposals_dashboard_controller.rb @@ -1,5 +1,5 @@ class ProposalsDashboardController < Dashboard::BaseController - helper_method :proposal_dashboard_action, :active_resources + helper_method :proposal_dashboard_action, :active_resources, :course def index authorize! :dashboard, proposal @@ -69,6 +69,10 @@ class ProposalsDashboardController < Dashboard::BaseController end def active_resources - ProposalDashboardAction.active.resources.order(required_supports: :asc, day_offset: :asc) + @active_resources ||= ProposalDashboardAction.active.resources.order(required_supports: :asc, day_offset: :asc) + end + + def course + @course ||= ProposalDashboardAction.course_for(proposal) end end diff --git a/app/models/proposal_dashboard_action.rb b/app/models/proposal_dashboard_action.rb index 7247c8dc7..3efd2cb87 100644 --- a/app/models/proposal_dashboard_action.rb +++ b/app/models/proposal_dashboard_action.rb @@ -51,6 +51,13 @@ class ProposalDashboardAction < ActiveRecord::Base .where('day_offset <= ?', (Date.today - published_at).to_i) end + scope :course_for, lambda { |proposal| + active + .resources + .where('required_supports > ?', proposal.votes_for.size) + .order(required_supports: :asc) + } + def active_for?(proposal) published_at = proposal.published_at&.to_date || Date.today @@ -58,10 +65,7 @@ class ProposalDashboardAction < ActiveRecord::Base end def self.next_goal_for(proposal) - active - .where('required_supports > ?', proposal.votes_for.size) - .order(required_supports: :asc) - &.first + course_for(proposal).first end def request_to_administrators? diff --git a/app/views/proposals_dashboard/_goal.html.erb b/app/views/proposals_dashboard/_goal.html.erb new file mode 100644 index 000000000..4116fecd5 --- /dev/null +++ b/app/views/proposals_dashboard/_goal.html.erb @@ -0,0 +1,27 @@ +
+ diff --git a/app/views/proposals_dashboard/_next_goal.html.erb b/app/views/proposals_dashboard/_next_goal.html.erb index dcb425125..e2c36e284 100644 --- a/app/views/proposals_dashboard/_next_goal.html.erb +++ b/app/views/proposals_dashboard/_next_goal.html.erb @@ -4,34 +4,22 @@