From ecb490cbd54556aa58504193534d216336bd4498 Mon Sep 17 00:00:00 2001 From: Rafael Salgado Date: Fri, 19 Jul 2024 19:58:39 -0300 Subject: [PATCH 01/10] Implementa tela de listagem completa com opcoes de filtro para RG, nome do visitante, nome do responsavel, e data autorizada para os registros de visitante do morador Co-authored-by: thalyta lima --- app/controllers/visitors_controller.rb | 27 ++- app/models/condo.rb | 8 + app/views/visitors/all.html.erb | 65 ++++++ app/views/visitors/find.html.erb | 1 + config/locales/models/visitor.pt-br.yml | 4 +- config/routes.rb | 1 + spec/factories/residents.rb | 3 +- ...ager_view_condo_full_visitors_list_spec.rb | 203 ++++++++++++++++++ 8 files changed, 309 insertions(+), 3 deletions(-) create mode 100644 app/views/visitors/all.html.erb create mode 100644 spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb diff --git a/app/controllers/visitors_controller.rb b/app/controllers/visitors_controller.rb index 0bab69a6..c2041a3f 100644 --- a/app/controllers/visitors_controller.rb +++ b/app/controllers/visitors_controller.rb @@ -1,6 +1,6 @@ class VisitorsController < ApplicationController before_action :set_resident, only: %i[index new create] - before_action :set_condo, only: %i[find] + before_action :set_condo, only: %i[find all] before_action :set_visitor, only: %i[confirm_entry] before_action :authenticate_resident!, only: %i[index new create] before_action :set_breadcrumbs_for_action, only: %i[index new create find] @@ -20,6 +20,20 @@ def find @visitors = @condo.expected_visitors(@date) end + def all + return @visitors = @condo.visitors if check_empty_params + + query_params = params.permit(:identity_number, :visitor_name, :resident_name, :visit_date) + @result = [] + query_params.each do |key, value| + key = 'full_name' if key == 'visitor_name' + + @result << find_visitors(key, value) if value.present? + end + + @visitors = @result.reduce(:&) + end + def confirm_entry return redirect_to find_condo_visitors_path(@visitor.condo) unless check_visitor(@visitor) @@ -114,4 +128,15 @@ def visitor_params def find_condo @condo.nil? ? @visitor.condo : @condo end + + def check_empty_params + params[:identity_number].blank? && params[:visitor_name].blank? && + params[:visit_date].blank? && params[:resident_name].blank? + end + + def find_visitors(key, value) + return @condo.search_visitors_by_resident_name(value) if key == 'resident_name' + + @condo.search_visitors_by_params(key, value) + end end diff --git a/app/models/condo.rb b/app/models/condo.rb index 0d14bb25..3efc3b62 100644 --- a/app/models/condo.rb +++ b/app/models/condo.rb @@ -55,6 +55,14 @@ def expected_visitors(date) visitors.where(visit_date: date) end + def search_visitors_by_resident_name(resident_name) + visitors.joins(:resident).where('residents.full_name LIKE ?', "%#{resident_name}%") + end + + def search_visitors_by_params(key, value) + visitors.where("#{key} LIKE ?", "%#{value}%") + end + private def ordered_units diff --git a/app/views/visitors/all.html.erb b/app/views/visitors/all.html.erb new file mode 100644 index 00000000..3c9e82db --- /dev/null +++ b/app/views/visitors/all.html.erb @@ -0,0 +1,65 @@ +
+
+

Visitantes/Funcionários cadastrados no <%= @condo.name %>

+
+ + <%= form_with url: all_condo_visitors_path(@condo), method: :get do |f| %> +
+
+ <%= f.label :identity_number, I18n.t("activerecord.attributes.visitor.identity_number") %> + <%= f.text_field :identity_number, class: "form-control" %> +
+
+ <%= f.label :visitor_name, I18n.t("activerecord.attributes.visitor.visitor_name") %> + <%= f.text_field :visitor_name, class: "form-control" %> +
+
+ <%= f.label :resident_name, I18n.t("activerecord.attributes.visitor.resident_name") %> + <%= f.text_field :resident_name, class: "form-control" %> +
+
+ <%= f.label :visit_date, I18n.t("activerecord.attributes.visitor.visit_date_query") %> + <%= f.date_field :visit_date, class: "form-control" %> +
+
+ <%= f.submit "Pesquisar", class: "btn btn-dark rounded-pill d-inline-flex align-items-center mb-2 px-4 shadow-sm" %> +
+
+ <% end %> + +
+ + + <% if @result %> + + <% end %> + + + + + + + + + + + + + <% @visitors.each do |visitor| %> + + + + + + + + + <% end %> + +
<%= "#{@visitors.count} resultados encontrados" %>
Nome CompletoRGCategoria:UnidadeResponsavel:Data Autorizada:
<%= visitor.full_name %><%= visitor.identity_number %><%= I18n.t("activerecord.attributes.visitor.categories.#{visitor.category}") %><%= visitor.resident.residence.tower_identifier %><%= visitor.resident.full_name %><%= I18n.l(visitor.visit_date) %> + <% if visitor.employee? %> + <%= I18n.t("activerecord.attributes.visitor.recurrences.#{visitor.recurrence}") %> + <% end %> +
+
+
\ No newline at end of file diff --git a/app/views/visitors/find.html.erb b/app/views/visitors/find.html.erb index 254e4d05..02f268ce 100644 --- a/app/views/visitors/find.html.erb +++ b/app/views/visitors/find.html.erb @@ -1,6 +1,7 @@

Agenda de visitantes/funcionários

