Skip to content

Commit

Permalink
add filters for events in the user menu
Browse files Browse the repository at this point in the history
  • Loading branch information
raul-fuentes committed Dec 21, 2017
1 parent 8a42735 commit 804a655
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 57 deletions.
11 changes: 11 additions & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class AdminController < ApplicationController
include PublicActivity::StoreController

before_action :authenticate_user!
before_action :events_root_path
layout 'admin'
rescue_from CanCan::AccessDenied do |exception|
redirect_to admin_path, :alert => t('backend.access_denied')
Expand All @@ -12,4 +13,14 @@ class AdminController < ApplicationController
hide_action :current_user
hide_action :get_title

def events_root_path
if current_user.user?
@events_path = events_path({"utf8"=>"✓", "search_title"=>"", "search_person"=>"",
"status"=>["requested", "declined"], "lobby_activity"=>"1",
"controller"=>"events", "action"=>"index"})
else
@events_path = events_path
end
end

end
6 changes: 3 additions & 3 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def create
@event = Event.new(event_params)
@event.user = current_user
if @event.save
redirect_to events_path, notice: t('backend.successfully_created_record')
redirect_to @events_path, notice: t('backend.successfully_created_record')
else
flash[:alert] = t('backend.review_errors')
render :new
Expand All @@ -29,7 +29,7 @@ def edit; end
def update
@event.user = current_user
if @event.update_attributes(event_params)
redirect_to events_path, notice: t('backend.successfully_updated_record')
redirect_to @events_path, notice: t('backend.successfully_updated_record')
else
set_holders
flash[:alert] = t('backend.review_errors')
Expand All @@ -39,7 +39,7 @@ def update

def destroy
@event.destroy
redirect_to events_path, notice: t('backend.successfully_destroyed_record')
redirect_to @events_path, notice: t('backend.successfully_destroyed_record')
end

def get_title
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/uweb_access_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def uweb_sign_in
@uweb_api.get_user_status(params[:clave_usuario],params[:fecha_conexion]).zero? &&
@user = User.find_by(user_key: params[:clave_usuario])
sign_in(:user, @user)
redirect_to events_path
redirect_to @events_path
else
redirect_to root_path
end
Expand Down
32 changes: 30 additions & 2 deletions app/helpers/admin/sidebar_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
module Admin::SidebarHelper

def active_menu(model, action=nil)
'active'.html_safe if params[:controller] == model && current_action?(action)
def active_menu(model, action=nil, shortcut = nil)
if active?(model, shortcut, action)
return 'active'.html_safe
end
end

def event_fixed_filters
{ 'tray' => {"utf8" => "✓", "search_title" => "", "search_person" => "",
"status" => ["requested", "declined"], "lobby_activity" => "1",
"controller" => "events", "action" => "index"} ,
'events' => {"utf8" => "✓", "search_title" => "", "search_person" => "",
"status" => ["accepted", "done", "canceled"],
"controller" => "events", "action" => "index"} }
end

private
Expand All @@ -10,4 +21,21 @@ def current_action?(action)
action.nil? || (params[:action] == action || params[:show] == action)
end

def event_filters?(shortcut)
event_fixed_filters[shortcut] == request.env['action_dispatch.request.parameters']
end

def unfiltered?
!(event_fixed_filters.values.include? request.env['action_dispatch.request.parameters'])
end

def active?(model, shortcut, action)
# common comprobation for active link excluding events controller
(params[:controller] == model && current_action?(action) && shortcut.nil? && unfiltered? ) ||
# activaction for the two event lionks
event_filters?(shortcut) ||
# edit, and new avent activate :tray link
(params[:controller] == model && current_action?(action) && shortcut == 'tray' && unfiltered? )
end

end
2 changes: 1 addition & 1 deletion app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
<%= submit_tag t('backend.save_request'), :class=> "button radius success right" %>
<% else %>
<%= submit_tag t('backend.save'), :class=> "button radius success right" %>
<%= link_to t('backend.exit_without_save'), events_path, class: "button radius alert right" %>
<%= link_to t('backend.exit_without_save'), @events_path, class: "button radius alert right" %>
<% end %>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="small-12 mt5">
<h1><%= t('backend.edit_event')%></h1>
<%= link_to t('backend.back'), events_path , :class=> "button tiny radius" %>
<%= link_to t('backend.back'), :back , :class=> "button tiny radius" %>
</div>

<%= render :partial => 'form' %>
2 changes: 1 addition & 1 deletion app/views/events/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="small-12 mt5">
<h1><%= t('backend.new_event')%></h1>
<%= link_to t('backend.back'), events_path , :class=> "button tiny radius" %>
<%= link_to t('backend.back'), :back , :class=> "button tiny radius" %>
</div>

