Skip to content

Commit

Permalink
You can now add and edit sentries from inside of a device. Fixed some…
Browse files Browse the repository at this point in the history
… routing problems.
  • Loading branch information
Jonathan Hoyt authored and Jonathan Hoyt committed Dec 23, 2008
1 parent 3027ff3 commit a2cdd69
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 6 deletions.
10 changes: 10 additions & 0 deletions app/controllers/application.rb
Expand Up @@ -6,4 +6,14 @@ class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery :secret => 'b0a876313f3f9195e9bd01473bc5cd06'
filter_parameter_logging :password, :password_confirmation
end

class Object
##
# @person ? @person.name : nil
# vs
# @person.try(:name)
def try(method)
send method if respond_to? method
end
end
33 changes: 33 additions & 0 deletions app/controllers/sentries_controller.rb
@@ -1,3 +1,36 @@
class SentriesController < ApplicationController
before_filter :login_required
layout nil

def edit
@sentry = Sentry.find(params[:id])
end

def create
@sentry = Sentry.new(params[:sentry])
if @sentry.save
flash[:notice] = "Sentry created successfully."
redirect_to :back
else
flash[:notice] = "Sentry could not be created."
redirect_to :back
end
end

def update
@sentry = Sentry.find(params[:id])
if @sentry.update_attributes(params[:sentry])
flash[:notice] = "Sentry updated successfully."
redirect_to :back
else
flash[:notice] = "Sentry could not be updated."
redirect_to :back
end
end

def destroy
@sentry = Sentry.find(params[:id])
@sentry.destroy
redirect_to :back
end
end
9 changes: 9 additions & 0 deletions app/helpers/sentries_helper.rb
@@ -0,0 +1,9 @@
module SentriesHelper
def sentry_state(sentry)
if sentry.state?
image_tag("/images/icons/emoticon_grin.png")
else
image_tag("/images/icons/emoticon_unhappy.png")
end
end
end
2 changes: 1 addition & 1 deletion app/models/sentry.rb
@@ -1,6 +1,6 @@
class Sentry < ActiveRecord::Base
has_many :events, :as => :recordable, :dependent => :destroy
belongs_to :devices
belongs_to :device
belongs_to :schedule

end
56 changes: 56 additions & 0 deletions app/views/devices/_sentries.html.erb
@@ -0,0 +1,56 @@
<div id="sentries">
<ul class="toolbar">
<li><a href="#" id="add_sentry">Add Sentry</a></li>
</ul>
<div id="add_sentry_form" class="toolbox hide">
<h3>Add Sentry</h3>
<% form_for @device.sentries.new do |f| %>
<table class="m">
<tr>
<td class="first">Goggle:</td><td><%= f.select :goggle_id, Goggle.find(:all).collect {|c| [c.name, c.id]} %></td>
<td class="first">Max # of Notifies:</td><td><%= f.select :notifications_to_send, ["1", "2", "3", "4", "5", "10", "100"] %></td>
</tr>
<tr>
<td class="first">Survey Interval (minutes):</td><td><%= f.select :survey_interval, ["1", "5", "10", "15", "20", "30", "60", "480", "1440"] %></td>
<td class="first">Notify Every (minutes):</td><td><%= f.select :maximum_notify_frequency, ["1", "5", "10", "15", "30", "60", "480"] %></td>
</tr>
<tr>
<td class="first"></td><td></td>
<td class="first">Notification Schedule:</td><td><%= f.select :schedule_id, Schedule.find(:all).collect {|c| [c.name, c.id]} %></td>
</tr>
</table>
<%= f.hidden_field :device_id, :value => @device.id %>
<%= f.submit "Add Sentry" %>
<% end %>
<br />
</div>
<h3>Sentries for this Device</h3>
<table class="itu">
<tr>
<th>ID</th><th>Last Message</th><th>State</th><th>Last Checked</th>
</tr>
<% @device.sentries.each do |sentry| %>
<tr alt="<%= sentry.message %>" id="sentry_<%= sentry.id %>">
<td><a href="#"><%= sentry.id %></a></td>
<td><a href="#"><%= sentry.message %></a></td>
<td><a href="#"><%= sentry_state(sentry) %></a></td>
<td><a href="#"><%= sentry.last_surveyed_at ? sentry.last_surveyed_at.strftime("%H:%M, %x") : "" %></a></td>
</tr>
<% end %>
</table>
<div id="sentry" class="toolbox hide"></div>
</div>

