Commit d1441f36 authored by Matheus Horstmann's avatar Matheus Horstmann 🐴
Browse files

Merge branch 'master' of gitlab.c3sl.ufpr.br:agendador/agendador into new_cep_method

parents aab3d4df f5d2f13e
load_professionals = (app_root_url, service_place_id = '', city_hall_id = 0) ->
$('select#report_professional_performer_id_eq').attr('disabled', 'disabled').html('<option value="">Carregando profissionais...</option>')
load_professionals = (app_root_url, field, service_place_id = '', city_hall_id = 0) ->
$(field).attr('disabled', 'disabled').html('<option value="">Carregando profissionais...</option>')
# get service_place's professionals
select = ['<option value="">Todos</option>']
if service_place_id == ''
......@@ -15,15 +15,15 @@ load_professionals = (app_root_url, service_place_id = '', city_hall_id = 0) ->
select.push('<option value="' + item.id + '">' + item.name + '</option>')
)
if select.length > 1
$('select#report_professional_performer_id_eq').html(select)
$(field).html(select)
.removeAttr('disabled')
else
$('select#report_professional_performer_id_eq').attr('disabled', 'disabled')
$(field).attr('disabled', 'disabled')
.html('<option value="">Nenhum profissional cadastrado neste local!</option>')
)
load_service_types = (app_root_url, service_place_id = '', city_hall_id = 0) ->
$('select#report_service_type_id_eq').attr('disabled', 'disabled').html('<option value="">Carregando tipos de atendimento...</option>')
load_service_types = (app_root_url, field, service_place_id = '', city_hall_id = 0) ->
$(field).attr('disabled', 'disabled').html('<option value="">Carregando tipos de atendimento...</option>')
# get service_place's service_types
select = ['<option value="">Todos</option>']
if service_place_id == ''
......@@ -39,16 +39,16 @@ load_service_types = (app_root_url, service_place_id = '', city_hall_id = 0) ->
select.push('<option value="' + item.id + '">' + item.description + '</option>')
)
if select.length > 1
$('select#report_service_type_id_eq').html(select)
$(field).html(select)
.removeAttr('disabled')
else
$('select#report_service_type_id_eq').attr('disabled', 'disabled')
$(field).attr('disabled', 'disabled')
.html('<option value="">Nenhum tipo de atendimento cadastrado neste local!</option>')
)
load_service_places = (app_root_url, city_hall_id) ->
$('select#report_service_place_id_eq').attr('disabled', 'disabled').html('<option value="">Carregando locais de atendimento...</option>')
# get city_hall's service_palces
load_service_places = (app_root_url, field, city_hall_id) ->
$(field).attr('disabled', 'disabled').html('<option value="">Carregando locais de atendimento...</option>')
# get city_hall's service_places
select = ['<option value="">Todos</option>']
$.getJSON(app_root_url + 'city_halls/' + parseInt(city_hall_id) + '/service_places')
.done((dados) ->
......@@ -56,13 +56,31 @@ load_service_places = (app_root_url, city_hall_id) ->
select.push('<option value="' + item.id + '">' + item.name + '</option>')
)
if select.length > 1
$('select#report_service_place_id_eq').html(select)
$(field).html(select)
.removeAttr('disabled')
else
$('select#report_service_place_id_eq').attr('disabled', 'disabled')
$(field).attr('disabled', 'disabled')
.html('<option value="">Nenhum local de atendimento cadastrado nesta prefeitura!</option>')
)
load_occupations = (app_root_url, city_hall_id) ->
$('select#q_occupation_id_eq').attr('disabled', 'disabled').html('<option value="">Carregando cargos...</option>')
select = ['<option value="">Todos</option>']
$.getJSON(app_root_url + 'city_halls/' + parseInt(city_hall_id) + '/occupations.json')
.done((dados) ->
$.each(dados, (i, item) ->
select.push('<option value="' + item['id'] + '">' + item['name'] + '</option>')
)
if select.length > 1
$('select#q_occupation_id_eq').html(select)
.removeAttr('disabled')
else
$('select#q_occupation_id_eq').attr('disabled', 'disabled')
.html('<option value="">Nenhum cargo cadastrado nesta prefeitura!</option>')
)
$(document).ready ->
$('#reset_button_report').click((e) ->
e.preventDefault()
......@@ -981,32 +999,53 @@ $(document).ready ->
app_root_url = $("input#app_root_url").val()
city_hall_id = $("select#city_hall_id").val()
current_report = window.location.pathname.split('/').pop()
if(current_report == 'schedules_report')
professional_field = 'select#report_shift_professional_performer_id_eq'
service_place_field = 'select#report_service_place_id_eq'
service_type_field = 'select#report_shift_service_type_id_eq'
else if(current_report == 'services_report')
professional_field = 'select#services_shift_professional_performer_id_eq'
service_place_field = 'select#services_service_place_id_eq'
service_type_field = 'select#services_shift_service_type_id_eq'
else if(current_report == 'professionals_report')
service_place_field = 'select#q_service_places_id_eq'
else
professional_field = 'select#report_professional_performer_id_eq'
service_place_field = 'select#report_service_place_id_eq'
service_type_field = 'select#report_service_type_id_eq'
if city_hall_id == undefined
if $('select#report_service_place_id_eq').val() != undefined
if $(service_place_field).val() != undefined
# adm_prefeitura
load_professionals(app_root_url)
load_service_types(app_root_url)
$('select#report_service_place_id_eq').on('change', () ->
service_place_id = $("select#report_service_place_id_eq").val()
load_professionals(app_root_url, service_place_id)
load_service_types(app_root_url, service_place_id)
load_professionals(app_root_url, professional_field)
load_service_types(app_root_url, service_type_field)
$(service_place_field).on('change', () ->
service_place_id = $(service_place_field).val()
load_professionals(app_root_url, professional_field, service_place_id)
load_service_types(app_root_url, service_type_field, service_place_id)
)
else
# adm_c3sl
city_id = $('select#city_hall_id').val()
load_service_places(app_root_url, city_id)
load_professionals(app_root_url,'',city_id)
load_service_types(app_root_url,'',city_id)
load_service_places(app_root_url, service_place_field, city_id)
load_professionals(app_root_url, professional_field, '',city_id)
load_service_types(app_root_url, service_type_field,'',city_id)
load_occupations(app_root_url, city_id)
$('select#city_hall_id').on('change', () ->
city_id = $('select#city_hall_id').val()
load_service_places(app_root_url, city_id)
load_professionals(app_root_url,'',city_id)
load_service_types(app_root_url,'',city_id)
load_service_places(app_root_url,service_place_field,city_id)
load_professionals(app_root_url,professional_field,'',city_id)
load_service_types(app_root_url,service_type_field,'',city_id)
load_occupations(app_root_url, city_id)
)
$('select#report_service_place_id_eq').on('change', () ->
service_place_id = $("select#report_service_place_id_eq").val()
load_professionals(app_root_url, service_place_id)
load_service_types(app_root_url, service_place_id)
$(service_place_field).on('change', () ->
service_place_id = $(service_place_field).val()
load_professionals(app_root_url, professional_field, service_place_id)
load_service_types(app_root_url, service_type_field, service_place_id)
)
translate_weekday = (div, index) ->
switch index%7
......@@ -1026,4 +1065,4 @@ translate_weekday = (div, index) ->
day = 'SAB'
# error
$(div).html day
return
\ No newline at end of file
return
......@@ -20,10 +20,90 @@ get_date_object = (string, separator) ->
date_object
update_city_hall_child_selects = (city_hall_id) ->
if city_hall_id || city_hall_id != ""
app_root_url = $("input#app_root_url").val()
$.getJSON(app_root_url + 'city_halls/' + city_hall_id + '/professionals.json')
.done((dados) ->
if dados.length > 0
select = []
select.push('<option value=\"\">Todos </option>')
$.each(dados, (i, professional) ->
select.push('<option value="' + professional['id'] + '">' + professional['name'] + '</option>')
)
$('select#q_shift_professional_performer_id_eq').html(select)
else
$('select#q_shift_professional_performer_id_eq').html('<option value="">Todos </option>')
)
update_professional_child_selects = (professional_id) ->
if professional_id or professional_id != ""
app_root_url = $("input#app_root_url").val()
$.getJSON(app_root_url + 'professionals/' + professional_id + '/service_places.json')
.done((dados) ->
if dados.length > 0
select = []
select.push('<option value=\"\">Todos </option>')
$.each(dados, (i, service_place) ->
select.push('<option value="' + service_place[0] + '">' + service_place[1] + '</option>')
)
$('select#q_service_place_id_eq').html(select)
else
$('select#q_service_place_id_eq').html('<option value="">Todos </option>')
)
update_service_place_child_selects = (service_place_id) ->
if service_place_id or service_place_id != ""
app_root_url = $("input#app_root_url").val()
$.getJSON(app_root_url + 'service_places/' + service_type_id + '/service_types.json')
.done((dados) ->
if dados.length > 0
select = []
select.push('<option value=\"\">Todos </option>')
$.each(dados, (i, service_type) ->
select.push('<option value="' + service_type['id'] + '">' + service_type['description'] + '</option>')
)
$('select#q_shift_service_type_id_eq').html(select)
else
$('select#q_shift_service_type_id_eq').html('<option value="">Todos </option>')
)
desabilita_selects_from_city_hall = () ->
$('select#q_service_place_id_eq').html('<option value="">Todos </option>')
$('select#q_shift_service_type_id_eq').html('<option value="">Todos </option>')
$('select#q_shift_professional_performer_id_eq').html('<option value="">Todos </option>')
desabilita_select_service_place = () ->
$('select#q_service_place_id_eq').html('<option value="">Todos </option>')
desabilita_select_service_type = () ->
$('select#q_shift_service_type_id_eq').html('<option value="">Todos </option>')
$(document).ready(->
# Parâmetros da URL
params = get_url_params()
$('select#q_service_place_city_hall_id_eq').on('change', () ->
city_hall_id = $("select#q_service_place_city_hall_id_eq").val()
update_city_hall_child_selects(city_hall_id)
desabilita_selects_from_city_hall()
)
$('select#q_shift_professional_performer_id_eq').on('change', () ->
professional_id = $("select#q_shift_professional_performer_id_eq").val()
update_professional_child_selects(professional_id)
desabilita_select_service_place()
desabilita_select_service_type()
)
$('select#q_service_place_id_eq').on('change', () ->
service_place_id = $("select#q_service_place_id_eq").val()
update_service_place_child_selects(service_place_id)
desabilita_select_service_type()
)
$('#reset_btn').click ->
$('.search-field').val('')
$('.ordenacao').val('Decrescente')
......
......@@ -28,6 +28,16 @@ class ApplicationController < ActionController::Base
before_filter :check_role, unless: :devise_controller?
before_action :load_professional_service_place, except: [:check_role]
before_filter :check_signin
protect_from_forgery
def check_signin
if session[:expires_at] && session[:expires_at].to_time < Time.current
sign_out
flash[:notice] = "Sua sessão expirou"
end
end
# write access log
def write_log
if params
......
......@@ -608,7 +608,7 @@ class CitizensController < ApplicationController
private
def situacao_bloqueio_citizen
if (!@currentCityHall.citizen_access)
mensagem = "A utilização do agendador pela internet está desatibilitada nesta cidade. "
mensagem = "A utilização do agendador pela internet está desabilitada nesta cidade. "
if @currentCityHall.block_text
mensagem += @currentCityHall.block_text.gsub("\n",'').gsub("\r",'')
end
......
......@@ -15,14 +15,14 @@ class ProfessionalsServicePlacesController < ApplicationController
redirect_to root_path
else
if params[:id] == "0"
@currentCityHall = CityHall.where(:city_id => current_citizen.city_id).first
if @currentCityHall.citizen_access
@currentCityHall = CityHall.find_by(:city_id => current_citizen.city_id)
if @currentCityHall.citizen_access && @currentCityHall.active
session[:active_role] = 0
redirect_to root_path, notice: "Acessando como cidadão em #{current_citizen.city.name}"
else
mensagem = "A utilização do agendador pela internet está desatibilitada nesta cidade. "
mensagem = "A utilização do agendador pela internet está desabilitada nesta cidade. "
if @currentCityHall.block_text
mensagem += @currentCityHall.block_text.gsub("\n",'').gsub("\r",'')
end
......
......@@ -21,17 +21,25 @@ class SessionsController < Devise::SessionsController
# yield resource if block_given?
# respond_with resource, location: after_sign_in_path_for(resource)
# Get resource
self.resource = warden.authenticate!(auth_options)
# Check if resource is not null and if a citizen has been signed_in
if !resource.nil? && citizen_signed_in?
# Get status of current city
current_city = CityHall.find_by(city_id: current_citizen.city_id)
# if !resource.active
# sign_out(resource)
# flash[:alert] = "Sua conta está inativa, por favor contate o administrador!"
# return redirect_to root_path
# end
# Set expiretion time to send message when expiring session
session[:expires_at] = Time.current + 24.hours
# Set variable to show loading bar
session[:carrega_pagina] = true
# Set active role to nil
......@@ -49,16 +57,25 @@ class SessionsController < Devise::SessionsController
redirect_to choose_role_path
end
else
# Define as citizen
session[:active_role] = 0
redirect_to root_path
# If this citizen has only a citizen permission check if city in active
if current_city.active && current_city.citizen_access
# Define as citizen
session[:active_role] = 0
redirect_to root_path
else
sign_out(resource)
mensagem = "A utilização do agendador nesta cidade está desativado. "
if @city_hall && @city_hall.textoBloqueio
mensagem += @city_hall.textoBloqueio
end
return redirect_to root_path, alert: mensagem.html_safe
end
end
else
if (!@current_city_hall.citizen_access)
if !current_city.active || (!current_city.citizen_access)
sign_out(resource)
mensagem = "A utilização do agendador pela internet está
desatibilitada nesta cidade. "
if @city_hall.textoBloqueio
mensagem = "A utilização do agendador nesta cidade está desativado. "
if @city_hall && @city_hall.textoBloqueio
mensagem += @city_hall.textoBloqueio
end
return redirect_to root_path, alert: mensagem.html_safe
......@@ -67,7 +84,7 @@ class SessionsController < Devise::SessionsController
# set_flash_message(:notice, :signed_in) if is_navigational_format?
# sign_in(resource_name, resource)
# respond_with resource, :location => root_path
end
end
......@@ -48,7 +48,7 @@ class UploaderController < ApplicationController
if not(@ceps.has_key?(cep))
if valida_cep(cep)
addr = get_address(cep)
city = City.where(:name => addr[:localidade]).first
city = City.where(:name => addr[:localidade]).first
cityHall = CityHall.where(:city_id => city[:id])
if not(cityHall.blank?)
@ceps[cep] = [cep, city, cityHall, addr]
......@@ -71,7 +71,7 @@ class UploaderController < ApplicationController
index << i
@error << ["Não é possível cadastrar cidadão para outro município",@lines[i]+2]
next
end
end
end
end
end
......@@ -147,7 +147,7 @@ class UploaderController < ApplicationController
uniq[cpf] = 1
end
end
end
end
deleteFromTransposed(index)
end
......@@ -172,7 +172,7 @@ class UploaderController < ApplicationController
@transposed[11].each_with_index do |phone,i|
if phone.to_s.length <= 14
if phone.blank?
index << i
index << i
@error << ["Telefone 1 não pode ficar em branco",@lines[i]+2]
else
if not(phone =~ phone_regex)
......@@ -188,8 +188,10 @@ class UploaderController < ApplicationController
deleteFromTransposed(index)
index = Array.new
@transposed[12].each_with_index do |phone,i|
if phone.to_s.length <= 14
if phone.blank?
@transposed[12][i] = ''
next
else
if not(phone =~ phone_regex)
......@@ -244,11 +246,11 @@ class UploaderController < ApplicationController
def upload_csv(file)
begin
csv_comma = SmarterCSV.process(file.path, options={:remove_empty_values =>false,
:remove_zero_values =>false,
csv_comma = SmarterCSV.process(file.path, options={:remove_empty_values =>false,
:remove_zero_values =>false,
:convert_values_to_numeric => false})
csv_semicolon = SmarterCSV.process(file.path, options={:remove_empty_values =>false,
:remove_zero_values =>false, :col_sep => ';',
csv_semicolon = SmarterCSV.process(file.path, options={:remove_empty_values =>false,
:remove_zero_values =>false, :col_sep => ';',
:convert_values_to_numeric => false})
rescue EOFError
return redirect_to :upload_instructions, alert: "Arquivo .csv vazio!"
......@@ -275,7 +277,7 @@ def upload_csv(file)
@error = Array.new
@values = Array.new
@transposed = Array.new
@ceps = Hash.new
@ceps = Hash.new
@columns = [ :name,
:cpf,
:rg,
......@@ -298,7 +300,7 @@ def upload_csv(file)
]
csv.each do |csv|
@values << csv.values
@values << csv.values
end
@transposed = @values.transpose
......@@ -308,7 +310,7 @@ def upload_csv(file)
end
#############################################
#nome = 0
#nome = 0
#cpf = 1
#rg = 2
#sus = 3
......@@ -327,23 +329,22 @@ def upload_csv(file)
#city_id = 16
##############################################
##VALIDAÇÕES##
validateCPF(citiz)
validateCEP(citiz)
validateName(citiz)
validateNumber(citiz)
validatePhone(citiz)
validateRG(citiz)
validateBirth(citiz)
validateBirth(citiz)
validateEmail(citiz)
#Verifica se existe no banco e remove da inserção
index = Array.new
@intersection = Citizen.all.pluck(:cpf) & @transposed[1]
......@@ -353,7 +354,7 @@ def upload_csv(file)
index << @transposed[1].index(inter)
@error << ["Usuário já cadastrado",@transposed[1].index(inter)+2]
end
end
end
end
deleteFromTransposed(index)
......@@ -371,7 +372,7 @@ def upload_csv(file)
end
end
hash_cep.each do |k,v|
hash_cep.each do |k,v|
v.map do |id|
@insert[id].insert(16,@ceps[k][1].id) # city_id
if not(@ceps[k][3][:logradouro].blank?)
......
......@@ -4,7 +4,19 @@
<div id="search-form">
<%= search_form_for(@search) do |f| %>
<div class="field-h col s12 m6 l3">
<div class="field-h col s12 m6 l3">
<%= f.label :city_hall_id, t(:city_hall) %><br />
<% if @currentProfessionalServicePlace.role == "adm_c3sl" %>
<%= f.collection_select :city_hall_id_eq, CityHall.active.order(:name),
:id, :name, { :include_blank => "Todos" }, { :class => "search-field" } %>
<% else %>
<%= f.collection_select :city_hall_id_eq, CityHall.where(id: @currentCityHall.id),
:id, :name, { disabled: true }, { :class => "search-field" } %>
<% end %>
</div>
<div class="field-h col s12 m6 l3">
<%= f.label :name, t(:Name)+": " %><br />
<%= f.text_field :name_cont, :class => "search-field"%>
</div>
......
......@@ -17,7 +17,7 @@
<%= f.label :service_places_city_hall_id, t(:city_hall) %><br />
<% if @currentProfessionalServicePlace.role == "adm_c3sl" %>
<%= f.collection_select :service_places_city_hall_id_eq, CityHall.active.order(:name),
:id, :name, { :include_blank => "Todos" }, { :class => "search-field" } %>
:id, :name, { :include_blank => "Todos", selected: 0 }, { :class => "search-field" } %>
<% else %>
<%= f.collection_select :service_places_city_hall_id_eq, CityHall.where(id: @currentCityHall.id),
:id, :name, { disabled: true }, { :class => "search-field" } %>
......
......@@ -4,6 +4,15 @@
<div id="search-form">
<%= search_form_for(@search, :url => { :controller => "users", :action => 'index'}) do |f| %>
<% if @currentProfessionalServicePlace.role == "adm_c3sl" %>
<div class="field-h col s12 m6 l3">
<%= f.label :city_hall, t(:city_hall)+": " %><br />
<%= f.collection_select :city_city_halls_id_eq, CityHall.active.order(:name),
:id, :name, { :include_blank => "Todos" }, { :class => "search-field" } %>
</div>
<% end %>
<div class="field-h col s12 m6 l3">
<%= f.label :name, t(:Name)+": " %><br />
<%= f.text_field :name_cont, :class => "search-field" %>
......
......@@ -31,32 +31,45 @@
{ :value => @limite_fim.strftime("%d/%m/%Y"), :class => "date agendamentos_atend_calendario", :readonly => "true" } %>
<% end %>
</div>
<div class="field-h col s12 m6 l3">
<%= f.label :service_place_city_hall_id, t(:city_hall) %><br />
<% if @currentProfessionalServicePlace.role == "adm_c3sl" %>
<%= f.collection_select :service_place_city_hall_id_eq, CityHall.active.order(:name),
:id, :name, { :include_blank => "Todos", selected: 0 }, { :class => "search-field" } %>
<% else %>
<%= f.collection_select :service_place_city_hall_id_eq, CityHall.where(id: @currentCityHall.id),
:id, :name, { disabled: true }, { :class => "search-field" } %>
<% end %>
</div>
<div class="field-h col s12 m6 l3">
<%= f.label :shift_professional_performer_id, t(:Professional)+": " %><br />
<%= f.collection_select :shift_professional_performer_id_eq, @professionals,
<%= f.collection_select :shift_professional_performer_id_eq, [],
:id, :name, {:include_blank => "Todos"}, {:class => "search-field"} %>
</div>
<div class="field-h col s12 m6 l3">
<%= f.label :service_place_id_eq, t(:service_place) %><br />
<%= f.collection_select :service_place_id_eq, [], :id,
:name,{ :include_blank => "Todos" },
{ :class => "search-field" } %>
</div>
<div class="field-h col s12 m6 l3">
<%= f.label :escala_tipo_atendimento_id, t(:service_type)+": " %><br />
<%= f.collection_select :shift_service_type_id_eq, @city_service_types,
<%= f.collection_select :shift_service_type_id_eq, [],
:id, :description, {:include_blank => "Todos"}, {:class => "search-field"} %>
</div>
<div class="field-h col s12 m6 l3">
<%= f.label :situation_id, t(:Situation)+": " %><br />
<%= f.collection_select :situation_id_eq, @situations, :id,
:description, {:include_blank => "Todos"},
{:class => "search-field"} %>
</div>