<%= render :partial => 'form' %>
126 changes: 83 additions & 43 deletions app/views/events/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,46 +1,86 @@
<div class="event-show-admin">
<h3><%= @event.title %></h3>
<%= link_to t('backend.edit'), edit_event_path(@event), :class=> "button tiny radius success" if can? :edit, @event%>
<%= link_to t('backend.back'), events_path , :class=> "button tiny radius" %>
<fieldset>
<legend><%= t('backend.basic_data') %></legend>
<p>
<strong><%= t('backend.holder') %></strong>
<%= @event.position.holder.full_name %>
</p>
<p>
<strong><%= t('backend.title') %></strong>
<%= @event.title %>
</p>
<p>
<strong><%= t('backend.location') %></strong>
<%= @event.location %>
</p>
<p>
<strong><%= t('backend.date') %></strong>
<%= I18n.l @event.scheduled, format: :short if @event.scheduled.present? %>
</p>
<p>
<strong><%= t('backend.description') %></strong>
<%= @event.description.html_safe if @event.description.present? %>
</p>
</fieldset>
<% if @event.user.present? %>
<fieldset>
<legend><%= t('backend.event_history_updates') %></legend>
<div class="row">
<div class="small-6 columns">
<p>
<strong><%= t('backend.event_update_user') %></strong>
<%= @event.user.full_name %>
</p>
</div>
<div class="small-6 columns">
<p>
<strong><%= t('backend.event_update_date') %></strong>
<%= I18n.l @event.updated_at, format: :short if @event.updated_at.present? %>
</p>
</div>
<h3><%= @event.title %></h3>
<%= link_to t('backend.edit'), edit_event_path(@event), :class=> "button tiny radius success" if can? :edit, @event%>
<%= link_to t('backend.back'), :back , :class=> "button tiny radius" %>
<fieldset>
<legend><%= t('backend.basic_data') %></legend>
<strong><%= t('backend.holder') %>:</strong>
<p><%= @event.position.holder.full_name %></p>
<strong><%= t('backend.title') %>:</strong>
<p><%= @event.title %></p>
<strong><%= t('backend.location') %>:</strong>
<p><%= @event.location %></p>
<strong><%= t('backend.date') %>:</strong>
<p><%= @event.scheduled.strftime(t('time.formats.short')) if @event.scheduled.present? %></p>
<strong><%= t('backend.description') %>:</strong>
<%= @event.description.html_safe if @event.description.present? %>
</fieldset>
<% if @event.user.present? %>
<fieldset>
<legend><%= t('backend.event_history_updates') %></legend>
<div class="row">
<div class="small-6 columns"><strong><%= t('backend.event_update_user') %></strong></div>
<div class="small-6 columns"><strong><%= t('backend.event_update_date') %></strong></div>
</div>
<div class="row">
<div class="small-6 columns">
<p><%= @event.user.full_name %></p>
</div>
<div class="small-6 columns">
<p><%= @event.updated_at.strftime(t('time.formats.short')) if @event.updated_at.present? %></p>
</div>
</div>
</fieldset>
<% end %>
<fieldset>
<legend><%= t('backend.participants') %></legend>
<div class="row">
<div class="small-4 columns">
<strong><%= t('backend.name') %></strong>
</div>
<div class="small-4 columns">
<strong><%= t('backend.position') %></strong>
</div>
<div class="small-4 columns">
<strong><%= t('backend.area') %></strong>
</div>
</div>
<% @event.participants.each do |participant| %>
<div class="row">
<div class="small-4 columns">
<p><%= participant.position.holder.full_name %></p>
</div>
<div class="small-4 columns">
<p><%= participant.position.title %></p>
</div>
<div class="small-4 columns">
<p><%= participant.position.area.title %></p>
</div>
</div>
<% end %>
</fieldset>
<fieldset>
<legend><%= t('backend.attendees') %></legend>
<div class="row">
<div class="small-4 columns">
<strong><%= t('backend.name') %></strong>
</div>
<div class="small-4 columns">
<strong><%= t('backend.position') %></strong>
</div>
<div class="small-4 columns">
<strong><%= t('backend.company') %></strong>
</div>
</div>
<% @event.attendees.each do |attendee| %>
<div class="row">
<div class="small-4 columns">
<p><%= attendee.name %></p>
</div>
<div class="small-4 columns">
<p><%= attendee.position %></p>
</div>
<div class="small-4 columns">
<p><%= attendee.company %></p>
</div>
</fieldset>
<% end %>
Expand Down
24 changes: 22 additions & 2 deletions app/views/layouts/_admin_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,23 @@
</a>
</li>
<% end %>
<% if current_user.user? %>
<li class="<%= active_menu('events', nil, 'tray') %>">
<a href="<%= @events_path %>">
<i class="fi-calendar size-18">
<%= t("backend.event_tray") %>
</i>
</a>
</li>
<% else %>
<li class="<%= active_menu('events') %>">
<a href="<%= events_path %>">
<i class="fi-calendar size-18"> <%= t("backend.events")%></i>
<a href="<%= @events_path %>">
<i class="fi-calendar size-18">
<%= t("organizations.show.events_title") %>
</i>
</a>
</li>
<% end %>
<% if current_user.admin? %>
<li class="<%= active_menu('admin/organizations') %>">
<a href="<%= admin_organizations_path %>">
Expand All @@ -44,6 +56,13 @@
</a>
</li>
<% end %>
<% if current_user.user? %>
<li class="<%= active_menu('events', nil, 'events') %>">
<a href="<%= events_path(event_fixed_filters['events']) %>">
<i class="fi-book size-18"> <%= t("backend.events") %></i>
</a>
</li>
<% end %>
<% if current_user.admin? %>
<li class="<%= active_menu('areas') %>">
<a href="<%= areas_path %>">
Expand Down Expand Up @@ -113,3 +132,4 @@
</li>
</ul>
</nav>

