From 2f442093a49120bc1c555ecc7a20c5c8adad0bc3 Mon Sep 17 00:00:00 2001 From: Sarah Nordstrom Date: Mon, 17 May 2010 20:50:51 -0400 Subject: [PATCH] Added 'recent visitors' functionality using the doord backend. --- backend/hacktouch-doord.rb | 6 +++--- backend/log4r.xml | 1 + frontend/hacktouch-frontend.rb | 19 +++++++++++++++++++ frontend/views/index.haml | 1 + frontend/views/main.sass | 5 +++++ 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/backend/hacktouch-doord.rb b/backend/hacktouch-doord.rb index f5a74f6..ff96ef3 100755 --- a/backend/hacktouch-doord.rb +++ b/backend/hacktouch-doord.rb @@ -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." diff --git a/backend/log4r.xml b/backend/log4r.xml index 5f3400d..8a0428d 100644 --- a/backend/log4r.xml +++ b/backend/log4r.xml @@ -17,4 +17,5 @@ + \ No newline at end of file diff --git a/frontend/hacktouch-frontend.rb b/frontend/hacktouch-frontend.rb index 684e8fe..90d305d 100755 --- a/frontend/hacktouch-frontend.rb +++ b/frontend/hacktouch-frontend.rb @@ -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 \ No newline at end of file diff --git a/frontend/views/index.haml b/frontend/views/index.haml index 1a12d06..95a814f 100644 --- a/frontend/views/index.haml +++ b/frontend/views/index.haml @@ -1,4 +1,5 @@ =partial :clock =partial :weather +=partial :door =partial :news =partial :mediaplayer \ No newline at end of file diff --git a/frontend/views/main.sass b/frontend/views/main.sass index e4c562b..255260d 100644 --- a/frontend/views/main.sass +++ b/frontend/views/main.sass @@ -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