Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
You can now add and edit sentries from inside of a device. Fixed some…
… routing problems.
- Loading branch information
Jonathan Hoyt
authored and
Jonathan Hoyt
committed
Dec 23, 2008
1 parent
3027ff3
commit a2cdd69
Showing
11 changed files
with
141 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters