ImportCitizen: Now the funcionality is almost done

parent 6e598a15
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
// Place all the styles related to the Uploader controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
......@@ -86,7 +86,7 @@ class Professionals::UsersController < ApplicationController
end
end
end
def edit
@link = "Cadastro de cidadãos"
@link2 = "Alterar Cidadão"
......@@ -189,6 +189,9 @@ class Professionals::UsersController < ApplicationController
end
def create
if not(params[:file].nil?)
upload(params[:file])
end
if @currentProfessionalServicePlace.role == "responsavel_atendimento"
return redirect_to root_path, alert: "Você não possui permissão para editar cidadãos."
end
......@@ -354,8 +357,5 @@ class Professionals::UsersController < ApplicationController
return true
end
def upload
end
end
class UploaderController < ApplicationController
def processData(hash)
@new_citizen=Citizen.create(hash)
@new_citizen.save!
end
def upload_csv(file)
p "THE FILE IS A .CSV"
csv = SmarterCSV.process(file.path)
size = csv.length
i = 0
p csv
while i < size do
hash = Hash.new
hash['name'] = csv[i][:nome]
hash['cpf'] = csv[i][:cpf]
hash['rg'] = csv[i][:rg]
hash['sus_number'] = csv[i][:cartao_sus]
hash['birth_date'] = csv[i][:data_de_nascimento]
hash['cep'] = csv[i][:cep]
hash['address_number'] = csv[i][:numero]
hash['address_complement'] = csv[i][:complemento]
hash['phone1'] = csv[i][:telefone_1]
hash['phone2'] = csv[i][:telefone_2]
hash['email'] = csv[i][:e_mail]
hash['note'] = csv[i][:observacao]
hash['password'] = "123456"
hash['password_confirmation'] = "123456"
i = i + 1
@hashs = hash
processData(hash)
end
@finished = 'true'
end
def upload()
file = params[:file]
if not(file.nil?)
@fileType = file.original_filename.to_s.split(".").last # Get the file format (csv)
else
return redirect_to :back, alert: "Por favor, selecione um arquivo para o upload"
end
case @fileType
when 'csv'
upload_csv(file)
else
return redirect_to :back, alert: "Somente arquivos do tipo .csv são suportados"
end
end
end
module UploaderHelper
end
......@@ -38,22 +38,20 @@
<div id="modal_upload_citizen" class="modal">
<div class="modal-content">
<h4 id="upload_citizen-header">Upload de arquivo</h4>
<p>Abaixo você poderá realizar o upload da tabela contendo todos os cidadãos da sua cidade!</p>
<div class="file-field input-field">
<div class="btn">
<span>Arquivo</span>
<%= file_field_tag 'planilha'%>
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text" placeholder="Escolha o arquivo de importaçãos">
</div>
</div>
<p>Abaixo você poderá realizar o upload da tabela contendo vários os cidadãos da sua cidade!</p>
<%= form_tag(upload_path, multipart: true) do %>
<%= file_field_tag :file %>
<%= submit_tag( "Upload" ) %>
<% end %>
</div>
<div class="modal-footer">
<a href="#!" class="modal-action modal-close waves-effect waves-red btn-flat left">Cancelar</a>
<%= link_to "Upload", { :controller => "users", :action => "index"}, :method => :upload, :class => "modal-action modal-close waves-effect waves-green btn-flat" %>
</div>
</div>
<p> Oi </p>
\ No newline at end of file
......@@ -79,6 +79,8 @@ Agendador::Application.routes.draw do
resources :users
end
post 'upload' => 'uploader#upload'
# devise_for :professionals, :skip => [:registrations],
# :controllers => {:sessions => "sessions",
# :passwords => "passwords",
......
require 'test_helper'
class UploaderControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class UploaderHelperTest < ActionView::TestCase
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment