diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 75f2e0bc0..54fed6771 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -1,5 +1,6 @@ class DashboardController < Dashboard::BaseController helper_method :dashboard_action, :active_resources, :course + before_action :set_done_and_pending_actions, only: [:recommended_actions, :progress] def show authorize! :dashboard, proposal @@ -11,8 +12,8 @@ class DashboardController < Dashboard::BaseController proposal.publish redirect_to proposal_dashboard_path(proposal), notice: t('proposals.notice.published') end - - def progress + + def progress authorize! :dashboard, proposal end @@ -21,7 +22,7 @@ class DashboardController < Dashboard::BaseController end private - + def active_resources @active_resources ||= Dashboard::Action.active.resources.order(required_supports: :asc, day_offset: :asc) end @@ -29,4 +30,9 @@ class DashboardController < Dashboard::BaseController def course @course ||= Dashboard::Action.course_for(proposal) end + + def set_done_and_pending_actions + @done_actions = proposed_actions.joins(:proposals).where("proposals.id = ?", proposal.id) + @pending_actions = proposed_actions - @done_actions + end end diff --git a/app/views/dashboard/_proposed_action.html.erb b/app/views/dashboard/_proposed_action.html.erb index e3f17c320..87494365a 100644 --- a/app/views/dashboard/_proposed_action.html.erb +++ b/app/views/dashboard/_proposed_action.html.erb @@ -17,8 +17,8 @@ <% if proposed_action.proposals.where(id: proposal.id).any? %>

<%= l(proposed_action.executed_actions.find_by(proposal: proposal).executed_at.to_date) %>

<% else %> - <% if proposed_action.short_description.present? %> -

<%= proposed_action.short_description %>

+ <% if proposed_action.description.present? %> +

<%= proposed_action.description.html_safe %>

<% end %> <% proposed_action.links.each do |link| %> diff --git a/app/views/dashboard/_recommended_actions.html.erb b/app/views/dashboard/_recommended_actions.html.erb deleted file mode 100644 index 62daeac8d..000000000 --- a/app/views/dashboard/_recommended_actions.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -<% if proposed_actions.any? %> -

<%= t("dashboard.recommended_actions.title") %>

- - <%= render partial: 'proposed_action', collection: proposed_actions %> -<% end %> diff --git a/app/views/dashboard/_recommended_actions_by_status.html.erb b/app/views/dashboard/_recommended_actions_by_status.html.erb new file mode 100644 index 000000000..5077713d0 --- /dev/null +++ b/app/views/dashboard/_recommended_actions_by_status.html.erb @@ -0,0 +1,17 @@ +

<%= t("dashboard.recommended_actions.#{status}_title") %>

+<% if actions.any? %> +
+ <% actions.first(4).each do |proposed_action| %> + <%= render 'proposed_action', proposed_action: proposed_action %> + <% end %> + <% if actions.count > 4 %> +
+ <%= link_to recommended_actions_proposal_dashboard_path(proposal.to_param) do %> + <%= t("dashboard.recommended_actions.see_proposed_actions") %> + <% end %> +
+ <% end %> +
+<% else %> + <%= t("dashboard.recommended_actions.without_#{status}_actions") %> +<% end %> diff --git a/app/views/dashboard/_summary_recommended_actions.html.erb b/app/views/dashboard/_summary_recommended_actions.html.erb new file mode 100644 index 000000000..2a5428fbe --- /dev/null +++ b/app/views/dashboard/_summary_recommended_actions.html.erb @@ -0,0 +1,4 @@ +

<%= t("dashboard.recommended_actions.title") %>