<script>
// show new sentry form on click
$("a#add_sentry").click(function(){
$("div#add_sentry_form").slideDown(500);
});
// load a sentry into the div on click
$("div#sentries > table a").click(function(){
var sentry = $(this).parent().parent().attr("id").split("sentry_")[1];
$("div#sentry").slideUp(500);
$("div#sentry").load("/sentries/"+sentry+"/edit");
$("div#sentry").slideDown(500);
})
</script>
2 changes: 2 additions & 0 deletions app/views/devices/show.html.erb
Expand Up @@ -15,6 +15,7 @@
<li class="ui-tabs-nav-item"><a href="#description" title="description">Description</a></li>
<li class="ui-tabs-nav-item"><a href="#tickets" title="tickets">Tickets</a></li>
<li class="ui-tabs-nav-item"><a href="#checklists" title="checklists">Checklists</a></li>
<li class="ui-tabs-nav-item"><a href="#sentries" title="sentries">Sentries</a></li>
<li class="ui-tabs-nav-item"><a href="#files" title="files">Files</a></li>
</ul>

Expand Down Expand Up @@ -69,6 +70,7 @@
</table>
<div id="checklist" class="hide"></div>
</div>
<%= render :partial => 'sentries', :locals => {:device => @device} %>
<%= render :partial => 'things', :locals => {:device => @device} %>
</div>

Expand Down
20 changes: 20 additions & 0 deletions app/views/sentries/edit.html.erb
@@ -0,0 +1,20 @@
<h3>Edit Sentry</h3>
<% form_for @sentry do |f| %>
<table class="m">
<tr>
<td class="first">Goggle:</td><td><%= f.select :goggle_id, Goggle.find(:all).collect {|c| [c.name, c.id]}, :selected => @sentry.goggle_id %></td>
<td class="first">Max # of Notifies:</td><td><%= f.select :notifications_to_send, [1, 2, 3, 4, 5, 10, 100], :selected => @sentry.notifications_to_send %></td>
</tr>
<tr>
<td class="first">Survey Interval (minutes):</td><td><%= f.select :survey_interval, [1, 5, 10, 15, 20, 30, 60, 480, 1440], :selected => @sentry.survey_interval %></td>
<td class="first">Notify Every (minutes):</td><td><%= f.select :maximum_notify_frequency, [1, 5, 10, 15, 30, 60, 480], :selected => @sentry.maximum_notify_frequency %></td>
</tr>
<tr>
<td class="first"></td><td></td>
<td class="first">Notification Schedule:</td><td><%= f.select :schedule_id, Schedule.find(:all).collect {|c| [c.name, c.id]}, :selected => @sentry.schedule_id %></td>
</tr>
</table>
<%= f.submit "Update Sentry" %>
<%= link_to image_tag("/images/icons/delete.png"), url_for(@sentry), :confirm => "Are you sure you want to delete this Sentry?", :method => :delete, :class => "delete_sentry_button" %>
<% end %>
<br />
6 changes: 3 additions & 3 deletions config/routes.rb
Expand Up @@ -14,11 +14,13 @@
map.resource :session

# Main Resources
map.search_clients '/clients/search', :controller => 'clients', :action => 'search'
map.resources :clients do |client|
client.resources :tickets
client.resources :devices
client.resources :users
end
map.search_tickets '/tickets/search', :controller => 'tickets', :action => 'search'
map.resources :tickets do |ticket|
ticket.resources :ticket_entries
ticket.resources :devices
Expand All @@ -43,11 +45,9 @@
map.resources :goggles
map.resources :schedules
map.resources :radchecks
map.resources :sentries

# Custom Routes
map.search_clients '/clients/search', :controller => 'clients', :action => 'search'
map.client_list '/clients/list', :controller => 'clients', :action => 'list'
map.search_tickets '/tickets/search', :controller => 'tickets', :action => 'search'
map.device_details '/tickets/:ticket_id/devices/:id/details', :controller => 'devices', :action => 'details'
map.add_to_ticket '/tickets/:ticket_id/devices/:id/add_to_ticket', :controller => 'devices', :action => 'add_to_ticket'
map.remove_device_from_ticket '/tickets/:ticket_id/devices/:id/remove_from_ticket', :controller => 'devices', :action => 'remove_from_ticket'
Expand Down
1 change: 1 addition & 0 deletions db/migrate/20081212174923_create_sentries.rb
Expand Up @@ -10,6 +10,7 @@ def self.up
t.integer :notifications_to_send
t.integer :maximum_notify_frequency
t.integer :notifications_sent
t.datetime :last_notified_at
t.integer :schedule_id
t.integer :goggle_id

Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb
Expand Up @@ -77,7 +77,7 @@
t.string "name"
t.string "firstname"
t.string "lastname"
t.boolean "company", :null => false
t.boolean "company", :default => false, :null => false
t.integer "belongs_to"
t.text "note"
t.string "mugshot_file_name"
Expand Down
6 changes: 5 additions & 1 deletion public/stylesheets/devices.css
Expand Up @@ -4,4 +4,8 @@
div.sidebar-list ul#devices li a.search {background:url("/images/icons/find.png") no-repeat;}

/* Search box */
#applesearch .sbox input {width:300px;}
#applesearch .sbox input {width:300px;}

/* Sentries */
div#sentry {position:relative;}
a.delete_sentry_button {position:absolute;top:10px;right:10px;}

0 comments on commit a2cdd69

Please sign in to comment.