diff --git a/app/assets/stylesheets/dashboard.scss b/app/assets/stylesheets/dashboard.scss index a61301d24..82c9804df 100644 --- a/app/assets/stylesheets/dashboard.scss +++ b/app/assets/stylesheets/dashboard.scss @@ -99,6 +99,7 @@ .action-content { display: inline-block; margin-left: $line-height / 4; + max-width: 90%; h4, p { 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 4ba6a6edb..6bc3f2059 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 @@ -20,6 +21,10 @@ class DashboardController < Dashboard::BaseController authorize! :dashboard, proposal end + def recommended_actions + authorize! :dashboard, proposal + end + private def active_resources @@ -32,4 +37,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/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/_proposed_action.html.erb b/app/views/dashboard/_proposed_action.html.erb index e3f17c320..5c653efef 100644 --- a/app/views/dashboard/_proposed_action.html.erb +++ b/app/views/dashboard/_proposed_action.html.erb @@ -10,21 +10,32 @@ <% end %> <% end %> -

    <%= proposed_action.title %>

    - <% 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 %>

    +

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

    + <% if proposed_action.description.present? %> + + <%= t("dashboard.recommended_actions.show_description") %> + +
    + <%= proposed_action.description.html_safe %> +
    + <% end %> + <% else %> + <% if proposed_action.description.present? %> + + <%= t("dashboard.recommended_actions.show_description") %> + +
    + <%= proposed_action.description.html_safe %> +
    <% end %> - <% proposed_action.links.each do |link| %>

    <%= link_to link.label, link.url, target: "_blank" %>

    <% end %> - <%= render partial: 'document', collection: proposed_action.documents %> <% end %>
    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..6d1833014 --- /dev/null +++ b/app/views/dashboard/_recommended_actions_by_status.html.erb @@ -0,0 +1,35 @@ +

    <%= 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 %> + + <% end %> +
    + <% if toggle == true %> + <% if actions.count > 4 %> +
    + <%= render partial: 'proposed_action', collection: actions - actions.first(4) %> + +
    + <% 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..5df780197 --- /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/app/views/dashboard/recommended_actions.html.erb b/app/views/dashboard/recommended_actions.html.erb new file mode 100644 index 000000000..ba75afe10 --- /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/i18n-tasks.yml b/config/i18n-tasks.yml index cef2c8f97..865bcaeea 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -167,6 +167,7 @@ ignore_unused: - 'polls.index.filters.*' - 'polls.index.section_header.*' - 'polls.index.orders.*' + - 'dashboard.recommended_actions.*' - 'debates.index.select_order' - 'debates.index.orders.*' - 'debates.index.section_header.*' diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index b1d00f0f3..c3a0bc3c9 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: @@ -515,6 +516,14 @@ en: resource_locked: Resource locked recommended_actions: title: Recommended actions + goto_proposed_actions: Go to recommended actions + see_proposed_actions: Check out recommended actions + hide_proposed_actions: Hide recommended actions + pending_title: Pending + show_description: Show description + without_pending_actions: No recommended actions pending + done_title: 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 c2b4f69ce..b5aaeb310 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: @@ -515,6 +516,14 @@ es: resource_locked: Recurso bloqueado recommended_actions: title: Acciones recomendadas + goto_proposed_actions: Ir a las acciones recomendadas + see_proposed_actions: Ver todas las acciones recomendadas + hide_proposed_actions: Ocultar acciones recomendadas + pending_title: Pendientes + show_description: Mostrar descripción + without_pending_actions: No hay acciones recomendadas pendientes + done_title: 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 c10735046..85bd04aaf 100644 --- a/spec/features/dashboard/dashboard_spec.rb +++ b/spec/features/dashboard/dashboard_spec.rb @@ -49,6 +49,77 @@ 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("Go to 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 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") + 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 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 + + 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) @@ -229,4 +300,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("Pending") + expect(page).to have_content("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