+ <%= link_to 'Ver Lista Completa', all_condo_visitors_path(@condo), class:'btn btn-dark rounded-pill px-4 m-2' %>
diff --git a/config/locales/models/visitor.pt-br.yml b/config/locales/models/visitor.pt-br.yml index 8f71780c..0722c7fa 100644 --- a/config/locales/models/visitor.pt-br.yml +++ b/config/locales/models/visitor.pt-br.yml @@ -20,9 +20,11 @@ pt-BR: visitor: Visitante attributes: visitor: + visit_date_query: 'Data Autorizada' full_name: 'Nome Completo' identity_number: 'RG' - + visitor_name: 'Nome do Visitante' + resident_name: 'Nome do Morador' visit_date: 'Data da Visita' category: 'Categoria' categories: diff --git a/config/routes.rb b/config/routes.rb index 91e9af16..11f7435d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,6 +46,7 @@ resources :visitors do get 'find', on: :collection + get 'all', on: :collection end resources :towers, only: [:new, :create] do diff --git a/spec/factories/residents.rb b/spec/factories/residents.rb index 18921839..0053354c 100644 --- a/spec/factories/residents.rb +++ b/spec/factories/residents.rb @@ -10,7 +10,8 @@ transient { condo { create :condo } } after(:create) do |resident, evaluator| - resident.residence = create(:unit, floor: create(:floor, tower: create(:tower, condo: evaluator.condo))) + tower = create(:tower, condo: evaluator.condo) + resident.residence = tower.floors[0].units[0] end end end diff --git a/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb b/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb new file mode 100644 index 00000000..232a660b --- /dev/null +++ b/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb @@ -0,0 +1,203 @@ +require 'rails_helper' + +describe 'Manager view condo full visitors list' do + it 'from visitors agenda' do + manager = create :manager + first_condo = create :condo, name: 'Condomínio Teste' + tower = create :tower, condo: first_condo, name: 'Torre A' + second_condo = create :condo + first_resident = create :resident, full_name: 'Alberto Silveira', residence: tower.floors[0].units[0] + second_resident = create :resident, full_name: 'Maria Silveira', residence: tower.floors[0].units[1] + first_visitor = create :visitor, condo: first_condo, resident: first_resident, + visit_date: Time.zone.today, full_name: 'João da Silva', identity_number: '12467' + second_visitor = create :visitor, condo: first_condo, resident: first_resident, + category: :employee, recurrence: :weekly, + visit_date: Time.zone.today, full_name: 'Maria Oliveira', identity_number: '45977' + third_visitor = create :visitor, condo: first_condo, resident: second_resident, + visit_date: 1.day.from_now, full_name: 'Marcos Lima', identity_number: '12345' + fourth_visitor = create :visitor, condo: second_condo, + visit_date: Time.zone.today, full_name: 'Juliana Ferreira' + + login_as manager, scope: :manager + visit find_condo_visitors_path first_condo + click_on 'Ver Lista Completa' + + expect(page).to have_content 'Visitantes/Funcionários cadastrados no Condomínio Teste' + expect(current_path).to eq all_condo_visitors_path first_condo + within("#visitor-#{first_visitor.id}") do + expect(page).to have_content 'João da Silva' + expect(page).to have_content '12467' + expect(page).to have_content 'Visitante' + expect(page).to have_content 'Torre A - 11' + expect(page).to have_content 'Alberto Silveira' + expect(page).to have_content I18n.l(Time.zone.today) + end + within("#visitor-#{second_visitor.id}") do + expect(page).to have_content 'Maria Oliveira' + expect(page).to have_content '45977' + expect(page).to have_content 'Funcionário' + expect(page).to have_content 'Torre A - 11' + expect(page).to have_content 'Alberto Silveira' + expect(page).to have_content I18n.l(Time.zone.today) + expect(page).to have_content 'Semanal' + end + within("#visitor-#{third_visitor.id}") do + expect(page).to have_content 'Marcos Lima' + expect(page).to have_content '12345' + expect(page).to have_content 'Visitante' + expect(page).to have_content 'Torre A - 12' + expect(page).to have_content 'Maria Silveira' + expect(page).to have_content I18n.l(1.day.from_now.to_date) + end + expect(page).not_to have_css "#visitor-#{fourth_visitor.id}" + expect(page).not_to have_content 'Juliana Ferreira' + end + + context 'and search with' do + it 'identity number filter' do + manager = create :manager + resident = create :resident, :with_residence, full_name: 'Alberto Silveira' + condo = resident.residence.condo + first_visitor = create :visitor, condo:, resident:, + visit_date: Time.zone.today, full_name: 'João da Silva', identity_number: '12467' + second_visitor = create :visitor, condo:, resident:, + category: :employee, recurrence: :weekly, + visit_date: Time.zone.today, full_name: 'Maria Lima', identity_number: '4677811' + create :visitor, condo:, full_name: 'Marcos Lima', identity_number: '12345' + + login_as manager, scope: :manager + visit all_condo_visitors_path condo + fill_in 'RG', with: '467' + click_on 'Pesquisar' + + expect(page).to have_content '2 resultados encontrados' + within("#visitor-#{first_visitor.id}") do + expect(page).to have_content 'João da Silva' + expect(page).to have_content '12467' + expect(page).to have_content 'Visitante' + expect(page).to have_content 'Torre A - 11' + expect(page).to have_content 'Alberto Silveira' + expect(page).to have_content I18n.l(Time.zone.today) + end + within("#visitor-#{second_visitor.id}") do + expect(page).to have_content 'Maria Lima' + expect(page).to have_content '4677811' + expect(page).to have_content 'Funcionário' + expect(page).to have_content 'Torre A - 11' + expect(page).to have_content 'Alberto Silveira' + expect(page).to have_content I18n.l(Time.zone.today) + expect(page).to have_content 'Semanal' + end + expect(page).not_to have_content 'Marcos Lima' + end + it 'visitors name filter' do + manager = create :manager + resident = create :resident, :with_residence, full_name: 'Alberto Silveira' + condo = resident.residence.condo + first_visitor = create :visitor, condo:, resident:, + visit_date: Time.zone.today, full_name: 'João da Silva', identity_number: '12467' + second_visitor = create :visitor, condo:, resident:, + category: :employee, recurrence: :weekly, + visit_date: 2.days.from_now, full_name: 'João Sousa', identity_number: '13331' + create :visitor, condo:, full_name: 'Marcos Lima', identity_number: '12345' + + login_as manager, scope: :manager + visit all_condo_visitors_path condo + fill_in 'Nome do Visitante', with: 'João' + click_on 'Pesquisar' + + expect(page).to have_content '2 resultados encontrados' + within("#visitor-#{first_visitor.id}") do + expect(page).to have_content 'João da Silva' + expect(page).to have_content '12467' + expect(page).to have_content 'Visitante' + expect(page).to have_content 'Torre A - 11' + expect(page).to have_content 'Alberto Silveira' + expect(page).to have_content I18n.l(Time.zone.today) + end + within("#visitor-#{second_visitor.id}") do + expect(page).to have_content 'João Sousa' + expect(page).to have_content '13331' + expect(page).to have_content 'Funcionário' + expect(page).to have_content 'Torre A - 11' + expect(page).to have_content 'Alberto Silveira' + expect(page).to have_content I18n.l(2.days.from_now.to_date) + expect(page).to have_content 'Semanal' + end + expect(page).not_to have_content 'Marcos Lima' + end + it 'resident name filter' do + manager = create :manager + resident = create :resident, :with_residence, full_name: 'Alberto Silveira' + condo = resident.residence.condo + first_visitor = create :visitor, condo:, resident:, + visit_date: Time.zone.today, full_name: 'João da Silva', identity_number: '12467' + second_visitor = create :visitor, condo:, resident:, + category: :employee, recurrence: :weekly, + visit_date: 2.days.from_now, full_name: 'Bruna Lima', identity_number: '13331' + create :visitor, condo:, full_name: 'Marcos Lima', identity_number: '12345' + + login_as manager, scope: :manager + visit all_condo_visitors_path condo + fill_in 'Nome do Morador', with: 'Alberto' + click_on 'Pesquisar' + + expect(page).to have_content '2 resultados encontrados' + within("#visitor-#{first_visitor.id}") do + expect(page).to have_content 'João da Silva' + expect(page).to have_content '12467' + expect(page).to have_content 'Visitante' + expect(page).to have_content 'Torre A - 11' + expect(page).to have_content 'Alberto Silveira' + expect(page).to have_content I18n.l(Time.zone.today) + end + within("#visitor-#{second_visitor.id}") do + expect(page).to have_content 'Bruna Lima' + expect(page).to have_content '13331' + expect(page).to have_content 'Funcionário' + expect(page).to have_content 'Torre A - 11' + expect(page).to have_content 'Alberto Silveira' + expect(page).to have_content I18n.l(2.days.from_now.to_date) + expect(page).to have_content 'Semanal' + end + expect(page).not_to have_content 'Marcos Lima' + end + + it 'visit date filter' do + manager = create :manager + resident = create :resident, :with_residence, full_name: 'Alberto Silveira' + condo = resident.residence.condo + first_visitor = create :visitor, condo:, resident:, + visit_date: 2.days.from_now, full_name: 'João da Silva', identity_number: '12467' + second_visitor = create :visitor, condo:, resident:, + category: :employee, recurrence: :weekly, + visit_date: 2.days.from_now, full_name: 'Bruna Lima', identity_number: '13331' + create :visitor, condo:, full_name: 'Marcos Lima', identity_number: '12345' + + login_as manager, scope: :manager + visit all_condo_visitors_path condo + fill_in 'Data Autorizada', with: 2.days.from_now.to_date + click_on 'Pesquisar' + + expect(page).to have_content '2 resultados encontrados' + within("#visitor-#{first_visitor.id}") do + expect(page).to have_content 'João da Silva' + expect(page).to have_content '12467' + expect(page).to have_content 'Visitante' + expect(page).to have_content 'Torre A - 11' + expect(page).to have_content 'Alberto Silveira' + expect(page).to have_content I18n.l(2.days.from_now.to_date) + end + within("#visitor-#{second_visitor.id}") do + expect(page).to have_content 'Bruna Lima' + expect(page).to have_content '13331' + expect(page).to have_content 'Funcionário' + expect(page).to have_content 'Torre A - 11' + expect(page).to have_content 'Alberto Silveira' + expect(page).to have_content I18n.l(2.days.from_now.to_date) + expect(page).to have_content 'Semanal' + end + expect(page).not_to have_content 'Marcos Lima' + end + end +end From d15bcd76dcf183e4f6b2d8f13234abc2a3f1dbe5 Mon Sep 17 00:00:00 2001 From: thalytalima211 Date: Fri, 19 Jul 2024 21:15:53 -0300 Subject: [PATCH 02/10] Implementa testes que verificam o uso dos 4 filtros simultaneamente e corrige I18n Co-authored-by: Rafael Salgado --- app/controllers/visitors_controller.rb | 18 +----- app/views/visitors/all.html.erb | 16 ++--- config/locales/models/visitor.pt-br.yml | 10 +++- .../requests/manager_confirms_visitor_spec.rb | 6 +- ...ager_view_condo_full_visitors_list_spec.rb | 59 +++++++++++++++++-- 5 files changed, 76 insertions(+), 33 deletions(-) diff --git a/app/controllers/visitors_controller.rb b/app/controllers/visitors_controller.rb index c2041a3f..29975534 100644 --- a/app/controllers/visitors_controller.rb +++ b/app/controllers/visitors_controller.rb @@ -35,7 +35,9 @@ def all end def confirm_entry - return redirect_to find_condo_visitors_path(@visitor.condo) unless check_visitor(@visitor) + unless @visitor.visit_date == Time.zone.today && @visitor.pending? + return redirect_to find_condo_visitors_path(@visitor.condo), alert: I18n.t('alerts.visitor.entry_denied') + end VisitorEntry.create(visitor_entry_params) @visitor.confirmed! @@ -58,20 +60,6 @@ def create private - def check_visitor(visitor) - if visitor.confirmed? - flash[:alert] = I18n.t('alerts.visitor.already_confirmed') - return false - end - - unless visitor.visit_date == Time.zone.today - flash[:alert] = I18n.t('alerts.visitor.invalid_date') - return false - end - - true - end - def set_visit_date_job return unless @visitor.employee? diff --git a/app/views/visitors/all.html.erb b/app/views/visitors/all.html.erb index 3c9e82db..8820eee1 100644 --- a/app/views/visitors/all.html.erb +++ b/app/views/visitors/all.html.erb @@ -5,24 +5,24 @@ <%= form_with url: all_condo_visitors_path(@condo), method: :get do |f| %>
-
+
<%= f.label :identity_number, I18n.t("activerecord.attributes.visitor.identity_number") %> <%= f.text_field :identity_number, class: "form-control" %>
-
- <%= f.label :visitor_name, I18n.t("activerecord.attributes.visitor.visitor_name") %> - <%= f.text_field :visitor_name, class: "form-control" %> -
<%= f.label :resident_name, I18n.t("activerecord.attributes.visitor.resident_name") %> <%= f.text_field :resident_name, class: "form-control" %>
+
+ <%= f.label :visitor_name, I18n.t("activerecord.attributes.visitor.visitor_name") %> + <%= f.text_field :visitor_name, class: "form-control" %> +
<%= f.label :visit_date, I18n.t("activerecord.attributes.visitor.visit_date_query") %> <%= f.date_field :visit_date, class: "form-control" %>
-
- <%= f.submit "Pesquisar", class: "btn btn-dark rounded-pill d-inline-flex align-items-center mb-2 px-4 shadow-sm" %> +
+ <%= f.submit "Pesquisar", class: "btn btn-dark rounded-pill d-inline-flex align-items-center mt-3 px-4 shadow-sm" %>
<% end %> @@ -31,7 +31,7 @@ <% if @result %> - + <% end %> diff --git a/config/locales/models/visitor.pt-br.yml b/config/locales/models/visitor.pt-br.yml index 0722c7fa..cbd4f42b 100644 --- a/config/locales/models/visitor.pt-br.yml +++ b/config/locales/models/visitor.pt-br.yml @@ -7,8 +7,7 @@ pt-BR: resident_block: 'Você não possui autorização para essa ação' not_allowed: 'Você não pode administrar visitantes para outra unidade além da sua' only_numbers_and_letters: 'só pode ter números e letras' - already_confirmed: 'Visitante já confirmado' - invalid_date: 'Só é possível confirmar visitantes do dia atual' + entry_denied: 'Essa entrada já foi confirmada antes ou não é referente ao dia de hoje' invalid_list_date: 'Não é possível acessar uma data passada' notice: visitor: @@ -17,7 +16,9 @@ pt-BR: entry_confirmed: 'Entrada do visitante registrada com sucesso.' activerecord: models: - visitor: Visitante + visitor: + one: 'Visitante' + other: 'Visitantes' attributes: visitor: visit_date_query: 'Data Autorizada' @@ -26,6 +27,9 @@ pt-BR: visitor_name: 'Nome do Visitante' resident_name: 'Nome do Morador' visit_date: 'Data da Visita' + found: + one: 'Encontrado' + other: 'Encontrados' category: 'Categoria' categories: visitor: 'Visitante' diff --git a/spec/requests/manager_confirms_visitor_spec.rb b/spec/requests/manager_confirms_visitor_spec.rb index dfe7fe55..fbc7a426 100644 --- a/spec/requests/manager_confirms_visitor_spec.rb +++ b/spec/requests/manager_confirms_visitor_spec.rb @@ -56,7 +56,7 @@ post confirm_entry_visitor_path(visitor) expect(response).to redirect_to find_condo_visitors_path(visitor.condo) - expect(flash[:alert]).to eq 'Visitante já confirmado' + expect(flash[:alert]).to eq 'Essa entrada já foi confirmada antes ou não é referente ao dia de hoje' expect(VisitorEntry.count).to eq 0 end @@ -70,7 +70,7 @@ post confirm_entry_visitor_path(visitor) expect(response).to redirect_to find_condo_visitors_path(visitor.condo) - expect(flash[:alert]).to eq 'Só é possível confirmar visitantes do dia atual' + expect(flash[:alert]).to eq 'Essa entrada já foi confirmada antes ou não é referente ao dia de hoje' expect(visitor.reload.confirmed?).to eq false end end @@ -83,7 +83,7 @@ post confirm_entry_visitor_path(visitor) expect(response).to redirect_to find_condo_visitors_path(visitor.condo) - expect(flash[:alert]).to eq 'Só é possível confirmar visitantes do dia atual' + expect(flash[:alert]).to eq 'Essa entrada já foi confirmada antes ou não é referente ao dia de hoje' expect(visitor.reload.confirmed?).to eq false end end diff --git a/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb b/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb index 232a660b..746a9679 100644 --- a/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb +++ b/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb @@ -70,7 +70,7 @@ fill_in 'RG', with: '467' click_on 'Pesquisar' - expect(page).to have_content '2 resultados encontrados' + expect(page).to have_content '2 visitantes encontrados' within("#visitor-#{first_visitor.id}") do expect(page).to have_content 'João da Silva' expect(page).to have_content '12467' @@ -106,7 +106,7 @@ fill_in 'Nome do Visitante', with: 'João' click_on 'Pesquisar' - expect(page).to have_content '2 resultados encontrados' + expect(page).to have_content '2 visitantes encontrados' within("#visitor-#{first_visitor.id}") do expect(page).to have_content 'João da Silva' expect(page).to have_content '12467' @@ -142,7 +142,7 @@ fill_in 'Nome do Morador', with: 'Alberto' click_on 'Pesquisar' - expect(page).to have_content '2 resultados encontrados' + expect(page).to have_content '2 visitantes encontrados' within("#visitor-#{first_visitor.id}") do expect(page).to have_content 'João da Silva' expect(page).to have_content '12467' @@ -179,7 +179,7 @@ fill_in 'Data Autorizada', with: 2.days.from_now.to_date click_on 'Pesquisar' - expect(page).to have_content '2 resultados encontrados' + expect(page).to have_content '2 visitantes encontrados' within("#visitor-#{first_visitor.id}") do expect(page).to have_content 'João da Silva' expect(page).to have_content '12467' @@ -199,5 +199,56 @@ end expect(page).not_to have_content 'Marcos Lima' end + + it 'all filters' do + manager = create :manager + resident = create :resident, :with_residence, full_name: 'Alberto Silveira' + condo = resident.residence.condo + first_visitor = create :visitor, condo:, resident:, + visit_date: 2.days.from_now, full_name: 'João da Silva', identity_number: '12467' + create :visitor, condo:, full_name: 'Bruna Lima' + create :visitor, condo:, full_name: 'Marcos Ferreira' + + login_as manager, scope: :manager + visit all_condo_visitors_path condo + fill_in 'Nome do Visitante', with: 'João da Silva' + fill_in 'RG', with: '12467' + fill_in 'Nome do Morador', with: 'Alberto Silveira' + fill_in 'Data Autorizada', with: 2.days.from_now.to_date + click_on 'Pesquisar' + + expect(page).to have_content '1 visitante encontrado' + within("#visitor-#{first_visitor.id}") do + expect(page).to have_content 'João da Silva' + expect(page).to have_content '12467' + expect(page).to have_content 'Visitante' + expect(page).to have_content 'Torre A - 11' + expect(page).to have_content 'Alberto Silveira' + expect(page).to have_content I18n.l(2.days.from_now.to_date) + end + expect(page).not_to have_content 'Bruna Lima' + expect(page).not_to have_content 'Marcos Ferreira' + end + + it 'no filters' do + manager = create :manager + condo = create :condo + create :visitor, condo:, full_name: 'João da Silva' + create :visitor, condo:, full_name: 'Bruna Lima' + create :visitor, condo:, full_name: 'Marcos Ferreira' + + login_as manager, scope: :manager + visit all_condo_visitors_path condo + fill_in 'Nome do Visitante', with: '' + fill_in 'RG', with: '' + fill_in 'Nome do Morador', with: '' + fill_in 'Data Autorizada', with: '' + click_on 'Pesquisar' + + expect(page).to have_content 'João da Silva' + expect(page).to have_content 'Bruna Lima' + expect(page).to have_content 'Marcos Ferreira' + expect(page).not_to have_content '3 resultados encontrados' + end end end From f80de25a627681936bf9d5878f005e9996a33487 Mon Sep 17 00:00:00 2001 From: thalytalima211 Date: Fri, 19 Jul 2024 21:36:19 -0300 Subject: [PATCH 03/10] =?UTF-8?q?Exibe=20mensagens=20de=20erro=20quando=20?= =?UTF-8?q?n=C3=A3o=20h=C3=A1=20visitantes=20cadastrados=20ou=20a=20busca?= =?UTF-8?q?=20retorna=20vazia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rafael Salgado --- app/views/visitors/all.html.erb | 43 +++++++++++-------- ...ager_view_condo_full_visitors_list_spec.rb | 39 ++++++++++++++--- 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/app/views/visitors/all.html.erb b/app/views/visitors/all.html.erb index 8820eee1..f1b0290a 100644 --- a/app/views/visitors/all.html.erb +++ b/app/views/visitors/all.html.erb @@ -5,19 +5,19 @@ <%= form_with url: all_condo_visitors_path(@condo), method: :get do |f| %>
-
- <%= f.label :identity_number, I18n.t("activerecord.attributes.visitor.identity_number") %> - <%= f.text_field :identity_number, class: "form-control" %> -
<%= f.label :resident_name, I18n.t("activerecord.attributes.visitor.resident_name") %> <%= f.text_field :resident_name, class: "form-control" %>
+ <%= f.label :identity_number, I18n.t("activerecord.attributes.visitor.identity_number") %> + <%= f.text_field :identity_number, class: "form-control" %> +
+
<%= f.label :visitor_name, I18n.t("activerecord.attributes.visitor.visitor_name") %> <%= f.text_field :visitor_name, class: "form-control" %>
-
+
<%= f.label :visit_date, I18n.t("activerecord.attributes.visitor.visit_date_query") %> <%= f.date_field :visit_date, class: "form-control" %>
@@ -45,19 +45,26 @@
- <% @visitors.each do |visitor| %> - - - - - - - - + <% if @visitors.any? %> + <% @visitors.each do |visitor| %> + + + + + + + + + <% end %> + + <% elsif @result %> +

