Permalink
Browse files

Added 'recent visitors' functionality using the doord backend.

  • Loading branch information...
sarahemm committed May 18, 2010
1 parent 6a18a54 commit 2f442093a49120bc1c555ecc7a20c5c8adad0bc3
Showing with 29 additions and 3 deletions.
  1. +3 −3 backend/hacktouch-doord.rb
  2. +1 −0 backend/log4r.xml
  3. +19 −0 frontend/hacktouch-frontend.rb
  4. +1 −0 frontend/views/index.haml
  5. +5 −0 frontend/views/main.sass
@@ -26,15 +26,15 @@
msg = HacktouchBackendMessage.new(header, msg);
case msg['command']
when 'recent' then
- msg['entries'] = '10' if !msg.has_key? 'entries'
- msg['entries'] = '100' if msg['entries'] > 100
+ msg['entries'] = 10 if !msg.has_key? 'entries'
+ msg['entries'] = 100 if msg['entries'] > 100
response_msg = Hash.new
response_msg['entries'] = []
@log.debug "Retrieving the most recent #{msg['entries']} door entries from the database."
db[:access_log].join(:card, :card_id => :card_id).reverse_order(:logged).limit(msg['entries']).each do |entry|
entry_hash = Hash.new
entry_hash['time'] = entry[:logged]
- entry_hash['name'] = entry[:user]
+ entry_hash['name'] = entry[:nick]
response_msg['entries'].push(entry_hash)
end
@log.debug "Replying to #{header.properties[:reply_to]} with #{msg['entries']} recent door entries."
View
@@ -17,4 +17,5 @@
<logger name="hacktouch::backend::audiod" />
<logger name="hacktouch::backend::newsd" />
<logger name="hacktouch::backend::weatherd" />
+ <logger name="hacktouch::backend::doord" />
</log4r_config>
@@ -81,5 +81,24 @@
rescue TimeoutException
halt 504, {'Content-Type' => 'text/plain'}, 'Request to weather backend timed out.'
end
+ "#{response_msg.to_json}"
+end
+
+get '/recent_visitors' do
+ content_type :json
+
+ msg = Hash.new
+ msg['command'] = 'recent'
+ msg['entries'] = 5
+ begin
+ response_msg = HacktouchMQ.mq_request("hacktouch.door.request", msg)
+ rescue TimeoutException
+ halt 504, {'Content-Type' => 'text/plain'}, 'Request to door system backend timed out.'
+ end
+ # add how many minutes ago it was, to make the frontend easier to deal with
+ response_msg['entries'].each do |entry|
+ entry['mins_ago'] = (Time.new - Time.parse(entry['time'])).to_i / 60
+ end
+
"#{response_msg.to_json}"
end
@@ -1,4 +1,5 @@
=partial :clock
=partial :weather
+=partial :door
=partial :news
=partial :mediaplayer
View
@@ -18,6 +18,11 @@ select
font-size: 1.5em
width: 95%
+ul
+ line-height: 1.25em
+ text-align: left
+ list-style: none
+
=box
font-family: sans-serif
background-color: #333

0 comments on commit 2f44209

Please sign in to comment.