+ +<%= render 'recommended_actions_by_status', status: 'pending', actions: @pending_actions, toggle: false %> +<%= render 'recommended_actions_by_status', status: 'done', actions: @done_actions, toggle: false %> diff --git a/app/views/dashboard/progress.html.erb b/app/views/dashboard/progress.html.erb index 03f1cd5c6..45b4547b9 100644 --- a/app/views/dashboard/progress.html.erb +++ b/app/views/dashboard/progress.html.erb @@ -33,5 +33,5 @@ <% end %> <%= render 'next_goal' %> -<%= render 'recommended_actions' %> +<%= render 'summary_recommended_actions' %> <%= render 'resources' %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 29d9a86ec..b3ff41e38 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -515,6 +515,10 @@ en: resource_locked: Resource locked recommended_actions: title: Recommended actions + see_proposed_actions: Check out recommended actions + hide_proposed_actions: Hide recommended actions + pending_title: Recommended actions pending + done_title: Recommended actions done next_goal: title: Goal see_complete_course: Check out the complete course diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 46422fd8c..41df3ce33 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -515,6 +515,10 @@ es: resource_locked: Recurso bloqueado recommended_actions: title: Acciones recomendadas + see_proposed_actions: Ver todas las acciones recomendadas + hide_proposed_actions: Ocultar acciones recomendadas + pending_title: Acciones recomendadas pendientes + done_title: Acciones recomendadas realizadas next_goal: title: Meta see_complete_course: Ver ruta completa diff --git a/spec/features/dashboard/dashboard_spec.rb b/spec/features/dashboard/dashboard_spec.rb index d2b433d6a..5ce77d6b3 100644 --- a/spec/features/dashboard/dashboard_spec.rb +++ b/spec/features/dashboard/dashboard_spec.rb @@ -49,6 +49,73 @@ feature "Proposal's dashboard" do scenario 'Dashboard progress show proposed actions' do action = create(:dashboard_action, :proposed_action, :active) + visit progress_proposal_dashboard_path(proposal) + + expect(page).to have_content(action.title) + end + + scenario "Dashboard progress do not display from the fourth proposed actions", js: true do + create_list(:dashboard_action, 4, :proposed_action, :active) + action_5 = create(:dashboard_action, :proposed_action, :active) + + visit progress_proposal_dashboard_path(proposal) + + expect(page).not_to have_content(action_5.title) + end + + scenario "Dashboard progress display link to new page for proposed actions when there are more than four proposed actions", js: true do + create_list(:dashboard_action, 4, :proposed_action, :active) + action_5 = create(:dashboard_action, :proposed_action, :active) + + visit progress_proposal_dashboard_path(proposal) + + expect(page).to have_link("Check out recommended actions") + end + + scenario "Dashboard progress do not display link to new page for proposed actions when there are less than five proposed actions", js: true do + create_list(:dashboard_action, 4, :proposed_action, :active) + + visit progress_proposal_dashboard_path(proposal) + + expect(page).not_to have_link("Check out recommended actions") + end + + scenario "Dashboard progress display proposed_action pending on his section" do + action = create(:dashboard_action, :proposed_action, :active) + + visit progress_proposal_dashboard_path(proposal) + + within "#proposed_actions_pending" do + expect(page).to have_content(action.title) + end + end + + scenario "Dashboard progress display no results text when there are not proposed_actions pending" do + visit progress_proposal_dashboard_path(proposal) + + expect(page).to have_content("No recommended actions pending") + end + + scenario "Dashboard progress display proposed_action done on his section" do + action = create(:dashboard_action, :proposed_action, :active) + + visit progress_proposal_dashboard_path(proposal) + find(:css, "#dashboard_action_#{action.id}_execute").click + + within "#proposed_actions_done" do + expect(page).to have_content(action.title) + end + end + + scenario "Dashboard progress display no results text when there are not proposed_actions pending" do + visit progress_proposal_dashboard_path(proposal) + + expect(page).to have_content("No recommended actions done") + end + + scenario "Dashboard progress can execute proposed action" do + action = create(:dashboard_action, :proposed_action, :active) + visit progress_proposal_dashboard_path(proposal) expect(page).to have_content(action.title)