3 changes: 2 additions & 1 deletion config/locales/admin.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ es:
new_event: "Nuevo evento"
edit_event: "Editar evento"
edit_agents: "Editar agentes"
add_interests: "“Editar intereses"
add_interests: "Editar intereses"
event_tray: Event tray
edit_title_interests: "Editar áreas de interés"
show_company: "Ver datos organización"
activity: "Registro de Actividad"
Expand Down
1 change: 1 addition & 0 deletions config/locales/admin.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ es:
edit_agents: "Editar agentes"
edit_title_interests: "Editar áreas de interés"
add_interests: "Editar intereses"
event_tray: Bandeja de solicitudes
show_company: "Ver datos lobby"
activity: "Registro de Actividad"
entries: "Registros"
Expand Down
60 changes: 58 additions & 2 deletions spec/features/admin/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,73 @@
describe 'user manager', type: :feature do

background do
@user_manager = create(:user, :user)
@organization = create(:organization)
@user_manager = create(:user, :user, organization: @organization)
@position = create(:position)
@agent = create(:agent, organization: @organization)
@user_manager.manages.create(holder_id: @position.holder_id)
signin(@user_manager.email, @user_manager.password)
end

describe "index" do

scenario 'visit the events index page' do
visit events_path
visit events_path("utf8" => "✓", "search_title" => "", "search_person" => "",
"status" => ["requested", "declined"], "lobby_activity" => "1",
"controller" => "events", "action" => "index" )
expect(page).to have_content I18n.t 'backend.events'
expect(page).to have_content I18n.t 'backend.event_tray'
end

scenario 'The liks from the menu should filter properly' do
event1 = create(:event, position: @position, title: '1 requested with lobby', lobby_activity: true)
event2 = create(:event, position: @position, title: '2 accepted with lobby', lobby_activity: true)
event3 = create(:event, position: @position, title: '3 done with lobby', lobby_activity: true)
event4 = create(:event, position: @position, title: '4 canceled with lobby', lobby_activity: true)
event5 = create(:event, position: @position, title: '5 declined with lobby', lobby_activity: true)
event6 = create(:event, position: @position, title: '6 requested')
event7 = create(:event, position: @position, title: '7 accepted')
event8 = create(:event, position: @position, title: '8 done')
event9 = create(:event, position: @position, title: '9 canceled')
event10 = create(:event, position: @position, title: '10 declined')

event1.update(status: :requested)
event2.update(status: :accepted)
event3.update(status: :done)
event4.update(status: :canceled)
event5.update(status: :declined)
event6.update(status: :requested)
event7.update(status: :accepted)
event8.update(status: :done)
event9.update(status: :canceled)
event10.update(status: :declined)

visit events_path("utf8" => "✓", "search_title" => "", "search_person" => "",
"status" => ["requested", "declined"], "lobby_activity" => "1",
"controller" => "events", "action" => "index" )

click_link I18n.t("backend.events")
expect(find_link(I18n.t("backend.event_tray")).first(:xpath, ".//..")[:class]).not_to eq "active"
expect(find_link(I18n.t("backend.events")).first(:xpath, ".//..")[:class]).to eq "active"

[event2, event3, event4, event7, event8, event9].each do |evnt|
expect(page).to have_content evnt.title
end
[event1, event5, event6, event10].each do |evnt|
expect(page).not_to have_content evnt.title
end

click_link I18n.t("backend.event_tray")
expect(find_link(I18n.t("backend.event_tray")).first(:xpath, ".//..")[:class]).to eq "active"
expect(find_link(I18n.t("backend.events")).first(:xpath, ".//..")[:class]).not_to eq "active"

[event1, event5].each do |evnt|
expect(page).to have_content evnt.title
end
[event2, event3, event4, event6, event7, event8, event9, event10].each do |evnt|
expect(page).not_to have_content evnt.title
end

end

scenario 'Should allow to download all attachments from event attachments dropdown', :js do
Expand Down

0 comments on commit 804a655

Please sign in to comment.