Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crear Crud de Hospitales y Ninos #8

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ gem 'bootstrap-will_paginate'
gem 'roo'
gem 'axlsx', '~> 2.0', git: "https://github.com/randym/axlsx.git"
gem 'axlsx_rails', '~> 0.2.0'

gem 'paperclip', ">= 4.1.1"

3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,6 @@ DEPENDENCIES
uglifier (>= 1.3.0)
web-console (~> 2.0)
will_paginate

BUNDLED WITH
1.11.2
4 changes: 3 additions & 1 deletion app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@
.calendar .fc-content .fc-event-container a.Colecta {background-color: #C8FDC8; }
.calendar .fc-content .fc-event-container a.Inducción {background-color: #E7CDFF; }


.center {
text-align: center;
}
7 changes: 6 additions & 1 deletion app/controllers/admin/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Admin::AdminController < ApplicationController
before_filter :authenticate_user!
before_filter :require_admin

before_filter :page_id, :events_count, :volunteers_count, :brigades_count, :children_count, :polls_count
before_filter :page_id, :events_count, :volunteers_count, :brigades_count, :children_count, :polls_count, :hospital_count

layout 'admin'

Expand Down Expand Up @@ -36,7 +36,12 @@ def children_count
@childrenCount = Child.count('name', :distinct => true)
end

def hospital_count
@hospitalsCount = Hospital.count('name', :distinct => true)
end

def polls_count
@pollsCount = Poll.count('code', :distinct => true)
end

end
49 changes: 49 additions & 0 deletions app/controllers/admin/children_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,49 @@ def index
@children = Child.paginate(page: params[:page], per_page: 50).order('created_at desc')
end


def new
@child = Child.new
@hospital = Hospital.new
render :edit
end

def create
@child = Child.new(child_params) # params[:hospital])
if @child.save
flash[:notice] = "Niño #{@child.name} guardada"
redirect_to admin_children_path and return
else
flash[:error] = "Niño #{@child.name} no pudo ser guardada"
render :edit
end
end

def edit
@child = Child.find(params[:id])
end

def update
@child = Child.find(params[:id])

if @child.save
flash[:notice] = "Niño #{@child.name} guardado"
redirect_to admin_children_path and return
else
render :edit
end
end


def destroy
child = Child.find(params[:id])
child.destroy
flash[:ok] = "Niño #{child.name} borrado"
redirect_to admin_children_path


end

def child_filter
@children = Child.order('created_at desc')
if (params[:child_name].present?)
Expand Down Expand Up @@ -47,5 +90,11 @@ def to_xlsx
def set_menu
@selected_menu = 'Children'
end

def child_params
params.require(:child).permit(:hospital_id, :diagnostic_id, :child_status_id, :genere,
:city_id, :name, :birth_date, :dream, :address )
end


end
65 changes: 65 additions & 0 deletions app/controllers/admin/hospitals_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# encoding: UTF-8
class Admin::HospitalsController < Admin::AdminController

before_filter :set_menu

def index
@hospitals = Hospital.paginate(:page => params[:page], :per_page => 50)
end

def new
@hospital = Hospital.new
render :edit
end

def create
@hospital = Hospital.new(hospital_params) # params[:hospital])
if @hospital.save
flash[:notice] = "Hospital #{@hospital.name} guardada"
redirect_to admin_hospitals_path and return
else
flash[:error] = "Hospital #{@hospital.name} no pudo ser guardada"
render :edit
end
end

def edit
@hospital = Hospital.find(params[:id])
end


def update

@hospital = Hospital.find(params[:id])

if @hospital.save
flash[:notice] = "Hospital #{@hospital.name} guardado"
redirect_to admin_hospitals_path and return
else
render :edit
end

end

def destroy
hospital = Hospital.find(params[:id])
hospital.destroy
flash[:ok] = "Hospital #{hospital.name} borrado"
redirect_to admin_hospitals_path
end

private

def set_menu
@selected_menu = 'Hospitals'
end

def hospital_params
params.require(:hospital).permit(:city_id, :name)
end





end
2 changes: 2 additions & 0 deletions app/helpers/admin/hospitals_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Admin::HospitalsHelper
end
7 changes: 7 additions & 0 deletions app/models/child.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@ class Child < ActiveRecord::Base
belongs_to :city
belongs_to :child_status
has_many :relatives, dependent: :destroy



validates :hospital_id, :diagnostic_id, :child_status_id, :genere,
:city_id, :name, :birth_date, :dream, :address, presence: true


end
1 change: 1 addition & 0 deletions app/models/city.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ class City < ActiveRecord::Base
has_many :events
has_many :users


end
6 changes: 6 additions & 0 deletions app/models/hospital.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
class Hospital < ActiveRecord::Base

belongs_to :city
has_many :children, dependent: :destroy

validates_presence_of :name



end
6 changes: 5 additions & 1 deletion app/views/admin/children/_children.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@
%th Sueño
%th Diagnóstico
%th Estado
%th Acciones
%tbody
- @children.each do |child|
%tr
%td= child.name
%td= link_to "#{child.name}", edit_admin_child_path(child.id)
%td= child.hospital.name
%td= child.birth_date.strftime("%Y-%m-%d") unless child.birth_date.nil?
%td= child.city.name
%td= child.relatives.where(relative_type_id: 3).first.try(:name)
%td= child.dream
%td= child.diagnostic.name
%td= child.child_status.name
%td
= link_to admin_child_path(child.id), method: :delete, class: 'btn btn-default btn-sm delete', title: 'Delete', data: {toggle: 'tooltip', confirm: "Esta segur@ que desea borrar el niño: #{child.name}?"} do
%i.glyphicon.glyphicon-trash

= will_paginate @children, params:{controller: "admin/children", action: 'children_filter', params: clear_search_params([:page])}, renderer: RemoteLinkPagination::LinkRenderer
%br/
Expand Down
113 changes: 113 additions & 0 deletions app/views/admin/children/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
.container.admin
= render 'shared/navigation_admin'
.row.adform
= form_for @child, url: (@child.new_record? ? admin_children_path : admin_child_path(@child.id)), method: (@child.new_record? ? 'post' : 'put'), html: {id: 'eventForm'} do |f|

.chart
%h3.module_header
#{(@child.new_record? ? 'Nuevo Niño' : "Editar Niño")}
.col-lg-12
.temp_list
%ul
- unless @child.errors.empty?
%li
.alert.alert-danger.errors
= @child.errors.full_messages.join(', ')

%li
.row
.col-lg-3
%span Hospital *
.col-lg-7
= f.select :hospital_id, options_from_collection_for_select(Hospital.all, :id, :name, @child.hospital_id), {}, {class: "form-control"}

%li
.row
.col-lg-3
%span Diagnostico *
.col-lg-7
= f.select :diagnostic_id, options_from_collection_for_select(Diagnostic.all, :id, :name, @child.diagnostic_id), {}, {class: "form-control"}

%li
.row
.col-lg-3
%span Estado *
.col-lg-7
= f.select :child_status_id, options_from_collection_for_select(ChildStatus.all, :id, :name, @child.child_status_id), {}, {class: "form-control"}

%li
.row
.col-lg-3
%span Ciudad *
.col-lg-7
= f.select :city_id, options_from_collection_for_select(City.all, :id, :name, @child.city_id), {}, {class: "form-control"}

%li
.row
.col-lg-3
%span Nombre *
.col-lg-7
= f.text_field :name, size: '250', maxlenght: '250', class: "form-control"

%li
.row
.col-lg-3
%span Genero *
.col-lg-7
= f.text_field :genere, size: '250', maxlenght: '50', class: "form-control"

%li
.row
.col-lg-3
%span Cumpleaños *
.col-lg-7{ :style => "text-align: left;" }
= f.text_field :birth_date, size: '5', maxlenght: '5', value: (@child.birth_date.nil? ? '' : @child.birth_date.strftime("%d/%m/%Y")), class: 'datepicker date', style: 'padding: 15px;'

%li
.row
.col-lg-3
%span Sueño *
.col-lg-7
= f.text_field :dream, size: '250', maxlenght: '250', class: "form-control"

%li
.row
.col-lg-3
%span Direccion *
.col-lg-7
= f.text_field :address, size: '250', maxlenght: '250', class: "form-control"

%li
%i{style: 'font-size: 12px;'} Los campos marcados con * son obligatorios
%hr/
.botones
= link_to "Guardar", "#", onclick: "$('#eventForm').submit(); return false;", class: 'btn btn-primary btn-inverse'
= link_to "Cancelar", admin_children_path, class: 'btn btn-default'
- unless @child.new_record?
= link_to "Borrar", admin_child_path(@child.id), class: 'btn btn-default', confirm: "Esta seguro que desea borrar el evento:#{@child.name}?", method: 'delete'

- content_for :js_footer do
:javascript
$.ajax({async:false});
$(function() {

$(".datepicker").datepicker({
dateFormat: "yy-mm-dd",
changeMonth: true,
changeYear: true,
minDate: "-12M",
maxDate: "+6M"
});
})




/ t.integer "siblings_over_18", limit: 4
/ t.integer "siblings_under_18", limit: 4

/ end




5 changes: 4 additions & 1 deletion app/views/admin/children/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
.container.admin
= render 'shared/navigation_admin'
.row
.col-lg-12
.col-lg-10
.chart
%h3.module_header
Niños
%span.count
#{@children.count}
= link_to 'Exportar a Excel', to_xlsx_admin_children_path(format: :xlsx), style: "margin-right:10px;", class: 'btn btn-xs btn-primary pull-right'
.col-lg-2
%a.my_button{href: new_admin_child_path, style: 'margin-top: 30px;'}
Nuevo Niño
.col-lg-12
.well
.row
Expand Down
15 changes: 15 additions & 0 deletions app/views/admin/hospitals/_hospitals.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.row
.col-md-12
%table.table.table-striped.table-responsive
%thead
%tr
%th Ciudad ID
%th Nombre
%th Actions
%tbody
- @hospitals.each do |hospital|
%tr
%td #{hospital.city.name}
%td= link_to "#{hospital.name}", edit_admin_hospital_path(hospital.id)
%td= button_to "delete", admin_hospital_path(hospital.id), data: {confirm: "Are you sure you want to delete user: #{hospital.name}?"}, method: :delete
= will_paginate @hospitals, class: "center"
Loading