diff --git a/app/controllers/dashboard/actions_controller.rb b/app/controllers/dashboard/actions_controller.rb index 7035658ec..1e6119750 100644 --- a/app/controllers/dashboard/actions_controller.rb +++ b/app/controllers/dashboard/actions_controller.rb @@ -1,4 +1,4 @@ -class Dashboard::ActionsController < Dashboard::BaseController +class Dashboard::ActionsController < Dashboard::BaseController helper_method :dashboard_action def new_request @@ -10,8 +10,8 @@ class Dashboard::ActionsController < Dashboard::BaseController authorize! :dashboard, proposal source_params = { - proposal: proposal, - action: dashboard_action, + proposal: proposal, + action: dashboard_action, executed_at: Time.now } @@ -30,7 +30,7 @@ class Dashboard::ActionsController < Dashboard::BaseController authorize! :dashboard, proposal Dashboard::ExecutedAction.create(proposal: proposal, action: dashboard_action, executed_at: Time.now) - redirect_to progress_proposal_dashboard_path(proposal.to_param) + redirect_to request.referer end private @@ -39,4 +39,3 @@ class Dashboard::ActionsController < Dashboard::BaseController @dashboard_action ||= Dashboard::Action.find(params[:id]) end end - diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 54fed6771..56e351abb 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -21,6 +21,10 @@ class DashboardController < Dashboard::BaseController authorize! :dashboard, proposal end + def recommended_actions + authorize! :dashboard, proposal + end + private def active_resources diff --git a/app/helpers/proposals_dashboard_helper.rb b/app/helpers/proposals_dashboard_helper.rb index 3c5497fcb..58d468e1b 100644 --- a/app/helpers/proposals_dashboard_helper.rb +++ b/app/helpers/proposals_dashboard_helper.rb @@ -11,6 +11,10 @@ module ProposalsDashboardHelper is_proposed_action_request? || (controller_name == 'dashboard' && action_name == 'progress') end + def recommended_actions_menu_active? + controller_name == "dashboard" && action_name == "recommended_actions" + end + def resources_menu_visible?(proposal, resources) can?(:manage_polls, proposal) || resources.any? end diff --git a/app/views/dashboard/_menu.html.erb b/app/views/dashboard/_menu.html.erb index e5704fdde..463ad470c 100644 --- a/app/views/dashboard/_menu.html.erb +++ b/app/views/dashboard/_menu.html.erb @@ -13,6 +13,13 @@ <% end %> + + <% if resources_menu_visible?(proposal, resources) %>
  • diff --git a/app/views/dashboard/_recommended_actions_by_status.html.erb b/app/views/dashboard/_recommended_actions_by_status.html.erb index 5077713d0..551814732 100644 --- a/app/views/dashboard/_recommended_actions_by_status.html.erb +++ b/app/views/dashboard/_recommended_actions_by_status.html.erb @@ -1,17 +1,36 @@

    <%= 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 %>
    + <% if toggle == true %> + + <%= t("dashboard.recommended_actions.see_proposed_actions") %> + + <% else %> <%= link_to recommended_actions_proposal_dashboard_path(proposal.to_param) do %> <%= t("dashboard.recommended_actions.see_proposed_actions") %> <% end %> + <% end %>
    <% end %>
    + <% if toggle == true %> + <% if actions.count > 4 %> +
    + <%= render partial: 'proposed_action', collection: actions %> + + +
    + <% end %> + <% end %> <% else %> <%= t("dashboard.recommended_actions.without_#{status}_actions") %> <% end %> diff --git a/app/views/dashboard/recommended_actions.html.erb b/app/views/dashboard/recommended_actions.html.erb new file mode 100644 index 000000000..47a4215d4 --- /dev/null +++ b/app/views/dashboard/recommended_actions.html.erb @@ -0,0 +1,4 @@ +

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

    + +<%= render 'recommended_actions_by_status', status: 'pending', actions: @pending_actions, toggle: true %> +<%= render 'recommended_actions_by_status', status: 'done', actions: @done_actions, toggle: true %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index b3ff41e38..b9bc95107 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -484,6 +484,7 @@ en: polls: Polls mailing: E-mail poster: Poster + recommended_actions: Recommended actions form: request: Request create_request: @@ -518,7 +519,9 @@ en: see_proposed_actions: Check out recommended actions hide_proposed_actions: Hide recommended actions pending_title: Recommended actions pending + without_pending_actions: No recommended actions pending done_title: Recommended actions done + without_done_actions: No 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 41df3ce33..b76d05804 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -484,6 +484,7 @@ es: polls: Encuestas mailing: Correo electrónico poster: Póster + recommended_actions: Acciones recomendadas form: request: Solicitar create_request: @@ -518,7 +519,9 @@ es: see_proposed_actions: Ver todas las acciones recomendadas hide_proposed_actions: Ocultar acciones recomendadas pending_title: Acciones recomendadas pendientes + without_pending_actions: No hay acciones recomendadas pendientes done_title: Acciones recomendadas realizadas + without_done_actions: No hay acciones recomendadas realizadas next_goal: title: Meta see_complete_course: Ver ruta completa diff --git a/config/routes/proposal.rb b/config/routes/proposal.rb index ad4dd8e2d..5d74d2ea2 100644 --- a/config/routes/proposal.rb +++ b/config/routes/proposal.rb @@ -4,6 +4,7 @@ resources :proposals do patch :publish get :progress get :community + get :recommended_actions end resources :resources, only: [:index], controller: 'dashboard/resources' diff --git a/spec/features/dashboard/dashboard_spec.rb b/spec/features/dashboard/dashboard_spec.rb index 5ce77d6b3..8f1043dc2 100644 --- a/spec/features/dashboard/dashboard_spec.rb +++ b/spec/features/dashboard/dashboard_spec.rb @@ -63,7 +63,8 @@ feature "Proposal's dashboard" do 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 + 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) @@ -72,7 +73,8 @@ feature "Proposal's dashboard" do 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 + 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) @@ -90,7 +92,8 @@ feature "Proposal's dashboard" do end end - scenario "Dashboard progress display no results text when there are not proposed_actions pending" do + scenario "Dashboard progress display contains 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") @@ -107,7 +110,8 @@ feature "Proposal's dashboard" do end end - scenario "Dashboard progress display no results text when there are not proposed_actions pending" do + scenario "Dashboard progress display contains 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") @@ -223,4 +227,88 @@ feature "Proposal's dashboard" do expect(page).to have_content('Comments') expect(page).to have_link('Access the community') end + + scenario "Dashboard has a link to recommended_actions", js: true do + expect(page).to have_link("Recommended actions") + click_link "Recommended actions" + + expect(page).to have_content("Recommended actions") + expect(page).to have_content("Recommended actions pending") + expect(page).to have_content("Recommended actions done") + end + + scenario "On recommended actions section display from the fourth proposed actions + when click see_proposed_actions_link", js: true do + create_list(:dashboard_action, 4, :proposed_action, :active) + action_5 = create(:dashboard_action, :proposed_action, :active) + + visit recommended_actions_proposal_dashboard_path(proposal.to_param) + find(:css, "#see_proposed_actions_link_pending").click + + expect(page).to have_content(action_5.title) + end + + scenario "On recommended actions section 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 recommended_actions_proposal_dashboard_path(proposal.to_param) + + expect(page).not_to have_content(action_5.title) + end + + scenario "On recommended actions section display link for toggle 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 recommended_actions_proposal_dashboard_path(proposal.to_param) + + expect(page).to have_content("Check out recommended actions") + end + + scenario "On recommended actions section do not display link for toggle when + there are less than five proposed actions", js: true do + create_list(:dashboard_action, 4, :proposed_action, :active) + + visit recommended_actions_proposal_dashboard_path(proposal.to_param) + + expect(page).not_to have_link("Check out recommended actions") + end + + scenario "On recommended actions section display proposed_action pending on his section" do + action = create(:dashboard_action, :proposed_action, :active) + + visit recommended_actions_proposal_dashboard_path(proposal.to_param) + + within "#proposed_actions_pending" do + expect(page).to have_content(action.title) + end + end + + scenario "On recommended actions section contains no_results_text when there are + not proposed_actions pending" do + visit recommended_actions_proposal_dashboard_path(proposal.to_param) + + expect(page).to have_content("No recommended actions pending") + end + + scenario "On recommended actions section display proposed_action done on his section" do + action = create(:dashboard_action, :proposed_action, :active) + + visit recommended_actions_proposal_dashboard_path(proposal.to_param) + find(:css, "#dashboard_action_#{action.id}_execute").click + + within "#proposed_actions_done" do + expect(page).to have_content(action.title) + end + end + + scenario "On recommended actions section contains 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 + end