Reporting door access logs on each card's page; also card access stats for last 7 days

This commit is contained in:
Will Bradley 2013-02-09 03:32:26 -07:00
parent 3f3eb1ed65
commit 1f63709887
3 changed files with 37 additions and 5 deletions

View File

@ -9,6 +9,19 @@ class CardsController < ApplicationController
#authorize! :read, @cards #authorize! :read, @cards
@cards = @cards.sort_by{|e| e[:id]} @cards = @cards.sort_by{|e| e[:id]}
if can? :read, DoorLog then
most_active_count = 0
@most_active_card = nil
@cards.each do |card|
card_num_R = card.card_number.to_i(16)%32767
card[:accesses_this_week] = DoorLog.where('key = "R" AND data =? AND created_at > ?', card_num_R, DateTime.now - 7.days).order("created_at DESC").count
if(card[:accesses_this_week] > most_active_count) then
most_active_count = card[:accesses_this_week]
@most_active_card = card
end
end
end
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb
format.json { render :json => @cards } format.json { render :json => @cards }
@ -18,8 +31,10 @@ class CardsController < ApplicationController
# GET /cards/1 # GET /cards/1
# GET /cards/1.json # GET /cards/1.json
def show def show
#@card = Card.find(params[:id]) if can? :read, DoorLog then
card_num_R = @card.card_number.to_i(16)%32767
@door_logs = DoorLog.where('key = "R" AND data =?', card_num_R).order("created_at DESC")
end
respond_to do |format| respond_to do |format|
format.html # show.html.erb format.html # show.html.erb
format.json { render :json => @card } format.json { render :json => @card }

View File

@ -2,6 +2,10 @@
<%= link_to 'New Card', new_card_path if can? :create, Card %> <%= link_to 'New Card', new_card_path if can? :create, Card %>
<%= link_to 'Upload all cards', upload_all_path if can? :upload_all, Card %> <%= link_to 'Upload all cards', upload_all_path if can? :upload_all, Card %>
<p>
<b>Most Active Card Last 7 Days:</b> <%= @most_active_card.name %> (<%= @most_active_card.accesses_this_week %> times)
</p>
<table> <table>
<col /> <col />
<col /> <col />
@ -14,6 +18,7 @@
<th>DB ID</th> <th>DB ID</th>
<th>Card #</th> <th>Card #</th>
<th>Access?</th> <th>Access?</th>
<th>Accesses Last 7 Days</th>
<th></th> <th></th>
<th></th> <th></th>
<th></th> <th></th>
@ -22,11 +27,12 @@
<% if !@cards.blank? %> <% if !@cards.blank? %>
<% @cards.each do |card| %> <% @cards.each do |card| %>
<tr> <tr>
<td><%= card.user.name %></td> <td><%= link_to card.user.name, card %></td>
<td><%= card.name %></td> <td><%= card.name %></td>
<td><%= card.id %></td> <td><%= card.id %></td>
<td><%= card.card_number %></td> <td><%= card.card_number %></td>
<td><%= if card.card_permissions == 1 then "Access" end %></td> <td><%= if card.card_permissions == 1 then "Access" end %></td>
<td><%= card.accesses_this_week unless card.accesses_this_week < 1 %></td>
<td><%= link_to 'Upload', upload_path(card) if can? :upload, card %></td> <td><%= link_to 'Upload', upload_path(card) if can? :upload, card %></td>
<td><%= link_to 'Edit', edit_card_path(card) if can? :update, card %></td> <td><%= link_to 'Edit', edit_card_path(card) if can? :update, card %></td>
<td><%= link_to 'Destroy', card, :confirm => 'Are you sure? WARNING: THIS DOES NOT REMOVE THE CARD FROM THE DOOR SYSTEM! DISABLE AND UPLOAD IT FIRST.', :method => :delete if can? :destroy, card %></td> <td><%= link_to 'Destroy', card, :confirm => 'Are you sure? WARNING: THIS DOES NOT REMOVE THE CARD FROM THE DOOR SYSTEM! DISABLE AND UPLOAD IT FIRST.', :method => :delete if can? :destroy, card %></td>

View File

@ -1,6 +1,6 @@
<p> <p>
<b>User:</b> <b>User:</b>
<%= @card.user.name unless @card.user.blank? %> <%= link_to @card.user.name, @card.user unless @card.user.blank? %>
</p> </p>
<p> <p>
@ -20,9 +20,20 @@
<p> <p>
<b>Card Permissions:</b> <b>Card Permissions:</b>
<%= @card.card_permissions %> <%= if @card.card_permissions == 1 then "Enabled" else "Disabled" end %>
</p> </p>
<% if can? :read, DoorLog %>
<p>
<b>Access attempts:</b>
<ul>
<% @door_logs.each do |log| %>
<li><%= log.created_at %></li>
<% end %>
</ul>
</p>
<% end %>
<%= link_to 'Upload to Door', upload_path(@card) if can? :upload, @card %> <%= link_to 'Upload to Door', upload_path(@card) if can? :upload, @card %>
<% if can? :update, @card then %><%= link_to 'Edit', edit_card_path(@card) %> |<% end %> <% if can? :update, @card then %><%= link_to 'Edit', edit_card_path(@card) %> |<% end %>
<%= link_to 'Back', cards_path %> <%= link_to 'Back', cards_path %>