Skip to content

Commit

Permalink
uniformes
Browse files Browse the repository at this point in the history
  • Loading branch information
fagianijunior committed Jul 4, 2014
1 parent e742c82 commit e21dd77
Show file tree
Hide file tree
Showing 37 changed files with 174 additions and 136 deletions.
12 changes: 2 additions & 10 deletions app/controllers/uniform_piece_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ def new
@uniform_piece_group = UniformPieceGroup.new
end

# Modal
def new_group_modal
@uniform_piece_group = UniformPieceGroup.new
respond_to do |format|
format.html { render :new }
format.js
end
end

# GET /uniform_piece_groups/1/edit
def edit
end
Expand All @@ -38,7 +29,8 @@ def create

respond_to do |format|
if @uniform_piece_group.save
format.html { redirect_to @uniform_piece_group, notice: 'Uniform piece group was successfully created.' }
#format.html { redirect_to @uniform_piece_group, notice: 'Uniform piece group was successfully created.' }
format.html { redirect_to new_uniform_path }
format.json { render :show, status: :created, location: @uniform_piece_group }
else
format.html { render :new }
Expand Down
14 changes: 2 additions & 12 deletions app/controllers/uniform_piece_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ def new
@uniform_piece_type = UniformPieceType.new
end

# Modal
def new_type_modal
@uniform_piece_type = UniformPieceType.new
respond_to do |format|
format.html { render :new }
format.js
end
end

# GET /uniform_piece_types/1/edit
def edit
end
Expand All @@ -38,13 +29,12 @@ def create

respond_to do |format|
if @uniform_piece_type.save
format.html { redirect_to @uniform_piece_type, notice: 'Uniform piece type was successfully created.' }
#format.html { redirect_to @uniform_piece_type, notice: 'Uniform piece type was successfully created.' }
format.html { redirect_to new_uniform_path }
format.json { render :show, status: :created, location: @uniform_piece_type }
# format.js { render :show, status: :created, location: @uniform }
else
format.html { render :new }
format.json { render json: @uniform_piece_type.errors, status: :unprocessable_entity }
# format.js { render json: @uniform_piece_type.errors, status: :unprocessable_entity }
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def index
# GET /users/1
# GET /users/1.json
def show
@uniforms_free = Uniform.where( :user => nil )

end

# GET /users/new
Expand Down
4 changes: 4 additions & 0 deletions app/models/uniform.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
class Uniform < ActiveRecord::Base

belongs_to :uniform_piece_type
belongs_to :uniform_piece_group
belongs_to :user

validates :uniform_piece_type, :uniform_piece_group, :entry, :expiration, presence: true

end
7 changes: 6 additions & 1 deletion app/models/uniform_piece_group.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
class UniformPieceGroup < ActiveRecord::Base
validate :group, required: true

before_save { self.group = group.humanize }
before_save { self.description = description.humanize }

validates :group, presence: true,
uniqueness: { case_sensitive: false }
end
6 changes: 5 additions & 1 deletion app/models/uniform_piece_type.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
class UniformPieceType < ActiveRecord::Base
validates :piece_type, presence: true

before_save { self.piece_type = piece_type.humanize }

validates :piece_type, presence: true,
uniqueness: { case_sensitive: false }
end
1 change: 0 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ class User < ActiveRecord::Base
has_secure_password

mount_uploader :avatar, AvatarUploader

end
6 changes: 3 additions & 3 deletions app/uploaders/avatar_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def store_dir

# Create different versions of your uploaded files:
version :large do
process :resize_to_fill => [400, 518]
process :resize_to_fill => [350, 350]
end

version :medium do
process :resize_to_fill => [200, 318]
process :resize_to_fill => [150, 150]
end

version :small do
process :resize_to_fill => [25,25]
process :resize_to_fill => [20,20]
end

def cache_dir
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
<%= render "layouts/footer" %>
</div>
</div>
<div id="modal-window" class="modal fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
</body>
</html>
4 changes: 2 additions & 2 deletions app/views/positions/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<%= render "admin/menu" %>
</div>
<div class="col-md-10 column">
<%= link_to '<< Voltar', positions_path, class: "btn btn-primary" %>
<%= link_to '<< Voltar', positions_path, class: "btn btn-default" %>
<hr>
<h2>Editando cargo</h2>
<%= render 'form' %>
</div>
</div><h1>Editing position</h1>
</div>
6 changes: 3 additions & 3 deletions app/views/uniform_piece_groups/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<%= simple_form_for(@uniform_piece_group) do |f| %>
<%= simple_form_for(@uniform_piece_group, html: { class: "form_horizontal" }, defaults: { input_html: { class: "form-control" }, label: false }) do |f| %>
<%= f.error_notification %>

<div class="form-inputs">
<%= f.input :group %>
<%= f.input :description %>
<%= f.input :group, placeholder: "Grupo" %>
<%= f.input :description, placeholder: "Descrição" %>
</div>
<br>
<div class="form-actions">
Expand Down
1 change: 1 addition & 0 deletions app/views/uniform_piece_groups/new.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$("#modal-window").html("<%= escape_javascript(render 'new') %>");
4 changes: 2 additions & 2 deletions app/views/uniform_piece_types/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<%= simple_form_for(@uniform_piece_type) do |f| %>
<%= simple_form_for(@uniform_piece_type, html: { class: "form-horizontal" }, defaults: { input_html: { class: "form-control" }, label: false }) do |f| %>
<%= f.error_notification %>

<div class="form-inputs">
<%= f.input :piece_type %>
<%= f.input :piece_type, placeholder: "Tipo" %>
</div>
<br>
<div class="form-actions">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<h3 id="myModalLabel">Novo tipo</h3>
</div>
<div class="modal-body">
<%= render "uniform_piece_types/form" %>
<%= render "form" %>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
Expand Down
1 change: 1 addition & 0 deletions app/views/uniform_piece_types/new.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$("#modal-window").html("<%= escape_javascript(render 'new') %>");
1 change: 0 additions & 1 deletion app/views/uniform_piece_types/new_type_modal.js.erb

This file was deleted.

14 changes: 14 additions & 0 deletions app/views/uniforms/_edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Adionar novo</h3>
</div>
<div class="modal-body">
<%= render "form" %>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
</div>
15 changes: 7 additions & 8 deletions app/views/uniforms/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
<div class="col-sm-12">
<div class="col-sm-5">
<div class="form-inputs">
<%= f.association :uniform_piece_type, label_method: :piece_type, prompt: "Tipo", label: false %>
<!-- <%= link_to '+Novo tipo', new_type_modal_path, { :remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window', 'data-update-target' => 'uniform_piece_type' } %> -->
<%= link_to '+Novo tipo', new_type_modal_path, { :remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window' } %>
<%= f.association :uniform_piece_group, label_method: :group, prompt: "Pertence ao grupo", label: false %>
<%= link_to '+Novo grupo', new_group_modal_path, { :remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window' } %>
<%= f.input :entry, label: "Data de entrada", start_year: Date.today.year-5, end_year: Date.today.year+10, order: [ :day, :month, :year ], prompt: ["Dia", "Mês", "Ano"], input_html: { class: "datepicker" } %>
<%= f.input :expiration, label: "Data para troca", start_year: Date.today.year, end_year: Date.today.year+20, order: [ :day, :month, :year ], prompt: ["Dia", "Mês", "Ano"], input_html: { class: "datepicker" } %>
<%= f.association :uniform_piece_type, collection: UniformPieceType.order( :piece_type ), label_method: :piece_type, prompt: "Tipo", label: false %>
<%= link_to '+Novo tipo', new_uniform_piece_type_path, { :remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window' } %>
<%= f.association :uniform_piece_group, collection: UniformPieceGroup.order( :group ), label_method: :group, prompt: "Pertence ao grupo", label: false %>
<%= link_to '+Novo grupo', new_uniform_piece_group_path, { :remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window' } %>
<%= f.input :entry, label: "Data de entrada", start_year: Date.today.year-5, end_year: Date.today.year+10, order: [ :day, :month, :year ], input_html: { class: "datepicker" } %>
<%= f.input :expiration, label: "Data para troca", start_year: Date.today.year, end_year: Date.today.year+20, order: [ :day, :month, :year ], input_html: { class: "datepicker" } %>

<!--%= f.association :user %-->
<%= f.association :user %>
</div>
<div class="form-actions">
<hr>
Expand Down
17 changes: 11 additions & 6 deletions app/views/uniforms/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<h1>Editing uniform</h1>

<%= render 'form' %>

<%= link_to 'Show', @uniform %> |
<%= link_to 'Back', uniforms_path %>
<div class="row clearfix">
<div class="col-md-2 column">
<%= render "admin/menu" %>
</div>
<div class="col-md-10 column">
<%= link_to 'Voltar', uniforms_path, class: "btn btn-primary" %>
<hr>
<h2>Editando peça de uniforme</h2>
<%= render 'form' %>
</div>
</div>
77 changes: 43 additions & 34 deletions app/views/uniforms/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@

<h1>Listing uniforms</h1>

<table class="table">
<thead>
<tr>
<th>Uniform piece type</th>
<th>Uniform piece group</th>
<th>Entry</th>
<th>Expiration</th>
<th>User</th>
<th colspan="3"></th>
</tr>
</thead>

<tbody>
<% @uniforms.each do |uniform| %>
<tr>
<td><%= uniform.uniform_piece_type.piece_type %></td>
<td><%= uniform.uniform_piece_group.group %></td>
<td><%= uniform.entry %></td>
<td><%= uniform.expiration %></td>
<td><%= uniform.user unless uniform.user.nil? %></td>
<td><%= link_to 'Show', uniform %></td>
<td><%= link_to 'Edit', edit_uniform_path(uniform) %></td>
<td><%= link_to 'Destroy', uniform, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Uniform', new_uniform_path %>
<div class="row clearfix">
<div class="col-md-2 column">
<%= render "admin/menu" %>
</div>
<div class="col-md-10 column">
<div class="row clearfix">
<div class="col-md-12 column">
<%= link_to 'Nova peça de uniforme', new_uniform_path, class: "btn btn-primary" %>
<hr>
</div>
<div class="col-md-12 column">
<table class="table">
<thead>
<tr>
<th> </th>
<th>Tipo</th>
<th>Pertence ao grupo</th>
<th>Data de entrada</th>
<th>Data para troca</th>
<th>Em mãos de</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @uniforms.each do |uniform| %>
<tr>
<td><%= image_tag(uniform.uniform_piece_type.picture, { width: 15, height: 15 } ) if uniform.uniform_piece_type.picture? %></td>
<td><%= uniform.uniform_piece_type.piece_type %></td>
<td><%= uniform.uniform_piece_group.group %></td>
<td><%= uniform.entry %></td>
<td><%= uniform.expiration %></td>
<td><%= uniform.user.name unless uniform.user.nil? %></td>
<td><%= link_to 'Detalhes', uniform %></td>
<td><%= link_to 'Editar', edit_uniform_path(uniform) %></td>
<td><%= link_to 'Apagar', uniform, method: :delete, data: { confirm: 'Você têm certeza?' } %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
</div>
57 changes: 32 additions & 25 deletions app/views/uniforms/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
<p id="notice"><%= notice %></p>
<div class="row clearfix">
<div class="col-md-2 column">
<%= render "admin/menu" %>
</div>
<div class="col-md-10 column">
<p id="notice"><%= notice %></p>

<p>
<strong>Uniform piece type:</strong>
<%= @uniform.uniform_piece_type %>
</p>
<p>
<strong>Tipo:</strong>
<%= @uniform.uniform_piece_type.piece_type %>
</p>

<p>
<strong>Uniform piece group:</strong>
<%= @uniform.uniform_piece_group %>
</p>
<p>
<strong>Grupo:</strong>
<%= @uniform.uniform_piece_group.group %>
</p>

<p>
<strong>Data de entrada:</strong>
<%= @uniform.entry %>
</p>

<p>
<strong>Entry:</strong>
<%= @uniform.entry %>
</p>
<p>
<strong>Data para troca:</strong>
<%= @uniform.expiration %>
</p>

<p>
<strong>Em mãos de:</strong>
<!--%= link_to @uniform.user.name, user_path(@uniform.user) %-->
</p>

<p>
<strong>Expiration:</strong>
<%= @uniform.expiration %>
</p>

<p>
<strong>User:</strong>
<%= @uniform.user %>
</p>

<%= link_to 'Edit', edit_uniform_path(@uniform) %> |
<%= link_to 'Back', uniforms_path %>
<%= link_to 'Edit', edit_uniform_path(@uniform) %> |
<%= link_to 'Back', uniforms_path %>
</div>
</div>
3 changes: 3 additions & 0 deletions app/views/users/_uniforms.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<%= select_tag "Uniforme", options_from_collection_for_select(@uniforms_free, "id","uniform_piece_type") %>
<%= link_to 'Adicionar novo', uniforms_path %>

<table class="table">
<thead>
<tr>
Expand Down
Loading

0 comments on commit e21dd77

Please sign in to comment.