Não foi possível encontrar visitantes com os filtros informados

+ <% else %> +

No momento, não há visitantes cadastrados para este condomínio

<% end %>
<%= "#{@visitors.count} resultados encontrados" %><%= "#{@visitors.count} #{Visitor.model_name.human(count: @visitors.count).downcase} #{I18n.t('activerecord.attributes.visitor.found', count: @visitors.count).downcase}" %>
<%= visitor.full_name %><%= visitor.identity_number %><%= I18n.t("activerecord.attributes.visitor.categories.#{visitor.category}") %><%= visitor.resident.residence.tower_identifier %><%= visitor.resident.full_name %><%= I18n.l(visitor.visit_date) %> - <% if visitor.employee? %> - <%= I18n.t("activerecord.attributes.visitor.recurrences.#{visitor.recurrence}") %> - <% end %> -
<%= visitor.full_name %><%= visitor.identity_number %><%= I18n.t("activerecord.attributes.visitor.categories.#{visitor.category}") %><%= visitor.resident.residence.tower_identifier %><%= visitor.resident.full_name %><%= I18n.l(visitor.visit_date) %> + <% if visitor.employee? %> + <%= I18n.t("activerecord.attributes.visitor.recurrences.#{visitor.recurrence}") %> + <% end %> +
diff --git a/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb b/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb index 746a9679..9b8bd38b 100644 --- a/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb +++ b/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb @@ -53,8 +53,18 @@ expect(page).not_to have_content 'Juliana Ferreira' end - context 'and search with' do - it 'identity number filter' do + it 'and sees if list is empty' do + manager = create :manager + condo = create :condo + + login_as manager, scope: :manager + visit all_condo_visitors_path condo + + expect(page).to have_content 'No momento, não há visitantes cadastrados para este condomínio' + end + + context 'and search visitors' do + it 'with identity number filter' do manager = create :manager resident = create :resident, :with_residence, full_name: 'Alberto Silveira' condo = resident.residence.condo @@ -90,7 +100,7 @@ end expect(page).not_to have_content 'Marcos Lima' end - it 'visitors name filter' do + it 'with visitors name filter' do manager = create :manager resident = create :resident, :with_residence, full_name: 'Alberto Silveira' condo = resident.residence.condo @@ -126,7 +136,7 @@ end expect(page).not_to have_content 'Marcos Lima' end - it 'resident name filter' do + it 'with resident name filter' do manager = create :manager resident = create :resident, :with_residence, full_name: 'Alberto Silveira' condo = resident.residence.condo @@ -163,7 +173,7 @@ expect(page).not_to have_content 'Marcos Lima' end - it 'visit date filter' do + it 'with visit date filter' do manager = create :manager resident = create :resident, :with_residence, full_name: 'Alberto Silveira' condo = resident.residence.condo @@ -200,7 +210,7 @@ expect(page).not_to have_content 'Marcos Lima' end - it 'all filters' do + it 'with all filters' do manager = create :manager resident = create :resident, :with_residence, full_name: 'Alberto Silveira' condo = resident.residence.condo @@ -230,7 +240,7 @@ expect(page).not_to have_content 'Marcos Ferreira' end - it 'no filters' do + it 'with no filters' do manager = create :manager condo = create :condo create :visitor, condo:, full_name: 'João da Silva' @@ -250,5 +260,20 @@ expect(page).to have_content 'Marcos Ferreira' expect(page).not_to have_content '3 resultados encontrados' end + + it 'and finds no one' do + manager = create :manager + condo = create :condo + create :visitor, condo:, full_name: 'João da Silva' + create :visitor, condo:, full_name: 'Bruna Lima' + create :visitor, condo:, full_name: 'Marcos Ferreira' + + login_as manager, scope: :manager + visit all_condo_visitors_path condo + fill_in 'Nome do Visitante', with: 'Pedro' + click_on 'Pesquisar' + + expect(page).to have_content 'Não foi possível encontrar visitantes com os filtros informados' + end end end From eaacb40872b8529138aa5b950b4ce160b871515f Mon Sep 17 00:00:00 2001 From: thalytalima211 Date: Fri, 19 Jul 2024 22:13:56 -0300 Subject: [PATCH 04/10] Preenche dados no seeds Co-authored-by: Rafael Salgado --- db/seeds.rb | 167 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 127 insertions(+), 40 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 9e97c3af..6ca14f8c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -8,17 +8,17 @@ admin1 = Manager.create!( - full_name: "Ednaldo Pereira", - registration_number: '745.808.535-55', - email: "adm@teste.com", - password: "teste123", + full_name: "Ednaldo Pereira", + registration_number: '745.808.535-55', + email: "adm@teste.com", + password: "teste123", is_super: true ) admin2 = Manager.create!( - full_name: "Adroaldo Silva Santos", - registration_number: '025.727.205-40', - email: "adm2@teste.com", + full_name: "Adroaldo Silva Santos", + registration_number: '025.727.205-40', + email: "adm2@teste.com", password: "teste123" ) @@ -357,53 +357,53 @@ tower16.complete! resident_not_owner1 = Resident.create!( - email: 'claudia@email.com', - password: 'teste123', - status: :not_owner, - full_name: 'Cláudia Rodrigues Gomes', + email: 'claudia@email.com', + password: 'teste123', + status: :not_owner, + full_name: 'Cláudia Rodrigues Gomes', registration_number: '458.456.480-92', residence: tower1.floors[0].units[0] ) - + resident_not_owner2 = Resident.create!( - email: 'joao@email.com', - password: 'teste123', - status: :not_owner, - full_name: 'João da Silva', + email: 'joao@email.com', + password: 'teste123', + status: :not_owner, + full_name: 'João da Silva', registration_number: '478.040.830-09', residence: tower1.floors[1].units[0] ) resident_not_owner3 = Resident.create!( - email: 'maria@email.com', - password: 'teste123', - status: :not_owner, - full_name: 'Maria Oliveira', + email: 'maria@email.com', + password: 'teste123', + status: :not_owner, + full_name: 'Maria Oliveira', registration_number: '231.887.610-07', residence: tower1.floors[2].units[0] ) resident_not_owner4 = Resident.create!( - email: 'pedro@email.com', - password: 'teste123', - status: :not_tenant, - full_name: 'Pedro Alves', + email: 'pedro@email.com', + password: 'teste123', + status: :not_tenant, + full_name: 'Pedro Alves', registration_number: '185.894.110-52', residence: tower1.floors[3].units[0] ) resident_not_owner5 = Resident.create!( - email: 'ana@email.com', - password: 'teste123', - status: :not_tenant, - full_name: 'Ana Souza', + email: 'ana@email.com', + password: 'teste123', + status: :not_tenant, + full_name: 'Ana Souza', registration_number: '031.661.130-10', residence: tower1.floors[4].units[0] ) resident1 = Resident.create!( email:'fernando@email.com', - password: 'teste123', + password: 'teste123', status: :mail_confirmed, full_name: 'Fernando Marques Gomes', registration_number: '065.858.303-42', @@ -416,7 +416,7 @@ resident2 = Resident.create!( email: 'marina@email.com', - password: 'teste123', + password: 'teste123', status: :mail_confirmed, full_name: 'Marina Santos Oliveira', registration_number: '077.497.020-08', @@ -433,7 +433,7 @@ resident3 = Resident.create!( email: 'rafael@email.com', - password: 'teste123', + password: 'teste123', status: :mail_confirmed, full_name: 'Rafael Souza Lima', registration_number: '533.621.940-10', @@ -446,7 +446,7 @@ resident4 = Resident.create!( email: 'carla@email.com', - password: 'teste123', + password: 'teste123', status: :mail_confirmed, full_name: 'Carla Oliveira Silva', registration_number: '013.484.600-16', @@ -459,7 +459,7 @@ resident5 = Resident.create!( email: 'gustavo@email.com', - password: 'teste123', + password: 'teste123', status: :mail_confirmed, full_name: 'Gustavo Pereira Santos', registration_number: '896.562.710-92', @@ -472,7 +472,7 @@ resident6 = Resident.create!( email: 'isabela@email.com', - password: 'teste123', + password: 'teste123', status: :mail_confirmed, full_name: 'Isabela Almeida Costa', registration_number: '614.881.230-47', @@ -485,7 +485,7 @@ resident7 = Resident.create!( email: 'pedro2@email.com', - password: 'teste123', + password: 'teste123', status: :mail_confirmed, full_name: 'Pedro Machado Barbosa', registration_number: '277.796.720-26', @@ -498,7 +498,7 @@ resident8 = Resident.create!( email: 'ana2@email.com', - password: 'teste123', + password: 'teste123', status: :mail_confirmed, full_name: 'Ana Luiza Cardoso', registration_number: '318.953.470-50', @@ -511,7 +511,7 @@ resident9 = Resident.create!( email: 'bruno@email.com', - password: 'teste123', + password: 'teste123', status: :mail_confirmed, full_name: 'Bruno Oliveira Santos', registration_number: '516.791.320-91', @@ -524,7 +524,7 @@ resident10 = Resident.create!( email: 'camila@email.com', - password: 'teste123', + password: 'teste123', status: :mail_confirmed, full_name: 'Camila Rodrigues Ferreira', registration_number: '564.830.190-17', @@ -537,7 +537,7 @@ resident11 = Resident.create!( email: 'lucas@email.com', - password: 'teste123', + password: 'teste123', status: :mail_confirmed, full_name: 'Lucas Almeida Pereira', registration_number: '314.787.200-93', @@ -550,7 +550,7 @@ resident12 = Resident.create!( email: 'julia@email.com', - password: 'teste123', + password: 'teste123', status: :mail_confirmed, full_name: 'Julia Ferreira Lima', registration_number: '922.771.400-66', @@ -720,3 +720,90 @@ max_occupancy: 15, rules: 'Acompanhamento de adulto obrigatório' ) + + +visitor_1 = Visitor.create!( + condo: resident1.residence.condo, + resident: resident1, + visit_date: Time.zone.today, + full_name: 'João da Silva Ferreira', + identity_number: '1456987', + category: :visitor +) +visitor_2 = Visitor.create!( + condo: resident1.residence.condo, + resident: resident1, + visit_date: Time.zone.today, + full_name: 'Maria Gomes de Oliveira', + identity_number: '2345678', + category: :employee, + recurrence: :working_days +) +visitor_3 = Visitor.create!( + condo: resident2.residence.condo, + resident: resident2, + visit_date: Time.zone.today, + full_name: 'Pedro Souza Santos', + identity_number: '3214567', + category: :visitor +) +visitor_4 = Visitor.create!( + condo: resident2.residence.condo, + resident: resident2, + visit_date: 1.day.from_now.to_date, + full_name: 'Ana Pereira dos Reis', + identity_number: '4123456', + category: :employee, + recurrence: :monthly +) +visitor_5 = Visitor.create!( + condo: resident3.residence.condo, + resident: resident3, + visit_date: 1.day.from_now.to_date, + full_name: 'Carlos Silva Mendes', + identity_number: '5012345', + category: :employee, + recurrence: :biweekly +) +visitor_6 = Visitor.create!( + condo: resident3.residence.condo, + resident: resident3, + visit_date: Time.zone.today, + full_name: 'Beatriz Oliveira Costa', + identity_number: '6901234', + category: :visitor +) +visitor_7 = Visitor.create!( + condo: resident3.residence.condo, + resident: resident3, + visit_date: 2.days.from_now.to_date, + full_name: 'Bruno Souza Nunes', + identity_number: '7890123', + category: :visitor +) +visitor_8 = Visitor.create!( + condo: resident4.residence.condo, + resident: resident4, + visit_date: Time.zone.today, + full_name: 'Clara Pereira Araújo', + identity_number: '8765432', + category: :employee, + recurrence: :bimonthly +) +visitor_9 = Visitor.create!( + condo: resident4.residence.condo, + resident: resident4, + visit_date: 1.day.from_now, + full_name: 'Diego Silva Lopes', + identity_number: '9654321', + category: :visitor +) +visitor_10 = Visitor.create!( + condo: resident5.residence.condo, + resident: resident5, + visit_date: Time.zone.today, + full_name: 'Gabriela Oliveira Martins', + identity_number: '0543210', + category: :employee, + recurrence: :semiannual +) From 9200512738ffa8c40de862cba14d694ec43eaff1 Mon Sep 17 00:00:00 2001 From: thalytalima211 Date: Sat, 20 Jul 2024 09:58:35 -0300 Subject: [PATCH 05/10] Corrige erros no rubocop e testes Co-authored-by: Rafael Salgado --- app/controllers/visitors_controller.rb | 5 +---- config/locales/models/visitor.pt-br.yml | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/controllers/visitors_controller.rb b/app/controllers/visitors_controller.rb index 8ba73181..950c51cb 100644 --- a/app/controllers/visitors_controller.rb +++ b/app/controllers/visitors_controller.rb @@ -78,10 +78,7 @@ def authenticate_resident! return redirect_to root_path, alert: I18n.t('alerts.visitor.manager_block') if manager_signed_in? if resident_signed_in? - if @resident.residence.nil? - return redirect_to root_path, - alert: I18n.t('alerts.visitor.residence_registration_pending') - end + return redirect_to root_path, alert: I18n.t('alerts.visitor.residence_pending') unless @resident.residence return redirect_to root_path, alert: I18n.t('alerts.visitor.not_allowed') unless current_resident == @resident end diff --git a/config/locales/models/visitor.pt-br.yml b/config/locales/models/visitor.pt-br.yml index 213cfff0..bb7c3910 100644 --- a/config/locales/models/visitor.pt-br.yml +++ b/config/locales/models/visitor.pt-br.yml @@ -2,7 +2,7 @@ pt-BR: alerts: visitor: not_created: 'Erro ao registrar visitante' - residence_registration_pending: 'Apenas moradores podem administrar visitantes' + residence_pending: 'Apenas moradores podem administrar visitantes' manager_block: 'Um administrador não pode administrar visitantes para uma unidade' resident_block: 'Você não possui autorização para essa ação' not_allowed: 'Você não pode administrar visitantes para outra unidade além da sua' From a690fb7426f9f5fa269395a3eb5f7d271ba84968 Mon Sep 17 00:00:00 2001 From: thalytalima211 Date: Sat, 20 Jul 2024 17:39:43 -0300 Subject: [PATCH 06/10] Implementa pesquisa em listagem de visitantes do morador e registros de entrada e popula seeds Co-authored-by: Rafael Salgado --- app/controllers/visitor_entries_controller.rb | 20 ++- app/controllers/visitors_controller.rb | 38 +++--- app/models/condo.rb | 1 + app/models/resident.rb | 4 + .../dashboard/_todays_visitors.html.erb | 4 +- app/views/condos/show.html.erb | 2 +- app/views/visitor_entries/index.html.erb | 53 ++++++-- app/views/visitors/all.html.erb | 4 + app/views/visitors/find.html.erb | 5 +- app/views/visitors/index.html.erb | 50 +++++-- config/locales/models/visitor_entry.pt-br.yml | 8 +- db/seeds.rb | 58 ++++++++ ...ager_view_condo_full_visitors_list_spec.rb | 47 +++++++ .../resident_sees_own_visitors_list_spec.rb | 110 +++++++++++++++ .../manager_see_visitor_entries_spec.rb | 128 +++++++++++++++++- 15 files changed, 479 insertions(+), 53 deletions(-) create mode 100644 spec/requests/manager_view_condo_full_visitors_list_spec.rb diff --git a/app/controllers/visitor_entries_controller.rb b/app/controllers/visitor_entries_controller.rb index 19f481aa..8036900a 100644 --- a/app/controllers/visitor_entries_controller.rb +++ b/app/controllers/visitor_entries_controller.rb @@ -6,7 +6,17 @@ class VisitorEntriesController < ApplicationController before_action :set_breadcrumbs_for_index, only: %i[index] def index - @visitor_entries = VisitorEntry.all.order! 'created_at DESC' + return @visitor_entries = @condo.visitor_entries.order('created_at DESC') if check_empty_params + + query_params = params.permit(:full_name, :visit_date, :identity_number) + @result = [] + query_params.each do |key, value| + key = 'created_at' if key == 'visit_date' + @result << find_visitor_entries(key, value) if value.present? + end + + @visitor_entries = @result.reduce(:&) + @visitor_entries = @visitor_entries.order('created_at DESC') if @visitor_entries.many? end def new @@ -32,6 +42,14 @@ def visitor_entry_params params.require(:visitor_entry).permit :full_name, :identity_number, :unit_id end + def check_empty_params + params[:full_name].blank? && params[:visit_date].blank? && params[:identity_number].blank? + end + + def find_visitor_entries(key, value) + @condo.visitor_entries.where("#{key} LIKE ?", "%#{value}%") + end + def set_condo @condo = Condo.find(params[:condo_id]) end diff --git a/app/controllers/visitors_controller.rb b/app/controllers/visitors_controller.rb index 950c51cb..5964dd01 100644 --- a/app/controllers/visitors_controller.rb +++ b/app/controllers/visitors_controller.rb @@ -4,20 +4,25 @@ class VisitorsController < ApplicationController before_action :set_visitor, only: %i[confirm_entry] before_action :authenticate_resident!, only: %i[index new create] before_action :set_breadcrumbs_for_action, only: %i[index new create find] - before_action :authenticate_manager!, only: %i[find confirm_entry] - before_action -> { authorize_condo_manager(find_condo) }, only: %i[find confirm_entry] + before_action :authenticate_manager!, only: %i[find confirm_entry all] + before_action -> { authorize_condo_manager(find_condo) }, only: %i[find confirm_entry all] def index - @visitors = @resident.visitors + return @visitors = @resident.visitors if check_empty_params + + @result = [] + params.permit(:visitor_name, :category).each do |key, value| + key = 'full_name' if key == 'visitor_name' + @result << search_visitors(key, value, @resident) if value.present? + end + + @visitors = @result.reduce(:&) end def find @date = params[:date].present? ? params[:date].to_date : Time.zone.today - if @date.past? - return redirect_to find_condo_visitors_path(@condo), - alert: I18n.t('alerts.visitor.invalid_list_date') - end + return redirect_to find_condo_visitors_path(@condo), alert: t('alerts.visitor.invalid_list_date') if @date.past? @visitors = @condo.expected_visitors(@date) end @@ -25,12 +30,11 @@ def find def all return @visitors = @condo.visitors if check_empty_params - query_params = params.permit(:identity_number, :visitor_name, :resident_name, :visit_date) @result = [] - query_params.each do |key, value| + params.permit(:identity_number, :visitor_name, :resident_name, :visit_date).each do |key, value| key = 'full_name' if key == 'visitor_name' - @result << find_visitors(key, value) if value.present? + @result << search_visitors(key, value, @condo) if value.present? end @visitors = @result.reduce(:&) @@ -104,10 +108,8 @@ def set_visitor end def visitor_entry_params - { - full_name: @visitor.full_name, identity_number: @visitor.identity_number, - unit_id: @visitor.resident.residence.id, condo_id: @visitor.condo_id - } + { full_name: @visitor.full_name, identity_number: @visitor.identity_number, + unit_id: @visitor.resident.residence.id, condo_id: @visitor.condo_id } end def visitor_params @@ -121,12 +123,12 @@ def find_condo def check_empty_params params[:identity_number].blank? && params[:visitor_name].blank? && - params[:visit_date].blank? && params[:resident_name].blank? + params[:visit_date].blank? && params[:resident_name].blank? && params[:category].blank? end - def find_visitors(key, value) - return @condo.search_visitors_by_resident_name(value) if key == 'resident_name' + def search_visitors(key, value, model) + return model.search_visitors_by_resident_name(value) if key == 'resident_name' - @condo.search_visitors_by_params(key, value) + model.search_visitors_by_params(key, value) end end diff --git a/app/models/condo.rb b/app/models/condo.rb index f82d9ee7..b13a58dd 100644 --- a/app/models/condo.rb +++ b/app/models/condo.rb @@ -6,6 +6,7 @@ class Condo < ApplicationRecord has_many :condo_managers, dependent: :destroy has_many :managers, through: :condo_managers has_many :visitors, dependent: :destroy + has_many :visitor_entries, dependent: :destroy has_many :floors, through: :towers has_many :units, through: :floors has_many :owners, through: :units diff --git a/app/models/resident.rb b/app/models/resident.rb index 1856f7ac..99aef828 100644 --- a/app/models/resident.rb +++ b/app/models/resident.rb @@ -24,6 +24,10 @@ def todays_visitors visitors.where(visit_date: Date.current) end + def search_visitors_by_params(key, value) + visitors.where("#{key} LIKE ?", "%#{value}%") + end + def description "#{full_name} - #{email}" end diff --git a/app/views/condos/dashboard/_todays_visitors.html.erb b/app/views/condos/dashboard/_todays_visitors.html.erb index bf0fc510..8887863e 100644 --- a/app/views/condos/dashboard/_todays_visitors.html.erb +++ b/app/views/condos/dashboard/_todays_visitors.html.erb @@ -2,10 +2,10 @@ Visitantes e funcionários esperados para hoje
- <%= link_to new_resident_visitor_path(current_resident), class:"btn btn-dark rounded-pill d-flex mb-2 shadow-sm" do %> + <%= link_to new_resident_visitor_path(current_resident), class:"btn btn-dark rounded-pill d-flex align-items-center mb-2 shadow-sm" do %>

Cadastrar Visitante/Funcionário

<% end %> - <%= link_to resident_visitors_path(current_resident), class:"btn btn-dark rounded-pill d-flex mb-2 shadow-sm" do %> + <%= link_to resident_visitors_path(current_resident), class:"btn btn-dark rounded-pill d-flex align-items-center mb-2 shadow-sm" do %>

Ver todos

<% end %>
diff --git a/app/views/condos/show.html.erb b/app/views/condos/show.html.erb index cac8d629..37cc40a4 100644 --- a/app/views/condos/show.html.erb +++ b/app/views/condos/show.html.erb @@ -42,7 +42,7 @@ <% end %> <%= link_to find_condo_visitors_path(@condo), class:"btn py-2 btn-warning border-0 rounded-pill d-flex justify-content-center align-items-center mb-2 shadow-sm bg-light-yellow w-100" do %> Agenda de visitantes/funcionários - + <% end %> <% end %> <% if resident_signed_in? && current_resident.residence&.condo == @condo %> diff --git a/app/views/visitor_entries/index.html.erb b/app/views/visitor_entries/index.html.erb index 2ae1a0e2..18e2569e 100644 --- a/app/views/visitor_entries/index.html.erb +++ b/app/views/visitor_entries/index.html.erb @@ -5,7 +5,30 @@ <%= link_to 'Registrar nova Entrada de Visitante', new_condo_visitor_entry_path(@condo), class:'btn btn-dark rounded-pill px-4 m-2' %>
- + <%= form_with url: condo_visitor_entries_path(@condo), method: :get do |f| %> +
+
+ <%= f.label :full_name, I18n.t("activerecord.attributes.visitor_entry.full_name") %> + <%= f.text_field :full_name, class: "form-control" %> +
+
+ <%= f.label :identity_number, I18n.t("activerecord.attributes.visitor_entry.identity_number") %> + <%= f.text_field :identity_number, class: "form-control" %> +
+
+ <%= f.label :visit_date, I18n.t("activerecord.attributes.visitor_entry.visit_date") %> + <%= f.date_field :visit_date, class: "form-control" %> +
+
+ <%= f.submit "Pesquisar", class: "btn btn-dark rounded-pill d-inline-flex align-items-center mt-3 px-4 shadow-sm" %> +
+
+ <% end %> +
+ <% if @result %> + + <% end %> + @@ -15,18 +38,24 @@ - <% @visitor_entries.each do |visitor| %> - - - - + <% if @visitor_entries.any? %> + <% @visitor_entries.each do |visitor| %> + + + + - <% if visitor.unit.nil? %> - - <% else %> - - <% end %> - + <% if visitor.unit.nil? %> + + <% else %> + + <% end %> + + <% end %> + <% elsif @result %> +

Não foi possível encontrar entradas de visitantes com os filtros informados

+ <% else %> +

No momento, não há entradas de visitantes cadastradas

<% end %>
<%= "#{@visitor_entries.count} #{VisitorEntry.model_name.human(count: @visitor_entries.count).downcase} #{I18n.t('activerecord.attributes.visitor_entry.found', count: @visitor_entries.count).downcase}" %>
Nome Completo
<%= visitor.full_name %><%= visitor.identity_number %><%= I18n.l(visitor.created_at, format: :long) %>
<%= visitor.full_name %><%= visitor.identity_number %><%= I18n.l(visitor.created_at, format: :long) %>Sem unidade referenciada<%= visitor.unit.floor.tower.name %> - <%= visitor.unit.short_identifier %>
Sem unidade referenciada<%= visitor.unit.floor.tower.name %> - <%= visitor.unit.short_identifier %>
diff --git a/app/views/visitors/all.html.erb b/app/views/visitors/all.html.erb index f1b0290a..6cf57e73 100644 --- a/app/views/visitors/all.html.erb +++ b/app/views/visitors/all.html.erb @@ -1,6 +1,10 @@

Visitantes/Funcionários cadastrados no <%= @condo.name %>

+ <%= link_to find_condo_visitors_path(@condo), class:'btn btn-dark d-inline-flex align-items-center rounded-pill px-4 m-2' do %> + Ver Agenda + + <% end %>
<%= form_with url: all_condo_visitors_path(@condo), method: :get do |f| %> diff --git a/app/views/visitors/find.html.erb b/app/views/visitors/find.html.erb index 6c814260..7ff8a913 100644 --- a/app/views/visitors/find.html.erb +++ b/app/views/visitors/find.html.erb @@ -1,7 +1,10 @@

Agenda de visitantes/funcionários

- <%= link_to 'Ver Lista Completa', all_condo_visitors_path(@condo), class:'btn btn-dark rounded-pill px-4 m-2' %> + <%= link_to all_condo_visitors_path(@condo), class:'btn btn-dark d-inline-flex align-items-center rounded-pill px-4 m-2' do %> + Ver Lista Completa + + <% end %>
diff --git a/app/views/visitors/index.html.erb b/app/views/visitors/index.html.erb index 31537a8c..66d763c6 100644 --- a/app/views/visitors/index.html.erb +++ b/app/views/visitors/index.html.erb @@ -4,8 +4,28 @@

Meus visitantes/funcionários registrados

<%= link_to 'Registrar Nova Entrada de Visitante', new_resident_visitor_path(@resident), class:'btn btn-dark rounded-pill px-4 m-2' %>
+ + <%= form_with url: resident_visitors_path(current_resident), method: :get do |f| %> +
+
+ <%= f.label :visitor_name, I18n.t("activerecord.attributes.visitor.visitor_name") %> + <%= f.text_field :visitor_name, class: "form-control" %> +
+
+ <%= f.label :category, I18n.t("activerecord.attributes.visitor.category") %> + <%= f.select :category, Visitor.categories.map { |category, value| [I18n.t("activerecord.attributes.visitor.categories.#{category}"), value] }, { include_blank: true }, class: "form-control form-select" %> +
+
+ <%= f.submit "Pesquisar", class: "btn btn-dark rounded-pill d-inline-flex align-items-center mt-3 px-4 shadow-sm" %> +
+
+ <% end %> +
- +
+ <% if @result %> + + <% end %> @@ -15,17 +35,23 @@ - <% @visitors.each do |visitor| %> - - - - - - + <% if @visitors.any? %> + <% @visitors.each do |visitor| %> + + + + + + + <% end %> + <% elsif @result %> +

Não foi possível encontrar visitantes com os filtros informados

+ <% else %> +

Não há visitante/funcionário cadastrados

<% end %>
<%= "#{@visitors.count} #{Visitor.model_name.human(count: @visitors.count).downcase} #{I18n.t('activerecord.attributes.visitor.found', count: @visitors.count).downcase}" %>
Nome Completo
<%= visitor.full_name %><%= visitor.identity_number %><%= I18n.t("activerecord.attributes.visitor.categories.#{visitor.category}") %><%= I18n.l(visitor.visit_date) %> - <% if visitor.employee? %> - <%= I18n.t("activerecord.attributes.visitor.recurrences.#{visitor.recurrence}") %> - <% end %> -
<%= visitor.full_name %><%= visitor.identity_number %><%= I18n.t("activerecord.attributes.visitor.categories.#{visitor.category}") %><%= I18n.l(visitor.visit_date) %> + <% if visitor.employee? %> + <%= I18n.t("activerecord.attributes.visitor.recurrences.#{visitor.recurrence}") %> + <% end %> +
diff --git a/config/locales/models/visitor_entry.pt-br.yml b/config/locales/models/visitor_entry.pt-br.yml index 5f49ce30..df937113 100644 --- a/config/locales/models/visitor_entry.pt-br.yml +++ b/config/locales/models/visitor_entry.pt-br.yml @@ -9,9 +9,15 @@ pt-BR: access_denied: 'Você não tem permissão para acessar essa página.' activerecord: models: - visitor_entry: Entrada de Visitante + visitor_entry: + one: 'Entrada de Visitante' + other: 'Entradas de Visitante' attributes: visitor_entry: + found: + one: 'Encontrada' + other: 'Encontradas' + visit_date: 'Data da Visita' full_name: 'Nome Completo' identity_number: 'RG' unit_id: 'Unidade visitada' diff --git a/db/seeds.rb b/db/seeds.rb index 2adeb884..d306532c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -807,3 +807,61 @@ category: :employee, recurrence: :semiannual ) + +visitor_entry1 = VisitorEntry.create!( + condo: condo1, + full_name: 'Maria Fernandes', + identity_number: '1234567', + unit: tower1.floors[0].units[0] +) +visitor_entry2 = VisitorEntry.create!( + condo: condo1, + full_name: 'João Pereira', + identity_number: '2345678', + unit: tower1.floors[0].units[1] +) +visitor_entry3 = VisitorEntry.create!( + condo: condo1, + full_name: 'Ana Souza', + identity_number: '3456789', + unit: tower1.floors[1].units[3] +) +visitor_entry4 = VisitorEntry.create!( + condo: condo1, + full_name: 'Carlos Lima', + identity_number: '4567890' +) +visitor_entry5 = VisitorEntry.create!( + condo: condo1, + full_name: 'Patricia Mendes', + identity_number: '5678901' +) +visitor_entry6 = VisitorEntry.create!( + condo: condo1, + full_name: 'Lucas Alves', + identity_number: '6789012', + unit: tower1.floors[2].units[0] +) +visitor_entry7 = VisitorEntry.create!( + condo: condo1, + full_name: 'Mariana Costa', + identity_number: '7890123', + unit: tower2.floors[2].units[0] +) +visitor_entry8 = VisitorEntry.create!( + condo: condo1, + full_name: 'Fernando Gomes', + identity_number: '8901234', + unit: tower2.floors[0].units[0] +) +visitor_entry9 = VisitorEntry.create!( + condo: condo2, + full_name: 'Juliana Oliveira', + identity_number: '9012345', + unit: tower3.floors[0].units[0] +) +visitor_entry10 = VisitorEntry.create!( + condo: condo2, + full_name: 'Gustavo Ferreira', + identity_number: '0123456' +) diff --git a/spec/requests/manager_view_condo_full_visitors_list_spec.rb b/spec/requests/manager_view_condo_full_visitors_list_spec.rb new file mode 100644 index 00000000..6228fdf6 --- /dev/null +++ b/spec/requests/manager_view_condo_full_visitors_list_spec.rb @@ -0,0 +1,47 @@ +require 'rails_helper' + +describe 'Manager view condo full visitors list' do + context 'GET /condos/:id/visitors/all' do + it 'only if authenticated' do + condo = create(:condo) + + get all_condo_visitors_path condo + + expect(response).to redirect_to new_manager_session_path + expect(flash[:alert]).to eq 'Para continuar, faça login ou registre-se.' + end + + it 'only if associated with the condo' do + condo = create(:condo) + manager = create(:manager, is_super: false) + + login_as manager, scope: :manager + get all_condo_visitors_path condo + + expect(response).to redirect_to root_path + expect(flash[:alert]).to eq 'Você não tem permissão para fazer isso' + end + + it 'successfully if associated with the condo' do + condo = create(:condo) + manager = create(:manager, is_super: false) + manager.condos << condo + + login_as manager, scope: :manager + get all_condo_visitors_path condo + + expect(response).to have_http_status :ok + end + + it 'and cannot be authenticated as resident' do + condo = create(:condo) + resident = create(:resident) + + login_as resident, scope: :resident + get all_condo_visitors_path condo + + expect(response).to redirect_to root_path + expect(flash[:alert]).to eq 'Você não possui autorização para essa ação' + end + end +end diff --git a/spec/system/visitor/resident_sees_own_visitors_list_spec.rb b/spec/system/visitor/resident_sees_own_visitors_list_spec.rb index 67c09e16..7aa4c061 100644 --- a/spec/system/visitor/resident_sees_own_visitors_list_spec.rb +++ b/spec/system/visitor/resident_sees_own_visitors_list_spec.rb @@ -47,6 +47,15 @@ expect(page).to have_content 'Você não pode administrar visitantes para outra unidade além da sua' end + it 'and sees no visitors registered' do + resident = create :resident, :with_residence + + login_as resident, scope: :resident + visit resident_visitors_path resident + + expect(page).to have_content 'Não há visitante/funcionário cadastrados' + end + it 'only if as a tenant' do resident = create :resident @@ -147,4 +156,105 @@ end end end + + context 'and searchs' do + it 'with visitor name filter' do + resident = create :resident, :with_residence + first_visitor = create :visitor, resident:, full_name: 'João Ferreira', identity_number: 145_364 + second_visitor = create :visitor, resident:, full_name: 'João Almeida', identity_number: 45_897 + third_visitor = create :visitor, resident:, full_name: 'Fernando Dias' + + login_as resident, scope: :resident + visit resident_visitors_path resident + fill_in 'Nome do Visitante', with: 'João' + click_on 'Pesquisar' + + expect(page).to have_content '2 visitantes encontrados' + within("#visitor-#{first_visitor.id}") do + expect(page).to have_content 'João Ferreira' + expect(page).to have_content '145364' + end + within("#visitor-#{second_visitor.id}") do + expect(page).to have_content 'João Almeida' + expect(page).to have_content '45897' + end + expect(page).not_to have_css "#visitor-#{third_visitor.id}" + expect(page).not_to have_content 'Fernando Dias' + end + + it 'with visitor category filter' do + resident = create :resident, :with_residence + first_visitor = create :visitor, resident:, category: :visitor, + full_name: 'João Ferreira', identity_number: 145_364 + second_visitor = create :visitor, resident:, category: :visitor, + full_name: 'Mario Almeida', identity_number: 45_897 + third_visitor = create :visitor, resident:, category: :employee, recurrence: :weekly, + full_name: 'Fernando Dias' + + login_as resident, scope: :resident + visit resident_visitors_path resident + select 'Visitante', from: 'Categoria' + click_on 'Pesquisar' + + expect(page).to have_content '2 visitantes encontrados' + within("#visitor-#{first_visitor.id}") do + expect(page).to have_content 'João Ferreira' + expect(page).to have_content '145364' + end + within("#visitor-#{second_visitor.id}") do + expect(page).to have_content 'Mario Almeida' + expect(page).to have_content '45897' + end + expect(page).not_to have_css "#visitor-#{third_visitor.id}" + expect(page).not_to have_content 'Fernando Dias' + end + + it 'with both filters' do + resident = create :resident, :with_residence + first_visitor = create :visitor, resident:, category: :visitor, + full_name: 'João Ferreira', identity_number: 145_364 + second_visitor = create :visitor, resident:, category: :visitor, + full_name: 'João Almeida', identity_number: 45_897 + third_visitor = create :visitor, resident:, category: :employee, recurrence: :weekly, + full_name: 'João Dias' + + login_as resident, scope: :resident + visit resident_visitors_path resident + fill_in 'Nome do Visitante', with: 'João' + select 'Visitante', from: 'Categoria' + click_on 'Pesquisar' + + expect(page).to have_content '2 visitantes encontrados' + within("#visitor-#{first_visitor.id}") do + expect(page).to have_content 'João Ferreira' + expect(page).to have_content '145364' + end + within("#visitor-#{second_visitor.id}") do + expect(page).to have_content 'João Almeida' + expect(page).to have_content '45897' + end + expect(page).not_to have_css "#visitor-#{third_visitor.id}" + expect(page).not_to have_content 'Fernando Dias' + end + it 'and no visitor is found' do + resident = create :resident, :with_residence + first_visitor = create :visitor, resident:, category: :visitor, + full_name: 'Maria Ferreira', identity_number: 145_364 + second_visitor = create :visitor, resident:, category: :employee, recurrence: :weekly, + full_name: 'Maria Dias' + + login_as resident, scope: :resident + visit resident_visitors_path resident + fill_in 'Nome do Visitante', with: 'João' + select 'Visitante', from: 'Categoria' + click_on 'Pesquisar' + + expect(page).to have_content '0 visitantes encontrados' + expect(page).to have_content 'Não foi possível encontrar visitantes com os filtros informados' + expect(page).not_to have_css "#visitor-#{first_visitor.id}" + expect(page).not_to have_content 'Maria Ferreira' + expect(page).not_to have_css "#visitor-#{second_visitor.id}" + expect(page).not_to have_content 'Maria Dias' + end + end end diff --git a/spec/system/visitor_entry/manager_see_visitor_entries_spec.rb b/spec/system/visitor_entry/manager_see_visitor_entries_spec.rb index 0ecb3f24..461dcbcd 100644 --- a/spec/system/visitor_entry/manager_see_visitor_entries_spec.rb +++ b/spec/system/visitor_entry/manager_see_visitor_entries_spec.rb @@ -16,19 +16,32 @@ it 'and the list of visitors appears in descending order of entry (created_at)' do manager = create :manager - condo = create :condo - create :visitor_entry, condo:, full_name: 'Nome Primeiro Visitante' - create :visitor_entry, condo:, full_name: 'Nome Último Visitante' + first_condo = create :condo + second_condo = create :condo + create :visitor_entry, condo: first_condo, full_name: 'Nome Primeiro Visitante' + create :visitor_entry, condo: first_condo, full_name: 'Nome Segundo Visitante' + create :visitor_entry, condo: second_condo, full_name: 'Nome Terceiro Visitante' login_as manager, scope: :manager - visit condo_visitor_entries_path condo + visit condo_visitor_entries_path first_condo within('.table > tbody > tr:nth-child(1)') do - expect(page).to have_content 'Nome Último Visitante' + expect(page).to have_content 'Nome Segundo Visitante' end within('.table > tbody > tr:nth-child(2)') do expect(page).to have_content 'Nome Primeiro Visitante' end + expect(page).not_to have_content 'Nome Terceiro Visitante' + end + + it 'and sees if list is empty' do + manager = create :manager + condo = create :condo + + login_as manager, scope: :manager + visit condo_visitor_entries_path condo + + expect(page).to have_content 'No momento, não há entradas de visitantes cadastradas' end it 'and a resident cant see the links related to visitors entries' do @@ -62,4 +75,109 @@ expect(current_path).to eq root_path end end + + context 'and search a entry' do + it 'with full name filter' do + manager = create :manager + condo = create :condo + create :visitor_entry, condo:, full_name: 'Nome Primeiro Visitante' + create :visitor_entry, condo:, full_name: 'Nome Último Visitante' + + login_as manager, scope: :manager + visit condo_visitor_entries_path condo + fill_in 'Nome Completo', with: 'Primeiro' + click_on 'Pesquisar' + + expect(page).to have_content '1 entrada de visitante encontrada' + within('.table > tbody > tr:nth-child(1)') { expect(page).to have_content 'Nome Primeiro Visitante' } + expect(page).not_to have_content 'Nome Último Visitante' + end + + it 'with visit date filter' do + manager = create :manager + condo = create :condo + create :visitor_entry, condo:, full_name: 'Nome Primeiro Visitante' + create :visitor_entry, condo:, full_name: 'Nome Último Visitante' + + login_as manager, scope: :manager + visit condo_visitor_entries_path condo + fill_in 'Data da Visita', with: Time.zone.today + click_on 'Pesquisar' + + expect(page).to have_content '2 entradas de visitante encontrada' + within('.table > tbody > tr:nth-child(1)') { expect(page).to have_content 'Nome Último Visitante' } + within('.table > tbody > tr:nth-child(2)') { expect(page).to have_content 'Nome Primeiro Visitante' } + end + + it 'with identity number filter' do + manager = create :manager + condo = create :condo + create :visitor_entry, condo:, full_name: 'Nome Primeiro Visitante', identity_number: '145697' + create :visitor_entry, condo:, full_name: 'Nome Último Visitante', identity_number: '789354' + + login_as manager, scope: :manager + visit condo_visitor_entries_path condo + fill_in 'RG', with: '789354' + click_on 'Pesquisar' + + expect(page).to have_content '1 entrada de visitante encontrada' + within('.table > tbody > tr:nth-child(1)') { expect(page).to have_content 'Nome Último Visitante' } + expect(page).not_to have_content 'Nome Primeiro Visitante' + end + + it 'with all filters' do + manager = create :manager + condo = create :condo + create :visitor_entry, condo:, full_name: 'Nome Primeiro Visitante', identity_number: '145697' + create :visitor_entry, condo:, full_name: 'Nome Segundo Visitante', identity_number: '789354' + create :visitor_entry, condo:, full_name: 'Nome Terceiro Visitante', identity_number: '78935447' + + login_as manager, scope: :manager + visit condo_visitor_entries_path condo + fill_in 'Nome Completo', with: 'Segundo' + fill_in 'RG', with: '789354' + fill_in 'Data da Visita', with: Time.zone.today + click_on 'Pesquisar' + + expect(page).to have_content '1 entrada de visitante encontrada' + within('.table > tbody > tr:nth-child(1)') { expect(page).to have_content 'Nome Segundo Visitante' } + expect(page).not_to have_content 'Nome Primeiro Visitante' + expect(page).not_to have_content 'Nome Terceiro Visitante' + end + + it 'with no filters' do + manager = create :manager + condo = create :condo + create :visitor_entry, condo:, full_name: 'Nome Primeiro Visitante' + create :visitor_entry, condo:, full_name: 'Nome Segundo Visitante' + create :visitor_entry, condo:, full_name: 'Nome Terceiro Visitante' + + login_as manager, scope: :manager + visit condo_visitor_entries_path condo + fill_in 'Nome Completo', with: '' + fill_in 'RG', with: '' + fill_in 'Data da Visita', with: '' + click_on 'Pesquisar' + + within('.table > tbody > tr:nth-child(1)') { expect(page).to have_content 'Nome Terceiro Visitante' } + within('.table > tbody > tr:nth-child(2)') { expect(page).to have_content 'Nome Segundo Visitante' } + within('.table > tbody > tr:nth-child(3)') { expect(page).to have_content 'Nome Primeiro Visitante' } + expect(page).not_to have_content '3 entradas de visitante encontrada' + end + + it 'and finds no entry' do + manager = create :manager + condo = create :condo + create :visitor_entry, condo:, full_name: 'Nome Primeiro Visitante' + create :visitor_entry, condo:, full_name: 'Nome Segundo Visitante' + + login_as manager, scope: :manager + visit condo_visitor_entries_path condo + fill_in 'Nome Completo', with: 'Terceiro' + click_on 'Pesquisar' + + expect(page).to have_content '0 entradas de visitante encontradas' + expect(page).to have_content 'Não foi possível encontrar entradas de visitantes com os filtros informados' + end + end end From bb4f45144734ae1c11ebb348321bde8039e2c473 Mon Sep 17 00:00:00 2001 From: Rafael Salgado Date: Sat, 20 Jul 2024 18:31:10 -0300 Subject: [PATCH 07/10] Ajusta breadcrumb Co-authored-by: thalyta lima --- app/controllers/visitors_controller.rb | 2 +- app/views/visitors/all.html.erb | 16 +++++++++------- config/locales/breadcrumb.pt-BR.yml | 1 + 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/controllers/visitors_controller.rb b/app/controllers/visitors_controller.rb index 5964dd01..28a940e4 100644 --- a/app/controllers/visitors_controller.rb +++ b/app/controllers/visitors_controller.rb @@ -3,7 +3,7 @@ class VisitorsController < ApplicationController before_action :set_condo, only: %i[find all] before_action :set_visitor, only: %i[confirm_entry] before_action :authenticate_resident!, only: %i[index new create] - before_action :set_breadcrumbs_for_action, only: %i[index new create find] + before_action :set_breadcrumbs_for_action, only: %i[index new create find all] before_action :authenticate_manager!, only: %i[find confirm_entry all] before_action -> { authorize_condo_manager(find_condo) }, only: %i[find confirm_entry all] diff --git a/app/views/visitors/all.html.erb b/app/views/visitors/all.html.erb index 6cf57e73..a352ad5a 100644 --- a/app/views/visitors/all.html.erb +++ b/app/views/visitors/all.html.erb @@ -1,7 +1,9 @@
-
-

Visitantes/Funcionários cadastrados no <%= @condo.name %>

- <%= link_to find_condo_visitors_path(@condo), class:'btn btn-dark d-inline-flex align-items-center rounded-pill px-4 m-2' do %> + +

Visitantes/Funcionários cadastrados no <%= @condo.name %>

+ +
+ <%= link_to find_condo_visitors_path(@condo), class:'btn btn-dark d-flex justify-content-center align-items-center rounded-pill px-4' do %> Ver Agenda <% end %> @@ -10,16 +12,16 @@ <%= form_with url: all_condo_visitors_path(@condo), method: :get do |f| %>
- <%= f.label :resident_name, I18n.t("activerecord.attributes.visitor.resident_name") %> - <%= f.text_field :resident_name, class: "form-control" %> + <%= f.label :visitor_name, I18n.t("activerecord.attributes.visitor.visitor_name") %> + <%= f.text_field :visitor_name, class: "form-control" %>
<%= f.label :identity_number, I18n.t("activerecord.attributes.visitor.identity_number") %> <%= f.text_field :identity_number, class: "form-control" %>
- <%= f.label :visitor_name, I18n.t("activerecord.attributes.visitor.visitor_name") %> - <%= f.text_field :visitor_name, class: "form-control" %> + <%= f.label :resident_name, I18n.t("activerecord.attributes.visitor.resident_name") %> + <%= f.text_field :resident_name, class: "form-control" %>
<%= f.label :visit_date, I18n.t("activerecord.attributes.visitor.visit_date_query") %> diff --git a/config/locales/breadcrumb.pt-BR.yml b/config/locales/breadcrumb.pt-BR.yml index 3943b0ee..a5716c0a 100644 --- a/config/locales/breadcrumb.pt-BR.yml +++ b/config/locales/breadcrumb.pt-BR.yml @@ -34,6 +34,7 @@ pt-BR: create: 'Cadastrar Visitante/Funcionário' index: 'Listagem de Visitantes/Funcionários' find: 'Agenda de Visitantes/Funcionários' + all: 'Listagem completa de Visitantes/Funcionários' bill: index: 'Lista de faturas' show: 'Detalhes de fatura' From b8229777fe203fe8bf0f8a3c5ca05acac9ca877c Mon Sep 17 00:00:00 2001 From: Rafael Salgado Date: Sun, 21 Jul 2024 15:58:36 -0300 Subject: [PATCH 08/10] Realiza ajustes indicados no PR Co-authored-by: thalyta lima --- app/controllers/visitor_entries_controller.rb | 5 +- app/controllers/visitors_controller.rb | 3 +- app/views/visitors/all.html.erb | 6 +- ...ager_view_condo_full_visitors_list_spec.rb | 97 ++++++++----------- .../manager_see_visitor_entries_spec.rb | 6 +- 5 files changed, 53 insertions(+), 64 deletions(-) diff --git a/app/controllers/visitor_entries_controller.rb b/app/controllers/visitor_entries_controller.rb index 8036900a..bf18624f 100644 --- a/app/controllers/visitor_entries_controller.rb +++ b/app/controllers/visitor_entries_controller.rb @@ -8,9 +8,8 @@ class VisitorEntriesController < ApplicationController def index return @visitor_entries = @condo.visitor_entries.order('created_at DESC') if check_empty_params - query_params = params.permit(:full_name, :visit_date, :identity_number) @result = [] - query_params.each do |key, value| + params.permit(:full_name, :visit_date, :identity_number).each do |key, value| key = 'created_at' if key == 'visit_date' @result << find_visitor_entries(key, value) if value.present? end @@ -43,7 +42,7 @@ def visitor_entry_params end def check_empty_params - params[:full_name].blank? && params[:visit_date].blank? && params[:identity_number].blank? + params.values_at(:identity_number, :full_name, :visit_date).all?(&:blank?) end def find_visitor_entries(key, value) diff --git a/app/controllers/visitors_controller.rb b/app/controllers/visitors_controller.rb index 28a940e4..739a5e36 100644 --- a/app/controllers/visitors_controller.rb +++ b/app/controllers/visitors_controller.rb @@ -122,8 +122,7 @@ def find_condo end def check_empty_params - params[:identity_number].blank? && params[:visitor_name].blank? && - params[:visit_date].blank? && params[:resident_name].blank? && params[:category].blank? + params.values_at(:identity_number, :visitor_name, :visit_date, :resident_name, :category).all?(&:blank?) end def search_visitors(key, value, model) diff --git a/app/views/visitors/all.html.erb b/app/views/visitors/all.html.erb index a352ad5a..ec2b64be 100644 --- a/app/views/visitors/all.html.erb +++ b/app/views/visitors/all.html.erb @@ -44,10 +44,10 @@ Nome Completo RG - Categoria: + Categoria Unidade - Responsavel: - Data Autorizada: + Responsavel + Data Autorizada diff --git a/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb b/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb index 9b8bd38b..b2ea2e60 100644 --- a/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb +++ b/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb @@ -8,15 +8,26 @@ second_condo = create :condo first_resident = create :resident, full_name: 'Alberto Silveira', residence: tower.floors[0].units[0] second_resident = create :resident, full_name: 'Maria Silveira', residence: tower.floors[0].units[1] - first_visitor = create :visitor, condo: first_condo, resident: first_resident, - visit_date: Time.zone.today, full_name: 'João da Silva', identity_number: '12467' - second_visitor = create :visitor, condo: first_condo, resident: first_resident, - category: :employee, recurrence: :weekly, - visit_date: Time.zone.today, full_name: 'Maria Oliveira', identity_number: '45977' - third_visitor = create :visitor, condo: first_condo, resident: second_resident, - visit_date: 1.day.from_now, full_name: 'Marcos Lima', identity_number: '12345' + first_visitor = create :visitor, condo: first_condo, + resident: first_resident, + visit_date: Time.zone.today, + full_name: 'João da Silva', + identity_number: '12467' + second_visitor = create :visitor, condo: first_condo, + resident: first_resident, + category: :employee, + recurrence: :weekly, + visit_date: Time.zone.today, + full_name: 'Maria Oliveira', + identity_number: '45977' + third_visitor = create :visitor, condo: first_condo, + resident: second_resident, + visit_date: 1.day.from_now, + full_name: 'Marcos Lima', + identity_number: '12345' fourth_visitor = create :visitor, condo: second_condo, - visit_date: Time.zone.today, full_name: 'Juliana Ferreira' + visit_date: Time.zone.today, + full_name: 'Juliana Ferreira' login_as manager, scope: :manager visit find_condo_visitors_path first_condo @@ -53,7 +64,7 @@ expect(page).not_to have_content 'Juliana Ferreira' end - it 'and sees if list is empty' do + it "and there's no visitors registered" do manager = create :manager condo = create :condo @@ -69,10 +80,13 @@ resident = create :resident, :with_residence, full_name: 'Alberto Silveira' condo = resident.residence.condo first_visitor = create :visitor, condo:, resident:, - visit_date: Time.zone.today, full_name: 'João da Silva', identity_number: '12467' + full_name: 'João da Silva', + identity_number: '12467' second_visitor = create :visitor, condo:, resident:, - category: :employee, recurrence: :weekly, - visit_date: Time.zone.today, full_name: 'Maria Lima', identity_number: '4677811' + category: :employee, + recurrence: :weekly, + full_name: 'Maria Lima', + identity_number: '4677811' create :visitor, condo:, full_name: 'Marcos Lima', identity_number: '12345' login_as manager, scope: :manager @@ -85,31 +99,27 @@ expect(page).to have_content 'João da Silva' expect(page).to have_content '12467' expect(page).to have_content 'Visitante' - expect(page).to have_content 'Torre A - 11' expect(page).to have_content 'Alberto Silveira' - expect(page).to have_content I18n.l(Time.zone.today) end within("#visitor-#{second_visitor.id}") do expect(page).to have_content 'Maria Lima' expect(page).to have_content '4677811' expect(page).to have_content 'Funcionário' - expect(page).to have_content 'Torre A - 11' expect(page).to have_content 'Alberto Silveira' - expect(page).to have_content I18n.l(Time.zone.today) expect(page).to have_content 'Semanal' end expect(page).not_to have_content 'Marcos Lima' end + it 'with visitors name filter' do manager = create :manager resident = create :resident, :with_residence, full_name: 'Alberto Silveira' condo = resident.residence.condo first_visitor = create :visitor, condo:, resident:, - visit_date: Time.zone.today, full_name: 'João da Silva', identity_number: '12467' + full_name: 'João da Silva' second_visitor = create :visitor, condo:, resident:, - category: :employee, recurrence: :weekly, - visit_date: 2.days.from_now, full_name: 'João Sousa', identity_number: '13331' - create :visitor, condo:, full_name: 'Marcos Lima', identity_number: '12345' + full_name: 'João Sousa' + create :visitor, condo:, full_name: 'Marcos Lima' login_as manager, scope: :manager visit all_condo_visitors_path condo @@ -119,33 +129,24 @@ expect(page).to have_content '2 visitantes encontrados' within("#visitor-#{first_visitor.id}") do expect(page).to have_content 'João da Silva' - expect(page).to have_content '12467' - expect(page).to have_content 'Visitante' - expect(page).to have_content 'Torre A - 11' expect(page).to have_content 'Alberto Silveira' - expect(page).to have_content I18n.l(Time.zone.today) end within("#visitor-#{second_visitor.id}") do expect(page).to have_content 'João Sousa' - expect(page).to have_content '13331' - expect(page).to have_content 'Funcionário' - expect(page).to have_content 'Torre A - 11' expect(page).to have_content 'Alberto Silveira' - expect(page).to have_content I18n.l(2.days.from_now.to_date) - expect(page).to have_content 'Semanal' end expect(page).not_to have_content 'Marcos Lima' end + it 'with resident name filter' do manager = create :manager resident = create :resident, :with_residence, full_name: 'Alberto Silveira' condo = resident.residence.condo first_visitor = create :visitor, condo:, resident:, - visit_date: Time.zone.today, full_name: 'João da Silva', identity_number: '12467' + full_name: 'João da Silva' second_visitor = create :visitor, condo:, resident:, - category: :employee, recurrence: :weekly, - visit_date: 2.days.from_now, full_name: 'Bruna Lima', identity_number: '13331' - create :visitor, condo:, full_name: 'Marcos Lima', identity_number: '12345' + full_name: 'Bruna Lima' + create :visitor, condo:, full_name: 'Marcos Lima' login_as manager, scope: :manager visit all_condo_visitors_path condo @@ -155,20 +156,11 @@ expect(page).to have_content '2 visitantes encontrados' within("#visitor-#{first_visitor.id}") do expect(page).to have_content 'João da Silva' - expect(page).to have_content '12467' - expect(page).to have_content 'Visitante' - expect(page).to have_content 'Torre A - 11' expect(page).to have_content 'Alberto Silveira' - expect(page).to have_content I18n.l(Time.zone.today) end within("#visitor-#{second_visitor.id}") do expect(page).to have_content 'Bruna Lima' - expect(page).to have_content '13331' - expect(page).to have_content 'Funcionário' - expect(page).to have_content 'Torre A - 11' expect(page).to have_content 'Alberto Silveira' - expect(page).to have_content I18n.l(2.days.from_now.to_date) - expect(page).to have_content 'Semanal' end expect(page).not_to have_content 'Marcos Lima' end @@ -178,11 +170,12 @@ resident = create :resident, :with_residence, full_name: 'Alberto Silveira' condo = resident.residence.condo first_visitor = create :visitor, condo:, resident:, - visit_date: 2.days.from_now, full_name: 'João da Silva', identity_number: '12467' + visit_date: 2.days.from_now, + full_name: 'João da Silva' second_visitor = create :visitor, condo:, resident:, - category: :employee, recurrence: :weekly, - visit_date: 2.days.from_now, full_name: 'Bruna Lima', identity_number: '13331' - create :visitor, condo:, full_name: 'Marcos Lima', identity_number: '12345' + visit_date: 2.days.from_now, + full_name: 'Bruna Lima' + create :visitor, condo:, full_name: 'Marcos Lima' login_as manager, scope: :manager visit all_condo_visitors_path condo @@ -192,20 +185,13 @@ expect(page).to have_content '2 visitantes encontrados' within("#visitor-#{first_visitor.id}") do expect(page).to have_content 'João da Silva' - expect(page).to have_content '12467' - expect(page).to have_content 'Visitante' - expect(page).to have_content 'Torre A - 11' expect(page).to have_content 'Alberto Silveira' expect(page).to have_content I18n.l(2.days.from_now.to_date) end within("#visitor-#{second_visitor.id}") do expect(page).to have_content 'Bruna Lima' - expect(page).to have_content '13331' - expect(page).to have_content 'Funcionário' - expect(page).to have_content 'Torre A - 11' expect(page).to have_content 'Alberto Silveira' expect(page).to have_content I18n.l(2.days.from_now.to_date) - expect(page).to have_content 'Semanal' end expect(page).not_to have_content 'Marcos Lima' end @@ -215,7 +201,9 @@ resident = create :resident, :with_residence, full_name: 'Alberto Silveira' condo = resident.residence.condo first_visitor = create :visitor, condo:, resident:, - visit_date: 2.days.from_now, full_name: 'João da Silva', identity_number: '12467' + visit_date: 2.days.from_now, + full_name: 'João da Silva', + identity_number: '12467' create :visitor, condo:, full_name: 'Bruna Lima' create :visitor, condo:, full_name: 'Marcos Ferreira' @@ -232,7 +220,6 @@ expect(page).to have_content 'João da Silva' expect(page).to have_content '12467' expect(page).to have_content 'Visitante' - expect(page).to have_content 'Torre A - 11' expect(page).to have_content 'Alberto Silveira' expect(page).to have_content I18n.l(2.days.from_now.to_date) end diff --git a/spec/system/visitor_entry/manager_see_visitor_entries_spec.rb b/spec/system/visitor_entry/manager_see_visitor_entries_spec.rb index 461dcbcd..03447a43 100644 --- a/spec/system/visitor_entry/manager_see_visitor_entries_spec.rb +++ b/spec/system/visitor_entry/manager_see_visitor_entries_spec.rb @@ -34,7 +34,7 @@ expect(page).not_to have_content 'Nome Terceiro Visitante' end - it 'and sees if list is empty' do + it "and there's no visitors entries" do manager = create :manager condo = create :condo @@ -96,6 +96,9 @@ it 'with visit date filter' do manager = create :manager condo = create :condo + travel_to 1.day.ago do + create :visitor_entry, condo:, full_name: 'Nome Visitante Ontem' + end create :visitor_entry, condo:, full_name: 'Nome Primeiro Visitante' create :visitor_entry, condo:, full_name: 'Nome Último Visitante' @@ -107,6 +110,7 @@ expect(page).to have_content '2 entradas de visitante encontrada' within('.table > tbody > tr:nth-child(1)') { expect(page).to have_content 'Nome Último Visitante' } within('.table > tbody > tr:nth-child(2)') { expect(page).to have_content 'Nome Primeiro Visitante' } + expect(page).not_to have_content 'Nome Visitante Ontem' end it 'with identity number filter' do From 8b9367128a1fc7bb2454010c088af5f42550d393 Mon Sep 17 00:00:00 2001 From: Rafael Salgado Date: Sun, 21 Jul 2024 17:50:58 -0300 Subject: [PATCH 09/10] Ajusta comentarios nao feitos no PR Co-authored-by: thalyta lima --- app/views/visitors/all.html.erb | 2 +- .../manager_view_condo_full_visitors_list_spec.rb | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/views/visitors/all.html.erb b/app/views/visitors/all.html.erb index ec2b64be..3374a147 100644 --- a/app/views/visitors/all.html.erb +++ b/app/views/visitors/all.html.erb @@ -46,7 +46,7 @@ RG Categoria Unidade - Responsavel + Responsável Data Autorizada diff --git a/spec/requests/manager_view_condo_full_visitors_list_spec.rb b/spec/requests/manager_view_condo_full_visitors_list_spec.rb index 6228fdf6..6fb7bf04 100644 --- a/spec/requests/manager_view_condo_full_visitors_list_spec.rb +++ b/spec/requests/manager_view_condo_full_visitors_list_spec.rb @@ -3,7 +3,7 @@ describe 'Manager view condo full visitors list' do context 'GET /condos/:id/visitors/all' do it 'only if authenticated' do - condo = create(:condo) + condo = create :condo get all_condo_visitors_path condo @@ -12,8 +12,8 @@ end it 'only if associated with the condo' do - condo = create(:condo) - manager = create(:manager, is_super: false) + condo = create :condo + manager = create :manager, is_super: false login_as manager, scope: :manager get all_condo_visitors_path condo @@ -23,8 +23,8 @@ end it 'successfully if associated with the condo' do - condo = create(:condo) - manager = create(:manager, is_super: false) + condo = create :condo + manager = create :manager, is_super: false manager.condos << condo login_as manager, scope: :manager @@ -34,8 +34,8 @@ end it 'and cannot be authenticated as resident' do - condo = create(:condo) - resident = create(:resident) + condo = create :condo + resident = create :resident login_as resident, scope: :resident get all_condo_visitors_path condo From 9cc0dc79b80f73f6e2d0eaebd8ff5718c5f88970 Mon Sep 17 00:00:00 2001 From: Rafael Salgado Date: Sun, 21 Jul 2024 17:54:32 -0300 Subject: [PATCH 10/10] Enter na linha 228 do teste de sistema resident sees own visitors list Co-authored-by: thalytalima211 --- spec/system/visitor/resident_sees_own_visitors_list_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/system/visitor/resident_sees_own_visitors_list_spec.rb b/spec/system/visitor/resident_sees_own_visitors_list_spec.rb index 7aa4c061..0d9b446a 100644 --- a/spec/system/visitor/resident_sees_own_visitors_list_spec.rb +++ b/spec/system/visitor/resident_sees_own_visitors_list_spec.rb @@ -236,6 +236,7 @@ expect(page).not_to have_css "#visitor-#{third_visitor.id}" expect(page).not_to have_content 'Fernando Dias' end + it 'and no visitor is found' do resident = create :resident, :with_residence first_visitor = create :visitor, resident:, category: :visitor,