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 @@ +
+
+ + + <%= t('.target_supports', count: number_with_precision(goal.required_supports, delimiter: '.', precision: 0)) %> + +
+
 
+ +
+ + <%= goal.title %> +
+
+

<%= t('.unlocked_resource') %>

+
+ + <% if goal.day_offset.positive? %> +
+ <%= t('.days', count: goal.day_offset) %> +
+
+

<%= t('.ideal_time') %>

+
+ <% end %> +
+ 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 @@
<%= t('.title') %>

-
-
- - - <%= t('.target_supports', count: number_with_precision(next_goal.required_supports, delimiter: '.', precision: 0)) %> - -
-
 
+ +
+ <%= render 'goal', goal: next_goal %>
- - <%= next_goal.title %> -
-
-

<%= t('.unlocked_resource') %>

-
- - <% if next_goal.day_offset.positive? %> -
- <%= t('.days', count: next_goal.day_offset) %> -
-
-

<%= t('.ideal_time') %>

-
- <% end %> - -
- <%= link_to t('.see_complete_course'), '#' %> + <%= t('.see_complete_course') %>
+ + <% if course.count > 1 %> +
+ <%= render partial: 'goal', collection: course %>, + + +
+ <% end %> <% end %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index f5de0f8dc..45e19f87e 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -540,6 +540,9 @@ en: title: Recommended actions next_goal: title: Goal + see_complete_course: Check out the complete course + hide_course: Hide course + goal: target_supports: one: Get %{count} support for your proposal other: Get %{count} supports for your proposal @@ -548,7 +551,6 @@ en: other: "%{count} days" unlocked_resource: Resource unlocked ideal_time: Ideal time - see_complete_course: Check out the complete course dashboard: polls: index: diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 48c28b069..39557c821 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -540,6 +540,9 @@ es: title: Acciones recomendadas next_goal: title: Meta + see_complete_course: Ver ruta completa + hide_course: Ocultar ruta + goal: target_supports: one: Consigue %{count} apoyo para tu propuesta other: Consigue %{count} apoyos para tu propuesta @@ -548,7 +551,6 @@ es: other: "%{count} días" unlocked_resource: Recurso desbloqueado ideal_time: Tiempo ideal - see_complete_course: Ver ruta completa dashboard: polls: index: