Skip to content

Commit

Permalink
Adding printer model
Browse files Browse the repository at this point in the history
Associating printer model with totem model
  • Loading branch information
fabianoalmeida committed Jun 17, 2013
1 parent 7b54a11 commit d2e722c
Show file tree
Hide file tree
Showing 27 changed files with 537 additions and 5 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/printers.js.coffee
@@ -0,0 +1,3 @@
# 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://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/printers.css.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the printers controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
56 changes: 56 additions & 0 deletions app/assets/stylesheets/scaffolds.css.scss
@@ -0,0 +1,56 @@
body {
background-color: #fff;
color: #333;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px; }

p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px; }

pre {
background-color: #eee;
padding: 10px;
font-size: 11px; }

a {
color: #000;
&:visited {
color: #666; }
&:hover {
color: #fff;
background-color: #000; } }

div {
&.field, &.actions {
margin-bottom: 10px; } }

#notice {
color: green; }

.field_with_errors {
padding: 2px;
background-color: red;
display: table; }

#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;
h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0px;
background-color: #c00;
color: #fff; }
ul li {
font-size: 12px;
list-style: square; } }
83 changes: 83 additions & 0 deletions app/controllers/printers_controller.rb
@@ -0,0 +1,83 @@
class PrintersController < ApplicationController
# GET /printers
# GET /printers.json
def index
@printers = Printer.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @printers }
end
end

# GET /printers/1
# GET /printers/1.json
def show
@printer = Printer.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @printer }
end
end

# GET /printers/new
# GET /printers/new.json
def new
@printer = Printer.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @printer }
end
end

# GET /printers/1/edit
def edit
@printer = Printer.find(params[:id])
end

# POST /printers
# POST /printers.json
def create
@printer = Printer.new(params[:printer])

respond_to do |format|
if @printer.save
format.html { redirect_to @printer, notice: 'Printer was successfully created.' }
format.json { render json: @printer, status: :created, location: @printer }
else
format.html { render action: "new" }
format.json { render json: @printer.errors, status: :unprocessable_entity }
end
end
end

# PUT /printers/1
# PUT /printers/1.json
def update
@printer = Printer.find(params[:id])

respond_to do |format|
if @printer.update_attributes(params[:printer])
format.html { redirect_to @printer, notice: 'Printer was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @printer.errors, status: :unprocessable_entity }
end
end
end

# DELETE /printers/1
# DELETE /printers/1.json
def destroy
@printer = Printer.find(params[:id])
@printer.destroy

respond_to do |format|
format.html { redirect_to printers_url }
format.json { head :no_content }
end
end
end
2 changes: 2 additions & 0 deletions app/controllers/totems_controller.rb
Expand Up @@ -30,6 +30,7 @@ def show
def new
@totem = Totem.new( :status => Status.active )
@place = Place.find(params[:place_id])
@printers = Printer.order(:name)

respond_to do |format|
format.html # new.html.erb
Expand All @@ -41,6 +42,7 @@ def new
def edit
@totem = Totem.find(params[:id])
@place = Place.find(params[:place_id])
@printers = Printer.order(:name)
end

# POST /totems
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/printers_helper.rb
@@ -0,0 +1,2 @@
module PrintersHelper
end
11 changes: 11 additions & 0 deletions app/models/printer.rb
@@ -0,0 +1,11 @@
class Printer < ActiveRecord::Base
extend FriendlyId

friendly_id :name, use: :slugged

attr_accessible :name

has_many :totems

validates :name, :presence => true
end
3 changes: 2 additions & 1 deletion app/models/totem.rb
Expand Up @@ -9,9 +9,10 @@ class Totem < ActiveRecord::Base

belongs_to :status
belongs_to :place
belongs_to :printer
has_many :tickets

validates :value, :ip, :user, :status, :place, :presence => true
validates :value, :ip, :user, :status, :place, :printer, :presence => true

validates :value,
:length => { :in => 1..80 },
Expand Down
6 changes: 5 additions & 1 deletion app/views/home/main.html.erb
Expand Up @@ -22,6 +22,10 @@
<div style="width : 184px; heigth: 200px; float: left">
<%= link_to image_tag("computer.png", :width => "184px"), locals_path, :style => "padding:0" %>
<h3 style="text-align: center">Locais</h3>
</div>
<div style="width : 184px; heigth: 200px; float: left">
<%= link_to image_tag("computer.png", :width => "184px"), printers_path, :style => "padding:0" %>
<h3 style="text-align: center">Impressoras</h3>
</div>
<div style="clear:both"></div>
</div>
</div>
22 changes: 22 additions & 0 deletions app/views/printers/_form.html.erb
@@ -0,0 +1,22 @@
<%= form_for(@printer) do |f| %>
<% if @printer.errors.any? %>
<div id="error_explanation">
<ul>
<% @printer.errors.full_messages.each do |msg| %>
<li class="form-msg-error"><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="grid-12-12">
<%= f.label :name, :class => "form-lbl form-req" %>
<%= f.text_field :name, :maxlength => 80, :size => 30, :class => "form-txt form-small", :disabled => disabled %>
</div>

<% unless disabled %>
<div class="grid-7-12 field-button field-clear">
<%= f.submit :class => "button form-right medium" %>
</div>
<% end %>
<% end %>
10 changes: 10 additions & 0 deletions app/views/printers/edit.html.erb
@@ -0,0 +1,10 @@
<div class="form">
<fieldset>
<legend><%= t('model.print.editing') %></legend>
<%= render :partial => 'form', :locals => {:disabled => false } %>
</fieldset>
</div>
<div class="buttons-nav">
<%= link_to t('model.show'), printer_path(@printer), :class => "button medium" %>
<%= link_to t('model.back'), printers_path, :class => "button medium" %>
</div>
24 changes: 24 additions & 0 deletions app/views/printers/index.html.erb
@@ -0,0 +1,24 @@
<div class="form">
<div class="search">
<input type="text" value="search" id="search"/>
<%= link_to image_tag("form/search.png") + t('application.search') , "#", :class => "button medium"%>
</div>
<table>
<tr>
<th><%= t('model.printer.name').pluralize %></th>
<th colspan="3" class="options"><%= t("application.options") %></th>
</tr>
<% @printers.each do |printer| %>
<tr class="row">
<td width ="100%"><%= printer.name %></td>
<td><%= link_to image_tag("form/search.gif"), printer %></td>
<td><%= link_to image_tag("form/edit.gif"), edit_printer_path(printer) %></td>
<td><%= link_to image_tag("form/trash.gif"), "#" %></td>
</tr>
<% end %>
</table>
</div>

<div class="buttons-nav">
<%= link_to t('model.printer.new'), new_printer_path , :class => "button medium"%>
</div>
9 changes: 9 additions & 0 deletions app/views/printers/new.html.erb
@@ -0,0 +1,9 @@
<div class="form">
<fieldset>
<legend><%= t('model.printer.new') %></legend>
<%= render :partial => 'form', :locals => { :disabled => false } %>
</fieldset>
</div>
<div class="buttons-nav">
<%= link_to t('model.back'), printers_path , :class => "button medium"%>
</div>
14 changes: 14 additions & 0 deletions app/views/printers/show.html.erb
@@ -0,0 +1,14 @@
<div class="form">
<fieldset>
<legend><%= t('model.printer.name') %></legend>
<% if notice %>
<span class="form-msg-success"><%= notice %></span>
<% end %>
<%= render :partial => 'form', :locals => { :disabled => true } %>
</fieldset>
</div>

<div class="buttons-nav">
<%= link_to t('model.edit'), edit_printer_path(@printer), :class => "button medium" %>
<%= link_to t('model.back'), printers_path, :class => "button medium" %>
</div>
8 changes: 8 additions & 0 deletions app/views/totems/_form.html.erb
Expand Up @@ -18,6 +18,14 @@
<%= f.label :ip, :class => "form-lbl form-req" %>
<%= f.text_field :ip, :maxlength => 15, :class => "form-txt form-small", :disabled => disabled %>
</div>
<div class="grid-12-12">
<%= f.label :printer, :class => "form-lbl form-req" %>
<% if @totem && @totem.printer_id && disabled %>
<input type="text" value="<%= @totem.printer.name %>" disabled="disabled" class="form-txt form-small" />
<% elsif %>
<%= f.collection_select( :printer_id, @printers, :id, :name, { :prompt => true }, :class => "form-small", :disabled => disabled ) %>
<% end %>
</div>
<div class="grid-12-12">
<%= f.label :status, :class => "form-lbl form-req" %>
<ul class="form-list-rdo">
Expand Down
6 changes: 4 additions & 2 deletions app/views/totems/index.html.erb
Expand Up @@ -10,14 +10,16 @@
<tr>
<th><%= t('model.totem.name').pluralize %></th>
<th><%= t('model.totem.ip') %></th>
<th><%= t('model.printer.name') %></th>
<th><%= t('model.status.name') %></th>
<th colspan="4" class="options"><%= t("application.options") %></th>
</tr>
<% @totems.each do |totem| %>
<tr class="row">
<td width="60%"><%= totem.value %></td>
<td width="50%"><%= totem.value %></td>
<td width="20%"><%= totem.ip %></td>
<td width="20%"><%= totem.active? ? t('model.status.active') : t('model.status.inactive') %></td>
<td width="20%"><%= totem.printer ? totem.printer.name : '' %></td>
<td width="10%"><%= totem.active? ? t('model.status.active') : t('model.status.inactive') %></td>
<td>
<%= link_to image_tag("form/search.gif"), place_totem_path(totem.place, totem), :title => t('model.show') %>
</td>
Expand Down
10 changes: 10 additions & 0 deletions config/locales/pt-BR.yml
Expand Up @@ -196,6 +196,7 @@
local: "Local"
place: "Localidade"
panel: "Painel"
printer: "Impressora"
totem: "Totem"
attributes:
status:
Expand Down Expand Up @@ -229,6 +230,8 @@
local:
des_local: "Descrição"
user: "Usuário"
printer:
name: "Nome"
place:
value: "Nome"
user: "Usuário"
Expand All @@ -241,6 +244,7 @@
totem:
value: "Valor"
ip: "IP"
printer: "Impressora"
panel:
value: "Valor"
ip: "IP"
Expand Down Expand Up @@ -384,6 +388,12 @@
name: "Local"
description: "Descrição"

printer:
new: "Nova Impressora"
editing: "Editando Impressora"
title: "Listando todas as Impressoras"
name: "Impressora"

place:
new: "Nova Localidade"
editing: "Editando Localidade"
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -8,6 +8,7 @@
resources :tickets, :path => 'senhas'
resources :statuses, :path => 'status'
resources :status_tickets, :path => 'status_de_senha'
resources :printers, :path => 'impressoras'

resources :ticket_type_groups, :path => 'grupos_tipo_de_senha' do
resources :ticket_types, :path => 'tipos_de_senha'
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20130617125744_create_printers.rb
@@ -0,0 +1,12 @@
class CreatePrinters < ActiveRecord::Migration
def change
create_table :printers do |t|
t.string :name, :null => false
t.string :slug

t.timestamps
end

add_index :printers, :slug, unique: true
end
end
7 changes: 7 additions & 0 deletions db/migrate/20130617130704_add_printer_to_totem.rb
@@ -0,0 +1,7 @@
class AddPrinterToTotem < ActiveRecord::Migration
def change
add_column :totems, :printer_id, :integer

add_index :totems, :printer_id
end
end

0 comments on commit d2e722c

Please sign in to comment.