Skip to content

Commit

Permalink
Added 'recent visitors' functionality using the doord backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahemm committed May 18, 2010
1 parent 6a18a54 commit 2f44209
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
6 changes: 3 additions & 3 deletions backend/hacktouch-doord.rb
Expand Up @@ -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."
Expand Down
1 change: 1 addition & 0 deletions backend/log4r.xml
Expand Up @@ -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>
19 changes: 19 additions & 0 deletions frontend/hacktouch-frontend.rb
Expand Up @@ -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 change: 1 addition & 0 deletions frontend/views/index.haml
@@ -1,4 +1,5 @@
=partial :clock
=partial :weather
=partial :door
=partial :news
=partial :mediaplayer
5 changes: 5 additions & 0 deletions frontend/views/main.sass
Expand Up @@ -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
Expand Down

0 comments on commit 2f44209

Please sign in to comment.