Got macs working

This commit is contained in:
Will Bradley 2013-01-31 22:39:33 -07:00
parent 998558cd30
commit 04764af983
7 changed files with 60 additions and 6 deletions

View File

@ -5,7 +5,10 @@ require "optparse"
#require "rubygems" #require "rubygems"
def index def index
@macs = Mac.all @active_macs = Mac.where(:active => true, :hidden => false)
@active_macs += Mac.where(:active => true, :hidden => nil)
@hidden_macs = Mac.where(:active => true, :hidden => true)
@inactive_macs = Mac.where(:active => false)
end end
# GET /macs/1 # GET /macs/1

View File

@ -1,4 +1,4 @@
class Mac < ActiveRecord::Base class Mac < ActiveRecord::Base
belongs_to :user belongs_to :user
attr_accessible :active, :ip, :mac, :refreshed, :since, :user_id attr_accessible :active, :ip, :mac, :refreshed, :since, :hidden, :note, :user_id
end end

View File

@ -13,12 +13,20 @@
<div class="field"> <div class="field">
<%= f.label :user_id, "User" %><br /> <%= f.label :user_id, "User" %><br />
<%= collection_select(:mac, :user_id, @users, :id, :name) %> <%= collection_select(:mac, :user_id, @users, :id, :name, :include_blank => true) %>
</div> </div>
<div class="field"> <div class="field">
<%= f.label :mac, "Mac" %><br /> <%= f.label :mac %><br />
<%= f.text_field :mac %> <%= f.text_field :mac %>
</div> </div>
<div class="field">
<%= f.label :note %><br />
<%= f.text_field :note %>
</div>
<div class="field">
<%= f.label :hidden %><br />
<%= f.check_box :hidden %>
</div>
<div class="actions"> <div class="actions">
<%= f.submit %> <%= f.submit %>
</div> </div>

View File

@ -1,5 +1,5 @@
<h2>What machines are on our network?</h2> <h2>What machines are on our network?</h2>
<% @macs.each do |mac| %> <% @active_macs.each do |mac| %>
<%= mac.user.name unless mac.user.blank? %> <%= mac.user.name unless mac.user.blank? %>
<%= mac.mac if mac.user.blank? %> <!-- <%= mac.mac if mac.user.blank? %> <!--
<%= mac.since %>, <%= mac.since %>,
@ -7,3 +7,23 @@
<%= mac.active %>--> | <%= mac.active %>--> |
<%= link_to 'Edit', edit_mac_path(mac) %> <br/> <%= link_to 'Edit', edit_mac_path(mac) %> <br/>
<% end %> <% end %>
<hr>
<% @hidden_macs.each do |mac| %>
<%= mac.user.name unless mac.user.blank? %>
<%= mac.mac if mac.user.blank? %>
(<%= mac.note %>) <!--
<%= mac.since %>,
<%= mac.refreshed %>,
<%= mac.active %>--> |
<%= link_to 'Edit', edit_mac_path(mac) %> <br/>
<% end %>
<hr>
<% @inactive_macs.each do |mac| %>
<%= mac.user.name unless mac.user.blank? %>
<%= mac.mac if mac.user.blank? %>
(<%= mac.note %>) <!--
<%= mac.since %>,
<%= mac.refreshed %>,
<%= mac.active %>--> |
<%= link_to 'Edit', edit_mac_path(mac) %> <br/>
<% end %>

View File

@ -8,5 +8,20 @@
<%= @mac.mac %> <%= @mac.mac %>
</p> </p>
<p>
<b>Note:</b>
<%= @mac.note %>
</p>
<p>
<b>Hidden:</b>
<%= @mac.hidden %>
</p>
<p>
<b>IP:</b>
<%= @mac.ip %>
</p>
<%= link_to 'Edit', edit_mac_path(@mac) %> | <%= link_to 'Edit', edit_mac_path(@mac) %> |
<%= link_to 'Back', macs_path %> <%= link_to 'Back', macs_path %>

View File

@ -0,0 +1,6 @@
class AddPropertiesToMacs < ActiveRecord::Migration
def change
add_column :macs, :hidden, :boolean
add_column :macs, :note, :string
end
end

View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130201022153) do ActiveRecord::Schema.define(:version => 20130201042646) do
create_table "cards", :force => true do |t| create_table "cards", :force => true do |t|
t.string "card_number" t.string "card_number"
@ -52,6 +52,8 @@ ActiveRecord::Schema.define(:version => 20130201022153) do
t.boolean "active" t.boolean "active"
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
t.boolean "hidden"
t.string "note"
end end
add_index "macs", ["user_id"], :name => "index_macs_on_user_id" add_index "macs", ["user_id"], :name => "index_macs_on_user_id"