Adding door alert emails (test mode) and adjusting door log graph view

This commit is contained in:
Will Bradley 2014-09-04 19:24:33 -07:00
parent 1d6699ae9f
commit 3ce0d3c45a
5 changed files with 44 additions and 5 deletions

View File

@ -1,8 +1,8 @@
class SpaceApiController < ApplicationController
# Individually remove authorizing stuff since there is no SpaceApi model
authorize_resource :except => [:index, :access, :access_post]
authorize_resource :except => [:index, :access, :access_post, :alert_if_not_status]
# User auth here happens via params, instead of form.
before_filter :authenticate_user!, :except => [:index, :access, :access_post]
before_filter :authenticate_user!, :except => [:index, :access, :access_post, :alert_if_not_status]
def index
@json = JSON.parse(Setting.space_api_json_template)
@ -102,4 +102,25 @@ class SpaceApiController < ApplicationController
end
# Expect status to be "open" or "closed"
def alert_if_not_status
@expected_status = params['status']
@status = DoorLog.show_status
if !["open","closed"].include?(@expected_status)
@output = "USAGE: Specify an expected status (/alert_if_not/open or /alert_if_not/closed). Alert emails will be sent if status doesn't match."
elsif @expected_status.to_s == "open" && @status[:unlocked] == true
@output = "Unlocked Status is OK."
elsif @expected_status.to_s == "closed" && @status[:unlocked] == false
@output = "Unlocked Status is OK."
else
@output = "Unlocked Status is NOT OK. Alerting."
@output += " - Mail result: "
@output += DoorMailer.alert(@status).deliver.inspect
end
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
render :json => {response: @output, status: @status}
end
end

12
app/mailers/door_mailer.rb Executable file
View File

@ -0,0 +1,12 @@
class DoorMailer < ActionMailer::Base
default :from => "no-reply@heatsynclabs.org"
def alert(status)
@url = "http://members.heatsynclabs.org"
@status = status
mail(:to => 'will@heatsynclabs.org',
:subject => "HSL Doors")
end
end

View File

@ -12,8 +12,8 @@ $(function() {
$( "#graph-dialog" ).dialog({
autoOpen: false,
height: 480,
width: 640,
height: 700,
width: 825,
modal: true,
});
@ -130,7 +130,7 @@ function generatePlotBands(start,end){
<div id="graph-dialog" title="Door Status">
<div id="graph" style="height: 400px; width: 600px; float: right;"></div>
<div id="graph" style="height: 600px; width: 800px; float: right;"></div>
<%= form_tag(nil, :method => :get) do %>
<label>Start Date

View File

@ -0,0 +1,5 @@
It's <%= DateTime.current.to_time.strftime("%l:%M %p") %> and the doors are <%= @status[:unlocked] ? "open" : "not open" %> !
See more info at: <a href="http://live.heatsynclabs.org">http://live.heatsynclabs.org</a>
<a href="http://twitter.com/willbradley>@willbradley</a> programmed me to let y'all know, just in case. Cheers!

View File

@ -55,6 +55,7 @@ Dooraccess::Application.routes.draw do
match 'cards/:id/upload' => 'cards#upload', :as => :upload
match 'space_api' => 'space_api#index', :as => :space_api
match 'space_api/alert_if_not/:status' => 'space_api#alert_if_not_status', :via => :get, :as => :space_api_alert_if_not_status
match 'space_api/access' => 'space_api#access', :via => :get, :as => :space_api_access
match 'space_api/access' => 'space_api#access_post', :via => :post