From 45afbc0b104bf19a93c3ba431029c015143c9fe1 Mon Sep 17 00:00:00 2001 From: taitus Date: Fri, 11 Jan 2019 13:13:58 +0100 Subject: [PATCH 1/7] New summary for recommended actions section on progress page - Divide recommended actions into actions done and actions pending. - Display recomended actions as goals (diplay four by defalut) without toggle but with link to new recommended actions page. - Display description over short_description --- app/controllers/dashboard_controller.rb | 12 +++- app/views/dashboard/_proposed_action.html.erb | 4 +- .../dashboard/_recommended_actions.html.erb | 5 -- .../_recommended_actions_by_status.html.erb | 17 +++++ .../_summary_recommended_actions.html.erb | 4 ++ app/views/dashboard/progress.html.erb | 2 +- config/locales/en/general.yml | 4 ++ config/locales/es/general.yml | 4 ++ spec/features/dashboard/dashboard_spec.rb | 67 +++++++++++++++++++ 9 files changed, 108 insertions(+), 11 deletions(-) delete mode 100644 app/views/dashboard/_recommended_actions.html.erb create mode 100644 app/views/dashboard/_recommended_actions_by_status.html.erb create mode 100644 app/views/dashboard/_summary_recommended_actions.html.erb 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) From 487c485fe087a7f85a988fe2515da0828c9d8d84 Mon Sep 17 00:00:00 2001 From: taitus Date: Fri, 11 Jan 2019 13:14:47 +0100 Subject: [PATCH 2/7] Add new section on sidebar menu for recommended proposals - Display recommended_proposals on new section as goals with toogle. - Divide recommended actions into actions done and actions pending to clarify the information to the user as summary_recomended_actions. --- .../dashboard/actions_controller.rb | 9 +- app/controllers/dashboard_controller.rb | 4 + app/helpers/proposals_dashboard_helper.rb | 4 + app/views/dashboard/_menu.html.erb | 7 ++ .../_recommended_actions_by_status.html.erb | 21 +++- .../dashboard/recommended_actions.html.erb | 4 + config/locales/en/general.yml | 3 + config/locales/es/general.yml | 3 + config/routes/proposal.rb | 1 + spec/features/dashboard/dashboard_spec.rb | 96 ++++++++++++++++++- 10 files changed, 142 insertions(+), 10 deletions(-) create mode 100644 app/views/dashboard/recommended_actions.html.erb 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 From 4d242bf50d4f3ece7f2a82ac5ff4f1da91a93a78 Mon Sep 17 00:00:00 2001 From: Alessandro Cuoghi Date: Mon, 4 Feb 2019 15:49:22 +0100 Subject: [PATCH 3/7] Add toggle description to proposed action --- app/views/dashboard/_proposed_action.html.erb | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/app/views/dashboard/_proposed_action.html.erb b/app/views/dashboard/_proposed_action.html.erb index 87494365a..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) %>

    +

    + <%= 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? %> -

    <%= proposed_action.description.html_safe %>

    + + <%= 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 %>
    From 980f0d4283bb3e859a806f4e4b72131bc2796117 Mon Sep 17 00:00:00 2001 From: Alessandro Cuoghi Date: Mon, 4 Feb 2019 15:57:17 +0100 Subject: [PATCH 4/7] Allow toggle for pending proposal and done proposal --- .../_recommended_actions_by_status.html.erb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/views/dashboard/_recommended_actions_by_status.html.erb b/app/views/dashboard/_recommended_actions_by_status.html.erb index 551814732..64f4c93e9 100644 --- a/app/views/dashboard/_recommended_actions_by_status.html.erb +++ b/app/views/dashboard/_recommended_actions_by_status.html.erb @@ -1,14 +1,14 @@

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