Display tag "new" on actions
An author will see a "new" tag on each action or resource that has appeared on his dashboard since his last login. Too add "new" tag on dashbord menu when there are new resources.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
class Dashboard::BaseController < ApplicationController
|
class Dashboard::BaseController < ApplicationController
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_user!, :detect_new_actions_after_last_login
|
||||||
|
|
||||||
include Dashboard::HasProposal
|
include Dashboard::HasProposal
|
||||||
|
|
||||||
@@ -35,4 +35,9 @@ class Dashboard::BaseController < ApplicationController
|
|||||||
def next_goal
|
def next_goal
|
||||||
@next_goal ||= Dashboard::Action.next_goal_for(proposal)
|
@next_goal ||= Dashboard::Action.next_goal_for(proposal)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def detect_new_actions_after_last_login
|
||||||
|
author_last_login = proposal.author.last_sign_in_at.to_date
|
||||||
|
@new_actions_since_last_login = Dashboard::Action.detect_new_actions_since(author_last_login, proposal)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -83,4 +83,12 @@ module ProposalsDashboardHelper
|
|||||||
return t("dashboard.resource.resource_requested") if resource.requested_for?(proposal)
|
return t("dashboard.resource.resource_requested") if resource.requested_for?(proposal)
|
||||||
t("dashboard.resource.request_resource")
|
t("dashboard.resource.request_resource")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_new_action_since_last_login?(proposed_action, new_actions_since_last_login)
|
||||||
|
new_actions_since_last_login.include?(proposed_action.id) if new_actions_since_last_login.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def new_resources_since_last_login?(resources, new_actions_since_last_login)
|
||||||
|
resources.pluck(:id).any? {|id| new_actions_since_last_login.include?(id) } if resources.present?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,12 +18,18 @@
|
|||||||
<%= link_to recommended_actions_proposal_dashboard_path(proposal.to_param) do %>
|
<%= link_to recommended_actions_proposal_dashboard_path(proposal.to_param) do %>
|
||||||
<strong><%= t("dashboard.menu.recommended_actions") %></strong>
|
<strong><%= t("dashboard.menu.recommended_actions") %></strong>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% if new_resources_since_last_login?(proposed_actions, @new_actions_since_last_login) %>
|
||||||
|
<span class="label"><%= t("dashboard.progress.new_action" ) %></span>
|
||||||
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<% if resources_menu_visible?(proposal, resources) %>
|
<% if resources_menu_visible?(proposal, resources) %>
|
||||||
<li class="section-title <%= 'is-active' if resources_menu_active? %>">
|
<li class="section-title <%= 'is-active' if resources_menu_active? %>">
|
||||||
<span class="icon-zip"></span>
|
<span class="icon-zip"></span>
|
||||||
<strong><%= t("dashboard.menu.resources") %></strong>
|
<strong><%= t("dashboard.menu.resources") %></strong>
|
||||||
|
<% if new_resources_since_last_login?(resources, @new_actions_since_last_login) %>
|
||||||
|
<span class="label"><%= t("dashboard.progress.new_action" ) %></span>
|
||||||
|
<% end %>
|
||||||
<ul class="no-bullet resources">
|
<ul class="no-bullet resources">
|
||||||
<% if can?(:manage_polls, proposal) %>
|
<% if can?(:manage_polls, proposal) %>
|
||||||
<li>
|
<li>
|
||||||
|
|||||||
@@ -12,6 +12,10 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
<div class="action-content">
|
<div class="action-content">
|
||||||
<h4><%= proposed_action.title %></h4>
|
<h4><%= proposed_action.title %></h4>
|
||||||
|
<% if is_new_action_since_last_login?(proposed_action, @new_actions_since_last_login) %>
|
||||||
|
<span class="label"><%= t("dashboard.progress.new_action") %></span>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<% if proposed_action.proposals.where(id: proposal.id).any? %>
|
<% if proposed_action.proposals.where(id: proposal.id).any? %>
|
||||||
<p class="inline">
|
<p class="inline">
|
||||||
<%= 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) %>
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
data-equalizer-watch="resources"
|
data-equalizer-watch="resources"
|
||||||
title="<%= resource_tooltip(resource, proposal) %>">
|
title="<%= resource_tooltip(resource, proposal) %>">
|
||||||
<h4><%= resource.title %></h4>
|
<h4><%= resource.title %></h4>
|
||||||
|
<% if is_new_action_since_last_login?(resource, @new_actions_since_last_login) %>
|
||||||
|
<span class="label"><%= t("dashboard.progress.new_action") %></span>
|
||||||
|
<% end %>
|
||||||
<p class="resource-description">
|
<p class="resource-description">
|
||||||
<%= resource.short_description %>
|
<%= resource.short_description %>
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -497,6 +497,7 @@ en:
|
|||||||
progress: Acumulated progress
|
progress: Acumulated progress
|
||||||
supports: Supports
|
supports: Supports
|
||||||
success: Ideal progress
|
success: Ideal progress
|
||||||
|
new_action: New
|
||||||
index:
|
index:
|
||||||
title: Edition
|
title: Edition
|
||||||
edit_proposal_link: Edit proposal
|
edit_proposal_link: Edit proposal
|
||||||
|
|||||||
@@ -497,6 +497,7 @@ es:
|
|||||||
progress: Progreso acumulado
|
progress: Progreso acumulado
|
||||||
supports: Apoyos
|
supports: Apoyos
|
||||||
success: Progreso ideal
|
success: Progreso ideal
|
||||||
|
new_action: Nuevo
|
||||||
index:
|
index:
|
||||||
title: Edición
|
title: Edición
|
||||||
edit_proposal_link: Editar propuesta
|
edit_proposal_link: Editar propuesta
|
||||||
|
|||||||
@@ -384,4 +384,74 @@ feature "Proposal's dashboard" do
|
|||||||
expect(page).to have_content("No recommended actions done")
|
expect(page).to have_content("No recommended actions done")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "detect_new_actions_after_last_login" do
|
||||||
|
|
||||||
|
before do
|
||||||
|
proposal.author.update(last_sign_in_at: Date.yesterday)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Display tag 'new' on resouce when it is new for author since last login" do
|
||||||
|
resource = create(:dashboard_action, :resource, :active, day_offset: 0, published_proposal: false)
|
||||||
|
|
||||||
|
visit progress_proposal_dashboard_path(proposal)
|
||||||
|
|
||||||
|
within "#dashboard_action_#{resource.id}" do
|
||||||
|
expect(page).to have_content('New')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Not display tag 'new' on resouce when there is not new resources since last login" do
|
||||||
|
resource = create(:dashboard_action, :resource, :active, day_offset: 0, published_proposal: false)
|
||||||
|
proposal.author.update(last_sign_in_at: Date.today)
|
||||||
|
|
||||||
|
visit progress_proposal_dashboard_path(proposal)
|
||||||
|
|
||||||
|
within "#dashboard_action_#{resource.id}" do
|
||||||
|
expect(page).not_to have_content('New')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Display tag 'new' on proposed_action when it is new for author since last login" do
|
||||||
|
proposed_action = create(:dashboard_action, :proposed_action, :active, day_offset: 0, published_proposal: false)
|
||||||
|
|
||||||
|
visit progress_proposal_dashboard_path(proposal)
|
||||||
|
|
||||||
|
within "#dashboard_action_#{proposed_action.id}" do
|
||||||
|
expect(page).to have_content('New')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Not display tag 'new' on proposed_action when there is not new proposed_action since last login" do
|
||||||
|
proposed_action = create(:dashboard_action, :proposed_action, :active, day_offset: 0, published_proposal: false)
|
||||||
|
proposal.author.update(last_sign_in_at: Date.today)
|
||||||
|
|
||||||
|
visit progress_proposal_dashboard_path(proposal)
|
||||||
|
|
||||||
|
within "#dashboard_action_#{proposed_action.id}" do
|
||||||
|
expect(page).not_to have_content('New')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Display tag 'new' on sidebar menu when there is a new resouce since last login" do
|
||||||
|
resource = create(:dashboard_action, :resource, :active, day_offset: 0, published_proposal: false)
|
||||||
|
|
||||||
|
visit progress_proposal_dashboard_path(proposal)
|
||||||
|
|
||||||
|
within "#side_menu" do
|
||||||
|
expect(page).to have_content('New')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Not display tag 'new' on sidebar menu when there is not a new resouce since last login" do
|
||||||
|
resource = create(:dashboard_action, :resource, :active, day_offset: 0, published_proposal: false)
|
||||||
|
proposal.author.update(last_sign_in_at: Date.today)
|
||||||
|
|
||||||
|
visit progress_proposal_dashboard_path(proposal)
|
||||||
|
|
||||||
|
within "#side_menu" do
|
||||||
|
expect(page).not_to have_content('New')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user